diff --git a/src/controllers/storeController.js b/src/controllers/storeController.js index d36cbf0a..c083671d 100644 --- a/src/controllers/storeController.js +++ b/src/controllers/storeController.js @@ -1285,7 +1285,14 @@ exports.createquotationforSensor = async (req, reply) => { const i_id = await generatequatationId(); const quatationId = `AWQU${i_id}`; const { installationId } = req.params; - const { customerId, masters, slaves, motor_switches, electricals } = req.body; + const { customerId, masters, slaves,sensors, motor_switches, electricals } = req.body; + // Ensure electricals field is properly formatted + const formattedElectricals = electricals.map((item) => ({ + type: item.type || "", + wire: item.wire || "", + switch: item.switch || "", + text: item.text || "", + })); // Create a new SensorQuotation document @@ -1295,8 +1302,9 @@ exports.createquotationforSensor = async (req, reply) => { installationId: installationId, masters, slaves, + sensors, motor_switches, - electricals, + electricals: formattedElectricals, }); diff --git a/src/models/store.js b/src/models/store.js index 72cdaf73..01846aa1 100644 --- a/src/models/store.js +++ b/src/models/store.js @@ -282,6 +282,7 @@ const sensorquotationSchema = new mongoose.Schema({ masters_quantity_price: { type: String }, masters_total_price: { type: String }, slaves: { type: String }, + sensors: { type: String }, slaves_quantity_price: { type: String }, slaves_total_price: { type: String }, motor_switches: { type: String }, @@ -290,13 +291,18 @@ const sensorquotationSchema = new mongoose.Schema({ quote_status: { type: String, default: null }, quoted_amount: { type: String, default: null }, comments: { type: String, default: null }, - electricals: [{ type: String }], + electricals: [ + { + type: { type: String, default: null }, + wire: { type: String, default: null }, + switch: { type: String, default: null }, + text: { type: String, default: null }, + }, + ], master_type_quantity_price: { type: String, default: null }, - master_type_total_price: { type: String, default: null }, - + master_type_total_price: { type: String, default: null }, sensor_type_quantity_price: { type: String , default: null}, - sensor_type_total_price: { type: String , default: null}, - + sensor_type_total_price: { type: String , default: null}, switch_type_quantity_price: { type: String, default: null }, switch_type_total_price: { type: String, default: null }, qutation_total_price: { type: String, default: null }, diff --git a/src/routes/storeRoute.js b/src/routes/storeRoute.js index f1bc02fc..769ec956 100644 --- a/src/routes/storeRoute.js +++ b/src/routes/storeRoute.js @@ -1134,6 +1134,7 @@ fastify.get("/api/getbatchnumbers/:storeId", { handler: storeController.getbatchnumbers, }); + fastify.post("/api/createquotationforSensor/:installationId", { schema: { description: "This is for create quotation for sensors", @@ -1155,12 +1156,21 @@ fastify.post("/api/createquotationforSensor/:installationId", { customerId: { type: "string" }, masters: { type: "string" }, slaves: { type: "string" }, + sensors: { type: "string" }, motor_switches: { type: "string" }, electricals: { type: "array", - items: { type: "string" }, - description: "List of electrical items", - }, + maxItems: 2500, + items: { + type: "object", + properties: { + type: { type: "string", default: null }, + wire: { type: "string", default: null }, + switch: { type: "string", default: null }, + text: { type: "string", default: null }, + }, + }, + }, }, }, },