changes in stop time in motoraction

master^2
Varun 9 months ago
parent abe8f01233
commit 1e9272faab

@ -2888,7 +2888,7 @@ exports.motorAction = async (req, reply) => {
// Perform stop operations in the background // Perform stop operations in the background
(async () => { (async () => {
await delay(300000);
const motorData = await MotorData.findOne({ customerId, motor_id: motorId, start_instance_id: start_instance_id }); const motorData = await MotorData.findOne({ customerId, motor_id: motorId, start_instance_id: start_instance_id });
if (motorData) { if (motorData) {
@ -2947,6 +2947,7 @@ exports.motorAction = async (req, reply) => {
this.publishMotorStopStatus(motorId, motorStopStatus); this.publishMotorStopStatus(motorId, motorStopStatus);
for await (const tank of Tank.find({ "connections.inputConnections.motor_id": motorId })) { for await (const tank of Tank.find({ "connections.inputConnections.motor_id": motorId })) {
const index = tank.connections.inputConnections.findIndex(connection => connection.motor_id === motorId); const index = tank.connections.inputConnections.findIndex(connection => connection.motor_id === motorId);
if (index !== -1) { if (index !== -1) {
await Tank.updateOne( await Tank.updateOne(
{ customerId, "connections.inputConnections.motor_id": motorId }, { customerId, "connections.inputConnections.motor_id": motorId },
@ -2978,7 +2979,7 @@ exports.motorAction = async (req, reply) => {
// fcmToken, // fcmToken,
// `Motor has reached its time threshold of ${req.body.manual_threshold_time} minutes and will stop.` // `Motor has reached its time threshold of ${req.body.manual_threshold_time} minutes and will stop.`
// ); // );
const currentTime = moment().tz('Asia/Kolkata').format('DD-MMM-YYYY - HH:mm');
await Tank.updateOne( await Tank.updateOne(
{ customerId, "connections.inputConnections.motor_id": motorId }, { customerId, "connections.inputConnections.motor_id": motorId },
{ {
@ -2987,7 +2988,8 @@ exports.motorAction = async (req, reply) => {
"connections.inputConnections.$.threshold_type": null, "connections.inputConnections.$.threshold_type": null,
"connections.inputConnections.$.manual_threshold_time": null, "connections.inputConnections.$.manual_threshold_time": null,
"connections.inputConnections.$.manual_threshold_percentage": null "connections.inputConnections.$.manual_threshold_percentage": null,
"connections.inputConnections.$.stopTime": currentTime,
} }
} }
); );
@ -3015,7 +3017,7 @@ exports.motorAction = async (req, reply) => {
delete motorIntervals[motorId]; // Remove from interval object delete motorIntervals[motorId]; // Remove from interval object
this.publishMotorStopStatus(motorId, "1"); this.publishMotorStopStatus(motorId, "1");
await delay(300000);
const motorData = await MotorData.findOne({ customerId, motor_id: motorId, start_instance_id: start_instance_id }); const motorData = await MotorData.findOne({ customerId, motor_id: motorId, start_instance_id: start_instance_id });
if (motorData) { if (motorData) {
const receiverTank = await Tank.findOne({ customerId, tankName: motorData.receiverTank, tankLocation: motorData.receiver_type.toLowerCase() }); const receiverTank = await Tank.findOne({ customerId, tankName: motorData.receiverTank, tankLocation: motorData.receiver_type.toLowerCase() });
@ -3033,7 +3035,7 @@ exports.motorAction = async (req, reply) => {
{ customerId, motor_id: motorId, start_instance_id: start_instance_id }, { customerId, motor_id: motorId, start_instance_id: start_instance_id },
{ {
$set: { $set: {
stopTime: req.body.stopTime, stopTime: currentTime,
receiverfinalwaterlevel: receiverFinalWaterLevel.toString(), receiverfinalwaterlevel: receiverFinalWaterLevel.toString(),
quantity_delivered: quantityDelivered.toString() quantity_delivered: quantityDelivered.toString()
} }
@ -5716,6 +5718,8 @@ client.on('message', async (topic, message) => {
if (inputConnection.motor_stop_status === "2" && status === 1) { if (inputConnection.motor_stop_status === "2" && status === 1) {
inputConnection.motor_stop_status = "1"; inputConnection.motor_stop_status = "1";
const currentTime = moment().tz('Asia/Kolkata').format('DD-MMM-YYYY - HH:mm');
inputConnection.stoptTime = currentTime;
// Emit motor stop notification with tankName // Emit motor stop notification with tankName
// eventEmitter.emit( // eventEmitter.emit(

Loading…
Cancel
Save