diff --git a/src/controllers/storeController.js b/src/controllers/storeController.js index 4bee54ad..9a7b5f56 100644 --- a/src/controllers/storeController.js +++ b/src/controllers/storeController.js @@ -529,7 +529,33 @@ exports.addStore = async (request, reply) => { } }; - + + + + + exports.installwaterlevelSensor = async (request, reply) => { + try { + const { storeId } = request.params; + const updateData = request.body; + + // Find the document by hardwareId and update it with the fields received in the body + const updatedSensor = await WaterLeverSensor.findOneAndUpdate( + { storeId:storeId,hardwareId: request.body.hardwareId, }, + { $set: updateData }, + { new: true } // Return the updated document + ); + + if (!updatedSensor) { + return reply.status(404).send({ error: 'Sensor not found' }); + } + + return reply.status(200).send(updatedSensor); + } catch (error) { + console.error(error); + return reply.status(500).send({ error: 'An error occurred while updating the sensor' }); + } + }; + exports.qccheckwaterlevelSensor = async (request, reply) => { try { const { hardwareId } = request.params; diff --git a/src/routes/storeRoute.js b/src/routes/storeRoute.js index 8c20d21f..6c4346b6 100644 --- a/src/routes/storeRoute.js +++ b/src/routes/storeRoute.js @@ -154,6 +154,37 @@ fastify.post("/api/createwaterlevelSensor/:storeId", { handler: storeController.createwaterlevelSensor, }) +fastify.post("/api/installwaterlevelSensor/:storeId", { + schema: { + description: "This is for installing waterlevel Sensor", + tags: ["Store-Data"], + summary: "This is for installing waterlevel Sensor", + params: { + required: ["storeId"], + type: "object", + properties: { + storeId: { + type: "string", + description: "storeId", + }, + }, + }, + + body: { + type: "object", + + properties: { + + hardwareId: { type: "string" }, + dateofinstallation: { type: "string" }, + customerId: { type: "string" }, + installedby: { type: "string" } + }, + }, + }, + handler: storeController.installwaterlevelSensor, +}) + fastify.post("/api/qccheckwaterlevelSensor/:hardwareId", { schema: { description: "This is for checking waterlevel Sensor",