|
|
@ -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 customer’s 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);
|
|
|
|