Skip to content

Commit

Permalink
chore(elastic-upgrade): import from right file, simplify conditionals
Browse files Browse the repository at this point in the history
  • Loading branch information
makelicious committed Jul 17, 2024
1 parent 7dd9e81 commit 7c80e28
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 20 deletions.
4 changes: 2 additions & 2 deletions packages/search/src/elasticsearch/dbhelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ export const updateComposition = async (
)
} catch (e) {
logger.error(`updateComposition: error: ${e}`)
}

return
return
}
}

export const searchByCompositionId = async (
Expand Down
4 changes: 1 addition & 3 deletions packages/search/src/features/registration/birth/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[]
Expand Down
12 changes: 5 additions & 7 deletions packages/search/src/features/registration/death/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,8 @@ import {
import {
composeOperationHistories,
createStatusHistory,
EVENT,
DeathDocument,
IOperationHistory,
NAME_EN,
REJECTED_STATUS,
composeAssignment
} from '@search/elasticsearch/utils'
import {
Expand All @@ -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'
Expand All @@ -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[]
}
Expand Down
14 changes: 6 additions & 8 deletions packages/search/src/features/registration/marriage/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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'
Expand All @@ -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[]
}
Expand Down

0 comments on commit 7c80e28

Please sign in to comment.