From 66dad3c6d9f0593b555b07e325e429887e8ab7c5 Mon Sep 17 00:00:00 2001 From: Dmitri Korin Date: Thu, 19 Dec 2024 12:28:41 -0800 Subject: [PATCH] Add sorting --- backend/src/v1/complaint/complaint.service.ts | 24 +++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/backend/src/v1/complaint/complaint.service.ts b/backend/src/v1/complaint/complaint.service.ts index af0be3b67..b724d5861 100644 --- a/backend/src/v1/complaint/complaint.service.ts +++ b/backend/src/v1/complaint/complaint.service.ts @@ -2074,6 +2074,24 @@ export class ComplaintService { return outcomeData.getCaseFileByLeadId; }; + const _sortRecords = (first: any, second: any): number => { + if (first.fileType < second.fileType) { + if (first.date < second.date) { + return -2; + } else { + return -1; + } + } + if (first.fileType > second.fileType) { + if (first.date > second.date) { + return 1; + } else { + return 2; + } + } + return 0; + }; + try { if (complaintType) { builder = this._generateQueryBuilder(complaintType); @@ -2200,7 +2218,8 @@ export class ComplaintService { date: _applyTimezone(item.date, tz, "datetime"), fileType: getFileType(item.name), }; - }); + }) + .sort((first, second) => _sortRecords(first, second)); data.hasComplaintAttachments = data.cAtts?.length > 0; data.oAtts = attachments @@ -2211,7 +2230,8 @@ export class ComplaintService { date: _applyTimezone(item.date, tz, "datetime"), fileType: getFileType(item.name), }; - }); + }) + .sort((first, second) => _sortRecords(first, second)); data.hasOutcomeAttachments = data.oAtts?.length > 0;