diff --git a/src/controllers/installationController.js b/src/controllers/installationController.js index 0fac0c6a..df4bddb1 100644 --- a/src/controllers/installationController.js +++ b/src/controllers/installationController.js @@ -7774,6 +7774,17 @@ exports.getDisconnectedCustomerDetails = async (req, reply) => { } }); + // ✅ Exclude resolved hardwareIds from disconnected list + const resolvedHardwareIds = new Set(); + (supportRecord.resolvedIssues || []).forEach(issue => { + if (issue.hardwareId) resolvedHardwareIds.add(issue.hardwareId.trim().toLowerCase()); + if (Array.isArray(issue.hardwareIds)) { + issue.hardwareIds.forEach(id => { + if (typeof id === "string") resolvedHardwareIds.add(id.trim().toLowerCase()); + }); + } + }); + const hardwareIdsArray = new Set(); unresolvedIssues.forEach((issue) => { if (issue.hardwareId) hardwareIdsArray.add(issue.hardwareId.trim()); @@ -7795,14 +7806,16 @@ exports.getDisconnectedCustomerDetails = async (req, reply) => { ] }).lean(); - // ✅ Filter out already categorized ones + // ✅ Filter out categorized and resolved sensors const sensors = relevantSensorsRaw.filter(sensor => { const ids = [ sensor.hardwareId?.trim().toLowerCase(), sensor.connected_to?.trim().toLowerCase(), sensor.tankhardwareId?.trim().toLowerCase() ]; - return !ids.some(id => existingCategorizedHardwareIds.has(id)); + return !ids.some(id => + existingCategorizedHardwareIds.has(id) || resolvedHardwareIds.has(id) + ); }); const customerHardwareMap = {}; @@ -7822,10 +7835,10 @@ exports.getDisconnectedCustomerDetails = async (req, reply) => { issue.hardwareId?.trim().toLowerCase() ]; - const isCategorizedMatch = [sensorHw, sensorConnected, sensorHardwareId].some(id => - id && existingCategorizedHardwareIds.has(id) + const isCategorizedOrResolved = [sensorHw, sensorConnected, sensorHardwareId].some(id => + id && (existingCategorizedHardwareIds.has(id) || resolvedHardwareIds.has(id)) ); - if (isCategorizedMatch) continue; + if (isCategorizedOrResolved) continue; if ( (sensorHw && allIssueHardwareIds.includes(sensorHw)) || @@ -7833,7 +7846,7 @@ exports.getDisconnectedCustomerDetails = async (req, reply) => { (sensorHardwareId && allIssueHardwareIds.includes(sensorHardwareId)) ) { for (const hw of allIssueHardwareIds) { - if (hw && !existingCategorizedHardwareIds.has(hw)) { + if (hw && !existingCategorizedHardwareIds.has(hw) && !resolvedHardwareIds.has(hw)) { customerHardwareMap[custId].add(hw); } } @@ -7917,6 +7930,7 @@ exports.getDisconnectedCustomerDetails = async (req, reply) => { + exports.getDisconnectedCustomerDetailsByTeamMemberId = async (req, reply) => { try { const { support_teamMemberId } = req.params;