From cd6c2d24048c79534eb0847dabdbfe9761622397 Mon Sep 17 00:00:00 2001 From: Varun Date: Tue, 11 Feb 2025 12:01:11 +0530 Subject: [PATCH] changes in edit sensors --- src/controllers/storeController.js | 22 ++++++++++++++++------ src/routes/storeRoute.js | 26 ++++++-------------------- 2 files changed, 22 insertions(+), 26 deletions(-) diff --git a/src/controllers/storeController.js b/src/controllers/storeController.js index 55021726..7955fa28 100644 --- a/src/controllers/storeController.js +++ b/src/controllers/storeController.js @@ -1165,24 +1165,34 @@ exports.installmotorswitch = async (request, reply) => { exports.updateSensorById = async (req, reply) => { - try { - const _id = req.params._id; + const { _id } = req.params; const updateData = req.body; - const updatedSensor = await Insensors.findByIdAndUpdate(_id, updateData, { new: true }); + const allowedFields = ["model", "type", "hardwareId_company", "hardwareId", "masterId"]; + + // Filter out unwanted fields + const filteredUpdateData = Object.keys(updateData) + .filter((key) => allowedFields.includes(key)) + .reduce((obj, key) => { + obj[key] = updateData[key]; + return obj; + }, {}); + + const updatedSensor = await Insensors.findByIdAndUpdate(_id, filteredUpdateData, { new: true }); if (!updatedSensor) { - return reply.code(404).send({ message: 'Sensor not found' }); + 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' }); + 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/routes/storeRoute.js b/src/routes/storeRoute.js index 73f197e6..a5ee11d6 100644 --- a/src/routes/storeRoute.js +++ b/src/routes/storeRoute.js @@ -1112,43 +1112,28 @@ fastify.post("/api/createwaterlevelSensorintime/:storeId", { fastify.post("/api/updateSensorById/:_id", { schema: { - description: "This is for editing Sensors after time", + description: "Edit specific sensor fields", tags: ["Store-Data"], - summary: "This is for editing Sensors after time", + summary: "Update specific fields of a sensor before macId", params: { required: ["_id"], type: "object", properties: { _id: { type: "string", - description: "storeId", + description: "Sensor ID", }, }, }, 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" } + masterId: { type: "string", nullable: true, description: "Master ID reference" } }, }, }, @@ -1156,6 +1141,7 @@ fastify.post("/api/updateSensorById/:_id", { }); + fastify.get("/api/getbatchnumbers/:storeId/:type", { schema: { tags: ["Store-Data"],