From c340e70a74607b7177b35251f1c216fa6022b854 Mon Sep 17 00:00:00 2001 From: Varun Date: Thu, 29 Aug 2024 12:12:58 +0530 Subject: [PATCH] sending quote for sensors --- src/controllers/storeController.js | 45 ++++++++++++++++++++++++++++-- src/models/store.js | 23 ++++++++++++++- src/routes/storeRoute.js | 39 +++++++++++++++++++++++++- 3 files changed, 103 insertions(+), 4 deletions(-) diff --git a/src/controllers/storeController.js b/src/controllers/storeController.js index 38d67adf..40fce191 100644 --- a/src/controllers/storeController.js +++ b/src/controllers/storeController.js @@ -10,7 +10,7 @@ const fastify = require("fastify")({ return uuidv4(); }, }); -const { Install, ProfilePictureInstall, generateinstallationId,Store,WaterLeverSensor,MotorSwitchSenso,Insensors} = require("../models/store"); +const { Install, ProfilePictureInstall, SensorQuotation,generateinstallationId,Store,WaterLeverSensor,MotorSwitchSenso,Insensors} = require("../models/store"); const { User,Counter, generateBookingId,resetCounter,generateCustomerId,ProfilePicture} = require('../models/User') @@ -1070,4 +1070,45 @@ exports.getusersofParticularInstaller = async (req, reply) => { } catch (err) { throw boom.boomify(err); } -}; \ No newline at end of file +}; + + +exports.createquotationforSensor = async (req, reply) => { + try { + // Extract parameters and body data from the request + const { installationId } = req.params; + const { customerId, masters, slaves, motor_switches, electricals } = req.body; + + // Create a new SensorQuotation document + const newQuotation = new SensorQuotation({ + customerIdId: customerId, + installationId: installationId, // Assuming installationId is being used as InstallerId + masters, + slaves, + motor_switches, + electricals, // This will store the array of electrical items + }); + + // Save the document to the database + const savedQuotation = await newQuotation.save(); + + // Send a success response with the saved document + reply.code(201).send({ + success: true, + message: 'Quotation for sensors created successfully.', + data: savedQuotation, + }); + } catch (error) { + // Handle errors and send error response + console.error('Error creating quotation:', error); + reply.code(500).send({ + success: false, + message: 'Failed to create quotation for sensors.', + error: error.message, + }); + } +}; + + + + diff --git a/src/models/store.js b/src/models/store.js index 36352be9..6f845493 100644 --- a/src/models/store.js +++ b/src/models/store.js @@ -251,6 +251,25 @@ const insensorsSchema = new mongoose.Schema({ }); +const sensorquotationSchema = new mongoose.Schema({ + customerIdId: { type: String }, + installationId: { type: String, default: null }, + masters: { type: String }, + slaves: { type: String }, + motor_switches: { type: String }, + quote_status: { type: String, default: null }, + quoted_amount: { type: String, default: null }, + comments: { type: String, default: null }, + + + // Define electricals as an array of strings or objects + electricals: [ + { + type: String, // or Object, based on your requirements + default: null + } + ] +}); @@ -260,7 +279,9 @@ const insensorsSchema = new mongoose.Schema({ const ProfilePictureStore = mongoose.model('ProfilePictureStore', profilePictureStoreSchema); const ProfilePictureInstall = mongoose.model('ProfilePictureInstall', profilePictureInstallSchema); const MotorSwitchSensor = mongoose.model('MotorSwitchSensor', motorSwitchSensorInSchema); + const SensorQuotation = mongoose.model('SensorQuotationSchema', sensorquotationSchema); + const Install = mongoose.model("Install", installationschema); - module.exports = { Install, ProfilePictureInstall, generateinstallationId,Store,ProfilePictureStore,WaterLeverSensor,MotorSwitchSensor,Insensors}; + module.exports = { Install, ProfilePictureInstall, SensorQuotation,generateinstallationId,Store,ProfilePictureStore,WaterLeverSensor,MotorSwitchSensor,Insensors,}; diff --git a/src/routes/storeRoute.js b/src/routes/storeRoute.js index 472f608c..429cc011 100644 --- a/src/routes/storeRoute.js +++ b/src/routes/storeRoute.js @@ -764,7 +764,44 @@ fastify.get("/api/getbatchnumbers/:storeId", { handler: storeController.getbatchnumbers, }); - +fastify.post("/api/createquotationforSensor/:installationId", { + schema: { + description: "This is for sending quotation for sensors", + tags: ["Install"], + summary: "This is for sending quotation for sensors", + params: { + required: ["installationId"], + type: "object", + properties: { + installationId: { + type: "string", + description: "installationId", + }, + }, + }, + + body: { + type: "object", + + properties: { + + customerId: { type: "string" }, + masters: { type: "string" }, + slaves: { type: "string" }, + motor_switches: { type: "string" }, + electricals: { + type: "array", + description: "List of electrical items", + items: { + type: "string" // or use "object" if each electrical item is more complex + } + }, + + }, + }, + }, + handler: storeController.createquotationforSensor, +}) next();