From ba19fba6e0051074d82767670421b4ae135b1ed4 Mon Sep 17 00:00:00 2001 From: Varun Date: Thu, 27 Mar 2025 10:50:42 +0530 Subject: [PATCH 1/4] added started by and stopped by in motordata --- src/controllers/tanksController.js | 24 +++++++++++++++--------- src/models/tanks.js | 3 ++- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/src/controllers/tanksController.js b/src/controllers/tanksController.js index b1911fe7..35c4d24f 100644 --- a/src/controllers/tanksController.js +++ b/src/controllers/tanksController.js @@ -2854,7 +2854,8 @@ exports.motorAction = async (req, reply) => { supplier_type: req.body.from_type, receiver_type: req.body.to_type, startTime: req.body.startTime, - receiverInitialwaterlevel: parseInt(receiverTank.waterlevel, 10) + receiverInitialwaterlevel: parseInt(receiverTank.waterlevel, 10), + started_by:loggedInUser }); await newMotorData.save(); console.log("entered time",motorId,motorStopStatus) @@ -2989,7 +2990,8 @@ exports.motorAction = async (req, reply) => { stopTime: currentTime, receiverfinalwaterlevel: receiverFinalWaterLevel.toString(), quantity_delivered: quantityDelivered.toString(), - runtime: runtime.toString() + runtime: runtime.toString(), + stopped_by:loggedInUser } } ); @@ -3021,7 +3023,8 @@ exports.motorAction = async (req, reply) => { receiver_type: req.body.to_type, startTime: req.body.startTime, receiverInitialwaterlevel:parseInt(receiver_tank_info7.waterlevel, 10), - supplierInitialwaterlevel:parseInt(supplier_tank_info7.waterlevel, 10) + supplierInitialwaterlevel:parseInt(supplier_tank_info7.waterlevel, 10), + started_by:loggedInUser }); await newMotorData.save(); // If threshold type is percentage, calculate percentage threshold @@ -3102,7 +3105,8 @@ exports.motorAction = async (req, reply) => { $set: { stopTime:stopTime, receiverfinalwaterlevel: receiverFinalWaterLevel.toString(), - quantity_delivered: quantityDelivered.toString() + quantity_delivered: quantityDelivered.toString(), + stopped_by:loggedInUser } } ); @@ -3129,7 +3133,7 @@ exports.motorAction = async (req, reply) => { } } - await stopMotor(motorId, customerId, dynamicInstanceId); + await stopMotor(motorId, customerId, dynamicInstanceId,loggedInUser); try { @@ -3166,7 +3170,7 @@ exports.motorAction = async (req, reply) => { }; -async function stopMotor(motorId, customerId, start_instance_id) { +async function stopMotor(motorId, customerId, start_instance_id,loggedInUser) { const currentTime = moment().tz('Asia/Kolkata').format('DD-MMM-YYYY - HH:mm'); await Tank.updateOne( { customerId, "connections.inputConnections.motor_id": motorId }, @@ -3200,7 +3204,7 @@ async function stopMotor(motorId, customerId, start_instance_id) { await MotorData.updateOne( { customerId, motor_id: motorId, start_instance_id }, - { $set: { stopTime: currentTime, receiverfinalwaterlevel: receiverFinalWaterLevel.toString(), quantity_delivered: quantityDelivered.toString(), runtime: runtime } } + { $set: { stopTime: currentTime, receiverfinalwaterlevel: receiverFinalWaterLevel.toString(), quantity_delivered: quantityDelivered.toString(), runtime: runtime,stopped_by:loggedInUser } } ); } } @@ -6094,7 +6098,8 @@ async function processIotData(hw_Id, data) { supplier_type: inputConnection.input_type, receiver_type: motorTank.tankLocation, startTime: formattedTime, - receiverInitialwaterlevel: parseInt(inputConnection.water_level, 10) + receiverInitialwaterlevel: parseInt(inputConnection.water_level, 10), + started_by:"manual" }); await newMotorData.save(); @@ -6143,7 +6148,8 @@ async function processIotData(hw_Id, data) { stopTime: currentTime, receiverfinalwaterlevel: receiverFinalWaterLevel.toString(), quantity_delivered: quantityDelivered.toString(), - runtime: runtime.toString() + runtime: runtime.toString(), + stopped_by:"manual" } } ); diff --git a/src/models/tanks.js b/src/models/tanks.js index a5fede93..c6d700d3 100644 --- a/src/models/tanks.js +++ b/src/models/tanks.js @@ -142,7 +142,8 @@ const motordataSchema = new mongoose.Schema({ quantity_delivered:{ type: String, default: null }, receiverInitialwaterlevel: { type: String, default: "0" }, receiverfinalwaterlevel: { type: String, default: "0" }, - + started_by: { type: String, default: "user" }, + stopped_by: { type: String, default: "user" } }); From febba81f0e7f149a8b06f36b98226357edf2824d Mon Sep 17 00:00:00 2001 From: Varun Date: Thu, 27 Mar 2025 12:24:03 +0530 Subject: [PATCH 2/4] changes --- src/controllers/tanksController.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/controllers/tanksController.js b/src/controllers/tanksController.js index 35c4d24f..c875b36a 100644 --- a/src/controllers/tanksController.js +++ b/src/controllers/tanksController.js @@ -2800,6 +2800,7 @@ exports.motorAction = async (req, reply) => { { role: "Staff", name: users.staff.staff.find(staff => staff.phone === phone).name, phone } : null; if (!loggedInUser) return reply.status(404).send({ error: "User not found" }); + console.log(loggedInUser) const fcmToken = users.fcmIds ? users.fcmIds.filter(id => id) : []; const receiverTank = await Tank.findOne({ customerId, tankName: req.body.to, tankLocation: req.body.to_type.toLowerCase() }); From e12bbbbb5d15f202538ec5cba4cdd7979887de78 Mon Sep 17 00:00:00 2001 From: Varun Date: Thu, 27 Mar 2025 12:27:29 +0530 Subject: [PATCH 3/4] changes --- src/controllers/tanksController.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/controllers/tanksController.js b/src/controllers/tanksController.js index c875b36a..c95ed3c5 100644 --- a/src/controllers/tanksController.js +++ b/src/controllers/tanksController.js @@ -2856,7 +2856,7 @@ exports.motorAction = async (req, reply) => { receiver_type: req.body.to_type, startTime: req.body.startTime, receiverInitialwaterlevel: parseInt(receiverTank.waterlevel, 10), - started_by:loggedInUser + started_by:loggedInUser.name }); await newMotorData.save(); console.log("entered time",motorId,motorStopStatus) @@ -3025,7 +3025,7 @@ exports.motorAction = async (req, reply) => { startTime: req.body.startTime, receiverInitialwaterlevel:parseInt(receiver_tank_info7.waterlevel, 10), supplierInitialwaterlevel:parseInt(supplier_tank_info7.waterlevel, 10), - started_by:loggedInUser + started_by:loggedInUser.name }); await newMotorData.save(); // If threshold type is percentage, calculate percentage threshold @@ -3107,7 +3107,7 @@ exports.motorAction = async (req, reply) => { stopTime:stopTime, receiverfinalwaterlevel: receiverFinalWaterLevel.toString(), quantity_delivered: quantityDelivered.toString(), - stopped_by:loggedInUser + stopped_by:loggedInUser.name } } ); @@ -3126,7 +3126,7 @@ exports.motorAction = async (req, reply) => { }); let dynamicInstanceId = null; - + let user_name = loggedInUser.name if (tankWithMotor) { const connection = tankWithMotor.connections.inputConnections.find(conn => conn.motor_id === motorId); if (connection && connection.start_instance_id) { @@ -3134,7 +3134,7 @@ exports.motorAction = async (req, reply) => { } } - await stopMotor(motorId, customerId, dynamicInstanceId,loggedInUser); + await stopMotor(motorId, customerId, dynamicInstanceId,user_name); try { @@ -3171,7 +3171,7 @@ exports.motorAction = async (req, reply) => { }; -async function stopMotor(motorId, customerId, start_instance_id,loggedInUser) { +async function stopMotor(motorId, customerId, start_instance_id,user_name) { const currentTime = moment().tz('Asia/Kolkata').format('DD-MMM-YYYY - HH:mm'); await Tank.updateOne( { customerId, "connections.inputConnections.motor_id": motorId }, @@ -3205,7 +3205,7 @@ async function stopMotor(motorId, customerId, start_instance_id,loggedInUser) { await MotorData.updateOne( { customerId, motor_id: motorId, start_instance_id }, - { $set: { stopTime: currentTime, receiverfinalwaterlevel: receiverFinalWaterLevel.toString(), quantity_delivered: quantityDelivered.toString(), runtime: runtime,stopped_by:loggedInUser } } + { $set: { stopTime: currentTime, receiverfinalwaterlevel: receiverFinalWaterLevel.toString(), quantity_delivered: quantityDelivered.toString(), runtime: runtime,stopped_by:user_name } } ); } } From a8ca0e9f4faded716cc77ac8d6c61c2876141778 Mon Sep 17 00:00:00 2001 From: Varun Date: Thu, 27 Mar 2025 12:50:39 +0530 Subject: [PATCH 4/4] changes --- src/controllers/tanksController.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/controllers/tanksController.js b/src/controllers/tanksController.js index c95ed3c5..a351a92e 100644 --- a/src/controllers/tanksController.js +++ b/src/controllers/tanksController.js @@ -2992,7 +2992,7 @@ exports.motorAction = async (req, reply) => { receiverfinalwaterlevel: receiverFinalWaterLevel.toString(), quantity_delivered: quantityDelivered.toString(), runtime: runtime.toString(), - stopped_by:loggedInUser + stopped_by:loggedInUser.name } } ); @@ -3127,6 +3127,7 @@ exports.motorAction = async (req, reply) => { let dynamicInstanceId = null; let user_name = loggedInUser.name + console.log(user_name,"user_name in stop1") if (tankWithMotor) { const connection = tankWithMotor.connections.inputConnections.find(conn => conn.motor_id === motorId); if (connection && connection.start_instance_id) { @@ -3172,6 +3173,7 @@ exports.motorAction = async (req, reply) => { async function stopMotor(motorId, customerId, start_instance_id,user_name) { + console.log(user_name,"user_name in stop2") const currentTime = moment().tz('Asia/Kolkata').format('DD-MMM-YYYY - HH:mm'); await Tank.updateOne( { customerId, "connections.inputConnections.motor_id": motorId },