From 75cdbf8db23bcc34a6f6411c8c81a78bdc797122 Mon Sep 17 00:00:00 2001 From: Bhaskar Date: Fri, 30 May 2025 14:38:44 +0530 Subject: [PATCH] changes on gsm support --- src/controllers/installationController.js | 65 +++++++++-------------- 1 file changed, 26 insertions(+), 39 deletions(-) diff --git a/src/controllers/installationController.js b/src/controllers/installationController.js index f09dcc11..6baa990d 100644 --- a/src/controllers/installationController.js +++ b/src/controllers/installationController.js @@ -691,19 +691,7 @@ exports.getByHardwareIdSupport = async (req, reply) => { const gsmStatus = isGSMConnected ? "connected" : "disconnected"; const gsmLastCheckTime = now.format("DD-MM-YYYY HH:mm:ss"); - await Insensors.updateMany( - { connected_to: hardwareId }, - { - $set: { - connected_gsm_date, - connected_gsm_time, - connected_status: gsmStatus, - support_gsm_last_check_time: gsmLastCheckTime - } - } - ); - - await Insensors.updateOne( + await Insensors.findOneAndUpdate( { hardwareId }, { $set: { @@ -728,7 +716,7 @@ exports.getByHardwareIdSupport = async (req, reply) => { // 🔁 Raise ticket if applicable const sensor = await Insensors.findOne({ hardwareId }).lean(); if (sensor?.customerId) { - await raiseATicketLikeLogic(sensor.customerId, hardwareId); + // await raiseATicketLikeLogic(sensor.customerId, hardwareId); } return reply.send({ @@ -746,9 +734,8 @@ exports.getByHardwareIdSupport = async (req, reply) => { time: latestRecord.time } }); - } catch (err) { - console.error("Error in getByHardwareIdSupport:", err); + console.error("Error in getByHardwareId:", err); return reply.status(500).send({ error: "Internal Server Error" }); } }; @@ -4002,34 +3989,34 @@ const raiseATicketLikeLogic = async (customerId, connected_to) => { // } // }); -// cron.schedule("* * * * *", async () => { -// try { -// console.log("🔁 Running auto-disconnect ticket check..."); -// const allMasters = await Insensors.find({ type: "master" }).lean(); +cron.schedule("* * * * *", async () => { + try { + console.log("🔁 Running auto-disconnect ticket check..."); + const allMasters = await Insensors.find({ type: "master" }).lean(); -// for (const master of allMasters) { -// const customerId = master.customerId; -// const hardwareId = master.hardwareId; + for (const master of allMasters) { + const customerId = master.customerId; + const hardwareId = master.hardwareId; -// const connectedSlaves = await Insensors.find({ -// connected_to: hardwareId, -// type: "slave" -// }).lean(); + const connectedSlaves = await Insensors.find({ + connected_to: hardwareId, + type: "slave" + }).lean(); -// const disconnectedSlaves = connectedSlaves.filter( -// s => s.connected_status === "disconnected" -// ); + const disconnectedSlaves = connectedSlaves.filter( + s => s.connected_status === "disconnected" + ); -// const masterIsDisconnected = master.connected_status === "disconnected"; + const masterIsDisconnected = master.connected_status === "disconnected"; -// if (masterIsDisconnected || disconnectedSlaves.length > 0) { -// await raiseATicketLikeLogic(customerId, hardwareId); -// } -// } -// } catch (err) { -// console.error("Cron error:", err); -// } -// }); + if (masterIsDisconnected || disconnectedSlaves.length > 0) { + await raiseATicketLikeLogic(customerId, hardwareId); + } + } + } catch (err) { + console.error("Cron error:", err); + } +}); exports.raiseATicketBuildingDetails = async (req, reply) => { try {