From 1271d6ece37143926ddfb675ba884428ffdce708 Mon Sep 17 00:00:00 2001 From: Bhaskar Date: Wed, 4 Jun 2025 12:51:08 +0530 Subject: [PATCH] revert --- src/controllers/installationController.js | 47 +++++++++-------------- 1 file changed, 19 insertions(+), 28 deletions(-) diff --git a/src/controllers/installationController.js b/src/controllers/installationController.js index 3b4ea527..898e01f3 100644 --- a/src/controllers/installationController.js +++ b/src/controllers/installationController.js @@ -5532,8 +5532,6 @@ exports.getRemoveConnectedMastersWithSlaves = async (req, reply) => { } }; -// const moment = require("moment-timezone"); - exports.getDisconnectedCustomerDetails = async (req, reply) => { try { const { supportId } = req.params; @@ -5567,44 +5565,32 @@ exports.getDisconnectedCustomerDetails = async (req, reply) => { } const hardwareIdsArray = Array.from(allHardwareIds); - + console.log("hardwareIdsArray",hardwareIdsArray) // 4. Find disconnected insensors using connected_to match + // const disconnectedSensors = await Insensors.find({ + // connected_to: { $in: hardwareIdsArray }, + // connected_status: "disconnected" + // }).lean(); const disconnectedSensors = await Insensors.find({ connected_to: { $in: hardwareIdsArray }, - connected_status: "disconnected" + connected_status: "disconnected", + support_issue_status: "active" }).lean(); + + console.log("disconnectedSensors",disconnectedSensors) if (!disconnectedSensors.length) { return reply.code(404).send({ message: "No disconnected issues found" }); } - // 4.5 Exclude customers who have any sensor with support_issue_status = "active" - const disconnectedCustomerIds = [...new Set(disconnectedSensors.map(s => s.customerId))]; - - const activeSensors = await Insensors.find({ - customerId: { $in: disconnectedCustomerIds }, - support_issue_status: "active" - }).lean(); - - const activeCustomerIds = new Set(activeSensors.map(s => s.customerId)); - - // Filter disconnectedSensors to exclude customers with active sensors - const filteredDisconnectedSensors = disconnectedSensors.filter( - s => !activeCustomerIds.has(s.customerId) - ); - - if (filteredDisconnectedSensors.length === 0) { - return reply.code(404).send({ message: "No disconnected issues found after filtering active sensors" }); - } - - // 5. Get unique customerIds from filtered disconnected sensors - const customerIds = [...new Set(filteredDisconnectedSensors.map(s => s.customerId))]; + // 5. Get unique customerIds from disconnected sensors + const customerIds = [...new Set(disconnectedSensors.map(s => s.customerId))]; const customers = await User.find({ customerId: { $in: customerIds } }).lean(); // 6. For each customer, calculate total unique hardwareIds involved in their disconnected sensors const customerHardwareMap = {}; - for (const sensor of filteredDisconnectedSensors) { + for (const sensor of disconnectedSensors) { const custId = sensor.customerId; if (!customerHardwareMap[custId]) { customerHardwareMap[custId] = new Set(); @@ -5625,9 +5611,12 @@ exports.getDisconnectedCustomerDetails = async (req, reply) => { ) { customerHardwareMap[custId].add(issue.hardwareId); } + console.log("allIssueHardwareIds",allIssueHardwareIds) + } } + // 7. Build final response const response = []; @@ -5640,9 +5629,12 @@ exports.getDisconnectedCustomerDetails = async (req, reply) => { const issueHw = issue.hardwareId?.trim().toLowerCase(); const hardwareIds = issue.hardwareIds?.map(id => id?.trim().toLowerCase()) || []; const allIds = [issueHw, ...hardwareIds]; + console.log("allIds",allIds) + console.log("Array.from(hardwareIdSet).some(hw => allIds.includes(hw?.trim().toLowerCase()))",Array.from(hardwareIdSet).some(hw => allIds.includes(hw?.trim().toLowerCase()))) return Array.from(hardwareIdSet).some(hw => allIds.includes(hw?.trim().toLowerCase())); - }); + }); + //console.log("relatedIssues",relatedIssues) let latestIssueTime = null; for (const issue of relatedIssues) { if (issue.lastTicketRaisedAt) { @@ -5706,7 +5698,6 @@ exports.getDisconnectedCustomerDetails = async (req, reply) => { - // exports.getDisconnectedCustomerDetails = async (req, reply) => { // try { // const { supportId } = req.params;