From 9724fcc33d0a316df8b07e67ff6d0e086a03795c Mon Sep 17 00:00:00 2001 From: Varun Date: Fri, 7 Feb 2025 11:24:03 +0530 Subject: [PATCH] edit for sensors in store --- src/controllers/storeController.js | 20 ++++++++++++ src/models/store.js | 4 +++ src/routes/storeRoute.js | 49 +++++++++++++++++++++++++++++- 3 files changed, 72 insertions(+), 1 deletion(-) diff --git a/src/controllers/storeController.js b/src/controllers/storeController.js index 9d35024b..55021726 100644 --- a/src/controllers/storeController.js +++ b/src/controllers/storeController.js @@ -1163,6 +1163,26 @@ exports.installmotorswitch = async (request, reply) => { } }; + +exports.updateSensorById = async (req, reply) => { + + try { + const _id = req.params._id; + const updateData = req.body; + + const updatedSensor = await Insensors.findByIdAndUpdate(_id, updateData, { new: true }); + + if (!updatedSensor) { + return reply.code(404).send({ message: 'Sensor not found' }); + } + + return reply.code(200).send(updatedSensor); + } catch (error) { + console.error('Error updating sensor:', error); + return reply.code(500).send({ message: 'Internal Server Error' }); + } +}; + exports.getpumpswitchqc = async (req, reply) => { try { await MotorSwitchSensor.find({storeId: req.params.storeId,motorId:req.body.motorId}) diff --git a/src/models/store.js b/src/models/store.js index c207b0b6..e73f73f9 100644 --- a/src/models/store.js +++ b/src/models/store.js @@ -274,6 +274,10 @@ const insensorsSchema = new mongoose.Schema({ }); + + + + const sensorquotationSchema = new mongoose.Schema({ customerId: { type: String }, installationId: { type: String, default: null }, diff --git a/src/routes/storeRoute.js b/src/routes/storeRoute.js index 705ae5ac..73f197e6 100644 --- a/src/routes/storeRoute.js +++ b/src/routes/storeRoute.js @@ -1109,6 +1109,53 @@ fastify.post("/api/createwaterlevelSensorintime/:storeId", { handler: storeController.createSensor, }) + +fastify.post("/api/updateSensorById/:_id", { + schema: { + description: "This is for editing Sensors after time", + tags: ["Store-Data"], + summary: "This is for editing Sensors after time", + params: { + required: ["_id"], + type: "object", + properties: { + _id: { + type: "string", + description: "storeId", + }, + }, + }, + body: { + type: "object", + + properties: { + batchno: { type: "string", description: "Batch number of the sensor" }, + model: { type: "string", description: "Model of the sensor" }, + type: { type: "string", description: "Type of sensor" }, + quantity: { type: "number", description: "Quantity of sensors" }, + indate: { type: "string", description: "Date of sensor entry" }, + hardwareId_company: { type: "string", description: "Company name of hardware ID" }, + hardwareId: { type: "string", nullable: true, description: "Hardware ID (if applicable)" }, + masterId: { type: "string", nullable: true, description: "Master ID reference" }, + qccheck: { type: "string", nullable: true, description: "QC check status" }, + qccheckdate: { type: "string", nullable: true, description: "QC check date" }, + qcby: { type: "string", nullable: true, description: "QC checked by" }, + comment: { type: "string", default: "0", description: "Comment field" }, + outforrepairdate: { type: "string", default: "0", description: "Date sensor sent for repair" }, + sendto: { type: "string", nullable: true, description: "Destination for repair" }, + repairfeedback: { type: "string", default: "0", description: "Repair feedback" }, + dateofinstallation: { type: "string", nullable: true, description: "Installation date" }, + installedby: { type: "string", default: "0", description: "Person who installed the sensor" }, + customerId: { type: "string", default: "0", description: "Customer ID" }, + comments: { type: "string", default: "0", description: "Additional comments" }, + sensor_type: { type: "string", enum: ["slaves", "motorswitch", "master"], description: "Type of sensor" } + }, + }, + }, + handler: storeController.updateSensorById, +}); + + fastify.get("/api/getbatchnumbers/:storeId/:type", { schema: { tags: ["Store-Data"], @@ -1142,7 +1189,7 @@ fastify.get("/api/getiots/:storeId/:type", { schema: { tags: ["Store-Data"], description: "This is to Get iots of particular store", - summary: "This is to iots of particular store", + summary: "This is to get iots of particular store", params: { type: "object", properties: {