From 2a31b99050d7a1f2164c1a8ad21ff041ef6b22ae Mon Sep 17 00:00:00 2001 From: wanlingt Date: Sun, 1 Oct 2023 23:07:56 +0800 Subject: [PATCH] fix: re-add childIdx to MyInfoChildHashKey for case of >1 child per field --- src/app/modules/myinfo/myinfo.types.ts | 4 ++-- src/app/modules/myinfo/myinfo.util.ts | 8 +++++--- .../submission/email-submission/email-submission.util.ts | 7 ++++++- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/app/modules/myinfo/myinfo.types.ts b/src/app/modules/myinfo/myinfo.types.ts index bc781f8410..17938972dc 100644 --- a/src/app/modules/myinfo/myinfo.types.ts +++ b/src/app/modules/myinfo/myinfo.types.ts @@ -23,9 +23,9 @@ export interface IMyInfoRedirectURLArgs { // Field ID or a special key for a Child export type MyInfoKey = string | MyInfoChildKey -// Field type, field ID, child attribute type, child name +// Field type, field ID, child attribute type, child index, child name export type MyInfoChildKey = - `${MyInfoAttribute.ChildrenBirthRecords}.${string}.${MyInfoChildAttributes}.${string}` + `${MyInfoAttribute.ChildrenBirthRecords}.${string}.${MyInfoChildAttributes}.${number}.${string}` export type MyInfoHashPromises = Partial< Record> diff --git a/src/app/modules/myinfo/myinfo.util.ts b/src/app/modules/myinfo/myinfo.util.ts index 8f4a089ecf..533d18a26b 100644 --- a/src/app/modules/myinfo/myinfo.util.ts +++ b/src/app/modules/myinfo/myinfo.util.ts @@ -114,7 +114,7 @@ function hashChildrenFieldValues( myInfoFormattedValue = formatMyinfoDate(value) } readOnlyHashPromises[ - getMyInfoChildHashKey(field._id, subField, childName) + getMyInfoChildHashKey(field._id, subField, childIdx, childName) ] = bcrypt.hash(myInfoFormattedValue, HASH_SALT_ROUNDS) }) }) @@ -486,9 +486,10 @@ export const getMyInfoAttr = ( export const getMyInfoChildHashKey = ( fieldId: string, childAttr: MyInfoChildAttributes, + childIdx: number, childName: string, ): MyInfoChildKey => { - return `${MyInfoAttribute.ChildrenBirthRecords}.${fieldId}.${childAttr}.${childName}` + return `${MyInfoAttribute.ChildrenBirthRecords}.${fieldId}.${childAttr}.${childIdx}.${childName}` } /** @@ -512,7 +513,7 @@ export const handleMyInfoChildHashResponse = ( if (!subFields) { return } - childField.answerArray.forEach((childAnswer) => { + childField.answerArray.forEach((childAnswer, childIndex) => { // Name should be first field for child answers const childName = childAnswer[0] // Validate each answer (child) @@ -520,6 +521,7 @@ export const handleMyInfoChildHashResponse = ( const key = getMyInfoChildHashKey( field._id as string, subFields[subFieldIndex], + childIndex, childName, ) const hash = hashes[key] diff --git a/src/app/modules/submission/email-submission/email-submission.util.ts b/src/app/modules/submission/email-submission/email-submission.util.ts index d4173ad9db..5ac3609369 100644 --- a/src/app/modules/submission/email-submission/email-submission.util.ts +++ b/src/app/modules/submission/email-submission/email-submission.util.ts @@ -228,7 +228,12 @@ export const getAnswersForChild = ( return arr.map((answer, idx) => { const subfield = subFields[idx] return { - _id: getMyInfoChildHashKey(response._id, subFields[idx], childName), + _id: getMyInfoChildHashKey( + response._id, + subFields[idx], + childIdx, + childName, + ), fieldType: response.fieldType, // qnChildIdx represents the index of the MyInfo field // childIdx represents the index of the child in this MyInfo field