Skip to content

Commit

Permalink
Merge pull request #3637 from gitcoinco/PAR-382
Browse files Browse the repository at this point in the history
fix: ensure all columns are present in csv
  • Loading branch information
thelostone-mc committed Sep 11, 2024
2 parents 478ec0c + 5e9a4e9 commit 5f8b5d8
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions packages/round-manager/src/features/api/exports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,16 @@ export async function roundApplicationsToCSV(
});

const decryptedData: Record<string, string>[] = [];
const columns = new Set();


for (const application of applications) {
const answers =
// eslint-disable-next-line @typescript-eslint/no-explicit-any
application.metadata?.application.answers.flatMap((answer: any) => {

columns.add(answer.question);

if (answer.answer) {
return [[answer.question, answer.answer]];
} else if (answer.encryptedAnswer) {
Expand Down Expand Up @@ -109,15 +114,16 @@ export async function roundApplicationsToCSV(
});
}

const columnsArray = Array.from(columns) as string[];

const csv = (await new Promise((resolve, reject) => {
stringifyCsv(decryptedData, { header: true }, (err, data) => {
stringifyCsv(decryptedData, { header: true , columns: columnsArray}, (err, data) => {
if (err) {
reject(err);
} else {
resolve(data);
}
});
})) as string;

return csv;
}

0 comments on commit 5f8b5d8

Please sign in to comment.