Bhaskara Kishore 2 years ago
commit 95ac32d682

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

Loading…
Cancel
Save