Individual data of master and slaves

master^2
Bhaskar 3 months ago
parent 7cc0a31ea2
commit aa8bfc04f4

@ -3095,6 +3095,49 @@ exports.getWaitingMasterSlaveSummary = async (req, reply) => {
}
};
exports.getMasterWithSlaves = async (req, reply) => {
try {
const { installationId, customerId, hardwareId } = req.params;
if (!installationId || !customerId || !hardwareId) {
return reply.code(400).send({ success: false, message: "installationId, customerId, and hardwareId are required" });
}
// Find order
const order = await Order.findOne({ installationId, customerId }).lean();
if (!order) {
return reply.code(404).send({ success: false, message: "Order not found" });
}
// Find master device in Insensors
const master = await Insensors.findOne({
hardwareId,
customerId,
}).lean();
if (!master) {
return reply.code(404).send({ success: false, message: "Master device not found in Insensors" });
}
// // Find slaves connected to this master
// const slaves = await Insensors.find({
// connected_to: hardwareId,
// customerId,
// type: 'slave'
// }).lean();
return reply.send({
success: true,
master,
});
} catch (error) {
console.error("Error fetching master and slaves:", error);
return reply.code(500).send({ success: false, message: "Internal server error" });
}
};
exports.getPendingMasterSlaveSummary = async (req, reply) => {
try {
const { customerId } = req.params;

@ -593,6 +593,81 @@ fastify.post(
handler: installationController.getMasterSlaveSummary,
});
fastify.get('/api/master-with-slaves/:installationId/:customerId/:hardwareId', {
schema: {
tags: ['Installation'],
summary: 'Get Individual master device and its connected slaves',
description: 'Fetch a master device from Insensors by hardwareId and list all connected slave devices for the same customer and installation.',
params: {
type: 'object',
required: ['installationId', 'customerId', 'hardwareId'],
properties: {
installationId: { type: 'string', description: 'Installation ID from Order' },
customerId: { type: 'string', description: 'Customer ID' },
hardwareId: { type: 'string', description: 'Master hardwareId' },
}
},
// response: {
// 200: {
// type: 'object',
// properties: {
// success: { type: 'boolean' },
// master: {
// type: 'object',
// description: 'Master device details',
// properties: {
// _id: { type: 'string' },
// hardwareId: { type: 'string' },
// customerId: { type: 'string' },
// type: { type: 'string' },
// // Add other master fields as needed...
// }
// },
// slaves: {
// type: 'array',
// description: 'List of connected slave devices',
// items: {
// type: 'object',
// properties: {
// _id: { type: 'string' },
// hardwareId: { type: 'string' },
// connected_to: { type: 'string' },
// customerId: { type: 'string' },
// type: { type: 'string' },
// // Add other slave fields as needed...
// }
// }
// }
// }
// },
// 400: {
// type: 'object',
// properties: {
// success: { type: 'boolean' },
// message: { type: 'string' }
// }
// },
// 404: {
// type: 'object',
// properties: {
// success: { type: 'boolean' },
// message: { type: 'string' }
// }
// },
// 500: {
// type: 'object',
// properties: {
// success: { type: 'boolean' },
// message: { type: 'string' }
// }
// }
// }
},
handler: installationController.getMasterWithSlaves,
});
fastify.get("/api/getwaitingmasterlistwithslaves/:customerId", {
schema: {
description: "Get waiting manager masrter connected slave data with full info",

Loading…
Cancel
Save