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 {
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 customers 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);

@ -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,

Loading…
Cancel
Save