made changes in tanks start and stop

master
varun 2 years ago
parent b8075479b8
commit bfc2a0f10b

@ -231,15 +231,15 @@ exports.motorAction = async (req, reply) => {
const receiver_capacity = parseInt((receiver_tank_info.capacity).replace(/,/g, ''), 10)
const desired_water_percentage = parseInt((req.body.percentage).replace(/,/g, ''), 10)
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"){
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"){
@ -251,6 +251,17 @@ exports.motorAction = async (req, reply) => {
// 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 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);
let supplier_waterlevel = parseInt(supplier_tank_info.waterlevel.replace(/,/g, ''), 10)
// console.log(supplier_waterlevel)
@ -268,7 +279,14 @@ exports.motorAction = async (req, reply) => {
clearInterval(intervals[receiver_tank]); // Clear the interval for this tank
delete intervals[receiver_tank];
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);
} else {
// Update water levels in database
@ -416,6 +434,13 @@ exports.motorAction = async (req, reply) => {
else if (action === "stop") {
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)
// clearInterval(intervalId);
await Tank.findOneAndUpdate({customerId, tankName: receiver_tank,tankLocation:(req.body.to_type).toLowerCase()}, { $set: { motor_status: "0" } });

@ -23,7 +23,7 @@ const tanksSchema = new mongoose.Schema({
motor_status: { type: String, default: 0 },
connections: {
source: { type: String},
inputConnections: [{ inputConnections: String,input_type:String }],
inputConnections: [{ inputConnections: String,input_type:String,motor_status:String }],
outputConnections: [{ outputConnections: String,output_type:String }]
}

Loading…
Cancel
Save