|
|
|
@ -2774,8 +2774,7 @@ exports.motoractiontest = async (req, reply) => {
|
|
|
|
|
const { motor_id, action } = req.body;
|
|
|
|
|
|
|
|
|
|
// Assuming you have a MongoDB model or connection
|
|
|
|
|
const customer = await db.collection('customers').findOne({ _id: customerId });
|
|
|
|
|
|
|
|
|
|
const customer = await Tank.findOne({ customerId });
|
|
|
|
|
if (!customer) {
|
|
|
|
|
return reply.status(404).send({ success: false, message: "Customer not found" });
|
|
|
|
|
}
|
|
|
|
@ -2783,10 +2782,10 @@ exports.motoractiontest = async (req, reply) => {
|
|
|
|
|
let motorFound = false;
|
|
|
|
|
|
|
|
|
|
// Traverse through tanks and their input connections
|
|
|
|
|
for (const tank of customer.tanks || []) {
|
|
|
|
|
for (const inputConnection of tank.inputconnections || []) {
|
|
|
|
|
if (inputConnection.motor_id === motor_id) {
|
|
|
|
|
motorFound = true;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (action === 'start') {
|
|
|
|
|
await this.publishMotorStopStatus(motor_id, "2");
|
|
|
|
@ -2796,10 +2795,10 @@ exports.motoractiontest = async (req, reply) => {
|
|
|
|
|
return reply.status(400).send({ success: false, message: "Invalid action" });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return reply.send({ success: true, message: `Motor ${action} command sent.` });
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!motorFound) {
|
|
|
|
|
return reply.status(404).send({ success: false, message: "Motor ID not found" });
|
|
|
|
|