diff --git a/src/helpers/enrichWithDefault.ts b/src/helpers/enrichWithDefault.ts index 4dff89e9..2f0fb4b4 100644 --- a/src/helpers/enrichWithDefault.ts +++ b/src/helpers/enrichWithDefault.ts @@ -7,6 +7,7 @@ import { OneTrustAssessmentQuestionRiskCodec, OneTrustAssessmentQuestionRisksCodec, OneTrustAssessmentSectionCodec, + OneTrustAssessmentSectionHeaderRiskStatisticsCodec, OneTrustAssessmentSectionSubmittedByCodec, OneTrustPrimaryEntityDetailsCodec, } from '../oneTrust/codecs'; @@ -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), diff --git a/src/oneTrust/flattenOneTrustAssessment.ts b/src/oneTrust/flattenOneTrustAssessment.ts index 98e5f2c5..2fcb3908 100644 --- a/src/oneTrust/flattenOneTrustAssessment.ts +++ b/src/oneTrust/flattenOneTrustAssessment.ts @@ -13,7 +13,6 @@ import { OneTrustAssessmentQuestionResponseCodec, OneTrustAssessmentSectionCodec, OneTrustAssessmentSectionHeaderCodec, - OneTrustAssessmentSectionHeaderRiskStatisticsCodec, OneTrustEnrichedRiskCodec, OneTrustGetAssessmentResponseCodec, } from './codecs'; @@ -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), @@ -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 }),