diff --git a/src/controllers/storeController.js b/src/controllers/storeController.js index 0a035954..f6900cfb 100644 --- a/src/controllers/storeController.js +++ b/src/controllers/storeController.js @@ -1234,12 +1234,13 @@ exports.deleteSensorById = async (req, reply) => { } }; + exports.updateSensorQC = async (req, reply) => { try { const { _id } = req.params; let updateData = req.body; - const allowedFields = ["qccheck", "qcby", "comment"]; + const allowedFields = ["qccheck", "qcby", "comment","status"]; // Filter only allowed fields const filteredUpdateData = Object.keys(updateData) @@ -1269,6 +1270,30 @@ exports.updateSensorQC = async (req, reply) => { } }; + +exports.getSensorsByStatus = async (req, reply) => { + try { + const { storeId } = req.params; + + const statuses = ["pending", "available", "rejected"]; + let result = {}; + + for (const status of statuses) { + result[status] = await Insensors.find({ storeId, status }); + } + + return reply.code(200).send(result); + } catch (error) { + console.error("Error fetching sensors:", 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 04b2633f..382dd07a 100644 --- a/src/models/store.js +++ b/src/models/store.js @@ -270,7 +270,7 @@ const insensorsSchema = new mongoose.Schema({ quantity: { type: Number, default: 0 }, batchno: { type: String, default: null }, sensor_type: { type: String, enum: ['slaves', 'motorswitch', 'master'] }, // adding sensor_type field - + status: { type: String, default: "pending" }, }); diff --git a/src/routes/storeRoute.js b/src/routes/storeRoute.js index b7a4301e..b8906c8f 100644 --- a/src/routes/storeRoute.js +++ b/src/routes/storeRoute.js @@ -1181,6 +1181,7 @@ fastify.post("/api/updateSensorQC/:_id", { qccheck: { type: "string", description: "QC check status" }, qcby: { type: "string", description: "QC checked by" }, comment: { type: "string", description: "QC comment" }, + status: { type: "string" }, }, }, }, @@ -1188,6 +1189,26 @@ fastify.post("/api/updateSensorQC/:_id", { }); +fastify.get("/api/getSensorsByStatus/:storeId", { + schema: { + description: "Get list of sensors grouped by status for a given store", + tags: ["Store-Data"], + summary: "Retrieve sensors grouped by status", + params: { + type: "object", + required: ["storeId"], + properties: { + storeId: { + type: "string", + description: "Store ID", + }, + }, + }, + }, + handler: storeController.getSensorsByStatus, +}); + + fastify.get("/api/getbatchnumbers/:storeId/:type", { schema: { tags: ["Store-Data"],