master deatils in induvidual

master^2
Bhaskar 3 months ago
parent 0045128e07
commit 742f3c73d4

@ -1849,6 +1849,90 @@ exports.masterConnectedSlaveList = async (req, reply) => {
};
exports.getTankDetailsByMaster = async (req, reply) => {
try {
const { customerId, hardwareId } = req.params;
if (!customerId || !hardwareId) {
return reply.code(400).send({
success: false,
message: 'customerId and hardwareId are required'
});
}
// Step 1: find master device (to confirm existence)
const masterDevice = await Insensors.findOne({ customerId, hardwareId, type: 'master' }).lean();
if (!masterDevice) {
return reply.code(404).send({
success: false,
message: 'Master device not found'
});
}
// Step 2: find order to get masterName & location
const orderRecord = await Order.findOne({ customerId, "master_connections.hardwareId": hardwareId }).lean();
if (!orderRecord) {
return reply.code(404).send({
success: false,
message: 'Order record not found for this hardwareId'
});
}
// find the master inside order
const masterInfo = orderRecord.master_connections.find(
m => m.hardwareId === hardwareId
);
const masterName = masterInfo ? masterInfo.master_name : null;
const location = masterInfo ? masterInfo.location : null;
// Step 3: get tank details
const tank = await Tank.findOne({ customerId, hardwareId }).lean();
if (!tank) {
return reply.code(404).send({
success: false,
message: 'Tank details not found'
});
}
// Step 4: parse & format dimensions
const tankHeightFeet = parseInt(tank.height, 10);
const tankWidthFeet = parseInt(tank.width, 10);
const tankLengthFeet = parseInt(tank.length, 10);
reply.send({
success: true,
data: {
masterName: masterName,
location: location,
hardwareId: hardwareId,
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 tank details:', error);
reply.code(500).send({
success: false,
message: 'Internal server error'
});
}
};
exports.updateWorkStatusAndProductStatus = async (req, reply) => {

@ -421,6 +421,25 @@ module.exports = function (fastify, opts, next) {
},
handler: installationController.masterConnectedSlaveList,
});
fastify.get('/api/tanks/master/:customerId/:hardwareId', {
schema: {
tags: ['Tank'],
summary: 'Get tank details by master device',
description: 'Fetch tank details by providing customerId and hardwareId for type master',
params: {
type: 'object',
required: ['customerId', 'hardwareId'],
properties: {
customerId: { type: 'string', },
hardwareId: { type: 'string', }
}
},
},
handler: installationController.getTankDetailsByMaster
});
fastify.post(

Loading…
Cancel
Save