Skip to content

Commit

Permalink
fix: re-add childIdx to MyInfoChildHashKey for case of >1 child per f…
Browse files Browse the repository at this point in the history
…ield
  • Loading branch information
wanlingt committed Oct 1, 2023
1 parent c4cb6a4 commit d173907
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/app/modules/myinfo/myinfo.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<MyInfoAttribute | MyInfoChildKey, Promise<string>>
Expand Down
8 changes: 5 additions & 3 deletions src/app/modules/myinfo/myinfo.util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ function hashChildrenFieldValues(
return
}
readOnlyHashPromises[
getMyInfoChildHashKey(field._id, subField, childName)
getMyInfoChildHashKey(field._id, subField, childIdx, childName)
] = bcrypt.hash(myInfoFormattedValue, HASH_SALT_ROUNDS)
})
})
Expand Down Expand Up @@ -487,9 +487,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}`
}

/**
Expand All @@ -513,14 +514,15 @@ 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)
childAnswer.forEach((attrAnswer, subFieldIndex) => {
const key = getMyInfoChildHashKey(
field._id as string,
subFields[subFieldIndex],
childIndex,
childName,
)
const hash = hashes[key]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit d173907

Please sign in to comment.