From 3af6c6470286148db669947b86e9dd3349fa39bd Mon Sep 17 00:00:00 2001 From: Varun Date: Tue, 1 Apr 2025 11:32:25 +0530 Subject: [PATCH 1/2] changes --- src/controllers/tanksController.js | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/src/controllers/tanksController.js b/src/controllers/tanksController.js index bdddffb8..c7e3d7ca 100644 --- a/src/controllers/tanksController.js +++ b/src/controllers/tanksController.js @@ -2774,8 +2774,7 @@ exports.motoractiontest = async (req, reply) => { const { motor_id, action } = req.body; // Assuming you have a MongoDB model or connection - const customer = await db.collection('customers').findOne({ _id: customerId }); - + const customer = await Tank.findOne({ customerId }); if (!customer) { return reply.status(404).send({ success: false, message: "Customer not found" }); } @@ -2783,10 +2782,10 @@ exports.motoractiontest = async (req, reply) => { let motorFound = false; // Traverse through tanks and their input connections - for (const tank of customer.tanks || []) { - for (const inputConnection of tank.inputconnections || []) { - if (inputConnection.motor_id === motor_id) { - motorFound = true; + + + + if (action === 'start') { await this.publishMotorStopStatus(motor_id, "2"); @@ -2796,10 +2795,10 @@ exports.motoractiontest = async (req, reply) => { return reply.status(400).send({ success: false, message: "Invalid action" }); } - return reply.send({ success: true, message: `Motor ${action} command sent.` }); - } - } - } + + + + if (!motorFound) { return reply.status(404).send({ success: false, message: "Motor ID not found" }); From efa92448d5dd4cdcf41fbde4424e33f02b1782ce Mon Sep 17 00:00:00 2001 From: Varun Date: Tue, 1 Apr 2025 11:54:23 +0530 Subject: [PATCH 2/2] 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 c7e3d7ca..3afa3376 100644 --- a/src/controllers/tanksController.js +++ b/src/controllers/tanksController.js @@ -6146,7 +6146,7 @@ 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(motorTank.waterlevel, 10), started_by:"manual" }); await newMotorData.save();