Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 15 additions & 10 deletions v1-to-v2-data-migration/helpers/defaultResolvers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,29 +45,34 @@ const informantResolver: ResolverMap = {
!isSpecialInformant(data.informant, eventType)
? resolveName(data, data.informant?.name?.[0])
: undefined, // FieldType.TEXT
'informant.dobUnknown': (data: EventRegistration, eventType: 'birth' | 'death') => {
if(isSpecialInformant(data.informant, eventType)) {
'informant.dobUnknown': (
data: EventRegistration,
eventType: 'birth' | 'death'
) => {
if (isSpecialInformant(data.informant, eventType)) {
return undefined
}
if(data.informant?.birthDate) {
if (data.informant?.birthDate) {
return false
}

return data.informant?.exactDateOfBirthUnknown
}, // FieldType.CHECKBOX
// @question, is this informant.age or informant.ageOfIndividualInYears?
'informant.age': (data: EventRegistration, eventType: 'birth' | 'death') => {
if(isSpecialInformant(data.informant, eventType)) {
if (isSpecialInformant(data.informant, eventType)) {
return undefined
}
if(data.informant?.birthDate) {
if (data.informant?.birthDate) {
return undefined
}

return data.informant?.ageOfIndividualInYears && {
age: parseInt(data.informant?.ageOfIndividualInYears?.toString(), 10),
asOfDateRef: eventType == 'birth' ? 'child.dob' : 'eventDetails.date',
};
return (
data.informant?.ageOfIndividualInYears && {
age: parseInt(data.informant?.ageOfIndividualInYears?.toString(), 10),
asOfDateRef: eventType == 'birth' ? 'child.dob' : 'eventDetails.date',
}
)
},
'informant.nationality': (
data: EventRegistration,
Expand All @@ -93,7 +98,7 @@ const informantResolver: ResolverMap = {
: undefined,
}

const documentsResolver: ResolverMap = {
export const documentsResolver: ResolverMap = {
'documents.proofOfBirth': (data: EventRegistration) =>
getDocument(data, 'CHILD'),
'documents.proofOfMother': (data: EventRegistration) =>
Expand Down
6 changes: 5 additions & 1 deletion v1-to-v2-data-migration/helpers/transform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import {
BIRTH_LOCATION_PRIVATE_HOME_KEY,
COUNTRY_CODE,
} from '../countryData/addressResolver.ts'
import { documentsResolver } from './defaultResolvers.ts'

const mappings = {
...DEFAULT_FIELD_MAPPINGS,
Expand All @@ -44,6 +45,9 @@ function patternMatch(
for (const [key, value] of Object.entries(correction)) {
const valueKey = mappings[key as keyof typeof mappings]
if (valueKey) {
if (Object.keys(documentsResolver).includes(valueKey)) {
continue
}
Comment on lines +48 to +50
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice 👍🏼

transformedData[valueKey] = value
} else if (NAME_MAPPINGS[key]) {
const nameMapping = NAME_MAPPINGS[key](value as string)
Expand Down Expand Up @@ -262,7 +266,7 @@ function legacyHistoryItemToV2ActionType(
status: 'Accepted',
type: 'REQUEST_CORRECTION' as ActionType,
declaration: correction.output,
annotation: { ...annotation, ...correction.input },
annotation: deepMerge(annotation, correction.input),
requestId: historyItem.id,
}
case 'APPROVED_CORRECTION':
Expand Down