|
|
@ -760,23 +760,40 @@ exports.masterConnectedSlaveList = async (req, reply) => {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
const { connectedTo } = req.params;
|
|
|
|
const { connectedTo } = req.params;
|
|
|
|
|
|
|
|
|
|
|
|
// Find all tanks where connected_to matches the given parameter
|
|
|
|
// Step 1: Find all slave tanks where connected_to matches
|
|
|
|
const tanks = await Insensors.find({ connected_to: connectedTo,type: "slave" });
|
|
|
|
const slaveTanks = await Insensors.find({ connected_to: connectedTo });
|
|
|
|
|
|
|
|
|
|
|
|
if (!tanks || tanks.length === 0) {
|
|
|
|
if (!slaveTanks || slaveTanks.length === 0) {
|
|
|
|
return reply.status(404).send({ success: false, message: "No tanks found for the given connected_to value" });
|
|
|
|
return reply.status(404).send({ success: false, message: "No tanks found for the given connected_to value" });
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return reply.send({ success: true, data: tanks });
|
|
|
|
// Step 2: Fetch `tankLocation` and `typeOfWater` from the Tank schema
|
|
|
|
|
|
|
|
const tankDetails = await Tank.findOne({ hardwareId: connectedTo }, { tankLocation: 1, typeOfWater: 1 });
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!tankDetails) {
|
|
|
|
|
|
|
|
return reply.status(404).send({ success: false, message: "Tank details not found for the given connectedTo" });
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Step 3: Count the number of connected slaves
|
|
|
|
|
|
|
|
const slaveCount = slaveTanks.length;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return reply.send({
|
|
|
|
|
|
|
|
success: true,
|
|
|
|
|
|
|
|
tankLocation: tankDetails.tankLocation,
|
|
|
|
|
|
|
|
typeOfWater: tankDetails.typeOfWater,
|
|
|
|
|
|
|
|
connectedSlaveCount: slaveCount,
|
|
|
|
|
|
|
|
data: slaveTanks,
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
} catch (error) {
|
|
|
|
} catch (error) {
|
|
|
|
console.error("Error fetching tanks:", error);
|
|
|
|
console.error("Error fetching master connected slave data:", error);
|
|
|
|
return reply.status(500).send({ success: false, message: "Internal Server Error" });
|
|
|
|
return reply.status(500).send({ success: false, message: "Internal Server Error" });
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
exports.mastrerList = async (req, reply) => {
|
|
|
|
exports.mastrerList = async (req, reply) => {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
const { customerId, installationId } = req.params;
|
|
|
|
const { customerId, installationId } = req.params;
|
|
|
|