From aa03b20985c62ae3efc7b61a5421b1a064fbbc8d Mon Sep 17 00:00:00 2001 From: Varun Date: Thu, 29 Aug 2024 12:34:54 +0530 Subject: [PATCH] changes --- src/controllers/storeController.js | 14 +++++++++++--- src/models/store.js | 7 ++++--- src/routes/storeRoute.js | 9 +++++++-- 3 files changed, 22 insertions(+), 8 deletions(-) diff --git a/src/controllers/storeController.js b/src/controllers/storeController.js index 40fce191..60f61179 100644 --- a/src/controllers/storeController.js +++ b/src/controllers/storeController.js @@ -1079,14 +1079,22 @@ exports.createquotationforSensor = async (req, reply) => { const { installationId } = req.params; const { customerId, masters, slaves, motor_switches, electricals } = req.body; + // Validate electricals field to ensure it's an array of objects + if (!Array.isArray(electricals) || electricals.some(e => typeof e !== 'object')) { + return reply.code(400).send({ + success: false, + message: 'Invalid data format for electricals. It should be an array of objects with "name" and "type".' + }); + } + // Create a new SensorQuotation document const newQuotation = new SensorQuotation({ - customerIdId: customerId, - installationId: installationId, // Assuming installationId is being used as InstallerId + customerId: customerId, + installationId: installationId, // Using installationId for the field masters, slaves, motor_switches, - electricals, // This will store the array of electrical items + electricals, // This will store the array of electrical items (objects) }); // Save the document to the database diff --git a/src/models/store.js b/src/models/store.js index 6f845493..d8200e56 100644 --- a/src/models/store.js +++ b/src/models/store.js @@ -252,7 +252,7 @@ const insensorsSchema = new mongoose.Schema({ const sensorquotationSchema = new mongoose.Schema({ - customerIdId: { type: String }, + customerId: { type: String }, installationId: { type: String, default: null }, masters: { type: String }, slaves: { type: String }, @@ -265,8 +265,9 @@ const sensorquotationSchema = new mongoose.Schema({ // Define electricals as an array of strings or objects electricals: [ { - type: String, // or Object, based on your requirements - default: null + name: { type: String }, + type: { type: String }, + } ] }); diff --git a/src/routes/storeRoute.js b/src/routes/storeRoute.js index 429cc011..c5010df3 100644 --- a/src/routes/storeRoute.js +++ b/src/routes/storeRoute.js @@ -793,8 +793,13 @@ fastify.post("/api/createquotationforSensor/:installationId", { type: "array", description: "List of electrical items", items: { - type: "string" // or use "object" if each electrical item is more complex - } + type: "object", + properties: { + name: { type: "string", description: "Name of the electrical item" }, + type: { type: "string", description: "Type of the electrical item" }, + }, + required: ["name", "type"], + }, }, },