Skip to content

Commit

Permalink
chore!: update searching with jurisdiction scopes
Browse files Browse the repository at this point in the history
  • Loading branch information
Nil20 committed Dec 3, 2024
1 parent 222db41 commit d94227d
Show file tree
Hide file tree
Showing 7 changed files with 165 additions and 47 deletions.
2 changes: 0 additions & 2 deletions packages/client/src/ListSyncController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import { client } from '@client/utils/apolloClient'
import { REGISTRATION_HOME_QUERY } from '@client/views/OfficeHome/queries'

export async function syncRegistrarWorkqueue(
locationId: string,
reviewStatuses: string[],
pageSize: number,
inProgressSkip: number,
Expand All @@ -28,7 +27,6 @@ export async function syncRegistrarWorkqueue(
const queryResult = await client.query({
query: REGISTRATION_HOME_QUERY,
variables: {
declarationLocationId: locationId,
pageSize,
reviewStatuses: reviewStatuses,
inProgressSkip: inProgressSkip,
Expand Down
29 changes: 5 additions & 24 deletions packages/client/src/views/OfficeHome/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ const EVENT_SEARCH_RESULT_FIELDS = gql`
export const REGISTRATION_HOME_QUERY = gql`
${EVENT_SEARCH_RESULT_FIELDS}
query registrationHome(
$declarationLocationId: String!
$pageSize: Int
$inProgressSkip: Int
$healthSystemSkip: Int
Expand All @@ -90,7 +89,6 @@ export const REGISTRATION_HOME_QUERY = gql`
) {
inProgressTab: searchEvents(
advancedSearchParameters: {
declarationLocationId: $declarationLocationId
registrationStatuses: ["IN_PROGRESS"]
compositionType: [
"birth-declaration"
Expand All @@ -108,7 +106,6 @@ export const REGISTRATION_HOME_QUERY = gql`
}
notificationTab: searchEvents(
advancedSearchParameters: {
declarationLocationId: $declarationLocationId
registrationStatuses: ["IN_PROGRESS"]
compositionType: [
"birth-notification"
Expand All @@ -125,10 +122,7 @@ export const REGISTRATION_HOME_QUERY = gql`
}
}
reviewTab: searchEvents(
advancedSearchParameters: {
declarationLocationId: $declarationLocationId
registrationStatuses: $reviewStatuses
}
advancedSearchParameters: { registrationStatuses: $reviewStatuses }
count: $pageSize
skip: $reviewSkip
) {
Expand All @@ -138,10 +132,7 @@ export const REGISTRATION_HOME_QUERY = gql`
}
}
rejectTab: searchEvents(
advancedSearchParameters: {
declarationLocationId: $declarationLocationId
registrationStatuses: ["REJECTED"]
}
advancedSearchParameters: { registrationStatuses: ["REJECTED"] }
count: $pageSize
skip: $rejectSkip
sortColumn: "createdAt.keyword"
Expand All @@ -154,7 +145,6 @@ export const REGISTRATION_HOME_QUERY = gql`
}
approvalTab: searchEvents(
advancedSearchParameters: {
declarationLocationId: $declarationLocationId
registrationStatuses: ["VALIDATED", "CORRECTION_REQUESTED"]
}
count: $pageSize
Expand All @@ -166,10 +156,7 @@ export const REGISTRATION_HOME_QUERY = gql`
}
}
externalValidationTab: searchEvents(
advancedSearchParameters: {
declarationLocationId: $declarationLocationId
registrationStatuses: ["WAITING_VALIDATION"]
}
advancedSearchParameters: { registrationStatuses: ["WAITING_VALIDATION"] }
count: $pageSize
skip: $externalValidationSkip
) {
Expand All @@ -179,10 +166,7 @@ export const REGISTRATION_HOME_QUERY = gql`
}
}
printTab: searchEvents(
advancedSearchParameters: {
declarationLocationId: $declarationLocationId
registrationStatuses: ["REGISTERED"]
}
advancedSearchParameters: { registrationStatuses: ["REGISTERED"] }
count: $pageSize
skip: $printSkip
) {
Expand All @@ -192,10 +176,7 @@ export const REGISTRATION_HOME_QUERY = gql`
}
}
issueTab: searchEvents(
advancedSearchParameters: {
declarationLocationId: $declarationLocationId
registrationStatuses: ["CERTIFIED"]
}
advancedSearchParameters: { registrationStatuses: ["CERTIFIED"] }
count: $pageSize
skip: $issueSkip
) {
Expand Down
8 changes: 2 additions & 6 deletions packages/client/src/workqueue/reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import {
} from '@client/declarations'
import { IStoreState } from '@client/store'
import { getUserDetails, getScope } from '@client/profile/profileSelectors'
import { getUserLocation, UserDetails } from '@client/utils/userUtils'
import { UserDetails } from '@client/utils/userUtils'
import { syncRegistrarWorkqueue } from '@client/ListSyncController'
import type {
GQLEventSearchResultSet,
Expand Down Expand Up @@ -348,10 +348,7 @@ async function getWorkqueueData(
userDetails: UserDetails,
workqueuePaginationParams: IWorkqueuePaginationParams
) {
const registrationLocationId =
(userDetails && getUserLocation(userDetails).id) || ''

const scope = getScope(state)
const scope = getScope(state)!
const reviewStatuses =
scope && scope.includes(SCOPES.RECORD_REGISTER)
? [
Expand All @@ -374,7 +371,6 @@ async function getWorkqueueData(
} = workqueuePaginationParams

const result = await syncRegistrarWorkqueue(
registrationLocationId,
reviewStatuses,
pageSize,
inProgressSkip,
Expand Down
8 changes: 6 additions & 2 deletions packages/gateway/src/features/search/root-resolvers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ export const resolvers: GQLResolver = {
sort = 'desc',
sortBy
},
{ headers: authHeader }
{ headers: authHeader, dataSources }
) {
if (
!inScope(authHeader, [
Expand All @@ -101,9 +101,13 @@ export const resolvers: GQLResolver = {
results: []
}

const userIdentifier = getTokenPayload(authHeader.Authorization).sub
const user = await dataSources.usersAPI.getUserById(userIdentifier!)

const filteredSearchParamsWithScopes = filterSearchParamsWithScope(
authHeader.Authorization,
advancedSearchParameters
advancedSearchParameters,
user
)

const searchCriteria: ISearchCriteria = {
Expand Down
45 changes: 40 additions & 5 deletions packages/gateway/src/features/search/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
Scope,
SCOPES
} from '@opencrvs/commons/authentication'
import { IUserModelData } from '@gateway/features/user/type-resolvers'

export interface ISearchCriteria {
parameters: GQLAdvancedSearchParametersInput
Expand Down Expand Up @@ -51,12 +52,43 @@ export const postAdvancedSearch = async (
}
}

const addEventParamForScope = (
const addJurisdictionIdParamWithScopes = (
currentScopes: Scope[],
searchParams: Omit<GQLAdvancedSearchParametersInput, 'event'> & {
event?: GQLEventType[]
birthJurisdictionId?: string
deathJurisdictionId?: string
marriageJurisdictionId?: string
},
user: IUserModelData
) => {
if (
searchParams.event &&
(searchParams.declarationJurisdictionId ||
searchParams.declarationLocationId)
) {
}

if (currentScopes.includes(SCOPES.SEARCH_BIRTH_MY_JURISDICTION)) {
searchParams.birthJurisdictionId = user.primaryOfficeId
}
if (currentScopes.includes(SCOPES.SEARCH_DEATH_MY_JURISDICTION)) {
searchParams.deathJurisdictionId = user.primaryOfficeId
}
if (currentScopes.includes(SCOPES.SEARCH_MARRIAGE_MY_JURISDICTION)) {
searchParams.marriageJurisdictionId = user.primaryOfficeId
}
}

const addSearchParamForScope = (
requiredScopes: Scope[],
event: GQLEventType,
tokenScopes: Scope[],
filteredParams: Omit<GQLAdvancedSearchParametersInput, 'event'> & {
event?: GQLEventType[]
birthJurisdictionId?: string
deathJurisdictionId?: string
marriageJurisdictionId?: string
},
searchParamEvent: GQLEventType | undefined
) => {
Expand All @@ -70,7 +102,8 @@ const addEventParamForScope = (

export const filterSearchParamsWithScope = (
token: string,
advancedSearchParameters: GQLAdvancedSearchParametersInput
advancedSearchParameters: GQLAdvancedSearchParametersInput,
user: IUserModelData
): Omit<
GQLAdvancedSearchParametersInput,
'event' & {
Expand All @@ -81,29 +114,31 @@ export const filterSearchParamsWithScope = (
advancedSearchParameters
const currentUserScopes = getTokenPayload(token).scope

addEventParamForScope(
addSearchParamForScope(
[SCOPES.SEARCH_BIRTH, SCOPES.SEARCH_BIRTH_MY_JURISDICTION],
GQLEventType.birth,
currentUserScopes,
filteredParams,
searchParamEvent
)

addEventParamForScope(
addSearchParamForScope(
[SCOPES.SEARCH_DEATH, SCOPES.SEARCH_DEATH_MY_JURISDICTION],
GQLEventType.death,
currentUserScopes,
filteredParams,
searchParamEvent
)

addEventParamForScope(
addSearchParamForScope(
[SCOPES.SEARCH_MARRIAGE, SCOPES.SEARCH_MARRIAGE_MY_JURISDICTION],
GQLEventType.marriage,
currentUserScopes,
filteredParams,
searchParamEvent
)

addJurisdictionIdParamWithScopes(currentUserScopes, filteredParams, user)

return filteredParams
}
3 changes: 3 additions & 0 deletions packages/search/src/features/search/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ export interface IAdvancedSearchParam {
brideDoBEnd?: string
brideIdentifier?: string
dateOfMarriage?: string
birthJurisdictionId?: UUID
deathJurisdictionId?: UUID
marriageJurisdictionId?: UUID
}

export interface ISearchCriteria {
Expand Down
Loading

0 comments on commit d94227d

Please sign in to comment.