|
|
|
@ -225,11 +225,6 @@ exports.updateTanklevels1 = async (req, reply) => {
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
exports.getTanklevels = async (req, reply) => {
|
|
|
|
|
try {
|
|
|
|
|
const customerId = req.params.customerId;
|
|
|
|
@ -249,17 +244,7 @@ exports.getTanklevels = async (req, reply) => {
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const changingfrom_tankwaterlevel = async (customerId,initial_update,supplier_tank_info) => {
|
|
|
|
|
//console.log(customerId,"0")
|
|
|
|
|
//console.log(update_level,"1")
|
|
|
|
|
//console.log(fromSump,"2")
|
|
|
|
|
|
|
|
|
|
var result = await Tank.findOneAndUpdate(
|
|
|
|
|
{customerId:customerId, tankName: supplier_tank_info.tankName}, { $set: { waterlevel: initial_update } }
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
return result.waterlevel;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -277,10 +262,12 @@ exports.motorAction = async (req, reply) => {
|
|
|
|
|
supplier_tank_type = req.body.from_type
|
|
|
|
|
|
|
|
|
|
if(supplier_tank_type==="sump"){
|
|
|
|
|
const supplier_tank_info1 = await Tank.findOne({ customerId ,tankName:supplier_tank});
|
|
|
|
|
initial_update = parseInt(supplier_tank_info1.capacity.replace(/,/g, ''), 10)-200;
|
|
|
|
|
await Tank.findOneAndUpdate({customerId, tankName: supplier_tank}, { $set: { waterlevel: initial_update } });
|
|
|
|
|
const supplier_tank_info = await Tank.findOne({ customerId ,tankName:supplier_tank});
|
|
|
|
|
initial_update = parseInt(supplier_tank_info.capacity.replace(/,/g, ''), 10)-200;
|
|
|
|
|
|
|
|
|
|
await changingfrom_tankwaterlevel(customerId,initial_update,supplier_tank_info);
|
|
|
|
|
|
|
|
|
|
//await changingfrom_tankwaterlevel(customerId,initial_update,supplier_tank_info);
|
|
|
|
|
let supplier_waterlevel = parseInt(supplier_tank_info.waterlevel.replace(/,/g, ''), 10)
|
|
|
|
|
let receiver_waterlevel = parseInt(receiver_tank_info.waterlevel.replace(/,/g, ''), 10)
|
|
|
|
|
intervalId = setInterval(async function () {
|
|
|
|
@ -306,13 +293,13 @@ exports.motorAction = async (req, reply) => {
|
|
|
|
|
}
|
|
|
|
|
}, 2000);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
if(supplier_tank_type==="bore"){
|
|
|
|
|
const supplier_tank_info1 = await Tank.findOne({ customerId ,tankName:supplier_tank});
|
|
|
|
|
initial_update = parseInt(supplier_tank_info1.capacity.replace(/,/g, ''), 10)/2;
|
|
|
|
|
await Tank.findOneAndUpdate({customerId, tankName: supplier_tank}, { $set: { waterlevel: initial_update } });
|
|
|
|
|
const supplier_tank_info = await Tank.findOne({ customerId ,tankName:supplier_tank});
|
|
|
|
|
initial_update = parseInt(supplier_tank_info.capacity.replace(/,/g, ''), 10)-200;
|
|
|
|
|
|
|
|
|
|
await changingfrom_tankwaterlevel(customerId,initial_update,supplier_tank_info);
|
|
|
|
|
let supplier_waterlevel = parseInt(supplier_tank_info.waterlevel.replace(/,/g, ''), 10)
|
|
|
|
|
let receiver_waterlevel = parseInt(receiver_tank_info.waterlevel.replace(/,/g, ''), 10)
|
|
|
|
|
intervalId = setInterval(async function () {
|
|
|
|
@ -357,4 +344,28 @@ exports.motorAction = async (req, reply) => {
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
exports.consumption = async (req, reply) => {
|
|
|
|
|
try {
|
|
|
|
|
const customerId = req.params.customerId;
|
|
|
|
|
const tanks = await Tank.find({ customerId });
|
|
|
|
|
|
|
|
|
|
for (const tank of tanks) {
|
|
|
|
|
const tankId = tank._id;
|
|
|
|
|
let capacity = parseInt(tank.capacity.replace(/,/g, ''), 10);
|
|
|
|
|
let waterLevel = capacity*2+1700; // initial water level
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const newWaterLevel = Math.floor(waterLevel);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
console.log(newWaterLevel);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return { message: 'Water level updates started' };
|
|
|
|
|
} catch (err) {
|
|
|
|
|
throw boom.boomify(err);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|