From d8f8f0ed2f6f60e9bde8081fa44c9c3cb94b8cad Mon Sep 17 00:00:00 2001 From: Bhaskar Date: Mon, 20 Jan 2025 15:59:23 +0530 Subject: [PATCH 1/5] notification manualmethods --- src/controllers/tanksController.js | 56 ++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/src/controllers/tanksController.js b/src/controllers/tanksController.js index 8bf74b93..7da84e2c 100644 --- a/src/controllers/tanksController.js +++ b/src/controllers/tanksController.js @@ -2238,6 +2238,43 @@ console.log(fcmToken) "connections.inputConnections.$.threshold_type": "time" } } ); + await Tank.updateOne( + { customerId, "connections.inputConnections.motor_id": motorId }, + { + $set: { + "connections.inputConnections.$.motor_stop_status": "2", + "connections.inputConnections.$.motor_on_type": "manual", + } + } + ); + + const startMessage = `Motor supplying water to '${tankName}' in block '${blockName}' started manually at ${startTime}.`; + eventEmitter.emit('sendMotorStartNotification', fcmToken, startMessage); + + // Schedule threshold check + // const thresholdTimeMs = manual_threshold_time * 60 * 1000; + motorIntervals[motorId] = setTimeout(async () => { + try { + const stopMessage = `Threshold time of ${manual_threshold_time} minutes reached for motor supplying water to '${tankName}' in block '${blockName}'.`; + eventEmitter.emit('sendThresholdTimeNotification', fcmToken, stopMessage); + + await Tank.updateOne( + { customerId, "connections.inputConnections.motor_id": motorId }, + { + $set: { + "connections.inputConnections.$.motor_stop_status": "1", + "connections.inputConnections.$.manual_threshold_time": null, + "connections.inputConnections.$.threshold_type": null, + } + } + ); + + delete motorIntervals[motorId]; + } catch (error) { + console.error("Error during threshold handling:", error); + } + }, thresholdTimeMs); + reply.code(200).send({ message: "Motor started successfully." }); // Schedule water level checks after motor start motorIntervals[motorId] = setInterval(async () => { @@ -2288,6 +2325,25 @@ console.log(fcmToken) stopTime, motorOnType ); + + await Tank.updateOne( + { customerId, "connections.inputConnections.motor_id": motorId }, + { + $set: { + "connections.inputConnections.$.motor_stop_status": "1", + "connections.inputConnections.$.motor_on_type": "manual", + } + } + ); + + const stopMessage = `Motor supplying water to '${tankName}' in block '${blockName}' stopped manually at ${stopTime}.`; + eventEmitter.emit('sendMotorStopNotification', fcmToken, stopMessage); + + if (motorIntervals[motorId]) { + clearTimeout(motorIntervals[motorId]); + delete motorIntervals[motorId]; + } + } else { throw new Error("Invalid action provided."); } From a1f518fdf217f8a11ecd8de01fa110edf6116014 Mon Sep 17 00:00:00 2001 From: Bhaskar Date: Mon, 20 Jan 2025 16:26:38 +0530 Subject: [PATCH 2/5] chnages --- src/controllers/tanksController.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/controllers/tanksController.js b/src/controllers/tanksController.js index 7da84e2c..84df5da0 100644 --- a/src/controllers/tanksController.js +++ b/src/controllers/tanksController.js @@ -2201,7 +2201,7 @@ console.log(fcmToken) motorIntervals[motorId] = setTimeout(async () => { try { // Perform threshold time logic (e.g., notification, motor stop) - console.log(`Threshold time of ${manualThresholdTime} minutes reached for motor ${motorId}`); + console.log(`Threshold time of ${manual_threshold_time} minutes reached for motor ${motorId}`); await Tank.updateOne( { customerId, "connections.inputConnections.motor_id": motorId }, { $set: { "connections.inputConnections.$.motor_stop_status": "1" } } @@ -2248,8 +2248,8 @@ console.log(fcmToken) } ); - const startMessage = `Motor supplying water to '${tankName}' in block '${blockName}' started manually at ${startTime}.`; - eventEmitter.emit('sendMotorStartNotification', fcmToken, startMessage); + // const startMessage = `Motor supplying water to '${tankName}' in block '${blockName}' started manually at ${startTime}.`; + // eventEmitter.emit('sendMotorStartNotification', fcmToken, startMessage); // Schedule threshold check // const thresholdTimeMs = manual_threshold_time * 60 * 1000; @@ -2336,8 +2336,8 @@ console.log(fcmToken) } ); - const stopMessage = `Motor supplying water to '${tankName}' in block '${blockName}' stopped manually at ${stopTime}.`; - eventEmitter.emit('sendMotorStopNotification', fcmToken, stopMessage); + // const stopMessage = `Motor supplying water to '${tankName}' in block '${blockName}' stopped manually at ${stopTime}.`; + // eventEmitter.emit('sendMotorStopNotification', fcmToken, stopMessage); if (motorIntervals[motorId]) { clearTimeout(motorIntervals[motorId]); From 8e6900e6c7df4623707041491b47eb23bda8f2b6 Mon Sep 17 00:00:00 2001 From: Bhaskar Date: Mon, 20 Jan 2025 17:36:12 +0530 Subject: [PATCH 3/5] chnages --- src/controllers/tanksController.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/controllers/tanksController.js b/src/controllers/tanksController.js index 84df5da0..46cdf23c 100644 --- a/src/controllers/tanksController.js +++ b/src/controllers/tanksController.js @@ -2255,8 +2255,8 @@ console.log(fcmToken) // const thresholdTimeMs = manual_threshold_time * 60 * 1000; motorIntervals[motorId] = setTimeout(async () => { try { - const stopMessage = `Threshold time of ${manual_threshold_time} minutes reached for motor supplying water to '${tankName}' in block '${blockName}'.`; - eventEmitter.emit('sendThresholdTimeNotification', fcmToken, stopMessage); + // const stopMessage = `Threshold time of ${manual_threshold_time} minutes reached for motor supplying water to '${tankName}' in block '${blockName}'.`; + // eventEmitter.emit('sendThresholdTimeNotification', fcmToken, stopMessage); await Tank.updateOne( { customerId, "connections.inputConnections.motor_id": motorId }, From 9773bb3f7c445a74f756ba581ab9e64238a3ad62 Mon Sep 17 00:00:00 2001 From: Bhaskar Date: Mon, 20 Jan 2025 17:41:49 +0530 Subject: [PATCH 4/5] changes --- src/controllers/tanksController.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/controllers/tanksController.js b/src/controllers/tanksController.js index 46cdf23c..026b7203 100644 --- a/src/controllers/tanksController.js +++ b/src/controllers/tanksController.js @@ -2178,7 +2178,7 @@ console.log(fcmToken) 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 - const motorOnType = req.body.motor_on_type || "App"; + const motorOnType = req.body.motor_on_type || "APP"; const manual_threshold_time = req.body.manual_threshold_time; if (action === "start") { From 12998d577ad379445c159fdf7bf7629cc064ca46 Mon Sep 17 00:00:00 2001 From: Bhaskar Date: Tue, 21 Jan 2025 11:00:09 +0530 Subject: [PATCH 5/5] changes --- src/controllers/tanksController.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/controllers/tanksController.js b/src/controllers/tanksController.js index 026b7203..8340c02b 100644 --- a/src/controllers/tanksController.js +++ b/src/controllers/tanksController.js @@ -1578,7 +1578,7 @@ eventEmitter.on( const message = `Tank Name: '${tankName}'\n` + `Pump started at: '${startTime}'\n` + - `Initiated by user(s): ${userNames}\n` + + `Initiated by : ${userNames}\n` + `Pump started by: '${motorOnType.toUpperCase()}'\n` + `Will stop at after: '${manual_threshold_time}' mins`; @@ -1604,7 +1604,7 @@ eventEmitter.on('motorStop', async (fcmTokens, tankName,stopTime, motorOnType) const message = `Tank Name: '${tankName}'\n` + `Pump stopped at: '${stopTime}'\n` + - `Initiated by user(s): ${userNames}\n` + + `Initiated by : ${userNames}\n` + `Motor On Type: '${motorOnType}'`; // Send the notification