|
|
@ -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();
|
|
|
|
const hardwareIdsArray = new Set();
|
|
|
|
unresolvedIssues.forEach((issue) => {
|
|
|
|
unresolvedIssues.forEach((issue) => {
|
|
|
|
if (issue.hardwareId) hardwareIdsArray.add(issue.hardwareId.trim());
|
|
|
|
if (issue.hardwareId) hardwareIdsArray.add(issue.hardwareId.trim());
|
|
|
@ -7795,14 +7806,16 @@ exports.getDisconnectedCustomerDetails = async (req, reply) => {
|
|
|
|
]
|
|
|
|
]
|
|
|
|
}).lean();
|
|
|
|
}).lean();
|
|
|
|
|
|
|
|
|
|
|
|
// ✅ Filter out already categorized ones
|
|
|
|
// ✅ Filter out categorized and resolved sensors
|
|
|
|
const sensors = relevantSensorsRaw.filter(sensor => {
|
|
|
|
const sensors = relevantSensorsRaw.filter(sensor => {
|
|
|
|
const ids = [
|
|
|
|
const ids = [
|
|
|
|
sensor.hardwareId?.trim().toLowerCase(),
|
|
|
|
sensor.hardwareId?.trim().toLowerCase(),
|
|
|
|
sensor.connected_to?.trim().toLowerCase(),
|
|
|
|
sensor.connected_to?.trim().toLowerCase(),
|
|
|
|
sensor.tankhardwareId?.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 = {};
|
|
|
|
const customerHardwareMap = {};
|
|
|
@ -7822,10 +7835,10 @@ exports.getDisconnectedCustomerDetails = async (req, reply) => {
|
|
|
|
issue.hardwareId?.trim().toLowerCase()
|
|
|
|
issue.hardwareId?.trim().toLowerCase()
|
|
|
|
];
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
|
|
const isCategorizedMatch = [sensorHw, sensorConnected, sensorHardwareId].some(id =>
|
|
|
|
const isCategorizedOrResolved = [sensorHw, sensorConnected, sensorHardwareId].some(id =>
|
|
|
|
id && existingCategorizedHardwareIds.has(id)
|
|
|
|
id && (existingCategorizedHardwareIds.has(id) || resolvedHardwareIds.has(id))
|
|
|
|
);
|
|
|
|
);
|
|
|
|
if (isCategorizedMatch) continue;
|
|
|
|
if (isCategorizedOrResolved) continue;
|
|
|
|
|
|
|
|
|
|
|
|
if (
|
|
|
|
if (
|
|
|
|
(sensorHw && allIssueHardwareIds.includes(sensorHw)) ||
|
|
|
|
(sensorHw && allIssueHardwareIds.includes(sensorHw)) ||
|
|
|
@ -7833,7 +7846,7 @@ exports.getDisconnectedCustomerDetails = async (req, reply) => {
|
|
|
|
(sensorHardwareId && allIssueHardwareIds.includes(sensorHardwareId))
|
|
|
|
(sensorHardwareId && allIssueHardwareIds.includes(sensorHardwareId))
|
|
|
|
) {
|
|
|
|
) {
|
|
|
|
for (const hw of allIssueHardwareIds) {
|
|
|
|
for (const hw of allIssueHardwareIds) {
|
|
|
|
if (hw && !existingCategorizedHardwareIds.has(hw)) {
|
|
|
|
if (hw && !existingCategorizedHardwareIds.has(hw) && !resolvedHardwareIds.has(hw)) {
|
|
|
|
customerHardwareMap[custId].add(hw);
|
|
|
|
customerHardwareMap[custId].add(hw);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -7917,6 +7930,7 @@ exports.getDisconnectedCustomerDetails = async (req, reply) => {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
exports.getDisconnectedCustomerDetailsByTeamMemberId = async (req, reply) => {
|
|
|
|
exports.getDisconnectedCustomerDetailsByTeamMemberId = async (req, reply) => {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
const { support_teamMemberId } = req.params;
|
|
|
|
const { support_teamMemberId } = req.params;
|
|
|
|