From c85c87ca7292875bd51c89d1f2e9eac9029085a3 Mon Sep 17 00:00:00 2001 From: varun Date: Wed, 10 Jan 2024 03:06:23 -0500 Subject: [PATCH] read motor_status changed to motor_stop_status --- src/controllers/tanksController.js | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/src/controllers/tanksController.js b/src/controllers/tanksController.js index 35fe470f..c1904b40 100644 --- a/src/controllers/tanksController.js +++ b/src/controllers/tanksController.js @@ -1474,11 +1474,11 @@ exports.readMotorStatus = async (req, reply) => { return reply.status(404).send({ status_code: 404, message: 'Tank not found for the specified motor_id' }); } - const motor_status = motorInfo.motor_status; + const motor_stop_status = motorInfo.motor_stop_status; - reply.send({ status_code: 200, motor_status:motor_status }); + reply.send({ status_code: 200, motor_stop_status:motor_stop_status }); } catch (err) { throw boom.boomify(err); } @@ -1520,21 +1520,25 @@ exports.writeMotorStatus = async (req, reply) => { exports.changeMotorStatus = async (req, reply) => { try { const motor_id = req.body.motor_id; - const action =req.body.action + const action = req.body.action; // 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 } + }); - - const result = await Tank.findOneAndUpdate( - { motor_id: motor_id }, - { $set: { motor_stop_status: action } }); - - + // Fetch the motor_status for the given motor_id + const updatedMotor = await Tank.findOne({ motor_id: motor_id }); - reply.send({ status_code: 200,motor_stop_status: action }); + // 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 + }); } catch (err) { throw boom.boomify(err); }