diff --git a/src/controllers/tanksController.js b/src/controllers/tanksController.js index ff7e52fd..cfa15f03 100644 --- a/src/controllers/tanksController.js +++ b/src/controllers/tanksController.js @@ -1972,28 +1972,30 @@ else if (currentWaterLevel >= highWaterThreshold) { } // Determine the motor stop status based on the action let motorStopStatus; + const blockName = req.body.from || "Unknown Block"; // Provide a fallback if `from` is missing + const tankName = req.body.to || "Unknown Tank"; // Provide a fallback if `to` is missing + const stopTime = req.body.stopTime || new Date().toISOString(); + const motorOnType = req.body.motor_on_type || "manual"; if (action === "start") { const startTime = req.body.startTime; - const motorOnType = req.body.motor_on_type || "manual"; const stopCriteria = motorOnType === "time" ? `${req.body.manual_threshold_time} minutes` : `${req.body.manual_threshold_litres} litres`; - eventEmitter.emit( + eventEmitter.emit( "motorStart", fcmToken, new Date().toISOString(), motorId, currentWaterLevel, - req.body.from, // Block Name - req.body.to, // Tank Name + blockName, // Block Name + tankName, // Tank Name startTime, motorOnType, stopCriteria ); - // Add any additional logic for starting the motor here await Tank.updateOne( { customerId, "connections.inputConnections.motor_id": motorId }, { $set: { "connections.inputConnections.$.motor_stop_status": "2" } } @@ -2002,7 +2004,16 @@ else if (currentWaterLevel >= highWaterThreshold) { reply.code(200).send({ message: "Motor started successfully." }); } else if (action === "stop") { motorStopStatus = "1"; // If action is stop, set stop status to "1" - // eventEmitter.emit('motorStop', fcmToken, motorId, currentWaterLevel,blockName, tankName,stopTime,motorOnType); + eventEmitter.emit( + "motorStop", + fcmToken, + motorId, + currentWaterLevel, + blockName, + tankName, + stopTime, + motorOnType + ); } else { throw new Error("Invalid action provided."); }