From 5ad517d68236596e53bfd8e2c35c7b08f509a959 Mon Sep 17 00:00:00 2001 From: varun Date: Fri, 29 Dec 2023 03:36:02 -0500 Subject: [PATCH] changes in read and write motor --- src/controllers/tanksController.js | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/src/controllers/tanksController.js b/src/controllers/tanksController.js index f01e89fc..cf5a58c3 100644 --- a/src/controllers/tanksController.js +++ b/src/controllers/tanksController.js @@ -1481,14 +1481,21 @@ exports.motorstatus = async (req, reply) => { exports.readMotorStatus = async (req, reply) => { try { - const motor_id = req.query.motor_id; + const motor_id = req.body.motor_id; + console.log(motor_id) // Perform any necessary logic based on action (1: Start, 2: Stop) // For example, you can update a database or trigger an action - const motorInfo = await Tank.findOne({ motor_id: motor_id }); - const motor_status = motorInfo.motor_status + const motorInfo = await Tank.findOne({motor_id : motor_id }); + + if (!motorInfo) { + return reply.status(404).send({ status_code: 404, message: 'Tank not found for the specified motor_id' }); + } + + const motor_status = motorInfo.motor_status; + reply.send({ status_code: 200, motor_status:motor_status }); @@ -1508,17 +1515,10 @@ exports.writeMotorStatus = async (req, reply) => { // For example, update a database with the new status, current, and temp values let result; - if (status === 'on') { - result = await Tank.findOneAndUpdate( - { motor_id: motor_id }, - { $set: { motor_status: "2" } } - ); - } else if (status === 'off') { - result = await Tank.findOneAndUpdate( - { motor_id: motor_id }, - { $set: { motor_stop_status: "1" } } - ); - } + result = await Tank.findOneAndUpdate( + { motor_id: motor_id }, + { $set: { motor_stop_status: "1" } } + ); reply.send({ status_code: 200, message: `Motor ${motor_id} status updated to ${status}` }); } catch (err) {