|
|
@ -301,6 +301,8 @@ exports.updateTanklevels = async (req, reply) => {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
exports.getTanklevels = async (req, reply) => {
|
|
|
|
exports.getTanklevels = async (req, reply) => {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
const customerId = req.params.customerId;
|
|
|
|
const customerId = req.params.customerId;
|
|
|
@ -317,23 +319,27 @@ exports.getTanklevels = async (req, reply) => {
|
|
|
|
console.log("updated_data", updated_data);
|
|
|
|
console.log("updated_data", updated_data);
|
|
|
|
|
|
|
|
|
|
|
|
updated_data.forEach((tank) => {
|
|
|
|
updated_data.forEach((tank) => {
|
|
|
|
const capacity = parseInt(tank.capacity.replace(/,/g, ''));
|
|
|
|
const waterlevel = parseInt(tank.waterlevel.replace(/,/g, ''), 10);
|
|
|
|
|
|
|
|
const capacity = parseInt(tank.capacity.replace(/,/g, ''), 10);
|
|
|
|
|
|
|
|
console.log(`Processing tank: ${tank.tankName}`);
|
|
|
|
|
|
|
|
console.log(`Type of Water: ${tank.typeOfWater}, Location: ${tank.tankLocation}, Waterlevel: ${waterlevel}, Capacity: ${capacity}`);
|
|
|
|
|
|
|
|
|
|
|
|
if (tank.tankLocation === 'sump' && tank.typeOfWater === 'Drinking Water') {
|
|
|
|
if (tank.tankLocation === 'sump' && tank.typeOfWater === 'Drinking Water') {
|
|
|
|
sumSumpDrinkingWater += parseInt(tank.waterlevel);
|
|
|
|
sumSumpDrinkingWater += waterlevel;
|
|
|
|
sumSumpDrinkingWaterCapacity += capacity;
|
|
|
|
sumSumpDrinkingWaterCapacity += capacity;
|
|
|
|
} else if (tank.tankLocation === 'overhead' && tank.typeOfWater === 'Drinking Water') {
|
|
|
|
} else if (tank.tankLocation === 'overhead' && tank.typeOfWater === 'Drinking Water') {
|
|
|
|
sumOverheadDrinkingWater += parseInt(tank.waterlevel);
|
|
|
|
sumOverheadDrinkingWater += waterlevel;
|
|
|
|
sumOverheadDrinkingWaterCapacity += capacity;
|
|
|
|
sumOverheadDrinkingWaterCapacity += capacity;
|
|
|
|
} else if (tank.tankLocation === 'sump' && tank.typeOfWater === 'Bore Water') {
|
|
|
|
} else if (tank.tankLocation === 'sump' && tank.typeOfWater === 'Bore Water') {
|
|
|
|
sumSumpBoreWater += parseInt(tank.waterlevel);
|
|
|
|
sumSumpBoreWater += waterlevel;
|
|
|
|
sumSumpBoreWaterCapacity += capacity;
|
|
|
|
sumSumpBoreWaterCapacity += capacity;
|
|
|
|
} else if (tank.tankLocation === 'overhead' && tank.typeOfWater === 'Bore Water') {
|
|
|
|
} else if (tank.tankLocation === 'overhead' && tank.typeOfWater === 'Bore Water') {
|
|
|
|
sumOverheadBoreWater += parseInt(tank.waterlevel);
|
|
|
|
sumOverheadBoreWater += waterlevel;
|
|
|
|
sumOverheadBoreWaterCapacity += capacity;
|
|
|
|
sumOverheadBoreWaterCapacity += capacity;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
reply.send({
|
|
|
|
const responseData = {
|
|
|
|
status_code: 200,
|
|
|
|
status_code: 200,
|
|
|
|
data: updated_data,
|
|
|
|
data: updated_data,
|
|
|
|
totalDrinkingWaterInSump: sumSumpDrinkingWater,
|
|
|
|
totalDrinkingWaterInSump: sumSumpDrinkingWater,
|
|
|
@ -344,14 +350,21 @@ exports.getTanklevels = async (req, reply) => {
|
|
|
|
totalDrinkingWaterInOverheadCapacity: sumOverheadDrinkingWaterCapacity,
|
|
|
|
totalDrinkingWaterInOverheadCapacity: sumOverheadDrinkingWaterCapacity,
|
|
|
|
totalBoreWaterInSumpCapacity: sumSumpBoreWaterCapacity,
|
|
|
|
totalBoreWaterInSumpCapacity: sumSumpBoreWaterCapacity,
|
|
|
|
totalBoreWaterInOverheadCapacity: sumOverheadBoreWaterCapacity,
|
|
|
|
totalBoreWaterInOverheadCapacity: sumOverheadBoreWaterCapacity,
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!reply.sent) {
|
|
|
|
|
|
|
|
reply.send(responseData);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return { message: 'success' };
|
|
|
|
|
|
|
|
} catch (err) {
|
|
|
|
} catch (err) {
|
|
|
|
|
|
|
|
if (!reply.sent) {
|
|
|
|
|
|
|
|
reply.code(500).send({ error: 'Internal Server Error' });
|
|
|
|
|
|
|
|
}
|
|
|
|
throw boom.boomify(err);
|
|
|
|
throw boom.boomify(err);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const intervals = {};
|
|
|
|
const intervals = {};
|
|
|
|
let sump_water_levels=[];
|
|
|
|
let sump_water_levels=[];
|
|
|
|
let supplier_tanks = [];
|
|
|
|
let supplier_tanks = [];
|
|
|
|