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

chore(application-systems): Switching shared user profile service to use v2 users api #15300

Merged
merged 6 commits into from
Jun 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { DynamicModule } from '@nestjs/common'
import { BaseTemplateAPIModuleConfig } from '../../../../types'
import { UserProfileService } from './user-profile.service'

import { Configuration, UserProfileApi } from '@island.is/clients/user-profile'
import { IslyklarApi, IslykillApiModule } from '@island.is/clients/islykill'
import { Configuration, V2UsersApi } from '@island.is/clients/user-profile'
import { IslykillApiModule } from '@island.is/clients/islykill'
export class UserProfileModule {
static register(config: BaseTemplateAPIModuleConfig): DynamicModule {
return {
Expand All @@ -18,9 +18,9 @@ export class UserProfileModule {
providers: [
UserProfileService,
{
provide: UserProfileApi,
provide: V2UsersApi,
useFactory: () =>
new UserProfileApi(
new V2UsersApi(
new Configuration({
fetchApi: fetch,
basePath: config.userProfile.serviceBasePath,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import { Injectable } from '@nestjs/common'
import { Auth, AuthMiddleware } from '@island.is/auth-nest-tools'
import { Auth, AuthMiddleware, User } from '@island.is/auth-nest-tools'
import { IslyklarApi } from '@island.is/clients/islykill'
import { UserProfileApi } from '@island.is/clients/user-profile'
import {
UserProfileControllerFindUserProfileClientTypeEnum,
V2UsersApi,
} from '@island.is/clients/user-profile'
import { isRunningOnEnvironment } from '@island.is/shared/utils'
import {
BaseTemplateAPIModuleConfig,
Expand All @@ -13,8 +16,7 @@ import {
UserProfile,
UserProfileParameters,
} from '@island.is/application/types'
import { TemplateApiError } from '@island.is/nest/problem'
import { coreErrorMessages, getSlugFromType } from '@island.is/application/core'
import { getSlugFromType } from '@island.is/application/core'
import { IdsClientConfig } from '@island.is/nest/config'
import { Inject } from '@nestjs/common'
import { ConfigService, ConfigType } from '@nestjs/config'
Expand All @@ -25,7 +27,7 @@ export const MAX_OUT_OF_DATE_MONTHS = 6
@Injectable()
export class UserProfileService extends BaseTemplateApiService {
constructor(
private readonly userProfileApi: UserProfileApi,
private readonly userProfileApi: V2UsersApi,
Ballioli marked this conversation as resolved.
Show resolved Hide resolved
private readonly islyklarApi: IslyklarApi,
@Inject(IdsClientConfig.KEY)
Ballioli marked this conversation as resolved.
Show resolved Hide resolved
private idsClientConfig: ConfigType<typeof IdsClientConfig>,
Expand All @@ -35,60 +37,50 @@ export class UserProfileService extends BaseTemplateApiService {
super('UserProfile')
}

userProfileApiWithAuth(auth: Auth): UserProfileApi {
userProfileApiWithAuth(auth: Auth): V2UsersApi {
return this.userProfileApi.withMiddleware(new AuthMiddleware(auth))
}

async userProfile({
application,
auth,
params,
}: TemplateApiModuleActionProps<UserProfileParameters>): Promise<UserProfile> {
// Temporary solution while we still run the old user profile service.
return this.islyklarApi
.islyklarGet({ ssn: auth.nationalId })

.then((results) => {
if (params?.validateBankInformation && !results?.bankInfo) {
// If individual does not have a valid bank account, then we fail this check
throw new TemplateApiError(
{
title: coreErrorMessages.noBankAccountError,
summary: coreErrorMessages.noBankAccountError,
},
400,
)
}

if (params?.validateEmail && !results?.email) {
throw new TemplateApiError(
{
title: coreErrorMessages.noEmailFound,
summary: {
...coreErrorMessages.noEmailFoundDescription,
values: { link: this.getIDSLink(application) },
},
},
500,
)
}

return {
mobilePhoneNumber: results?.mobile,
email: results?.email,
bankInfo: results?.bankInfo,
}
const { mobilePhoneNumber, email } = await this.userProfileApiWithAuth(auth)
.userProfileControllerFindUserProfile({
xParamNationalId: auth.nationalId,
clientType:
UserProfileControllerFindUserProfileClientTypeEnum.FirstParty,
})
.catch((error) => {
if (isRunningOnEnvironment('local')) {
return {
email: 'mockEmail@island.is',
mobilePhoneNumber: '9999999',
bankInfo: '0000-11-222222',
}
}
if (params?.catchMock) {
return {}
throw error
})
/// Temporary dependency on íslykill for bank info retrieval via FJS API.
/// A refactor is planned to integrate bank info directly from FJS API to eliminate íslykill dependency.
const bankInfo = await this.getBankInfoFromIslykill(auth)

return {
mobilePhoneNumber: mobilePhoneNumber ?? undefined,
email: email ?? undefined,
bankInfo,
}
}

private async getBankInfoFromIslykill(
auth: User,
): Promise<string | undefined> {
return this.islyklarApi
.islyklarGet({ ssn: auth.nationalId })
.then((results) => {
return results?.bankInfo
})
.catch((error) => {
if (isRunningOnEnvironment('local')) {
return '0000-11-222222'
}
throw error
})
Expand Down
Loading