notification changes

master
Bhaskar 10 months ago
parent 4aca575e86
commit 88739037c6

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

Loading…
Cancel
Save