From fd4ff96b83a779e0674b66c809b4c1f43171774e Mon Sep 17 00:00:00 2001 From: Varun Date: Fri, 6 Sep 2024 14:44:50 +0530 Subject: [PATCH] change motor status --- src/controllers/tanksController.js | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/src/controllers/tanksController.js b/src/controllers/tanksController.js index a89267ac..c96496f9 100644 --- a/src/controllers/tanksController.js +++ b/src/controllers/tanksController.js @@ -3774,19 +3774,27 @@ exports.changeMotorStatus = async (req, reply) => { // Perform any necessary logic to handle motor status update from the device // For example, update a database with the new status, current, and temp values - const result = await Tank.findOneAndUpdate( - { motor_id: motor_id }, - { $set: { motor_stop_status: action } - }); + + await Tank.updateOne( + { "connections.inputConnections.motor_id": motor_id }, + { + $set: { + "connections.inputConnections.$.motor_stop_status":action , + + } + } + ); + + // Send immediat // Fetch the motor_status for the given motor_id - const updatedMotor = await Tank.findOne({ motor_id: motor_id }); + // Send the response with motor_stop_status and motor_status reply.send({ status_code: 200, motor_stop_status: action, - motor_status: updatedMotor.motor_status // Assuming motor_status is a field in your Tank model + // motor_status: updatedMotor.motor_status // Assuming motor_status is a field in your Tank model });