diff --git a/src/controllers/tanksController.js b/src/controllers/tanksController.js index f95db004..fe2aeeb4 100644 --- a/src/controllers/tanksController.js +++ b/src/controllers/tanksController.js @@ -1515,16 +1515,20 @@ exports.writeMotorStatus = async (req, reply) => { const existingRecord = await Tank.findOne({ motor_id: motor_id }); if (existingRecord && (existingRecord.motor_stop_status === '1' || existingRecord.motor_stop_status === '2')) { - if (existingRecord.motor_status !== status) { - const result = await Tank.findOneAndUpdate( - { motor_id: motor_id }, - { $set: { motor_status: status } }, - { new: true } // To return the updated document - ); - - reply.send({ status_code: 200, motor_status: result.motor_status }); + if (existingRecord.motor_stop_status === status) { + if (existingRecord.motor_status !== status) { + const result = await Tank.findOneAndUpdate( + { motor_id: motor_id }, + { $set: { motor_status: status } }, + { new: true } // To return the updated document + ); + + reply.send({ status_code: 200, motor_status: result.motor_status }); + } else { + reply.send({ status_code: 200, motor_status: status }); + } } else { - reply.send({ status_code: 200, motor_status: status }); + reply.send({ status_code: 200, message: 'Status and motor_stop_status are not the same.' }); } } else { reply.send({ status_code: 200, message: 'Motor stop status is not "on" or "off".' }); @@ -1535,6 +1539,7 @@ exports.writeMotorStatus = async (req, reply) => { }; + exports.changeMotorStatus = async (req, reply) => { try { const motor_id = req.body.motor_id;