From 2d1017fdc7eaeea3d843712d3cbdfd6f4082314f Mon Sep 17 00:00:00 2001 From: Bhaskar Date: Wed, 2 Apr 2025 17:16:14 +0530 Subject: [PATCH] installationId added in get masterlist --- src/controllers/installationController.js | 13 +++++++------ src/routes/installationRoute.js | 6 +++--- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/controllers/installationController.js b/src/controllers/installationController.js index 0bcc6ced..e18ef9db 100644 --- a/src/controllers/installationController.js +++ b/src/controllers/installationController.js @@ -777,12 +777,13 @@ exports.masterConnectedSlaveList = async (req, reply) => { -exports.mastrerList = async (req, reply) => { +exports.mastrerList = async (req, reply) => { try { - const { customerId } = req.params; + const { customerId, installationId } = req.params; // Step 1: Get User and extract buildingName - const user = await User.findOne({ customerId }); + const user = await User.findOne({ customerId , installationId + }); if (!user) { return reply.status(404).send({ success: false, message: "User not found" }); @@ -800,9 +801,9 @@ exports.mastrerList = async (req, reply) => { // Step 3: Extract hardwareId from tanks const hardwareIds = tanks.map(tank => tank.hardwareId); - // Step 4: Find master tanks in InSensors with customerId filter + // Step 4: Find master tanks in InSensors with both customerId and installationId const masterTanks = await Insensors.find({ - customerId, // Ensure only this customer’s data is fetched + customerId, connected_to: { $in: hardwareIds }, type: "master" }); @@ -811,7 +812,7 @@ exports.mastrerList = async (req, reply) => { return reply.status(404).send({ success: false, message: "No master tanks found" }); } - return reply.send({ success: true, buildingName, data: masterTanks,user }); + return reply.send({ success: true, buildingName, data: masterTanks, user }); } catch (error) { console.error("Error fetching master tanks:", error); diff --git a/src/routes/installationRoute.js b/src/routes/installationRoute.js index 1bb960ce..9d8f8a2d 100644 --- a/src/routes/installationRoute.js +++ b/src/routes/installationRoute.js @@ -359,7 +359,7 @@ module.exports = function (fastify, opts, next) { handler: installationController.masterConnectedSlaveList, }); - fastify.get("/api/getmasterList/:customerId", { + fastify.get("/api/getmasterList/:customerId/:installationId", { schema: { description: "Get masrter connected slave data", tags: ["Installation"], @@ -368,9 +368,9 @@ module.exports = function (fastify, opts, next) { type: "object", properties: { customerId: { type: "string" }, - + installationId: { type: "string" }, }, - required: [ "customerId"], + required: [ "customerId","installationId"], }, }, handler: installationController.mastrerList,