ashok 3 months ago
commit 2fdb6e1290

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

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

@ -731,61 +731,7 @@ fastify.post(
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,

Loading…
Cancel
Save