From 5ad517d68236596e53bfd8e2c35c7b08f509a959 Mon Sep 17 00:00:00 2001 From: varun Date: Fri, 29 Dec 2023 03:36:02 -0500 Subject: [PATCH 1/3] 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) { From 5392fa01629876e77f23b0621658fc529e0d5e76 Mon Sep 17 00:00:00 2001 From: varun Date: Fri, 29 Dec 2023 03:39:30 -0500 Subject: [PATCH 2/3] change in read motor status --- src/controllers/tanksController.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/controllers/tanksController.js b/src/controllers/tanksController.js index cf5a58c3..dc4659fd 100644 --- a/src/controllers/tanksController.js +++ b/src/controllers/tanksController.js @@ -1481,7 +1481,7 @@ exports.motorstatus = async (req, reply) => { exports.readMotorStatus = async (req, reply) => { try { - const motor_id = req.body.motor_id; + const motor_id = req.query.motor_id; console.log(motor_id) // Perform any necessary logic based on action (1: Start, 2: Stop) From 19a2b92b799b9ff969c6b6ebc4cdf76a736ff497 Mon Sep 17 00:00:00 2001 From: varun Date: Fri, 29 Dec 2023 03:45:20 -0500 Subject: [PATCH 3/3] change in write motor status --- src/controllers/tanksController.js | 2 +- src/routes/tanksRoute.js | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/controllers/tanksController.js b/src/controllers/tanksController.js index dc4659fd..671caf0a 100644 --- a/src/controllers/tanksController.js +++ b/src/controllers/tanksController.js @@ -1517,7 +1517,7 @@ exports.writeMotorStatus = async (req, reply) => { result = await Tank.findOneAndUpdate( { motor_id: motor_id }, - { $set: { motor_stop_status: "1" } } + { $set: { motor_status: status } } ); reply.send({ status_code: 200, message: `Motor ${motor_id} status updated to ${status}` }); diff --git a/src/routes/tanksRoute.js b/src/routes/tanksRoute.js index 0ea4c56c..aac91347 100644 --- a/src/routes/tanksRoute.js +++ b/src/routes/tanksRoute.js @@ -583,7 +583,7 @@ module.exports = function (fastify, opts, next) { required: ['motor_id', 'status'], properties: { motor_id: { type: 'string' }, - status: { type: 'string', enum: ['on', 'off'] }, + status: { type: 'string'}, current: { type: 'string' }, temp: { type: 'string' }, }, @@ -610,6 +610,8 @@ module.exports = function (fastify, opts, next) { }, // required: ['motor_id'], }, + + }, handler: tanksController.readMotorStatus