Skip to content

Commit

Permalink
remove potential bugs from flattenOneTrustAssessment
Browse files Browse the repository at this point in the history
  • Loading branch information
abrantesarthur committed Jan 16, 2025
1 parent 4deaa2d commit cf23df8
Showing 1 changed file with 20 additions and 15 deletions.
35 changes: 20 additions & 15 deletions src/oneTrust/helpers/flattenOneTrustAssessment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,9 @@ const flattenOneTrustRisks = (
'categories',
]);
return {
...flattenObject({ obj: { risks }, prefix }),
...flattenOneTrustRiskCategories(categories, `${prefix}_risks`),
...(risks && flattenObject({ obj: { risks }, prefix })),
...(categories &&
flattenOneTrustRiskCategories(categories, `${prefix}_risks`)),
};
});

Expand All @@ -111,13 +112,15 @@ const flattenOneTrustQuestions = (
]);

return {
...flattenObject({ obj: { questions }, prefix }),
...flattenOneTrustNestedQuestions(nestedQuestions, prefix),
...flattenOneTrustRisks(allRisks, `${prefix}_questions`),
...flattenOneTrustQuestionResponses(
allQuestionResponses,
`${prefix}_questions`,
),
...(questions && flattenObject({ obj: { questions }, prefix })),
...(nestedQuestions &&
flattenOneTrustNestedQuestions(nestedQuestions, prefix)),
...(allRisks && flattenOneTrustRisks(allRisks, `${prefix}_questions`)),
...(allQuestionResponses &&
flattenOneTrustQuestionResponses(
allQuestionResponses,
`${prefix}_questions`,
)),
};
},
);
Expand All @@ -136,28 +139,30 @@ const flattenOneTrustSectionHeaders = (
'riskStatistics',
]);

const flatFlatHeaders = restHeaders.map((h) =>
const flatFlatHeaders = (restHeaders ?? []).map((h) =>
flattenObject({ obj: h, prefix }),
);
return {
...aggregateObjects({ objs: flatFlatHeaders }),
...flattenObject({ obj: { riskStatistics }, prefix }),
...(riskStatistics && flattenObject({ obj: { riskStatistics }, prefix })),
};
};

const flattenOneTrustSections = (
sections: OneTrustEnrichedAssessmentSection[],
): any => {
// filter out sections without questions (shouldn't happen, but just to be safe)
const sectionsWithQuestions = sections.filter((s) => s.questions.length > 0);
const {
questions: allQuestions,
header: headers,
rest: restSections,
} = transposeObjectArray(sections, ['questions', 'header']);
} = transposeObjectArray(sectionsWithQuestions, ['questions', 'header']);

return {
...flattenObject({ obj: { sections: restSections } }),
...flattenOneTrustSectionHeaders(headers, 'sections'),
...flattenOneTrustQuestions(allQuestions, 'sections'),
...(restSections && flattenObject({ obj: { sections: restSections } })),
...(headers && flattenOneTrustSectionHeaders(headers, 'sections')),
...(allQuestions && flattenOneTrustQuestions(allQuestions, 'sections')),
};
};

Expand Down

0 comments on commit cf23df8

Please sign in to comment.