From 5c925c25e083d39486ba4776ac2556dc3f93b938 Mon Sep 17 00:00:00 2001 From: Varun Date: Wed, 19 Feb 2025 11:28:03 +0530 Subject: [PATCH] added qc check --- src/controllers/storeController.js | 35 ++++++++++++++++++++++++++++++ src/routes/storeRoute.js | 27 +++++++++++++++++++++++ 2 files changed, 62 insertions(+) diff --git a/src/controllers/storeController.js b/src/controllers/storeController.js index 772eb819..5f90603b 100644 --- a/src/controllers/storeController.js +++ b/src/controllers/storeController.js @@ -1218,6 +1218,41 @@ exports.updateSensorById = async (req, reply) => { }; +exports.updateSensorQC = async (req, reply) => { + try { + const { _id } = req.params; + let updateData = req.body; + + const allowedFields = ["qccheck", "qcby", "comment"]; + + // Filter only allowed fields + const filteredUpdateData = Object.keys(updateData) + .filter((key) => allowedFields.includes(key)) + .reduce((obj, key) => { + obj[key] = updateData[key]; + return obj; + }, {}); + + // Update qccheckdate with the current date in "DD-MMM-YYYY - HH:MM" format + filteredUpdateData.qccheckdate = moment().format("DD-MMM-YYYY - HH:mm"); + + const updatedSensor = await Insensors.findByIdAndUpdate( + _id, + filteredUpdateData, + { 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 QC fields:", 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 f4d75e3e..f272cb25 100644 --- a/src/routes/storeRoute.js +++ b/src/routes/storeRoute.js @@ -1141,6 +1141,33 @@ fastify.post("/api/updateSensorById/:_id", { }); +fastify.post("/api/updateSensorQC/:_id", { + schema: { + description: "Edit specific sensor QC fields", + tags: ["Store-Data"], + summary: "Update QC fields of a sensor", + params: { + required: ["_id"], + type: "object", + properties: { + _id: { + type: "string", + description: "Sensor ID", + }, + }, + }, + body: { + type: "object", + properties: { + qccheck: { type: "string", description: "QC check status" }, + qcby: { type: "string", description: "QC checked by" }, + comment: { type: "string", description: "QC comment" }, + }, + }, + }, + handler: storeController.updateSensorQC, +}); + fastify.get("/api/getbatchnumbers/:storeId/:type", { schema: {