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/fhir/fhir-utils.ts b/packages/search/src/features/fhir/fhir-utils.ts index 781a0cdf76f..3f6462e5ed0 100644 --- a/packages/search/src/features/fhir/fhir-utils.ts +++ b/packages/search/src/features/fhir/fhir-utils.ts @@ -25,10 +25,10 @@ import { SavedComposition, SavedLocation, SavedTask, - TaskHistory + TaskHistory, + SearchDocument } from '@opencrvs/commons/types' import { FHIR_URL } from '@search/constants' -import { SearchDocument } from '@search/elasticsearch/utils' import { logger } from '@opencrvs/commons' import fetch from 'node-fetch' diff --git a/packages/search/src/features/registration/assignment/service.ts b/packages/search/src/features/registration/assignment/service.ts index 53f51caef28..138547d40d2 100644 --- a/packages/search/src/features/registration/assignment/service.ts +++ b/packages/search/src/features/registration/assignment/service.ts @@ -12,7 +12,6 @@ import { updateComposition } from '@search/elasticsearch/dbhelper' import { getUser, IAssignment, - SearchDocument, IUserModelData, NAME_EN } from '@search/elasticsearch/utils' @@ -25,7 +24,8 @@ import { getTaskFromSavedBundle, LAST_USER_EXTENSION_URL, resourceIdentifierToUUID, - SavedBundle + SavedBundle, + SearchDocument } from '@opencrvs/commons/types' export async function updateEventToAddAssignment(requestBundle: Hapi.Request) { 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[] } diff --git a/packages/search/src/features/reindex/reindex.ts b/packages/search/src/features/reindex/reindex.ts index 3ad61412428..3295e0c84e8 100644 --- a/packages/search/src/features/reindex/reindex.ts +++ b/packages/search/src/features/reindex/reindex.ts @@ -8,10 +8,14 @@ * * Copyright (C) The OpenCRVS Authors located at https://github.com/opencrvs/opencrvs-core/blob/master/AUTHORS. */ -import { EVENT_TYPE, ValidRecord } from '@opencrvs/commons/types' +import { + EVENT_TYPE, + ValidRecord, + SearchDocument +} from '@opencrvs/commons/types' import { OPENCRVS_INDEX_NAME } from '@search/constants' import { client } from '@search/elasticsearch/client' -import { BirthDocument, SearchDocument } from '@search/elasticsearch/utils' +import { BirthDocument } from '@search/elasticsearch/utils' import { streamAllRecords } from '@search/features/records/service' import { composeDocument as composeBirthDocument } from '@search/features/registration/birth/service' import { composeDocument as composeDeathDocument } from '@search/features/registration/death/service' diff --git a/packages/search/src/features/search/utils.ts b/packages/search/src/features/search/utils.ts index 59ebdee1660..2149b71d958 100644 --- a/packages/search/src/features/search/utils.ts +++ b/packages/search/src/features/search/utils.ts @@ -11,12 +11,10 @@ import { findPatientIdentifier, Patient, - SUPPORTED_PATIENT_IDENTIFIER_CODES -} from '@opencrvs/commons/types' -import { + SUPPORTED_PATIENT_IDENTIFIER_CODES, CERTIFIED_STATUS, REGISTERED_STATUS -} from '@search/elasticsearch/utils' +} from '@opencrvs/commons/types' import { IAdvancedSearchParam } from '@search/features/search/types' import { transformDeprecatedParamsToSupported } from './deprecation-support' import { resolveLocationChildren } from './location'