|
|
|
@ -160,12 +160,15 @@ exports.updateTanklevels = async (req, reply) => {
|
|
|
|
|
const tankId = tank._id;
|
|
|
|
|
const tank_name = tank.tankName
|
|
|
|
|
let capacity = parseInt(tank.capacity.replace(/,/g, ''), 10);
|
|
|
|
|
let waterLevel = parseInt(tank.waterlevel.replace(/,/g, ''), 10);
|
|
|
|
|
let waterLevel = parseInt(tank.waterlevel.replace(/,/g, ''), 10);
|
|
|
|
|
|
|
|
|
|
const intervalId = setInterval(async function () {
|
|
|
|
|
console.log(waterLevel)
|
|
|
|
|
const motorStatus = tank.motor_status
|
|
|
|
|
const newWaterLevel = Math.floor(waterLevel - 200);
|
|
|
|
|
console.log("motorstatus:"+motorStatus)
|
|
|
|
|
|
|
|
|
|
if (newWaterLevel <= 0) {
|
|
|
|
|
if (newWaterLevel <= 0,motorStatus === "1") {
|
|
|
|
|
clearInterval(intervals[tankId]);
|
|
|
|
|
console.log(`Stopped updating tank with ID ${tankId}`);
|
|
|
|
|
return;
|
|
|
|
@ -197,76 +200,26 @@ exports.updateTanklevels = async (req, reply) => {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// exports.getTanklevels = async (req, reply) => {
|
|
|
|
|
// try {
|
|
|
|
|
// const customerId = req.params.customerId;
|
|
|
|
|
|
|
|
|
|
// const updated_data = await Tank.find({ customerId: customerId });
|
|
|
|
|
|
|
|
|
|
// let sumSumpDrinkingWater = 0;
|
|
|
|
|
// let sumOverheadDrinkingWater = 0;
|
|
|
|
|
|
|
|
|
|
// updated_data.forEach((tank) => {
|
|
|
|
|
// if (tank.tankLocation === 'sump' && tank.typeOfWater === 'Drinking Water') {
|
|
|
|
|
// sumSumpDrinkingWater += parseInt(tank.waterlevel);
|
|
|
|
|
// } else if (tank.tankLocation === 'overhead' && tank.typeOfWater === 'Drinking Water') {
|
|
|
|
|
// sumOverheadDrinkingWater += parseInt(tank.waterlevel);
|
|
|
|
|
// }
|
|
|
|
|
// });
|
|
|
|
|
|
|
|
|
|
// reply.send({
|
|
|
|
|
// status_code: 200,
|
|
|
|
|
// data: updated_data,
|
|
|
|
|
// totalDrinkingWaterInSump: sumSumpDrinkingWater,
|
|
|
|
|
// totalDrinkingWaterInOverhead: sumOverheadDrinkingWater
|
|
|
|
|
// });
|
|
|
|
|
|
|
|
|
|
// return { message: 'success' };
|
|
|
|
|
// } catch (err) {
|
|
|
|
|
// throw boom.boomify(err);
|
|
|
|
|
// }
|
|
|
|
|
// };
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
exports.getTanklevels = async (req, reply) => {
|
|
|
|
|
try {
|
|
|
|
|
const customerId = req.params.customerId;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const updated_data = await Tank.find({ customerId: customerId });
|
|
|
|
|
|
|
|
|
|
reply.send({ status_code: 200, data: updated_data});
|
|
|
|
|
|
|
|
|
|
let sumSumpDrinkingWater = 0;
|
|
|
|
|
let sumOverheadDrinkingWater = 0;
|
|
|
|
|
let sumSumpBoreWater = 0;
|
|
|
|
|
let sumOverheadBoreWater = 0;
|
|
|
|
|
|
|
|
|
|
updated_data.forEach((tank) => {
|
|
|
|
|
if (tank.tankLocation === 'sump' && tank.typeOfWater === 'Drinking Water') {
|
|
|
|
|
sumSumpDrinkingWater += parseInt(tank.waterlevel);
|
|
|
|
|
} else if (tank.tankLocation === 'overhead' && tank.typeOfWater === 'Drinking Water') {
|
|
|
|
|
sumOverheadDrinkingWater += parseInt(tank.waterlevel);
|
|
|
|
|
} else if (tank.tankLocation === 'sump' && tank.typeOfWater === 'Bore Water') {
|
|
|
|
|
sumSumpBoreWater += parseInt(tank.waterlevel);
|
|
|
|
|
} else if (tank.tankLocation === 'overhead' && tank.typeOfWater === 'Bore Water') {
|
|
|
|
|
sumOverheadBoreWater += parseInt(tank.waterlevel);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
reply.send({
|
|
|
|
|
status_code: 200,
|
|
|
|
|
data: updated_data,
|
|
|
|
|
totalDrinkingWaterInSump: sumSumpDrinkingWater,
|
|
|
|
|
totalDrinkingWaterInOverhead: sumOverheadDrinkingWater,
|
|
|
|
|
totalBoreWaterInSump: sumSumpBoreWater,
|
|
|
|
|
totalBoreWaterInOverhead: sumOverheadBoreWater
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return { message: 'success' };
|
|
|
|
|
} catch (err) {
|
|
|
|
|
|
|
|
|
|
return { message: 'success' };
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
catch (err) {
|
|
|
|
|
throw boom.boomify(err);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
exports.motorAction = async (req, reply) => {
|
|
|
|
|
try {
|
|
|
|
|
//let start_time,stop_time
|
|
|
|
|