|
|
|
@ -4,7 +4,7 @@ const jwt = require('jsonwebtoken');
|
|
|
|
|
const customJwtAuth = require("../customAuthJwt");
|
|
|
|
|
const { Deparments } = require("../models/Department");
|
|
|
|
|
const { Install, SensorStock, SensorQuotation, Order, Insensors, MasterSlaveData, ElectrictyWorkPictures, PlumbingWorkPictures, MaterialRecievedPictures } = require("../models/store");
|
|
|
|
|
const { Counter } = require("../models/User");
|
|
|
|
|
const { Counter, User } = require("../models/User");
|
|
|
|
|
const { IotData, Tank } = require("../models/tanks");
|
|
|
|
|
const fastify = require("fastify")({
|
|
|
|
|
logger: true,
|
|
|
|
@ -774,3 +774,47 @@ exports.masterConnectedSlaveList = async (req, reply) => {
|
|
|
|
|
return reply.status(500).send({ success: false, message: "Internal Server Error" });
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
exports.mastrerList = async (req, reply) => {
|
|
|
|
|
try {
|
|
|
|
|
const { customerId } = req.params;
|
|
|
|
|
|
|
|
|
|
// Step 1: Get User and extract buildingName
|
|
|
|
|
const user = await User.findOne({ customerId });
|
|
|
|
|
|
|
|
|
|
if (!user) {
|
|
|
|
|
return reply.status(404).send({ success: false, message: "User not found" });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const { buildingName } = user;
|
|
|
|
|
|
|
|
|
|
// Step 2: Get Tanks with matching customerId
|
|
|
|
|
const tanks = await Tank.find({ customerId });
|
|
|
|
|
|
|
|
|
|
if (!tanks.length) {
|
|
|
|
|
return reply.status(404).send({ success: false, message: "No tanks found for this customer" });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Step 3: Extract hardwareId from tanks
|
|
|
|
|
const hardwareIds = tanks.map(tank => tank.hardwareId);
|
|
|
|
|
|
|
|
|
|
// Step 4: Find master tanks in InSensors with customerId filter
|
|
|
|
|
const masterTanks = await Insensors.find({
|
|
|
|
|
customerId, // Ensure only this customer’s data is fetched
|
|
|
|
|
connected_to: { $in: hardwareIds },
|
|
|
|
|
type: "master"
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (!masterTanks.length) {
|
|
|
|
|
return reply.status(404).send({ success: false, message: "No master tanks found" });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return reply.send({ success: true, buildingName, data: masterTanks });
|
|
|
|
|
|
|
|
|
|
} catch (error) {
|
|
|
|
|
console.error("Error fetching master tanks:", error);
|
|
|
|
|
return reply.status(500).send({ success: false, message: "Internal Server Error" });
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|