unquie hardwareIds and lastticket raise at

master^2
Bhaskar 4 months ago
parent 6ea6912654
commit f698d345df

@ -6791,9 +6791,29 @@ exports.getDisconnectedCustomerDetails = async (req, reply) => {
// }); // });
const customerResults = customerDetails.map((customer) => { const customerResults = customerDetails.map((customer) => {
const affectedHardwareSet = customerHardwareMap[customer.customerId] || new Set(); const customerId = customer.customerId;
const affectedHardwareSet = customerHardwareMap[customerId] || new Set();
const affectedLowerSet = new Set([...affectedHardwareSet].map(id => id.toLowerCase().trim())); const affectedLowerSet = new Set([...affectedHardwareSet].map(id => id.toLowerCase().trim()));
// Filter only sensors that belong to this customer and are disconnected
const disconnectedSensorsForCustomer = disconnectedSensors.filter(sensor =>
sensor.customerId === customerId
);
// Collect actual disconnected hardwareIds (only masters and slaves)
const uniqueDisconnectedHardwareIds = new Set();
for (const sensor of disconnectedSensorsForCustomer) {
if (
(sensor.type === 'master' || sensor.type === 'slave') &&
sensor.connected_status === 'disconnected'
) {
const hw = sensor.tankhardwareId || sensor.hardwareId || sensor.connected_to;
if (hw) {
uniqueDisconnectedHardwareIds.add(hw.trim());
}
}
}
// Get all unresolved issues related to this customer's affected hardwareIds // Get all unresolved issues related to this customer's affected hardwareIds
const customerIssues = unresolvedIssues.filter(issue => { const customerIssues = unresolvedIssues.filter(issue => {
const allIssueHardwareIds = [ const allIssueHardwareIds = [
@ -6803,7 +6823,7 @@ exports.getDisconnectedCustomerDetails = async (req, reply) => {
return allIssueHardwareIds.some(hw => affectedLowerSet.has(hw)); return allIssueHardwareIds.some(hw => affectedLowerSet.has(hw));
}); });
// Get the latest lastTicketRaisedAt from the issues // Get latest ticket raise timestamp
const lastTicketRaisedAt = customerIssues.reduce((latest, issue) => { const lastTicketRaisedAt = customerIssues.reduce((latest, issue) => {
const issueTime = new Date(issue.lastTicketRaisedAt); const issueTime = new Date(issue.lastTicketRaisedAt);
if (!isNaN(issueTime)) { if (!isNaN(issueTime)) {
@ -6827,8 +6847,8 @@ exports.getDisconnectedCustomerDetails = async (req, reply) => {
city: customer.profile?.city || "", city: customer.profile?.city || "",
latitude: customer.latitude, latitude: customer.latitude,
longitude: customer.longitude, longitude: customer.longitude,
totalHardwareIdsCount: affectedHardwareSet.size, totalHardwareIdsCount: uniqueDisconnectedHardwareIds.size,
hardwareIds: [...affectedHardwareSet], hardwareIds: [...uniqueDisconnectedHardwareIds],
lastTicketRaisedAt: lastTicketRaisedAt || null lastTicketRaisedAt: lastTicketRaisedAt || null
}; };
}); });

Loading…
Cancel
Save