From b2376d6f47c85cef95cc56e021e4239e75269369 Mon Sep 17 00:00:00 2001 From: Bhaskar Date: Wed, 2 Apr 2025 11:07:32 +0530 Subject: [PATCH] master connected slave data --- src/controllers/installationController.js | 18 ++++++++++++++++++ src/routes/installationRoute.js | 17 ++++++++++++++++- 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/src/controllers/installationController.js b/src/controllers/installationController.js index 0ffdda97..05ee2541 100644 --- a/src/controllers/installationController.js +++ b/src/controllers/installationController.js @@ -756,3 +756,21 @@ exports.createMasterSlaveData = async (req, reply) => { } }; +exports.masterConnectedSlaveList = async (req, reply) => { + try { + const { connectedTo } = req.params; + + // Find all tanks where connected_to matches the given parameter + const tanks = await Insensors.find({ connected_to: connectedTo,type: "slave" }); + + if (!tanks || tanks.length === 0) { + return reply.status(404).send({ success: false, message: "No tanks found for the given connected_to value" }); + } + + return reply.send({ success: true, data: tanks }); + + } catch (error) { + console.error("Error fetching tanks:", error); + return reply.status(500).send({ success: false, message: "Internal Server Error" }); + } +}; \ No newline at end of file diff --git a/src/routes/installationRoute.js b/src/routes/installationRoute.js index 56456f27..78055fa8 100644 --- a/src/routes/installationRoute.js +++ b/src/routes/installationRoute.js @@ -342,7 +342,22 @@ module.exports = function (fastify, opts, next) { handler: installationController.createMasterSlaveData }); - + fastify.get("/api/getmasterConnectedSlaveData/:connectedTo", { + schema: { + description: "Get masrter connected slave data", + tags: ["Installation"], + summary: "Get masrter connected slave data", + params: { + type: "object", + properties: { + connectedTo: { type: "string" }, + + }, + required: [ "connectedTo"], + }, + }, + handler: installationController.masterConnectedSlaveList, + }); next();