bhaskar 2 years ago
commit d30bdaec58

@ -360,6 +360,14 @@ exports.motorAction = async (req, reply) => {
const receiver_capacity = parseInt(receiver_tank_info.capacity.replace(/,/g, ''), 10)
// console.log(receiver_capacity,"0",receiver_tank_info.tankName)
await Tank.findOneAndUpdate({customerId, tankName: receiver_tank,tankLocation:receiver_type}, { $set: { motor_status: "1" } });
const sumpTank = await Tank.findOne({ customerId, tankName: receiver_tank, tankLocation: receiver_type });
const connection = sumpTank.connections.inputConnections.find((conn) => conn.inputConnections === supplier_tank);
if (connection) {
connection.motor_status = "1";
await sumpTank.save();
}
let receiver_waterlevel = parseInt(receiver_tank_info.waterlevel.replace(/,/g, ''), 10)
// console.log(receiver_waterlevel,"1")
@ -376,6 +384,13 @@ exports.motorAction = async (req, reply) => {
await Tank.findOneAndUpdate({customerId, tankName: receiver_tank,tankLocation:receiver_type}, { $set: { motor_status: "0" } });
clearInterval(intervals[receiver_tank]); // Clear the interval for this tank
delete intervals[receiver_tank];
const sumpTank = await Tank.findOne({ customerId, tankName: receiver_tank, tankLocation: receiver_type });
const connection = sumpTank.connections.inputConnections.find((conn) => conn.inputConnections === supplier_tank);
if (connection) {
connection.motor_status = "0";
await sumpTank.save();
}
console.log("end for" + receiver_tank);
} else {
// Update water levels in database

@ -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,motor_status:String }],
inputConnections: [{ inputConnections: String,input_type:String,motor_status: { type: String, default: "0" } }],
outputConnections: [{ outputConnections: String,output_type:String }]
}

Loading…
Cancel
Save