|
|
|
@ -2691,6 +2691,47 @@ const checkWaterLevel = async (customerId, motorId, fcmToken, receiverTank) => {
|
|
|
|
|
// };
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
exports.getPumpsAndUsers = async (req, reply) => {
|
|
|
|
|
try {
|
|
|
|
|
const { customerId } = req.params;
|
|
|
|
|
|
|
|
|
|
// Fetch motor_id from inputConnections of all tanks for the customer
|
|
|
|
|
const tanks = await Tank.find({ customerId }, { "connections.inputConnections.motor_id": 1 });
|
|
|
|
|
|
|
|
|
|
const motorIds = tanks.flatMap((tank) =>
|
|
|
|
|
tank.connections?.inputConnections?.map((conn) => conn.motor_id).filter(Boolean) || []
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
// Fetch username and staff names from User collection
|
|
|
|
|
const user = await User.findOne({ customerId }, { username: 1, "staff.staff.name": 1 });
|
|
|
|
|
|
|
|
|
|
const staffNames = user?.staff?.staff?.map((s) => s.name) || [];
|
|
|
|
|
const username = user?.username || "";
|
|
|
|
|
|
|
|
|
|
// Include username at the beginning of staffNames and add "manual" at the end
|
|
|
|
|
const updatedStaffNames = [username, ...staffNames, "manual"];
|
|
|
|
|
|
|
|
|
|
// Prepare response
|
|
|
|
|
const result = {
|
|
|
|
|
motorIds,
|
|
|
|
|
staffNames: updatedStaffNames,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return reply.send({ success: true, data: result });
|
|
|
|
|
} catch (error) {
|
|
|
|
|
console.error("Error fetching data:", error);
|
|
|
|
|
return reply.status(500).send({ success: false, message: "Internal Server Error" });
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const monitorWaterLevels = async () => {
|
|
|
|
|
try {
|
|
|
|
|
const tanks = await Tank.find({});
|
|
|
|
@ -2736,6 +2777,8 @@ async function calculateTotalPumpedWater(customerId, motorId, start_instance_id)
|
|
|
|
|
}
|
|
|
|
|
return 0; // Return 0 if no data found
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
exports.motorAction = async (req, reply) => {
|
|
|
|
|
try {
|
|
|
|
|
const customerId = req.params.customerId;
|
|
|
|
|