Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(new-primary-school): Data implementation #15309

Closed
wants to merge 30 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
683f97c
Added latest version of clientConfig and latest endpoints from Juni
birkirkristmunds Jun 21, 2024
750e727
testing
birkirkristmunds Jun 21, 2024
ede00b1
Rollback test
birkirkristmunds Jun 21, 2024
e350021
feat(new-primary-school): Allergies and intolerances - Data implement…
veronikasif Jun 24, 2024
226044f
Refactor/new primary school data implementation (#15381)
alexdiljar Jun 28, 2024
6613335
Comment out UserApi
veronikasif Jun 28, 2024
0fdad8c
feat(new-primary-school): Move child page to prerequisites (#15394)
veronikasif Jul 1, 2024
0b4582b
feat(new-primary-school): Relatives - Data implementation (#15403)
veronikasif Jul 5, 2024
4a00af1
feat(new-primary-school): pronoun (#15408)
helgifr Jul 10, 2024
4ea99c0
Merge branch 'main' into new-primary-school-data-implementation
birkirkristmunds Jul 16, 2024
f2d0601
Merge branch 'main' into new-primary-school-data-implementation
birkirkristmunds Aug 20, 2024
053a6c1
Merge branch 'main' into new-primary-school-data-implementation
veronikasif Sep 2, 2024
ac9fba8
Merge branch 'main' into new-primary-school-data-implementation
veronikasif Sep 5, 2024
e668d0a
Update Frigg service path
veronikasif Sep 6, 2024
98076ef
Merge branch 'main' into new-primary-school-data-implementation
veronikasif Sep 6, 2024
d0eb54b
Update clientConfig
veronikasif Sep 9, 2024
a37643e
Merge branch 'main' into new-primary-school-data-implementation
birkirkristmunds Sep 10, 2024
6541ee9
Merge branch 'main' into new-primary-school-data-implementation
birkirkristmunds Sep 16, 2024
d9df374
feat(new-primary-school): Implement no children found page (#15909)
veronikasif Sep 17, 2024
d78f21b
feat(new-primary): Update new primary school application (#15849)
veronikasif Sep 17, 2024
43d52d1
[TS-904] Remove Allergies and intolerances page (#15923)
veronikasif Sep 18, 2024
9554c77
Merge branch 'main' into new-primary-school-data-implementation
birkirkristmunds Sep 18, 2024
f792a93
Remove duplicated translations
birkirkristmunds Sep 18, 2024
a0f004c
feat(new-primary-school): New school - Data implementation (#15437)
veronikasif Sep 18, 2024
d62a26f
Fixed codegen error?
veronikasif Sep 19, 2024
07e34d5
Updated loadOptions in FriggOptionsAsyncSelectField
veronikasif Sep 19, 2024
3103e57
Updated clientConfig
veronikasif Sep 19, 2024
f685ab3
Updated other parent address
veronikasif Sep 19, 2024
be73344
Allow children to pass through for testing
veronikasif Sep 19, 2024
40871a8
chore: nx format:write update dirty files
andes-it Sep 19, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions charts/islandis/values.dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ api:
XROAD_ICELAND_UNIVERSITY_OF_THE_ARTS_PATH: 'IS-DEV/EDU/10049/LHI-Protected/brautskraning-v1'
XROAD_INNA_PATH: 'IS-DEV/GOV/10066/MMS-Protected/inna-v1'
XROAD_INTELLECTUAL_PROPERTIES_PATH: 'IS-DEV/GOV/10030/WebAPI-Public/HUG-webAPI/'
XROAD_MMS_FRIGG_PATH: 'IS-DEV/GOV/10066/MMS-Protected/frigg-api'
XROAD_MMS_FRIGG_PATH: 'IS-DEV/GOV/10066/MMS-Protected/frigg-form-service'
XROAD_MMS_GRADE_SERVICE_ID: 'IS-DEV/GOV/10066/MMS-Protected/grade-api-v1'
XROAD_MMS_LICENSE_SERVICE_ID: 'IS-DEV/GOV/10066/MMS-Protected/license-api-v1'
XROAD_NATIONAL_REGISTRY_REDIS_NODES: '["clustercfg.general-redis-cluster-group.5fzau3.euw1.cache.amazonaws.com:6379"]'
Expand Down Expand Up @@ -647,7 +647,7 @@ application-system-api:
XROAD_HOLAR_UNIVERSITY_PATH: 'IS-DEV/EDU/10055/Holar-Protected/brautskraning-v1'
XROAD_ICELAND_UNIVERSITY_OF_THE_ARTS_PATH: 'IS-DEV/EDU/10049/LHI-Protected/brautskraning-v1'
XROAD_INNA_PATH: 'IS-DEV/GOV/10066/MMS-Protected/inna-v1'
XROAD_MMS_FRIGG_PATH: 'IS-DEV/GOV/10066/MMS-Protected/frigg-api'
XROAD_MMS_FRIGG_PATH: 'IS-DEV/GOV/10066/MMS-Protected/frigg-form-service'
XROAD_NATIONAL_REGISTRY_REDIS_NODES: '["clustercfg.general-redis-cluster-group.5fzau3.euw1.cache.amazonaws.com:6379"]'
XROAD_NATIONAL_REGISTRY_SERVICE_PATH: 'IS-DEV/GOV/10001/SKRA-Protected/Einstaklingar-v1'
XROAD_OFFICIAL_JOURNAL_APPLICATION_PATH: 'IS-DEV/GOV/10014/DMR-Protected/official-journal-application'
Expand Down
4 changes: 2 additions & 2 deletions charts/islandis/values.prod.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ api:
XROAD_ICELAND_UNIVERSITY_OF_THE_ARTS_PATH: 'IS/EDU/4210984099/LHI-Protected/brautskraning-v1'
XROAD_INNA_PATH: 'IS/GOV/6601241280/MMS-Protected/inna-v1'
XROAD_INTELLECTUAL_PROPERTIES_PATH: 'IS/GOV/6501912189/WebAPI-Public/HUG-webAPI/'
XROAD_MMS_FRIGG_PATH: 'IS/GOV/10066/MMS-Protected/frigg-api'
XROAD_MMS_FRIGG_PATH: 'IS/GOV/10066/MMS-Protected/frigg-form-service'
XROAD_MMS_GRADE_SERVICE_ID: 'IS/GOV/6601241280/MMS-Protected/grade-api-v1'
XROAD_MMS_LICENSE_SERVICE_ID: 'IS/GOV/6601241280/MMS-Protected/license-api-v1'
XROAD_NATIONAL_REGISTRY_REDIS_NODES: '["clustercfg.general-redis-cluster-group.whakos.euw1.cache.amazonaws.com:6379"]'
Expand Down Expand Up @@ -637,7 +637,7 @@ application-system-api:
XROAD_HOLAR_UNIVERSITY_PATH: 'IS/EDU/5001694359/Holar-Protected/brautskraning-v1'
XROAD_ICELAND_UNIVERSITY_OF_THE_ARTS_PATH: 'IS/EDU/4210984099/LHI-Protected/brautskraning-v1'
XROAD_INNA_PATH: 'IS/GOV/6601241280/MMS-Protected/inna-v1'
XROAD_MMS_FRIGG_PATH: 'IS/GOV/10066/MMS-Protected/frigg-api'
XROAD_MMS_FRIGG_PATH: 'IS/GOV/10066/MMS-Protected/frigg-form-service'
XROAD_NATIONAL_REGISTRY_REDIS_NODES: '["clustercfg.general-redis-cluster-group.whakos.euw1.cache.amazonaws.com:6379"]'
XROAD_NATIONAL_REGISTRY_SERVICE_PATH: 'IS/GOV/6503760649/SKRA-Protected/Einstaklingar-v1'
XROAD_OFFICIAL_JOURNAL_APPLICATION_PATH: 'IS/GOV/10014/DMR-Protected/official-journal-application'
Expand Down
4 changes: 2 additions & 2 deletions charts/islandis/values.staging.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ api:
XROAD_ICELAND_UNIVERSITY_OF_THE_ARTS_PATH: 'IS-TEST/EDU/10049/LHI-Protected/brautskraning-v1'
XROAD_INNA_PATH: 'IS-TEST/GOV/6601241280/MMS-Protected/inna-v1'
XROAD_INTELLECTUAL_PROPERTIES_PATH: 'IS-TEST/GOV/6501912189/WebAPI-Public/HUG-webAPI/'
XROAD_MMS_FRIGG_PATH: 'IS-TEST/GOV/10066/MMS-Protected/frigg-api'
XROAD_MMS_FRIGG_PATH: 'IS-TEST/GOV/10066/MMS-Protected/frigg-form-service'
XROAD_MMS_GRADE_SERVICE_ID: 'IS-TEST/GOV/6601241280/MMS-Protected/grade-api-v1'
XROAD_MMS_LICENSE_SERVICE_ID: 'IS-TEST/GOV/6601241280/MMS-Protected/license-api-v1'
XROAD_NATIONAL_REGISTRY_REDIS_NODES: '["clustercfg.general-redis-cluster-group.ab9ckb.euw1.cache.amazonaws.com:6379"]'
Expand Down Expand Up @@ -645,7 +645,7 @@ application-system-api:
XROAD_HOLAR_UNIVERSITY_PATH: 'IS-TEST/EDU/10055/Holar-Protected/brautskraning-v1'
XROAD_ICELAND_UNIVERSITY_OF_THE_ARTS_PATH: 'IS-TEST/EDU/10049/LHI-Protected/brautskraning-v1'
XROAD_INNA_PATH: 'IS-TEST/GOV/6601241280/MMS-Protected/inna-v1'
XROAD_MMS_FRIGG_PATH: 'IS-TEST/GOV/10066/MMS-Protected/frigg-api'
XROAD_MMS_FRIGG_PATH: 'IS-TEST/GOV/10066/MMS-Protected/frigg-form-service'
XROAD_NATIONAL_REGISTRY_REDIS_NODES: '["clustercfg.general-redis-cluster-group.ab9ckb.euw1.cache.amazonaws.com:6379"]'
XROAD_NATIONAL_REGISTRY_SERVICE_PATH: 'IS-TEST/GOV/6503760649/SKRA-Protected/Einstaklingar-v1'
XROAD_OFFICIAL_JOURNAL_APPLICATION_PATH: 'IS-TEST/GOV/10014/DMR-Protected/official-journal-application'
Expand Down
6 changes: 3 additions & 3 deletions infra/src/dsl/xroad.ts
Original file line number Diff line number Diff line change
Expand Up @@ -884,9 +884,9 @@ export const OfficialJournalOfIcelandApplication = new XroadConf({
export const Frigg = new XroadConf({
env: {
XROAD_MMS_FRIGG_PATH: {
dev: 'IS-DEV/GOV/10066/MMS-Protected/frigg-api',
staging: 'IS-TEST/GOV/10066/MMS-Protected/frigg-api',
prod: 'IS/GOV/10066/MMS-Protected/frigg-api',
dev: 'IS-DEV/GOV/10066/MMS-Protected/frigg-form-service',
staging: 'IS-TEST/GOV/10066/MMS-Protected/frigg-form-service',
prod: 'IS/GOV/10066/MMS-Protected/frigg-form-service',
},
},
})
Expand Down
23 changes: 16 additions & 7 deletions libs/api/domains/education/src/lib/graphql/frigg.resolver.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
import { Args, Query, Resolver } from '@nestjs/graphql'

import { UseGuards } from '@nestjs/common'

import type { User } from '@island.is/auth-nest-tools'
import {
CurrentUser,
IdsUserGuard,
Scopes,
ScopesGuard,
} from '@island.is/auth-nest-tools'

import type { User } from '@island.is/auth-nest-tools'
import { ApiScope } from '@island.is/auth/scopes'
import { FriggClientService, KeyOption } from '@island.is/clients/mms/frigg'
import {
FriggClientService,
KeyOption,
OrganizationModel,
} from '@island.is/clients/mms/frigg'
import { UseGuards } from '@nestjs/common'
import { Args, Query, Resolver } from '@nestjs/graphql'

import { KeyOptionModel } from './frigg/keyOption.model'
import { FriggOptionListInput } from './frigg/optionList.input'
import { FriggOrganizationModel } from './frigg/organization.model'

@UseGuards(IdsUserGuard, ScopesGuard)
@Scopes(ApiScope.internal)
Expand All @@ -30,4 +32,11 @@ export class FriggResolver {
): Promise<KeyOption[]> {
return this.friggClientService.getAllKeyOptions(user, input.type)
}

@Query(() => [FriggOrganizationModel], { nullable: true })
friggSchoolsByMunicipality(
@CurrentUser() user: User,
): Promise<OrganizationModel[]> {
return this.friggClientService.getAllSchoolsByMunicipality(user)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { Field, ObjectType, registerEnumType } from '@nestjs/graphql'

export enum OrganizationModelTypeEnum {
Municipality = 'municipality',
National = 'national',
School = 'school',
}

registerEnumType(OrganizationModelTypeEnum, {
name: 'OrganizationModelTypeEnum',
})

@ObjectType('EducationFriggOrganizationModel')
export class FriggOrganizationModel {
@Field()
id!: string

@Field()
nationalId!: string

@Field()
name!: string

@Field(() => OrganizationModelTypeEnum)
type!: OrganizationModelTypeEnum

@Field(() => [String], { nullable: true })
gradeLevels?: string[]

@Field(() => [FriggOrganizationModel], { nullable: true })
children?: FriggOrganizationModel[]
}
Original file line number Diff line number Diff line change
@@ -1,28 +1,90 @@
import { Inject, Injectable } from '@nestjs/common'
import { NationalRegistryXRoadService } from '@island.is/api/domains/national-registry-x-road'
import {
errorMessages,
getApplicationAnswers,
} from '@island.is/application/templates/new-primary-school'
import { ApplicationTypes } from '@island.is/application/types'
import { BaseTemplateApiService } from '../../base-template-api.service'
import { FriggClientService } from '@island.is/clients/mms/frigg'
import { LOGGER_PROVIDER } from '@island.is/logging'
import { TemplateApiError } from '@island.is/nest/problem'
import { Inject, Injectable } from '@nestjs/common'
import * as kennitala from 'kennitala'
import { TemplateApiModuleActionProps } from '../../../types'
import { BaseTemplateApiService } from '../../base-template-api.service'
import { isRunningOnEnvironment } from '@island.is/shared/utils'

@Injectable()
export class NewPrimarySchoolService extends BaseTemplateApiService {
constructor(
@Inject(LOGGER_PROVIDER) private logger: Logger,
private readonly friggClientService: FriggClientService,
private readonly nationalRegistryService: NationalRegistryXRoadService,
) {
super(ApplicationTypes.NEW_PRIMARY_SCHOOL)
}

async getTypes({ auth }: TemplateApiModuleActionProps) {
return await this.friggClientService.getTypes(auth)
async getKeyOptionsTypes({ auth }: TemplateApiModuleActionProps) {
return await this.friggClientService.getKeyOptionsTypes(auth)
}

async getAllKeyOptions({ auth }: TemplateApiModuleActionProps) {
return await this.friggClientService.getAllKeyOptions(auth, '')
return await this.friggClientService.getAllKeyOptions(auth, undefined)
}

async getChildInformation({
auth,
application,
}: TemplateApiModuleActionProps) {
const { childNationalId } = getApplicationAnswers(application.answers)

return await this.friggClientService.getUserById(auth, childNationalId)
}

async getHealth({ auth }: TemplateApiModuleActionProps) {
return await this.friggClientService.getHealth(auth)
async getChildren({ auth }: TemplateApiModuleActionProps) {
const children =
await this.nationalRegistryService.getChildrenCustodyInformation(auth)

const currentYear = new Date().getFullYear()
const maxYear = currentYear - 7 // 2nd grade
const minYear = currentYear - 16 // 10th grade

// Check if the child is at primary school age and lives with the applicant
const filteredChildren = children.filter((child) => {
// Allow children to pass through
const validChildren = [
'1111111119',
'2222222229',
'5555555559',
'6666666669',
]
if (
isRunningOnEnvironment('local') &&
validChildren.includes(child.nationalId)
) {
return true
}

const yearOfBirth = kennitala
.info(child.nationalId)
.birthday.getFullYear()

return (
child.livesWithApplicant &&
yearOfBirth >= minYear &&
yearOfBirth <= maxYear
)
})

if (filteredChildren.length === 0) {
throw new TemplateApiError(
{
title: errorMessages.noChildrenFoundTitle,
summary: errorMessages.noChildrenFoundMessage,
},
400,
)
}

return filteredChildren
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,20 @@ import {
defineTemplateApi,
} from '@island.is/application/types'

export const GetTypesApi = defineTemplateApi({
action: 'getTypes',
externalDataId: 'types',
export const GetKeyOptionsTypesApi = defineTemplateApi({
action: 'getKeyOptionsTypes',
externalDataId: 'keyOptionsTypes',
namespace: ApplicationTypes.NEW_PRIMARY_SCHOOL,
})

export const GetHealthApi = defineTemplateApi({
action: 'getHealth',
externalDataId: 'health',
export const OptionsApi = defineTemplateApi({
action: 'getAllKeyOptions',
externalDataId: 'KeyOptions',
namespace: ApplicationTypes.NEW_PRIMARY_SCHOOL,
})

export const ChildrenApi = defineTemplateApi({
action: 'getChildren',
externalDataId: 'children',
namespace: ApplicationTypes.NEW_PRIMARY_SCHOOL,
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
import { coreErrorMessages } from '@island.is/application/core'
import {
FieldBaseProps,
FieldComponents,
FieldTypes,
FormText,
} from '@island.is/application/types'
import { AsyncSelectFormField } from '@island.is/application/ui-fields'
import { useLocale } from '@island.is/localization'
import React, { FC } from 'react'
import { OptionsType } from '../../lib/constants'
import { friggOptionsQuery } from '../../graphql/queries'
import {
FriggOptionsQuery,
FriggOptionsQueryVariables,
} from '../../types/schema'

type FriggOptionsAsyncSelectFieldProps = {
field: {
props: {
optionsType: OptionsType
placeholder: FormText
isMulti?: boolean
}
}
}

const FriggOptionsAsyncSelectField: FC<
React.PropsWithChildren<FieldBaseProps & FriggOptionsAsyncSelectFieldProps>
> = ({ error, field, application }) => {
const { lang } = useLocale()
const { title, props, defaultValue, id } = field
const { isMulti = true, optionsType, placeholder } = props

return (
<AsyncSelectFormField
application={application}
error={error}
field={{
type: FieldTypes.ASYNC_SELECT,
component: FieldComponents.ASYNC_SELECT,
children: undefined,
id,
title,
placeholder,
defaultValue,
loadingError: coreErrorMessages.failedDataProvider,
loadOptions: async ({ apolloClient }) => {
const { data } = await apolloClient.query<
FriggOptionsQuery,
FriggOptionsQueryVariables
>({
query: friggOptionsQuery,
variables: {
type: {
type: optionsType,
},
},
})

return (
data?.friggOptions?.flatMap(({ options }) =>
options.flatMap(({ value, key }) => {
let content = value.find(
({ language }) => language === lang,
)?.content
if (!content) {
content = value.find(
({ language }) => language === 'is',
)?.content
}
return { value: key ?? '', label: content ?? '' }
}),
) ?? []
)
},
isMulti,
backgroundColor: 'blue',
}}
/>
)
}

export default FriggOptionsAsyncSelectField
Loading
Loading