|
|
@ -6867,7 +6867,6 @@ client.on('connect', () => {
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// });
|
|
|
|
// });
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
client.on('message', async (topic, message) => {
|
|
|
|
client.on('message', async (topic, message) => {
|
|
|
|
console.log(`Message received on topic ${topic}:`, message.toString());
|
|
|
|
console.log(`Message received on topic ${topic}:`, message.toString());
|
|
|
|
|
|
|
|
|
|
|
@ -6961,45 +6960,19 @@ client.on('message', async (topic, message) => {
|
|
|
|
|
|
|
|
|
|
|
|
// Find the inputConnection for the motor and update motor status
|
|
|
|
// Find the inputConnection for the motor and update motor status
|
|
|
|
const inputConnection = motorTank.connections.inputConnections.find(conn => conn.motor_id === hw_Id); // Updated variable name
|
|
|
|
const inputConnection = motorTank.connections.inputConnections.find(conn => conn.motor_id === hw_Id); // Updated variable name
|
|
|
|
const user = await User.findOne({ customerId: motorTank.customerId }); // Fetch user by customerId
|
|
|
|
|
|
|
|
const allowNotifications = user?.manualStartAndStopNotify ?? true; // Default to true if not set
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (inputConnection) {
|
|
|
|
if (inputConnection) {
|
|
|
|
inputConnection.motor_status = status; // Update motor status
|
|
|
|
inputConnection.motor_status = status; // Update motor status
|
|
|
|
const tankName = motorTank.tankName;
|
|
|
|
if (inputConnection.motor_stop_status === "1" && status === 2 && inputConnection.motor_on_type !== "forced_manual") {
|
|
|
|
if (allowNotifications && inputConnection.motor_stop_status === "1" && status === 2 && inputConnection.motor_on_type !== "forced_manual") {
|
|
|
|
|
|
|
|
const currentTime = moment().tz('Asia/Kolkata').format('DD-MMM-YYYY - HH:mm');
|
|
|
|
const currentTime = moment().tz('Asia/Kolkata').format('DD-MMM-YYYY - HH:mm');
|
|
|
|
inputConnection.motor_stop_status = "2";
|
|
|
|
inputConnection.motor_stop_status = "2";
|
|
|
|
inputConnection.motor_on_type = "forced_manual";
|
|
|
|
inputConnection.motor_on_type = "forced_manual";
|
|
|
|
inputConnection.startTime = currentTime;
|
|
|
|
inputConnection.startTime = currentTime;
|
|
|
|
|
|
|
|
|
|
|
|
eventEmitter.emit(
|
|
|
|
|
|
|
|
"sendMotorStartNotification",
|
|
|
|
|
|
|
|
fcmToken, // FCM tokens
|
|
|
|
|
|
|
|
hw_Id, // Motor ID
|
|
|
|
|
|
|
|
inputConnection.water_level || 0, // Water level
|
|
|
|
|
|
|
|
motorTank.blockName || "N/A", // Block name
|
|
|
|
|
|
|
|
tankName, // Tank name
|
|
|
|
|
|
|
|
inputConnection.motor_on_type, // Motor on type
|
|
|
|
|
|
|
|
"threshold", // Stop criteria
|
|
|
|
|
|
|
|
manual_threshold_time // Threshold time in mins
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (allowNotifications && inputConnection.motor_stop_status === "2" && status === 1) {
|
|
|
|
if (inputConnection.motor_stop_status === "2" && status === 1) {
|
|
|
|
const currentTime = moment().tz('Asia/Kolkata').format('DD-MMM-YYYY - HH:mm');
|
|
|
|
const currentTime = moment().tz('Asia/Kolkata').format('DD-MMM-YYYY - HH:mm');
|
|
|
|
inputConnection.motor_stop_status = "1";
|
|
|
|
inputConnection.motor_stop_status = "1";
|
|
|
|
inputConnection.stopTime = currentTime;
|
|
|
|
inputConnection.stopTime = currentTime;
|
|
|
|
|
|
|
|
|
|
|
|
eventEmitter.emit(
|
|
|
|
|
|
|
|
"sendMotorStopNotification",
|
|
|
|
|
|
|
|
fcmToken, // FCM tokens
|
|
|
|
|
|
|
|
hw_Id, // Motor ID
|
|
|
|
|
|
|
|
inputConnection.water_level || 0, // Water level
|
|
|
|
|
|
|
|
motorTank.blockName || "N/A", // Block name
|
|
|
|
|
|
|
|
tankName, // Tank name
|
|
|
|
|
|
|
|
inputConnection.motor_on_type // Motor on type
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
await motorTank.save(); // Save the updated tank
|
|
|
|
await motorTank.save(); // Save the updated tank
|
|
|
@ -7016,6 +6989,8 @@ client.on('message', async (topic, message) => {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
exports.getPendingAndCompletedsurveyOfparticularInstaller = async (request, reply) => {
|
|
|
|
exports.getPendingAndCompletedsurveyOfparticularInstaller = async (request, reply) => {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
const { installationId } = request.params;
|
|
|
|
const { installationId } = request.params;
|
|
|
|