Bhaskar 6 months ago
commit 91e7bac1ae

@ -2768,6 +2768,50 @@ 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 });
if (!customer) {
return reply.status(404).send({ success: false, message: "Customer not found" });
}
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");
} 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.` });
}
}
}
if (!motorFound) {
return reply.status(404).send({ success: false, message: "Motor ID not found" });
}
} catch (error) {
console.error("Error fetching data:", error);
return reply.status(500).send({ success: false, message: "Internal Server Error" });
}
};
const motorIntervals = {};
async function calculateTotalPumpedWater(customerId, motorId, start_instance_id) {

@ -372,6 +372,49 @@ module.exports = function (fastify, opts, next) {
});
fastify.route({
method: "PUT",
url: "/api/motorActiontest/:customerId",
schema: {
tags: ["Install"],
summary: "This is for start and stop test",
params: {
required: ["customerId"],
type: "object",
properties: {
customerId: {
type: "string",
description: "customerId",
},
},
},
body: {
type: "object",
// required: ['phone'],
properties: {
motor_id:{type:"string"},
action:{type:"string"},
},
},
security: [
{
basicAuth: [],
},
],
},
// preHandler: [
// fastify.auth([fastify.operatorAuthenticate]),
// validationHandler.validatePhoneFormat,
// ],
//preHandler: fastify.auth([fastify.authenticate]),
handler: tanksController.motoractiontest,
});
// fastify.route({
// method: "PUT",
// url: "/api/consumption/:customerId",

Loading…
Cancel
Save