|
|
|
@ -198,23 +198,53 @@ exports.updateTanklevels = async (req, reply) => {
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
exports.getTanklevels = async (req, reply) => {
|
|
|
|
|
try {
|
|
|
|
|
const customerId = req.params.customerId;
|
|
|
|
|
|
|
|
|
|
let sumSumpDrinkingWater = 0;
|
|
|
|
|
let sumOverheadDrinkingWater = 0;
|
|
|
|
|
let sumSumpBoreWater = 0;
|
|
|
|
|
let sumOverheadBoreWater = 0;
|
|
|
|
|
let sumSumpDrinkingWaterCapacity = 0;
|
|
|
|
|
let sumOverheadDrinkingWaterCapacity = 0;
|
|
|
|
|
let sumSumpBoreWaterCapacity = 0;
|
|
|
|
|
let sumOverheadBoreWaterCapacity = 0;
|
|
|
|
|
|
|
|
|
|
const updated_data = await Tank.find({ customerId: customerId });
|
|
|
|
|
console.log("updated_data", updated_data);
|
|
|
|
|
|
|
|
|
|
updated_data.forEach((tank) => {
|
|
|
|
|
const capacity = parseInt(tank.capacity.replace(/,/g, ''));
|
|
|
|
|
if (tank.tankLocation === 'sump' && tank.typeOfWater === 'Drinking Water') {
|
|
|
|
|
sumSumpDrinkingWater += parseInt(tank.waterlevel);
|
|
|
|
|
sumSumpDrinkingWaterCapacity += capacity;
|
|
|
|
|
} else if (tank.tankLocation === 'overhead' && tank.typeOfWater === 'Drinking Water') {
|
|
|
|
|
sumOverheadDrinkingWater += parseInt(tank.waterlevel);
|
|
|
|
|
sumOverheadDrinkingWaterCapacity += capacity;
|
|
|
|
|
} else if (tank.tankLocation === 'sump' && tank.typeOfWater === 'Bore Water') {
|
|
|
|
|
sumSumpBoreWater += parseInt(tank.waterlevel);
|
|
|
|
|
sumSumpBoreWaterCapacity += capacity;
|
|
|
|
|
} else if (tank.tankLocation === 'overhead' && tank.typeOfWater === 'Bore Water') {
|
|
|
|
|
sumOverheadBoreWater += parseInt(tank.waterlevel);
|
|
|
|
|
sumOverheadBoreWaterCapacity += capacity;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
reply.send({ status_code: 200, data: updated_data});
|
|
|
|
|
|
|
|
|
|
reply.send({
|
|
|
|
|
status_code: 200,
|
|
|
|
|
data: updated_data,
|
|
|
|
|
totalDrinkingWaterInSump: sumSumpDrinkingWater,
|
|
|
|
|
totalDrinkingWaterInOverhead: sumOverheadDrinkingWater,
|
|
|
|
|
totalBoreWaterInSump: sumSumpBoreWater,
|
|
|
|
|
totalBoreWaterInOverhead: sumOverheadBoreWater,
|
|
|
|
|
totalDrinkingWaterInSumpCapacity: sumSumpDrinkingWaterCapacity,
|
|
|
|
|
totalDrinkingWaterInOverheadCapacity: sumOverheadDrinkingWaterCapacity,
|
|
|
|
|
totalBoreWaterInSumpCapacity: sumSumpBoreWaterCapacity,
|
|
|
|
|
totalBoreWaterInOverheadCapacity: sumOverheadBoreWaterCapacity,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return { message: 'success' };
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
catch (err) {
|
|
|
|
|
} catch (err) {
|
|
|
|
|
throw boom.boomify(err);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|