From 2b2dc44fdd4994310af4b44789751ff540f4d737 Mon Sep 17 00:00:00 2001 From: varun Date: Tue, 9 Jul 2024 00:31:52 -0400 Subject: [PATCH] getting hardware based on storeIds --- src/controllers/storeController.js | 17 +++++++++++++++++ src/routes/storeRoute.js | 26 ++++++++++++++++++++++++++ src/routes/tanksRoute.js | 4 ++-- 3 files changed, 45 insertions(+), 2 deletions(-) diff --git a/src/controllers/storeController.js b/src/controllers/storeController.js index 1af716d2..e93b00fe 100644 --- a/src/controllers/storeController.js +++ b/src/controllers/storeController.js @@ -543,4 +543,21 @@ exports.addStore = async (request, reply) => { return reply.status(500).send({ error: 'An error occurred while updating the sensor' }); } }; + + + exports.getHardware = async (req, reply) => { + try { + await WaterLeverSensor.find({storeId: req.params.storeId}) + .exec() + .then((docs) => { + reply.send({ status_code: 200, data: docs, count: docs.length }); + }) + .catch((err) => { + console.log(err); + reply.send({ error: err }); + }); + } catch (err) { + throw boom.boomify(err); + } + }; \ No newline at end of file diff --git a/src/routes/storeRoute.js b/src/routes/storeRoute.js index f96619bc..9b382ce6 100644 --- a/src/routes/storeRoute.js +++ b/src/routes/storeRoute.js @@ -187,5 +187,31 @@ fastify.post("/api/qccheckwaterlevelSensor/:hardwareId", { }) +fastify.get("/api/getHardware/:storeId", { + schema: { + tags: ["Tank"], + description: "This is Get Hardware Data", + summary: "This is to Hardware Tank Data", + params: { + required: ["storeId"], + type: "object", + properties: { + storeId: { + type: "string", + description: "storeId", + }, + }, + }, + security: [ + { + basicAuth: [], + }, + ], + }, + // preHandler: fastify.auth([fastify.authenticate]), + handler: storeController.getHardware, +}); + + next(); }; diff --git a/src/routes/tanksRoute.js b/src/routes/tanksRoute.js index 8d2acfdb..8b77c595 100644 --- a/src/routes/tanksRoute.js +++ b/src/routes/tanksRoute.js @@ -180,8 +180,8 @@ module.exports = function (fastify, opts, next) { fastify.get("/api/getTanks", { schema: { tags: ["Tank"], - description: "This is for Get Tank Data", - summary: "This is for to Get Tank Data", + description: "This is to Get Tank Data", + summary: "This is to Get Tank Data", querystring: { customerId: {type: 'string'} },