From 51b01ec12797a01409aeaedf2ae7df7843fa4cc9 Mon Sep 17 00:00:00 2001 From: Varun Date: Tue, 4 Mar 2025 14:34:36 +0530 Subject: [PATCH] changes in store quote --- src/controllers/storeController.js | 29 +++++++++++++++++++++++-- src/models/store.js | 1 + src/routes/storeRoute.js | 35 ++++++++++++++++++++++++++---- 3 files changed, 59 insertions(+), 6 deletions(-) diff --git a/src/controllers/storeController.js b/src/controllers/storeController.js index 40165ffc..2a1fd6fb 100644 --- a/src/controllers/storeController.js +++ b/src/controllers/storeController.js @@ -1422,6 +1422,31 @@ exports.getbatchnumbers = async (req, reply) => { }; +exports.getbatquotationsforparticularstore = async (req, reply) => { + try { + const storeId = req.params.storeId; + let type = req.params.type ? req.params.type.toLowerCase() : null; // Convert type to uppercase + + let query = { storeId: storeId }; + + if (type !== "ALL") { + query.type = type; + } + + // Fetch data based on the query + const result = await Insensors.find(query); + + if (!result ) { + return reply.send({ status_code: 404, error: "not found" }); + } + + reply.send({ status_code: 200, data: result }); + } catch (err) { + throw boom.boomify(err); + } +}; + + exports.getiots = async (req, reply) => { try { const storeId = req.params.storeId; @@ -1475,7 +1500,7 @@ exports.createquotationforSensor = async (req, reply) => { try { const i_id = await generatequatationId(); const quatationId = `AWQU${i_id}`; - const { installationId } = req.params; + const { surveyId } = req.params; const { customerId, masters, slaves, sensors, motor_switches, electricals } = req.body; // Format electricals field @@ -1518,7 +1543,7 @@ exports.createquotationforSensor = async (req, reply) => { const newQuotation = new SensorQuotation({ quatationId, customerId, - installationId, + surveyId, quote_status: "sentfrominstaller", masters, slaves, diff --git a/src/models/store.js b/src/models/store.js index afa37d7e..cc2a7031 100644 --- a/src/models/store.js +++ b/src/models/store.js @@ -381,6 +381,7 @@ const orderSchema = new mongoose.Schema({ const sensorquotationSchema = new mongoose.Schema({ customerId: { type: String }, + surveyId: { type: String, default: null }, installationId: { type: String, default: null }, quatationId: { type: String, default: null }, masters: { type: String }, diff --git a/src/routes/storeRoute.js b/src/routes/storeRoute.js index 01c211c8..e788bcd1 100644 --- a/src/routes/storeRoute.js +++ b/src/routes/storeRoute.js @@ -1238,6 +1238,33 @@ fastify.get("/api/getbatchnumbers/:storeId/:type", { handler: storeController.getbatchnumbers, }); + +fastify.get("/api/getbatquotationsforparticularstore/:storeId", { + schema: { + tags: ["Store-Data"], + description: "This is to Get quotations for store based on store id", + summary: "This is to Get quotations for store based on store id", + params: { + type: "object", + properties: { + storeId: { + type: "string", + description: "storeId", + }, + + }, + required: ["storeId"], + }, + security: [ + { + basicAuth: [], + }, + ], + }, + // preHandler: fastify.auth([fastify.authenticate]), + handler: storeController.getbatquotationsforparticularstore, +}); + fastify.get("/api/getiots/:storeId/:type", { schema: { tags: ["Store-Data"], @@ -1268,18 +1295,18 @@ fastify.get("/api/getiots/:storeId/:type", { }); -fastify.post("/api/createquotationforSensor/:installationId", { +fastify.post("/api/createquotationforSensor/:surveyId", { schema: { description: "This is for create quotation for sensors", tags: ["Install"], summary: "This is for create quotation for sensors", params: { - required: ["installationId"], + required: ["surveyId"], type: "object", properties: { - installationId: { + surveyId: { type: "string", - description: "installationId", + description: "surveyId", }, }, },