|
|
@ -231,15 +231,15 @@ exports.motorAction = async (req, reply) => {
|
|
|
|
const receiver_capacity = parseInt((receiver_tank_info.capacity).replace(/,/g, ''), 10)
|
|
|
|
const receiver_capacity = parseInt((receiver_tank_info.capacity).replace(/,/g, ''), 10)
|
|
|
|
const desired_water_percentage = parseInt((req.body.percentage).replace(/,/g, ''), 10)
|
|
|
|
const desired_water_percentage = parseInt((req.body.percentage).replace(/,/g, ''), 10)
|
|
|
|
const intervals = {};
|
|
|
|
const intervals = {};
|
|
|
|
|
|
|
|
const supplier_tank = req.body.from
|
|
|
|
|
|
|
|
const supplier_tank_type = (req.body.from_type).toLowerCase()
|
|
|
|
|
|
|
|
const receiver_type = (req.body.to_type).toLowerCase()
|
|
|
|
|
|
|
|
console.log(supplier_tank)
|
|
|
|
|
|
|
|
|
|
|
|
if(action === "start"){
|
|
|
|
if(action === "start"){
|
|
|
|
const start_time = new Date().toLocaleString('en-US', {timeZone: 'Asia/Kolkata'})
|
|
|
|
const start_time = new Date().toLocaleString('en-US', {timeZone: 'Asia/Kolkata'})
|
|
|
|
|
|
|
|
|
|
|
|
const supplier_tank = req.body.from
|
|
|
|
|
|
|
|
const supplier_tank_type = (req.body.from_type).toLowerCase()
|
|
|
|
|
|
|
|
const receiver_type = (req.body.to_type).toLowerCase()
|
|
|
|
|
|
|
|
console.log(supplier_tank)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(supplier_tank_type==="sump" && receiver_type === "overhead"){
|
|
|
|
if(supplier_tank_type==="sump" && receiver_type === "overhead"){
|
|
|
@ -251,6 +251,17 @@ exports.motorAction = async (req, reply) => {
|
|
|
|
// await Tank.findOneAndUpdate({customerId, tankName: supplier_tank,tankLocation:supplier_tank_type}, { $set: { waterlevel: initial_update } });
|
|
|
|
// await Tank.findOneAndUpdate({customerId, tankName: supplier_tank,tankLocation:supplier_tank_type}, { $set: { waterlevel: initial_update } });
|
|
|
|
const supplier_tank_info = await Tank.findOne({ customerId ,tankName:supplier_tank,tankLocation:supplier_tank_type});
|
|
|
|
const supplier_tank_info = await Tank.findOne({ customerId ,tankName:supplier_tank,tankLocation:supplier_tank_type});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const overheadTank = await Tank.findOne({ customerId, tankName: receiver_tank, tankLocation: receiver_type });
|
|
|
|
|
|
|
|
const connection = overheadTank.connections.inputConnections.find((conn) => conn.inputConnections === supplier_tank);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (connection) {
|
|
|
|
|
|
|
|
connection.motor_status = "1";
|
|
|
|
|
|
|
|
await overheadTank.save();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 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 supplier_waterlevel = parseInt(supplier_tank_info.waterlevel.replace(/,/g, ''), 10)
|
|
|
|
// console.log(supplier_waterlevel)
|
|
|
|
// console.log(supplier_waterlevel)
|
|
|
@ -268,6 +279,13 @@ exports.motorAction = async (req, reply) => {
|
|
|
|
clearInterval(intervals[receiver_tank]); // Clear the interval for this tank
|
|
|
|
clearInterval(intervals[receiver_tank]); // Clear the interval for this tank
|
|
|
|
delete intervals[receiver_tank];
|
|
|
|
delete intervals[receiver_tank];
|
|
|
|
await Tank.findOneAndUpdate({customerId, tankName: receiver_tank,tankLocation:receiver_type}, { $set: { motor_status: "0" } });
|
|
|
|
await Tank.findOneAndUpdate({customerId, tankName: receiver_tank,tankLocation:receiver_type}, { $set: { motor_status: "0" } });
|
|
|
|
|
|
|
|
const overheadTank = await Tank.findOne({ customerId, tankName: receiver_tank, tankLocation: receiver_type });
|
|
|
|
|
|
|
|
const connection = overheadTank.connections.inputConnections.find((conn) => conn.inputConnections === supplier_tank);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (connection) {
|
|
|
|
|
|
|
|
connection.motor_status = "0";
|
|
|
|
|
|
|
|
await overheadTank.save();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
console.log("end for"+receiver_tank);
|
|
|
|
console.log("end for"+receiver_tank);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
@ -416,6 +434,13 @@ exports.motorAction = async (req, reply) => {
|
|
|
|
|
|
|
|
|
|
|
|
else if (action === "stop") {
|
|
|
|
else if (action === "stop") {
|
|
|
|
const stop_time = new Date().toLocaleString('en-US', {timeZone: 'Asia/Kolkata'})
|
|
|
|
const stop_time = new Date().toLocaleString('en-US', {timeZone: 'Asia/Kolkata'})
|
|
|
|
|
|
|
|
const overheadTank = await Tank.findOne({ customerId, tankName: receiver_tank, tankLocation: receiver_type });
|
|
|
|
|
|
|
|
const connection = overheadTank.connections.inputConnections.find((conn) => conn.inputConnections === supplier_tank);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (connection) {
|
|
|
|
|
|
|
|
connection.motor_status = "0";
|
|
|
|
|
|
|
|
await overheadTank.save();
|
|
|
|
|
|
|
|
}
|
|
|
|
// console.log(stop_time)
|
|
|
|
// console.log(stop_time)
|
|
|
|
// clearInterval(intervalId);
|
|
|
|
// clearInterval(intervalId);
|
|
|
|
await Tank.findOneAndUpdate({customerId, tankName: receiver_tank,tankLocation:(req.body.to_type).toLowerCase()}, { $set: { motor_status: "0" } });
|
|
|
|
await Tank.findOneAndUpdate({customerId, tankName: receiver_tank,tankLocation:(req.body.to_type).toLowerCase()}, { $set: { motor_status: "0" } });
|
|
|
|