|
|
|
@ -102,7 +102,7 @@ exports.deleteTanksInfo = async (req, reply) => {
|
|
|
|
|
try {
|
|
|
|
|
var customerId = req.params.customerId;
|
|
|
|
|
var tankName = req.query.tankName;
|
|
|
|
|
const tank = await Tank.findOneAndDelete({ tankName: tankName,customerId:customerId });
|
|
|
|
|
const tank = await Tank.findOneAndDelete({ tankName: tankName,customerId:customerId,tankLocation:req.body.tankLocation.toLowerCase() });
|
|
|
|
|
|
|
|
|
|
reply.send({ status_code: 200, data: tank});
|
|
|
|
|
// return tank;
|
|
|
|
@ -193,72 +193,6 @@ exports.updateTanklevels = async (req, reply) => {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
exports.updateTanklevels1 = async (req, reply) => {
|
|
|
|
|
try {
|
|
|
|
|
const customerId = req.params.customerId;
|
|
|
|
|
const tanks = await Tank.find({ customerId });
|
|
|
|
|
|
|
|
|
|
const intervals = {};
|
|
|
|
|
|
|
|
|
|
for (const tank of tanks) {
|
|
|
|
|
const tankName = tank.tankName;
|
|
|
|
|
const tank_type = tank.tankLocation
|
|
|
|
|
let capacity = parseInt(tank.capacity.replace(/,/g, ''), 10);
|
|
|
|
|
|
|
|
|
|
const waterLevel = parseInt(tank.waterLevel.replace(/,/g, ''), 10);
|
|
|
|
|
//capacity - 100; // initial water level
|
|
|
|
|
const intervalId = setInterval(async function () {
|
|
|
|
|
const motor_status = tank.motor_status
|
|
|
|
|
if(motor_status === "0"){
|
|
|
|
|
const newWaterLevel = Math.floor(waterLevel - 200);
|
|
|
|
|
console.log(tank.tankName,newWaterLevel)
|
|
|
|
|
const result = await Tank.findOneAndUpdate(
|
|
|
|
|
{ customerId, tankName, },
|
|
|
|
|
{ $set: { waterlevel: newWaterLevel } }
|
|
|
|
|
);
|
|
|
|
|
if (newWaterLevel === 0) {
|
|
|
|
|
clearInterval(intervals[tankName]);
|
|
|
|
|
console.log(`Stopped updating ${tankName}`);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
waterLevel = newWaterLevel;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
else{
|
|
|
|
|
if(tank.tankLocation==="overhead",motor_status==="1"){
|
|
|
|
|
tank_waterlevel = math.floor(waterLevel + 250)
|
|
|
|
|
const supplier_water= await findOne({customerId:req.params.customerId,tankName:req.body.from,tankLocation:req.body.from_type})
|
|
|
|
|
const supplier_waterlevel = parseInt(supplier_water.waterlevel .replace(/,/g, ''), 10);
|
|
|
|
|
const newSupplierWaterLevel = math.floor(supplier_waterlevel - 250)
|
|
|
|
|
|
|
|
|
|
await Tank.findOneAndUpdate({customerId:req.params.customerId,tankName:req.body.from,tankLocation:req.body.from_type}, { $set: { waterlevel: newSupplierWaterLevel } })
|
|
|
|
|
await tank.save()
|
|
|
|
|
}
|
|
|
|
|
if(tank.tankLocation==="sump",motor_status==="1"){
|
|
|
|
|
const sumpwaterlevel = math.floor(waterLevel + 250)
|
|
|
|
|
await tank.save()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// console.log(result);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}, 2000);
|
|
|
|
|
|
|
|
|
|
intervals[tankName] = intervalId;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return { message: 'Water level updates started' };
|
|
|
|
|
} catch (err) {
|
|
|
|
|
throw boom.boomify(err);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
exports.getTanklevels = async (req, reply) => {
|
|
|
|
|
try {
|
|
|
|
@ -786,3 +720,7 @@ exports.checkStatusofIot = async (req, reply) => {
|
|
|
|
|
reply.code(500).send({ error: err.message });
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|