|
|
@ -270,9 +270,12 @@ exports.motorAction = async (req, reply) => {
|
|
|
|
supplier_tank = req.body.from
|
|
|
|
supplier_tank = req.body.from
|
|
|
|
supplier_tank_type = req.body.from_type
|
|
|
|
supplier_tank_type = req.body.from_type
|
|
|
|
receiver_type = req.body.to_type
|
|
|
|
receiver_type = req.body.to_type
|
|
|
|
|
|
|
|
console.log(supplier_tank)
|
|
|
|
|
|
|
|
await Tank.findOneAndUpdate({customerId, tankName: receiver_tank}, { $set: { motor_status: 1 } });
|
|
|
|
|
|
|
|
|
|
|
|
if(supplier_tank_type==="sump" && receiver_type === "overhead"){
|
|
|
|
if(supplier_tank_type==="sump" && receiver_type === "overhead"){
|
|
|
|
const supplier_tank_info1 = await Tank.findOne({ customerId ,tankName:supplier_tank});
|
|
|
|
const supplier_tank_info1 = await Tank.findOne({ customerId ,tankName:supplier_tank});
|
|
|
|
|
|
|
|
console.log(supplier_tank_info1)
|
|
|
|
initial_update = parseInt(supplier_tank_info1.capacity.replace(/,/g, ''), 10)-200;
|
|
|
|
initial_update = parseInt(supplier_tank_info1.capacity.replace(/,/g, ''), 10)-200;
|
|
|
|
await Tank.findOneAndUpdate({customerId, tankName: supplier_tank}, { $set: { waterlevel: initial_update } });
|
|
|
|
await Tank.findOneAndUpdate({customerId, tankName: supplier_tank}, { $set: { waterlevel: initial_update } });
|
|
|
|
const supplier_tank_info = await Tank.findOne({ customerId ,tankName:supplier_tank});
|
|
|
|
const supplier_tank_info = await Tank.findOne({ customerId ,tankName:supplier_tank});
|
|
|
@ -289,6 +292,8 @@ exports.motorAction = async (req, reply) => {
|
|
|
|
// Check if updating should stop
|
|
|
|
// Check if updating should stop
|
|
|
|
if ((newSupplierWaterLevel/supplier_capacity)*100 <= 5 || (newWaterLevel/receiver_capacity)*100 >= 95 || (newWaterLevel/receiver_capacity)*100 >= desired_water_percentage) {
|
|
|
|
if ((newSupplierWaterLevel/supplier_capacity)*100 <= 5 || (newWaterLevel/receiver_capacity)*100 >= 95 || (newWaterLevel/receiver_capacity)*100 >= desired_water_percentage) {
|
|
|
|
clearInterval(intervalId)
|
|
|
|
clearInterval(intervalId)
|
|
|
|
|
|
|
|
await Tank.findOneAndUpdate({customerId, tankName: receiver_tank}, { $set: { motor_status: 0 } });
|
|
|
|
|
|
|
|
|
|
|
|
console.log("end");
|
|
|
|
console.log("end");
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
// Update water levels in database
|
|
|
|
// Update water levels in database
|
|
|
@ -307,6 +312,8 @@ exports.motorAction = async (req, reply) => {
|
|
|
|
|
|
|
|
|
|
|
|
if(supplier_tank_type==="bore" && receiver_type === "sump"){
|
|
|
|
if(supplier_tank_type==="bore" && receiver_type === "sump"){
|
|
|
|
const receiver_capacity = receiver_tank_info.capacity
|
|
|
|
const receiver_capacity = receiver_tank_info.capacity
|
|
|
|
|
|
|
|
await Tank.findOneAndUpdate({customerId, tankName: receiver_tank}, { $set: { motor_status: 1 } });
|
|
|
|
|
|
|
|
|
|
|
|
let receiver_waterlevel = parseInt(receiver_tank_info.waterlevel.replace(/,/g, ''), 10)
|
|
|
|
let receiver_waterlevel = parseInt(receiver_tank_info.waterlevel.replace(/,/g, ''), 10)
|
|
|
|
intervalId = setInterval(async function () {
|
|
|
|
intervalId = setInterval(async function () {
|
|
|
|
// Calculate new water levels
|
|
|
|
// Calculate new water levels
|
|
|
@ -314,6 +321,8 @@ exports.motorAction = async (req, reply) => {
|
|
|
|
// Check if updating should stop
|
|
|
|
// Check if updating should stop
|
|
|
|
if ((newWaterLevel/receiver_capacity)*100 >= 97 || (newWaterLevel/receiver_capacity)*100 >= desired_water_percentage ) {
|
|
|
|
if ((newWaterLevel/receiver_capacity)*100 >= 97 || (newWaterLevel/receiver_capacity)*100 >= desired_water_percentage ) {
|
|
|
|
clearInterval(intervalId)
|
|
|
|
clearInterval(intervalId)
|
|
|
|
|
|
|
|
await Tank.findOneAndUpdate({customerId, tankName: receiver_tank}, { $set: { motor_status: 0 } });
|
|
|
|
|
|
|
|
|
|
|
|
console.log("end");
|
|
|
|
console.log("end");
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
// Update water levels in database
|
|
|
|
// Update water levels in database
|
|
|
@ -404,6 +413,8 @@ exports.motorAction = async (req, reply) => {
|
|
|
|
// stop_time = new Date().toLocaleString('en-US', {timeZone: 'Asia/Kolkata'})
|
|
|
|
// stop_time = new Date().toLocaleString('en-US', {timeZone: 'Asia/Kolkata'})
|
|
|
|
// console.log(stop_time)
|
|
|
|
// console.log(stop_time)
|
|
|
|
clearInterval(intervalId);
|
|
|
|
clearInterval(intervalId);
|
|
|
|
|
|
|
|
await Tank.findOneAndUpdate({customerId, tankName: receiver_tank}, { $set: { motor_status: 0 } });
|
|
|
|
|
|
|
|
|
|
|
|
// reply.send({ status_code: 200, "stop time": stop_time});
|
|
|
|
// reply.send({ status_code: 200, "stop time": stop_time});
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
throw new Error("Invalid action");
|
|
|
|
throw new Error("Invalid action");
|
|
|
|