Skip to content

Commit

Permalink
fix: include all child location in `getStatusWiseRegistrationCountHan…
Browse files Browse the repository at this point in the history
…dler` (#7917)

* fix: include all child location in `getStatusWiseRegistrationCountHandler`

* fix: unit test

* refactor: include children location directly to matchRules

* fix: use terms for matchRule

* fix: test: remove one http response

* chore: remove comment
  • Loading branch information
jamil314 authored Nov 12, 2024
1 parent 3b5b672 commit e9d8982
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
3 changes: 3 additions & 0 deletions packages/search/src/features/search/handler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import { ICountQueryParam } from './handler'
import { SearchDocument } from '@opencrvs/commons'
import * as searchService from './service'
import { OPENCRVS_INDEX_NAME } from '@search/constants'
import * as fetchAny from 'jest-fetch-mock'
const fetch = fetchAny as fetchAny.FetchMock

jest.setTimeout(100000)

Expand Down Expand Up @@ -118,6 +120,7 @@ describe('Verify handlers', () => {
it('Should return 200 for valid payload', async () => {
const t = await setupTestCases(setup, { scope: ['register'] })

fetch.mockResponses([JSON.stringify([{ id: '123' }]), { status: 200 }])
const res = await t.callStatusWiseRegistrationCount({
declarationJurisdictionId: '123',
status: ['REGISTERED']
Expand Down
11 changes: 8 additions & 3 deletions packages/search/src/features/search/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ import {
logger,
SearchDocument,
EVENT,
getSearchTotalCount
getSearchTotalCount,
UUID
} from '@opencrvs/commons'
import { badRequest, internal } from '@hapi/boom'
import { DEFAULT_SIZE, advancedSearch } from '@search/features/search/service'
Expand All @@ -33,6 +34,7 @@ import {
searchForBirthDuplicates
} from '@search/features/registration/deduplicate/service'
import { capitalize } from 'lodash'
import { resolveLocationChildren } from './location'

type IAssignmentPayload = {
compositionId: string
Expand Down Expand Up @@ -138,9 +140,12 @@ export async function getStatusWiseRegistrationCountHandler(
}
]
if (payload.declarationJurisdictionId) {
const leafLevelJurisdictionIds = await resolveLocationChildren(
payload.declarationJurisdictionId as UUID
)
matchRules.push({
match: {
declarationJurisdictionIds: payload.declarationJurisdictionId
terms: {
'declarationJurisdictionIds.keyword': leafLevelJurisdictionIds
}
})
}
Expand Down

0 comments on commit e9d8982

Please sign in to comment.