ashok 3 months ago
commit 2fdb6e1290

@ -3536,47 +3536,47 @@ exports.getCompleteMasterSlaveSummary = async (req, reply) => {
return reply.status(500).send({ error: "Internal Server Error" }); return reply.status(500).send({ error: "Internal Server Error" });
} }
}; };
exports.getMasterWithSlaves = async (req, reply) => { // exports.getMasterWithSlaves = async (req, reply) => {
try { // try {
const { installationId, customerId, hardwareId } = req.params; // const { installationId, customerId, hardwareId } = req.params;
if (!installationId || !customerId || !hardwareId) { // if (!installationId || !customerId || !hardwareId) {
return reply.code(400).send({ success: false, message: "installationId, customerId, and hardwareId are required" }); // return reply.code(400).send({ success: false, message: "installationId, customerId, and hardwareId are required" });
} // }
// Find order // // Find order
const order = await Order.findOne({ installationId, customerId }).lean(); // const order = await Order.findOne({ installationId, customerId }).lean();
if (!order) { // if (!order) {
return reply.code(404).send({ success: false, message: "Order not found" }); // return reply.code(404).send({ success: false, message: "Order not found" });
} // }
// Find master device in Insensors // // Find master device in Insensors
const master = await Insensors.findOne({ // const master = await Insensors.findOne({
hardwareId, // hardwareId,
customerId, // customerId,
}).lean(); // }).lean();
if (!master) { // if (!master) {
return reply.code(404).send({ success: false, message: "Master device not found in Insensors" }); // return reply.code(404).send({ success: false, message: "Master device not found in Insensors" });
} // }
// // Find slaves connected to this master // // // Find slaves connected to this master
// const slaves = await Insensors.find({ // // const slaves = await Insensors.find({
// connected_to: hardwareId, // // connected_to: hardwareId,
// customerId, // // customerId,
// type: 'slave' // // type: 'slave'
// }).lean(); // // }).lean();
return reply.send({ // return reply.send({
success: true, // success: true,
master, // master,
}); // });
} catch (error) { // } catch (error) {
console.error("Error fetching master and slaves:", error); // console.error("Error fetching master and slaves:", error);
return reply.code(500).send({ success: false, message: "Internal server error" }); // return reply.code(500).send({ success: false, message: "Internal server error" });
} // }
}; // };
// exports.editTankDimensions = async (req, reply) => { // exports.editTankDimensions = async (req, reply) => {
// try { // try {
@ -3709,6 +3709,59 @@ exports.getMasterWithSlaves = 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 matching master in order.master_connections
const matchingMaster = order.master_connections?.find(m => m.hardwareId === hardwareId);
let masterName = null;
let location = null;
if (matchingMaster) {
masterName = matchingMaster.master_name ?? null;
location = matchingMaster.location ?? null;
}
// Build enriched master object
const enrichedMaster = {
...master,
masterName,
location,
hardwareId: master.hardwareId // keep hardwareId here explicitly if needed
};
return reply.send({
success: true,
master: enrichedMaster
});
} 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) => { exports.getPendingMasterSlaveSummary = async (req, reply) => {
try { try {

@ -8314,6 +8314,9 @@ exports.compareMeasuredHeight = async (req, reply) => {
sensorGapCm = Math.round(tankHeightFromSensor); sensorGapCm = Math.round(tankHeightFromSensor);
sensorWaterLevelInCm = Math.max(0, tankHeightInCmFromDB - sensorGapCm); sensorWaterLevelInCm = Math.max(0, tankHeightInCmFromDB - sensorGapCm);
sensorWaterLevelLiters = Math.round(sensorWaterLevelInCm * capacityPerCm); sensorWaterLevelLiters = Math.round(sensorWaterLevelInCm * capacityPerCm);
var dynamicTankHeightInCm = sensorGapCm + sensorWaterLevelInCm;
console.log("dynamicTankHeightInCm",dynamicTankHeightInCm)
} }
} }
} }
@ -8334,7 +8337,7 @@ exports.compareMeasuredHeight = async (req, reply) => {
tankName, tankName,
capacity: tank.capacity, capacity: tank.capacity,
sensor: { sensor: {
tankHeightInCm: tankHeightInCmFromDB, // from DB tankHeightInCm: dynamicTankHeightInCm, // from DB
sensorGapCm, sensorGapCm,
waterLevelInCm: sensorWaterLevelInCm, waterLevelInCm: sensorWaterLevelInCm,
waterLevelLiters: sensorWaterLevelLiters waterLevelLiters: sensorWaterLevelLiters

@ -731,61 +731,7 @@ fastify.post(
hardwareId: { type: 'string', description: 'Master hardwareId' }, 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, handler: installationController.getMasterWithSlaves,

Loading…
Cancel
Save