|
|
@ -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) => {
|
|
|
|
exports.updateWorkStatusAndProductStatus = async (req, reply) => {
|
|
|
|