changes in change motorstatus

master
varun 2 years ago
parent e621b2171f
commit 627286e52b

@ -1598,24 +1598,7 @@ exports.changeMotorStatus = async (req, reply) => {
motor_status: updatedMotor.motor_status // Assuming motor_status is a field in your Tank model motor_status: updatedMotor.motor_status // Assuming motor_status is a field in your Tank model
}); });
// Schedule a check for motor_status after 2 minutes
setTimeout(async () => {
try {
// Fetch the motor_status again
const finalMotor = await Tank.findOne({ motor_id: motor_id });
// Check if motor_status is different from motor_stop_status
if (finalMotor && finalMotor.motor_status !== finalMotor.motor_stop_status) {
// If they are different, update motor_stop_status to motor_status
await Tank.findOneAndUpdate(
{ motor_id: motor_id },
{ $set: { motor_stop_status: finalMotor.motor_status } }
);
}
} catch (error) {
console.error("Error in setTimeout:", error);
}
}, 2 * 60 * 1000); // 2 minutes in milliseconds
} catch (err) { } catch (err) {
throw boom.boomify(err); throw boom.boomify(err);
} }

Loading…
Cancel
Save