diff --git a/src/controllers/storeController.js b/src/controllers/storeController.js index 4125cf48..a20f362f 100644 --- a/src/controllers/storeController.js +++ b/src/controllers/storeController.js @@ -1240,7 +1240,7 @@ exports.updateSensorQC = async (req, reply) => { const { _id } = req.params; let updateData = req.body; - const allowedFields = ["qccheck", "qcby", "comments","status"]; + const allowedFields = ["qccheck", "qcby", "comments", "status"]; // Filter only allowed fields const filteredUpdateData = Object.keys(updateData) @@ -1253,6 +1253,11 @@ exports.updateSensorQC = async (req, reply) => { // Update qccheckdate with the current date in "DD-MMM-YYYY - HH:MM" format filteredUpdateData.qccheckdate = moment().format("DD-MMM-YYYY - HH:mm"); + // Update status based on qccheck value + if (filteredUpdateData.qccheck) { + filteredUpdateData.status = filteredUpdateData.qccheck.toLowerCase() === "ok" ? "available" : "rejected"; + } + const updatedSensor = await Insensors.findByIdAndUpdate( _id, filteredUpdateData, diff --git a/src/routes/storeRoute.js b/src/routes/storeRoute.js index 73ec194d..4731289f 100644 --- a/src/routes/storeRoute.js +++ b/src/routes/storeRoute.js @@ -1181,7 +1181,7 @@ fastify.post("/api/updateSensorQC/:_id", { qccheck: { type: "string", description: "QC check status" }, qcby: { type: "string", description: "QC checked by" }, comments: { type: "string", description: "QC comment" }, - status: { type: "string" }, + }, }, },