Skip to content

Commit

Permalink
Always sort by status
Browse files Browse the repository at this point in the history
  • Loading branch information
omfj committed Aug 29, 2024
1 parent 8e4318e commit d16d7dc
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions apps/web/src/lib/csv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,6 @@ export const toCsv = (happening: FullHappening, selectedHeaders: Array<string> =
obj[question.title] = formattedAnswer;
});

// If there are no selected headers, return the full object
if (selectedHeaders.length > 0) {
for (const key in obj) {
if (!selectedHeaders.includes(key)) {
delete obj[key];
}
}
}

return obj;
})
.sort((a, b) => {
Expand All @@ -62,6 +53,17 @@ export const toCsv = (happening: FullHappening, selectedHeaders: Array<string> =
return (
statusOrder[a.Status as RegistrationStatus] - statusOrder[b.Status as RegistrationStatus]
);
})
.map((registration) => {
const obj: Record<string, string> = registration;

for (const key in registration) {
if (!selectedHeaders.includes(key)) {
delete obj[key];
}
}

return obj;
});

const parser = new Parser();
Expand Down

0 comments on commit d16d7dc

Please sign in to comment.