slave individual details

master^2
Bhaskar 3 months ago
parent 742f3c73d4
commit 00ec6b9f89

@ -1932,6 +1932,95 @@ exports.getTankDetailsByMaster = async (req, reply) => {
}; };
exports.getSlaveTankDetails = async (req, reply) => {
try {
const { customerId, hardwareId, tankHardwareId } = req.params;
if (!customerId || !hardwareId || !tankHardwareId) {
return reply.code(400).send({
success: false,
message: 'customerId, hardwareId, and tankHardwareId are required'
});
}
// Step 1: find slave device (type: slave)
const slaveDevice = await Insensors.findOne({ customerId, connected_to: hardwareId, type: 'slave' }).lean();
if (!slaveDevice) {
return reply.code(404).send({
success: false,
message: 'Slave device not found'
});
}
// Step 2: find master hardwareId from slave.connected_to
const masterHardwareId = slaveDevice.connected_to;
if (!masterHardwareId) {
return reply.code(404).send({
success: false,
message: 'Slave device has no connected_to (master hardwareId)'
});
}
// Step 3: find master info from Order.master_connections
const order = await Order.findOne({ customerId, "master_connections.hardwareId": masterHardwareId }).lean();
if (!order) {
return reply.code(404).send({
success: false,
message: 'Order not found for connected master'
});
}
const masterInfo = order.master_connections.find(m => m.hardwareId === masterHardwareId);
const masterName = masterInfo ? masterInfo.master_name : null;
const location = masterInfo ? masterInfo.location : null;
// Step 4: get slave's tank details
const tank = await Tank.findOne({ customerId, hardwareId, tankhardwareId: tankHardwareId }).lean();
if (!tank) {
return reply.code(404).send({
success: false,
message: 'Tank not found for slave'
});
}
// Step 5: parse dimensions
const tankHeightFeet = parseInt(tank.height, 10);
const tankWidthFeet = parseInt(tank.width, 10);
const tankLengthFeet = parseInt(tank.length, 10);
return reply.send({
success: true,
data: {
masterName,
location,
slaveHardwareId: hardwareId,
tankHardwareId,
tankName: tank.tankName,
blockName: tank.blockName,
shape: tank.shape,
capacity: tank.capacity,
waterCapacityPerCm: tank.waterCapacityPerCm,
typeOfWater: tank.typeOfWater,
tankLocation: tank.tankLocation,
height: tankHeightFeet,
width: tankWidthFeet,
length: tankLengthFeet,
heightInCm: tankHeightFeet * 30.48,
widthInCm: tankWidthFeet * 30.48,
lengthInCm: tankLengthFeet * 30.48
}
});
} catch (error) {
console.error('Error fetching slave tank details:', error);
reply.code(500).send({
success: false,
message: 'Internal server error'
});
}
};

@ -442,6 +442,24 @@ fastify.get('/api/tanks/master/:customerId/:hardwareId', {
}); });
fastify.get('/api/slave-tank-details/:customerId/:hardwareId/:tankHardwareId', {
schema: {
tags: ['Tank'],
summary: 'Get slave tank details with master info',
params: {
type: 'object',
required: ['customerId', 'hardwareId', 'tankHardwareId'],
properties: {
customerId: { type: 'string' },
hardwareId: { type: 'string' },
tankHardwareId: { type: 'string' }
}
},
},
handler: installationController.getSlaveTankDetails
});
fastify.post( fastify.post(
'/api/update-status/:connectedTo/:teamMemberId/:customerId', '/api/update-status/:connectedTo/:teamMemberId/:customerId',
{ {

Loading…
Cancel
Save