diff --git a/packages/client/src/search/transformer.ts b/packages/client/src/search/transformer.ts index 70c7b21813..7f2a277618 100644 --- a/packages/client/src/search/transformer.ts +++ b/packages/client/src/search/transformer.ts @@ -9,8 +9,8 @@ * Copyright (C) The OpenCRVS Authors located at https://github.com/opencrvs/opencrvs-core/blob/master/AUTHORS. */ import { ITaskHistory } from '@client/declarations' -import { EMPTY_STRING, LANG_EN } from '@client/utils/constants' -import { createNamesMap } from '@client/utils/data-formatting' +import { EMPTY_STRING } from '@client/utils/constants' +import { getLocalisedName } from '@client/utils/data-formatting' import { formatLongDate } from '@client/utils/date-formatting' import { EventSearchSet, @@ -21,7 +21,6 @@ import { import type { GQLBirthEventSearchSet, GQLDeathEventSearchSet, - GQLHumanName, GQLMarriageEventSearchSet, GQLRegStatus } from '@client/utils/gateway-deprecated-do-not-use' @@ -60,42 +59,39 @@ export const transformData = ( let birthReg let deathReg let marriageReg - let names - let groomNames - let brideNames + let name + let groomName + let brideName let dateOfEvent - let mergedMarriageName const assignedReg = reg if (reg.registration) { if (isBirthEvent(reg)) { birthReg = reg - names = (birthReg.childName as GQLHumanName[]) || [] + name = birthReg.childName + ? getLocalisedName(intl, birthReg.childName[0] as HumanName) + : EMPTY_STRING dateOfEvent = birthReg.dateOfBirth } else if (isDeathEvent(reg)) { deathReg = reg - names = (deathReg.deceasedName as GQLHumanName[]) || [] + name = deathReg.deceasedName + ? getLocalisedName(intl, deathReg.deceasedName[0] as HumanName) + : EMPTY_STRING dateOfEvent = deathReg && deathReg.dateOfDeath } else if (isMarriageEvent(reg)) { - marriageReg = reg - groomNames = - (marriageReg && (marriageReg.groomName as GQLHumanName[])) || [] - brideNames = - (marriageReg && (marriageReg.brideName as GQLHumanName[])) || [] + groomName = reg.groomName + ? getLocalisedName(intl, reg.groomName[0] as HumanName) + : EMPTY_STRING + brideName = reg.brideName + ? getLocalisedName(intl, reg.brideName[0] as HumanName) + : EMPTY_STRING - const groomName = - (createNamesMap(groomNames as HumanName[])[locale] as string) || - (createNamesMap(groomNames as HumanName[])[LANG_EN] as string) - const brideName = - (createNamesMap(brideNames as HumanName[])[locale] as string) || - (createNamesMap(brideNames as HumanName[])[LANG_EN] as string) - - mergedMarriageName = + name = brideName && groomName ? `${groomName} & ${brideName}` : brideName || groomName || EMPTY_STRING - dateOfEvent = marriageReg && marriageReg.dateOfMarriage + dateOfEvent = marriageReg && reg.dateOfMarriage } } const status = @@ -104,12 +100,7 @@ export const transformData = ( return { id: assignedReg.id, - name: - assignedReg.type === EventType.Marriage - ? mergedMarriageName - : (createNamesMap(names as HumanName[])[locale] as string) || - (createNamesMap(names as HumanName[])[LANG_EN] as string) || - '', + name, dob: (birthReg?.dateOfBirth?.length && formatLongDate(birthReg.dateOfBirth, locale)) ||