| 
						
						
							
								
							
						
						
					 | 
					 | 
					@ -691,19 +691,7 @@ exports.getByHardwareIdSupport = async (req, reply) => {
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    const gsmStatus = isGSMConnected ? "connected" : "disconnected";
 | 
					 | 
					 | 
					 | 
					    const gsmStatus = isGSMConnected ? "connected" : "disconnected";
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    const gsmLastCheckTime = now.format("DD-MM-YYYY HH:mm:ss");
 | 
					 | 
					 | 
					 | 
					    const gsmLastCheckTime = now.format("DD-MM-YYYY HH:mm:ss");
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    await Insensors.updateMany(
 | 
					 | 
					 | 
					 | 
					    await Insensors.findOneAndUpdate(
 | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					      { connected_to: hardwareId },
 | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					      {
 | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        $set: {
 | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					          connected_gsm_date,
 | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					          connected_gsm_time,
 | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					          connected_status: gsmStatus,
 | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					          support_gsm_last_check_time: gsmLastCheckTime
 | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        }
 | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					      }
 | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    );
 | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    await Insensors.updateOne(
 | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					      { hardwareId },
 | 
					 | 
					 | 
					 | 
					      { hardwareId },
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					      {
 | 
					 | 
					 | 
					 | 
					      {
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        $set: {
 | 
					 | 
					 | 
					 | 
					        $set: {
 | 
				
			
			
		
	
	
		
		
			
				
					| 
						
						
						
							
								
							
						
					 | 
					 | 
					@ -728,7 +716,7 @@ exports.getByHardwareIdSupport = async (req, reply) => {
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    // 🔁 Raise ticket if applicable
 | 
					 | 
					 | 
					 | 
					    // 🔁 Raise ticket if applicable
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    const sensor = await Insensors.findOne({ hardwareId }).lean();
 | 
					 | 
					 | 
					 | 
					    const sensor = await Insensors.findOne({ hardwareId }).lean();
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    if (sensor?.customerId) {
 | 
					 | 
					 | 
					 | 
					    if (sensor?.customerId) {
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					      await raiseATicketLikeLogic(sensor.customerId, hardwareId);
 | 
					 | 
					 | 
					 | 
					     // await raiseATicketLikeLogic(sensor.customerId, hardwareId);
 | 
				
			
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    }
 | 
					 | 
					 | 
					 | 
					    }
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    return reply.send({
 | 
					 | 
					 | 
					 | 
					    return reply.send({
 | 
				
			
			
		
	
	
		
		
			
				
					| 
						
						
						
							
								
							
						
					 | 
					 | 
					@ -746,9 +734,8 @@ exports.getByHardwareIdSupport = async (req, reply) => {
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        time: latestRecord.time
 | 
					 | 
					 | 
					 | 
					        time: latestRecord.time
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					      }
 | 
					 | 
					 | 
					 | 
					      }
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    });
 | 
					 | 
					 | 
					 | 
					    });
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					  } catch (err) {
 | 
					 | 
					 | 
					 | 
					  } catch (err) {
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    console.error("Error in getByHardwareIdSupport:", err);
 | 
					 | 
					 | 
					 | 
					    console.error("Error in getByHardwareId:", err);
 | 
				
			
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    return reply.status(500).send({ error: "Internal Server Error" });
 | 
					 | 
					 | 
					 | 
					    return reply.status(500).send({ error: "Internal Server Error" });
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					  }
 | 
					 | 
					 | 
					 | 
					  }
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					};
 | 
					 | 
					 | 
					 | 
					};
 | 
				
			
			
		
	
	
		
		
			
				
					| 
						
							
								
							
						
						
							
								
							
						
						
					 | 
					 | 
					@ -4002,34 +3989,34 @@ const raiseATicketLikeLogic = async (customerId, connected_to) => {
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					//   }
 | 
					 | 
					 | 
					 | 
					//   }
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					// });
 | 
					 | 
					 | 
					 | 
					// });
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					// cron.schedule("* * * * *", async () => {
 | 
					 | 
					 | 
					 | 
					cron.schedule("* * * * *", async () => {
 | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					//   try {
 | 
					 | 
					 | 
					 | 
					  try {
 | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					//     console.log("🔁 Running auto-disconnect ticket check...");
 | 
					 | 
					 | 
					 | 
					    console.log("🔁 Running auto-disconnect ticket check...");
 | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					//     const allMasters = await Insensors.find({ type: "master" }).lean();
 | 
					 | 
					 | 
					 | 
					    const allMasters = await Insensors.find({ type: "master" }).lean();
 | 
				
			
			
				
				
			
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					//     for (const master of allMasters) {
 | 
					 | 
					 | 
					 | 
					    for (const master of allMasters) {
 | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					//       const customerId = master.customerId;
 | 
					 | 
					 | 
					 | 
					      const customerId = master.customerId;
 | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					//       const hardwareId = master.hardwareId;
 | 
					 | 
					 | 
					 | 
					      const hardwareId = master.hardwareId;
 | 
				
			
			
				
				
			
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					//       const connectedSlaves = await Insensors.find({
 | 
					 | 
					 | 
					 | 
					      const connectedSlaves = await Insensors.find({
 | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					//         connected_to: hardwareId,
 | 
					 | 
					 | 
					 | 
					        connected_to: hardwareId,
 | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					//         type: "slave"
 | 
					 | 
					 | 
					 | 
					        type: "slave"
 | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					//       }).lean();
 | 
					 | 
					 | 
					 | 
					      }).lean();
 | 
				
			
			
				
				
			
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					//       const disconnectedSlaves = connectedSlaves.filter(
 | 
					 | 
					 | 
					 | 
					      const disconnectedSlaves = connectedSlaves.filter(
 | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					//         s => s.connected_status === "disconnected"
 | 
					 | 
					 | 
					 | 
					        s => s.connected_status === "disconnected"
 | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					//       );
 | 
					 | 
					 | 
					 | 
					      );
 | 
				
			
			
				
				
			
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					//       const masterIsDisconnected = master.connected_status === "disconnected";
 | 
					 | 
					 | 
					 | 
					      const masterIsDisconnected = master.connected_status === "disconnected";
 | 
				
			
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					//       if (masterIsDisconnected || disconnectedSlaves.length > 0) {
 | 
					 | 
					 | 
					 | 
					      if (masterIsDisconnected || disconnectedSlaves.length > 0) {
 | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					//         await raiseATicketLikeLogic(customerId, hardwareId);
 | 
					 | 
					 | 
					 | 
					        await raiseATicketLikeLogic(customerId, hardwareId);
 | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					//       }
 | 
					 | 
					 | 
					 | 
					      }
 | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					//     }
 | 
					 | 
					 | 
					 | 
					    }
 | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					//   } catch (err) {
 | 
					 | 
					 | 
					 | 
					  } catch (err) {
 | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					//     console.error("Cron error:", err);
 | 
					 | 
					 | 
					 | 
					    console.error("Cron error:", err);
 | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					//   }
 | 
					 | 
					 | 
					 | 
					  }
 | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					// });
 | 
					 | 
					 | 
					 | 
					});
 | 
				
			
			
				
				
			
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					exports.raiseATicketBuildingDetails = async (req, reply) => {
 | 
					 | 
					 | 
					 | 
					exports.raiseATicketBuildingDetails = async (req, reply) => {
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					  try {
 | 
					 | 
					 | 
					 | 
					  try {
 | 
				
			
			
		
	
	
		
		
			
				
					| 
						
							
								
							
						
						
						
					 | 
					 | 
					
 
 |