diff --git a/packages/search/src/elasticsearch/dbhelper.ts b/packages/search/src/elasticsearch/dbhelper.ts index f5af6d5c571..5ae14f55dd4 100644 --- a/packages/search/src/elasticsearch/dbhelper.ts +++ b/packages/search/src/elasticsearch/dbhelper.ts @@ -57,9 +57,9 @@ export const updateComposition = async ( ) } catch (e) { logger.error(`updateComposition: error: ${e}`) - } - return + return + } } export const searchByCompositionId = async ( diff --git a/packages/search/src/features/registration/birth/service.ts b/packages/search/src/features/registration/birth/service.ts index 961d048a979..5c6a03673cc 100644 --- a/packages/search/src/features/registration/birth/service.ts +++ b/packages/search/src/features/registration/birth/service.ts @@ -73,9 +73,7 @@ export const composeDocument = ( compositionId: composition.id, event: EVENT.BIRTH, createdAt: - (existingDocument && - existingDocument.body.hits.hits.length > 0 && - existingDocument.body.hits.hits[0]?._source?.createdAt) || + existingDocument?.body?.hits?.hits?.[0]?._source?.createdAt || Date.now().toString(), modifiedAt: Date.now().toString(), operationHistories: composeOperationHistories(record) as IOperationHistory[] diff --git a/packages/search/src/features/registration/death/service.ts b/packages/search/src/features/registration/death/service.ts index 37d39af22ff..a4953b071e3 100644 --- a/packages/search/src/features/registration/death/service.ts +++ b/packages/search/src/features/registration/death/service.ts @@ -15,11 +15,8 @@ import { import { composeOperationHistories, createStatusHistory, - EVENT, DeathDocument, - IOperationHistory, NAME_EN, - REJECTED_STATUS, composeAssignment } from '@search/elasticsearch/utils' import { @@ -43,7 +40,10 @@ import { resourceIdentifierToUUID, findFirstTaskHistory, getInformantType, - ValidRecord + ValidRecord, + REJECTED_STATUS, + IOperationHistory, + EVENT } from '@opencrvs/commons/types' import { findAssignment } from '@opencrvs/commons/assignment' import { findPatientPrimaryIdentifier } from '@search/features/search/utils' @@ -66,9 +66,7 @@ export const composeDocument = ( compositionId: composition.id, event: EVENT.DEATH, createdAt: - (existingDocument && - existingDocument.body.hits.hits.length > 0 && - existingDocument.body.hits.hits[0]?._source?.createdAt) || + existingDocument?.body?.hits?.hits?.[0]?._source?.createdAt || Date.now().toString(), operationHistories: composeOperationHistories(bundle) as IOperationHistory[] } diff --git a/packages/search/src/features/registration/marriage/service.ts b/packages/search/src/features/registration/marriage/service.ts index 61d7265218d..727a527fd5f 100644 --- a/packages/search/src/features/registration/marriage/service.ts +++ b/packages/search/src/features/registration/marriage/service.ts @@ -14,12 +14,8 @@ import { } from '@search/elasticsearch/dbhelper' import { createStatusHistory, - EVENT, - SearchDocument, MarriageDocument, - IOperationHistory, NAME_EN, - REJECTED_STATUS, composeOperationHistories, composeAssignment } from '@search/elasticsearch/utils' @@ -45,7 +41,11 @@ import { SavedRelatedPerson, findFirstTaskHistory, getInformantType, - ValidRecord + ValidRecord, + EVENT, + SearchDocument, + IOperationHistory, + REJECTED_STATUS } from '@opencrvs/commons/types' import { findAssignment } from '@opencrvs/commons/assignment' import { findPatientPrimaryIdentifier } from '@search/features/search/utils' @@ -66,9 +66,7 @@ export const composeDocument = ( compositionId: composition.id, event: EVENT.MARRIAGE, createdAt: - (existingDocument && - existingDocument.body.hits.hits.length > 0 && - existingDocument.body.hits.hits[0]?._source?.createdAt) || + existingDocument?.body?.hits?.hits?.[0]?._source?.createdAt || Date.now().toString(), operationHistories: composeOperationHistories(bundle) as IOperationHistory[] }