From a356f2e263fd9627abeec2a143a4f1b7196a8c67 Mon Sep 17 00:00:00 2001 From: Varun Date: Wed, 26 Mar 2025 17:04:11 +0530 Subject: [PATCH] changes in stop motor --- src/controllers/tanksController.js | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/controllers/tanksController.js b/src/controllers/tanksController.js index e25884a9..aafe0a51 100644 --- a/src/controllers/tanksController.js +++ b/src/controllers/tanksController.js @@ -3274,7 +3274,24 @@ exports.motorAction = async (req, reply) => { } } else if (action === "stop") { - await stopMotor(motorId, customerId, start_instance_id); + // Dynamically find start_instance_id from tank + const tankWithMotor = await Tank.findOne({ + customerId, + "connections.inputConnections.motor_id": motorId + }); + + let dynamicInstanceId = null; + + if (tankWithMotor) { + const connection = tankWithMotor.connections.inputConnections.find(conn => conn.motor_id === motorId); + if (connection && connection.start_instance_id) { + dynamicInstanceId = connection.start_instance_id; + } + } + + await stopMotor(motorId, customerId, dynamicInstanceId); + + try {