get the master list

master^2
Bhaskar 6 months ago
parent b2376d6f47
commit f82395bb80

@ -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,
@ -773,4 +773,48 @@ exports.masterConnectedSlaveList = async (req, reply) => {
console.error("Error fetching tanks:", error);
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 customers 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" });
}
};

@ -358,6 +358,24 @@ module.exports = function (fastify, opts, next) {
},
handler: installationController.masterConnectedSlaveList,
});
fastify.get("/api/getmasterList/:customerId", {
schema: {
description: "Get masrter connected slave data",
tags: ["Installation"],
summary: "Get masrter List",
params: {
type: "object",
properties: {
customerId: { type: "string" },
},
required: [ "customerId"],
},
},
handler: installationController.mastrerList,
});
next();

Loading…
Cancel
Save