change in motoraction

master
varun 1 year ago
parent 8f21f33985
commit 8889b69bba

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

Loading…
Cancel
Save