Skip to content

Commit

Permalink
create enrichRiskStatisticsWithDefault
Browse files Browse the repository at this point in the history
  • Loading branch information
abrantesarthur committed Jan 11, 2025
1 parent ec8e77c commit 35d5fd7
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 17 deletions.
13 changes: 13 additions & 0 deletions src/helpers/enrichWithDefault.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
OneTrustAssessmentQuestionRiskCodec,
OneTrustAssessmentQuestionRisksCodec,
OneTrustAssessmentSectionCodec,
OneTrustAssessmentSectionHeaderRiskStatisticsCodec,
OneTrustAssessmentSectionSubmittedByCodec,
OneTrustPrimaryEntityDetailsCodec,
} from '../oneTrust/codecs';
Expand Down Expand Up @@ -40,12 +41,24 @@ const enrichRisksWithDefault = (
? createDefaultCodec(t.array(OneTrustAssessmentQuestionRiskCodec))
: risks;

// TODO: test the shit out of this
const enrichRiskStatisticsWithDefault = (
riskStatistics: OneTrustAssessmentSectionHeaderRiskStatisticsCodec,
): OneTrustAssessmentSectionHeaderRiskStatisticsCodec =>
riskStatistics === null
? createDefaultCodec(OneTrustAssessmentSectionHeaderRiskStatisticsCodec)
: riskStatistics;

// TODO: test the shit out of this
export const enrichSectionsWithDefault = (
sections: OneTrustAssessmentSectionCodec[],
): OneTrustAssessmentSectionCodec[] =>
sections.map((s) => ({
...s,
header: {
...s.header,
riskStatistics: enrichRiskStatisticsWithDefault(s.header.riskStatistics),
},
questions: s.questions.map((q) => ({
...q,
question: enrichQuestionWithDefault(q.question),
Expand Down
18 changes: 1 addition & 17 deletions src/oneTrust/flattenOneTrustAssessment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import {
OneTrustAssessmentQuestionResponseCodec,
OneTrustAssessmentSectionCodec,
OneTrustAssessmentSectionHeaderCodec,
OneTrustAssessmentSectionHeaderRiskStatisticsCodec,
OneTrustEnrichedRiskCodec,
OneTrustGetAssessmentResponseCodec,
} from './codecs';
Expand Down Expand Up @@ -108,13 +107,6 @@ const flattenOneTrustQuestionResponses = (
['responses'],
);

// TODO: replace possible null values within responses
// const defaultObject = {
// id: null,
// name: null,
// nameKey: null,
// };

// TODO: do we handle it right when empty?
const responsesFlat = (responses ?? []).map((r) =>
flattenObject(r, prefix),
Expand Down Expand Up @@ -176,21 +168,13 @@ const flattenOneTrustSectionHeaders = (
headers: OneTrustAssessmentSectionHeaderCodec[],
prefix: string,
): any => {
// TODO: set a default for EVERY nested object that may be null
const defaultRiskStatistics: OneTrustAssessmentSectionHeaderRiskStatisticsCodec =
{
maxRiskLevel: null,
riskCount: null,
sectionId: null,
};

const { riskStatistics, rest: restHeaders } = extractProperties(headers, [
'riskStatistics',
]);

const flatFlatHeaders = restHeaders.map((h) => flattenObject(h, prefix));
const flatRiskStatistics = riskStatistics.map((r) =>
flattenObject(r ?? defaultRiskStatistics, `${prefix}_riskStatistics`),
flattenObject(r, `${prefix}_riskStatistics`),
);
return {
...aggregateObjects({ objs: flatFlatHeaders }),
Expand Down

0 comments on commit 35d5fd7

Please sign in to comment.