diff --git a/src/controllers/tanksController.js b/src/controllers/tanksController.js index 17918fa1..61b3339b 100644 --- a/src/controllers/tanksController.js +++ b/src/controllers/tanksController.js @@ -2036,7 +2036,8 @@ else if (currentWaterLevel >= highWaterThreshold) { "connections.inputConnections.$.stopTime": req.body.stopTime, "connections.inputConnections.$.threshold_type": null, "connections.inputConnections.$.manual_threshold_time": null, - "connections.inputConnections.$.manual_threshold_percentage": null + "connections.inputConnections.$.manual_threshold_percentage": null, + "connections.inputConnections.$.stop_threshold_time": null } } ); @@ -2103,6 +2104,7 @@ else if (currentWaterLevel >= highWaterThreshold) { // Update the tank connections with start time and threshold time for await (const tank of Tank.find({ "connections.inputConnections.motor_id": motorId })) { this.publishMotorStopStatus(motorId, motorStopStatus); + const thresholdTime = moment().add(req.body.manual_threshold_time, 'minutes').toDate(); for await (const tank of Tank.find({ "connections.inputConnections.motor_id": motorId })) { const index = tank.connections.inputConnections.findIndex(connection => connection.motor_id === motorId); if (index !== -1) { @@ -2113,21 +2115,23 @@ else if (currentWaterLevel >= highWaterThreshold) { [`connections.inputConnections.${index}.manual_threshold_time`]: req.body.manual_threshold_time, [`connections.inputConnections.${index}.threshold_type`]: "time", [`connections.inputConnections.${index}.startTime`]: req.body.startTime, - [`connections.inputConnections.${index}.start_instance_id`]: start_instance_id + [`connections.inputConnections.${index}.start_instance_id`]: start_instance_id , + [`connections.inputConnections.${index}.stop_threshold_time`]: thresholdTime, } } ); } } - const thresholdTime = moment().add(req.body.manual_threshold_time, 'minutes').toDate(); + // const thresholdTime = moment().add(req.body.manual_threshold_time, 'minutes').toDate(); console.log(thresholdTime,"at start") const intervalId = setInterval(async () => { const supplierTank = await Tank.findOne({ customerId, tankName: req.body.from, tankLocation: req.body.from_type.toLowerCase() }); const currentWaterLevel = parseInt(supplierTank.waterlevel, 10); const currentWaterPercentage = (currentWaterLevel / parseInt(supplierTank.capacity.replace(/,/g, ''), 10)) * 100; - - if (moment().isSameOrAfter(thresholdTime) || currentWaterPercentage <= lowWaterThreshold) { + const receiverTank1 = await Tank.findOne({ customerId, tankName: req.body.to, tankLocation: req.body.to_type.toLowerCase() }); + const stop_threshold_time = receiverTank1.connections.inputConnections[inputConnectionIndex].stop_threshold_time + if (moment().isSameOrAfter(stop_threshold_time) || currentWaterPercentage <= lowWaterThreshold) { console.log(thresholdTime,"thresholdtime") console.log(new Date(),"new time") console.log(currentWaterPercentage,"currentWaterPercentage") @@ -2139,8 +2143,8 @@ else if (currentWaterLevel >= highWaterThreshold) { { $set: { "connections.inputConnections.$.motor_stop_status": "1", - "connections.inputConnections.$.threshold_type": null, + "connections.inputConnections.$.stop_threshold_time": null, "connections.inputConnections.$.manual_threshold_time": null, "connections.inputConnections.$.manual_threshold_percentage": null } diff --git a/src/models/tanks.js b/src/models/tanks.js index d9dfc9fd..b2da1e2d 100644 --- a/src/models/tanks.js +++ b/src/models/tanks.js @@ -70,6 +70,7 @@ const tanksSchema = new mongoose.Schema({ water_level: { type: String, default: null }, manual_threshold_percentage: { type: String, default: "90" }, manual_threshold_time: { type: String, default: null }, + stop_threshold_time: { type: String, default: null }, threshold_type: { type: String, default: "percentage" }, startTime: { type: String, default: null }, start_instance_id: { type: String, default: null },