diff --git a/src/controllers/tanksController.js b/src/controllers/tanksController.js index 0c94a531..b5fa25e7 100644 --- a/src/controllers/tanksController.js +++ b/src/controllers/tanksController.js @@ -1940,7 +1940,11 @@ exports.writeMotorStatus = async (req, reply) => { // Update the motor_status of the inputConnection inputConnection.motor_status = status; - inputConnection.real_motor_status = status; + if (status === "1" && inputConnection.real_motor_status === "4") { + inputConnection.real_motor_status = 1; + } else if (status === "2" && inputConnection.real_motor_status === "3") { + inputConnection.real_motor_status = 2; + } // Save the updated tank await tank.save(); @@ -1955,46 +1959,46 @@ exports.writeMotorStatus = async (req, reply) => { } }; -exports.writeMotorStatus = async (req, reply) => { - try { - const motor_id = req.body.motor_id; - const status = req.body.status; +// exports.writeMotorStatus = async (req, reply) => { +// try { +// const motor_id = req.body.motor_id; +// const status = req.body.status; - // Find the tank that contains the specified motor_id in its inputConnections - const tank = await Tank.findOne({ "connections.inputConnections.motor_id": motor_id }); +// // Find the tank that contains the specified motor_id in its inputConnections +// const tank = await Tank.findOne({ "connections.inputConnections.motor_id": motor_id }); - if (!tank) { - return reply.status(404).send({ - status_code: 404, - message: 'Motor not found for the specified motor_id' - }); - } +// if (!tank) { +// return reply.status(404).send({ +// status_code: 404, +// message: 'Motor not found for the specified motor_id' +// }); +// } - // Find the inputConnection with the specified motor_id - const inputConnection = tank.connections.inputConnections.find(conn => conn.motor_id === motor_id); +// // Find the inputConnection with the specified motor_id +// const inputConnection = tank.connections.inputConnections.find(conn => conn.motor_id === motor_id); - // Update the motor_status of the inputConnection - inputConnection.motor_status = status; - - // Update real_motor_status based on the conditions - if (status === "1" && inputConnection.real_motor_status === "4") { - inputConnection.real_motor_status = 1; - } else if (status === "2" && inputConnection.real_motor_status === "3") { - inputConnection.real_motor_status = 2; - } +// // Update the motor_status of the inputConnection +// inputConnection.motor_status = status; + +// // Update real_motor_status based on the conditions +// if (status === "1" && inputConnection.real_motor_status === "4") { +// inputConnection.real_motor_status = 1; +// } else if (status === "2" && inputConnection.real_motor_status === "3") { +// inputConnection.real_motor_status = 2; +// } - // Save the updated tank - await tank.save(); +// // Save the updated tank +// await tank.save(); - // Send the response with the updated motor_status - reply.send({ - status_code: 200, - motor_status: status - }); - } catch (err) { - throw boom.boomify(err); - } -}; +// // Send the response with the updated motor_status +// reply.send({ +// status_code: 200, +// motor_status: status +// }); +// } catch (err) { +// throw boom.boomify(err); +// } +// };