slaves data count

master^2
Bhaskar 6 months ago
parent 2d1017fdc7
commit 88e118010e

@ -760,23 +760,40 @@ exports.masterConnectedSlaveList = async (req, reply) => {
try {
const { connectedTo } = req.params;
// Find all tanks where connected_to matches the given parameter
const tanks = await Insensors.find({ connected_to: connectedTo,type: "slave" });
// Step 1: Find all slave tanks where connected_to matches
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.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) {
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" });
}
};
exports.mastrerList = async (req, reply) => {
try {
const { customerId, installationId } = req.params;

Loading…
Cancel
Save