From 5e79fa5a2061b6b0b561676c3773d29edeaa6600 Mon Sep 17 00:00:00 2001 From: Bhaskar Date: Tue, 1 Apr 2025 12:00:19 +0530 Subject: [PATCH] changes --- src/controllers/tanksController.js | 34 ++++++++++++++++-------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/src/controllers/tanksController.js b/src/controllers/tanksController.js index bdddffb8..1979964e 100644 --- a/src/controllers/tanksController.js +++ b/src/controllers/tanksController.js @@ -2767,14 +2767,15 @@ exports.getPumpsAndUsers = async (req, reply) => { } }; - exports.motoractiontest = async (req, reply) => { try { const { customerId } = req.params; const { motor_id, action } = req.body; - // Assuming you have a MongoDB model or connection - const customer = await db.collection('customers').findOne({ _id: customerId }); + // Fetch Tank data using customerId + const customer = await Tank.findOne({ customerId }); + + // console.log("Customer Data:", customer); if (!customer) { return reply.status(404).send({ success: false, message: "Customer not found" }); @@ -2782,22 +2783,22 @@ 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; + // Traverse through inputConnections instead of tanks.inputconnections + for (const inputConnection of customer.connections.inputConnections || []) { + console.log("Checking Motor ID:", inputConnection.motor_id); - if (action === 'start') { - await this.publishMotorStopStatus(motor_id, "2"); - } else if (action === 'stop') { - await this.publishMotorStopStatus(motor_id, "1"); - } else { - return reply.status(400).send({ success: false, message: "Invalid action" }); - } + if (String(inputConnection.motor_id) === String(motor_id)) { // Convert both to string + motorFound = true; - return reply.send({ success: true, message: `Motor ${action} command sent.` }); + if (action === "start") { + await this.publishMotorStopStatus(motor_id, "2"); + } else if (action === "stop") { + await this.publishMotorStopStatus(motor_id, "1"); + } else { + return reply.status(400).send({ success: false, message: "Invalid action" }); } + + return reply.send({ success: true, message: `Motor ${action} command sent.` }); } } @@ -2813,6 +2814,7 @@ exports.motoractiontest = async (req, reply) => { + const motorIntervals = {}; async function calculateTotalPumpedWater(customerId, motorId, start_instance_id) { const motorData = await MotorData.findOne({ customerId, motor_id: motorId, start_instance_id: start_instance_id });