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