installationId added in get masterlist

master^2
Bhaskar 6 months ago
parent 7817fcf790
commit 2d1017fdc7

@ -777,12 +777,13 @@ exports.masterConnectedSlaveList = async (req, reply) => {
exports.mastrerList = async (req, reply) => { exports.mastrerList = async (req, reply) => {
try { try {
const { customerId } = req.params; const { customerId, installationId } = req.params;
// Step 1: Get User and extract buildingName // Step 1: Get User and extract buildingName
const user = await User.findOne({ customerId }); const user = await User.findOne({ customerId , installationId
});
if (!user) { if (!user) {
return reply.status(404).send({ success: false, message: "User not found" }); 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 // Step 3: Extract hardwareId from tanks
const hardwareIds = tanks.map(tank => tank.hardwareId); 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({ const masterTanks = await Insensors.find({
customerId, // Ensure only this customers data is fetched customerId,
connected_to: { $in: hardwareIds }, connected_to: { $in: hardwareIds },
type: "master" 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.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) { } catch (error) {
console.error("Error fetching master tanks:", error); console.error("Error fetching master tanks:", error);

@ -359,7 +359,7 @@ module.exports = function (fastify, opts, next) {
handler: installationController.masterConnectedSlaveList, handler: installationController.masterConnectedSlaveList,
}); });
fastify.get("/api/getmasterList/:customerId", { fastify.get("/api/getmasterList/:customerId/:installationId", {
schema: { schema: {
description: "Get masrter connected slave data", description: "Get masrter connected slave data",
tags: ["Installation"], tags: ["Installation"],
@ -368,9 +368,9 @@ module.exports = function (fastify, opts, next) {
type: "object", type: "object",
properties: { properties: {
customerId: { type: "string" }, customerId: { type: "string" },
installationId: { type: "string" },
}, },
required: [ "customerId"], required: [ "customerId","installationId"],
}, },
}, },
handler: installationController.mastrerList, handler: installationController.mastrerList,

Loading…
Cancel
Save