Skip to content

Commit

Permalink
Use humanName for other search/transformer.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
Siyasanga committed Jan 15, 2025
1 parent 8ab4750 commit fbb4521
Showing 1 changed file with 20 additions and 29 deletions.
49 changes: 20 additions & 29 deletions packages/client/src/search/transformer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -21,7 +21,6 @@ import {
import type {
GQLBirthEventSearchSet,
GQLDeathEventSearchSet,
GQLHumanName,
GQLMarriageEventSearchSet,
GQLRegStatus
} from '@client/utils/gateway-deprecated-do-not-use'
Expand Down Expand Up @@ -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 =
Expand All @@ -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)) ||
Expand Down

0 comments on commit fbb4521

Please sign in to comment.