Skip to content

Commit

Permalink
improve variable names
Browse files Browse the repository at this point in the history
  • Loading branch information
abrantesarthur committed Jan 10, 2025
1 parent 4822fba commit 5636c78
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions src/oneTrust/flattenOneTrustAssessment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,15 @@ const flattenList = (list: any[], prefix: string): any => {
if (list.length === 0) {
return {};
}
const flattenedList = list.map((obj) => flattenObject(obj, prefix));
const listFlat = list.map((obj) => flattenObject(obj, prefix));

// get all possible keys from the flattenedList
// get all possible keys from the listFlat
// TODO: make helper
const allKeys = Array.from(
new Set(flattenedList.flatMap((a) => Object.keys(a))),
);
const allKeys = Array.from(new Set(listFlat.flatMap((a) => Object.keys(a))));

// build a single object where all the keys contain the respective values of flattenedList
// build a single object where all the keys contain the respective values of listFlat
return allKeys.reduce((acc, key) => {
const values = flattenedList.map((a) => a[key] ?? '').join(',');
const values = listFlat.map((a) => a[key] ?? '').join(',');
acc[key] = values;
return acc;
}, {} as Record<string, any>);
Expand Down Expand Up @@ -212,14 +210,14 @@ const flattenOneTrustSections = (
unnestedSections: [],
},
);
const flattenedSections = flattenList(unnestedSections, prefix);
const flattenedHeaders = flattenOneTrustSectionHeaders(headers, prefix);
const flattenedQuestions = flattenOneTrustQuestions(
const sectionsFlat = flattenList(unnestedSections, prefix);
const headersFlat = flattenOneTrustSectionHeaders(headers, prefix);
const questionsFlat = flattenOneTrustQuestions(
allQuestions,
`${prefix}_questions`,
);

return { ...flattenedSections, ...flattenedHeaders, ...flattenedQuestions };
return { ...sectionsFlat, ...headersFlat, ...questionsFlat };
};

export const flattenOneTrustAssessment = ({
Expand All @@ -245,7 +243,7 @@ export const flattenOneTrustAssessment = ({
// approvers,
// primaryEntityDetails,
// respondents,
// eslintdisablenextline @typescripteslint/nounusedvars
// eslint-disable-next-line @typescript-eslint/no-unused-vars
respondent,
sections,
...rest
Expand Down

0 comments on commit 5636c78

Please sign in to comment.