Skip to content

Commit

Permalink
fix multi-location-id queries not finding anything (#3574)
Browse files Browse the repository at this point in the history
  • Loading branch information
rikukissa authored Jun 27, 2022
1 parent 97fd087 commit 11aa0fa
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 10 deletions.
2 changes: 1 addition & 1 deletion packages/gateway/src/features/search/root-resolvers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export const resolvers: GQLResolver = {
if (locationIds.length <= 0 || locationIds.includes('')) {
return await Promise.reject(new Error('Invalid location id'))
}
searchCriteria.declarationLocationId = locationIds.join(',')
searchCriteria.declarationLocationId = locationIds
} else if (authHeader && !hasScope(authHeader, 'register')) {
// Only register scope user can search without locationIds
return await Promise.reject(new Error('User does not have permission'))
Expand Down
2 changes: 1 addition & 1 deletion packages/gateway/src/features/search/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ type EventProgressSet {
type Query {
searchEvents(
userId: String
locationIds: [String]
locationIds: [String!]
status: [String]
type: [String]
trackingId: String
Expand Down
2 changes: 1 addition & 1 deletion packages/gateway/src/features/search/type-resolvers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ interface ISearchDataTemplate {
[key: string]: any
}
export interface ISearchCriteria {
declarationLocationId?: string
declarationLocationId?: string[]
declarationLocationHirarchyId?: string
status?: string[]
type?: string[]
Expand Down
2 changes: 1 addition & 1 deletion packages/gateway/src/graphql/schema.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1914,7 +1914,7 @@ export interface QueryToFetchTimeLoggedMetricsByPractitionerResolver<

export interface QueryToSearchEventsArgs {
userId?: string
locationIds?: Array<string | null>
locationIds?: Array<string>
status?: Array<string | null>
type?: Array<string | null>
trackingId?: string
Expand Down
2 changes: 1 addition & 1 deletion packages/gateway/src/graphql/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ type Query {
): TimeLoggedMetricsResultSet
searchEvents(
userId: String
locationIds: [String]
locationIds: [String!]
status: [String]
type: [String]
trackingId: String
Expand Down
2 changes: 1 addition & 1 deletion packages/search/src/features/search/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export interface ISearchQuery {
event?: string
type?: string[]
status?: string[]
declarationLocationId?: string
declarationLocationId?: string | string[]
declarationLocationHirarchyId?: string
createdBy?: string
from?: number
Expand Down
18 changes: 14 additions & 4 deletions packages/search/src/features/search/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export function queryBuilder(
eventLocationId: string,
gender: string,
nameCombinations: INameCombination[],
declarationLocationId: string,
declarationLocationId: string | string[],
declarationLocationHirarchyId: string,
createdBy: string,
filters: IFilter
Expand Down Expand Up @@ -147,13 +147,23 @@ export function queryBuilder(
})
}

if (declarationLocationId !== EMPTY_STRING) {
if (Array.isArray(declarationLocationId)) {
declarationLocationId.forEach((id) => {
should.push({
term: {
'declarationLocationId.keyword': {
value: id,
boost: 2
}
}
})
})
} else if (declarationLocationId !== EMPTY_STRING) {
must.push({
term: {
'declarationLocationId.keyword': {
value: declarationLocationId,
// tslint:disable-next-line
boost: 2.0
boost: 2
}
}
})
Expand Down

0 comments on commit 11aa0fa

Please sign in to comment.