Skip to content

Commit

Permalink
Improve attachments order
Browse files Browse the repository at this point in the history
  • Loading branch information
dmitri-korin-bcps committed Dec 24, 2024
1 parent 31b73ae commit 8c72176
Showing 1 changed file with 37 additions and 4 deletions.
41 changes: 37 additions & 4 deletions backend/src/v1/complaint/complaint.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2073,6 +2073,27 @@ export class ComplaintService {
return outcomeData.getCaseFileByLeadId;
};

const _multiFieldCompare = (first: any, second: any, compareInfo: { field: string; sort: string }[]): number => {
for (const item of compareInfo) {
if (item.sort === "asc") {
if (first[item.field] < second[item.field]) {
return -1;
}
if (first[item.field] > second[item.field]) {
return 1;
}
} else if (item.sort === "desc") {
if (first[item.field] > second[item.field]) {
return -1;
}
if (first[item.field] < second[item.field]) {
return 1;
}
}
}
return 0;
};

try {
if (complaintType) {
builder = this._generateQueryBuilder(complaintType);
Expand Down Expand Up @@ -2196,21 +2217,33 @@ export class ComplaintService {
.map((item) => {
return {
name: item.name,
date: _applyTimezone(item.date, tz, "datetime"),
date: item.date,
fileType: getFileType(item.name),
};
});
})
.sort((first, second) =>
_multiFieldCompare(first, second, [
{ field: "fileType", sort: "asc" },
{ field: "date", sort: "asc" },
]),
);
data.hasComplaintAttachments = data.cAtts?.length > 0;

data.oAtts = attachments
.filter((item) => item.type === AttachmentType.OUTCOME_ATTACHMENT)
.map((item) => {
return {
name: item.name,
date: _applyTimezone(item.date, tz, "datetime"),
date: item.date,
fileType: getFileType(item.name),
};
});
})
.sort((first, second) =>
_multiFieldCompare(first, second, [
{ field: "fileType", sort: "asc" },
{ field: "date", sort: "asc" },
]),
);

data.hasOutcomeAttachments = data.oAtts?.length > 0;

Expand Down

0 comments on commit 8c72176

Please sign in to comment.