master^2
Bhaskar 9 months ago
parent 91e7bac1ae
commit 5e79fa5a20

@ -2767,14 +2767,15 @@ exports.getPumpsAndUsers = async (req, reply) => {
}
};
exports.motoractiontest = async (req, reply) => {
try {
const { customerId } = req.params;
const { motor_id, action } = req.body;
// Assuming you have a MongoDB model or connection
const customer = await db.collection('customers').findOne({ _id: customerId });
// Fetch Tank data using customerId
const customer = await Tank.findOne({ customerId });
// console.log("Customer Data:", customer);
if (!customer) {
return reply.status(404).send({ success: false, message: "Customer not found" });
@ -2782,22 +2783,22 @@ 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;
// Traverse through inputConnections instead of tanks.inputconnections
for (const inputConnection of customer.connections.inputConnections || []) {
console.log("Checking Motor ID:", inputConnection.motor_id);
if (action === 'start') {
await this.publishMotorStopStatus(motor_id, "2");
} else if (action === 'stop') {
await this.publishMotorStopStatus(motor_id, "1");
} else {
return reply.status(400).send({ success: false, message: "Invalid action" });
}
if (String(inputConnection.motor_id) === String(motor_id)) { // Convert both to string
motorFound = true;
return reply.send({ success: true, message: `Motor ${action} command sent.` });
if (action === "start") {
await this.publishMotorStopStatus(motor_id, "2");
} else if (action === "stop") {
await this.publishMotorStopStatus(motor_id, "1");
} else {
return reply.status(400).send({ success: false, message: "Invalid action" });
}
return reply.send({ success: true, message: `Motor ${action} command sent.` });
}
}
@ -2813,6 +2814,7 @@ exports.motoractiontest = async (req, reply) => {
const motorIntervals = {};
async function calculateTotalPumpedWater(customerId, motorId, start_instance_id) {
const motorData = await MotorData.findOne({ customerId, motor_id: motorId, start_instance_id: start_instance_id });

Loading…
Cancel
Save