Skip to content

Commit

Permalink
fix(application-system-api): Fix user-profile shared-api module (#15439)
Browse files Browse the repository at this point in the history
* Use V2MeApi from UserProfile V2.
Add validation error handling for bank account and email.

* updating module to match service

---------

Co-authored-by: Baldur Óli <[email protected]>
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
  • Loading branch information
3 people authored and oskarjs committed Aug 20, 2024
1 parent 29663ea commit e75ff7a
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 17 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { DynamicModule } from '@nestjs/common'
import { BaseTemplateAPIModuleConfig } from '../../../../types'
import { UserProfileService } from './user-profile.service'
import { Configuration, V2UsersApi } from '@island.is/clients/user-profile'
import { Configuration, V2MeApi } from '@island.is/clients/user-profile'
import { IslykillApiModule } from '@island.is/clients/islykill'
export class UserProfileModule {
static register(config: BaseTemplateAPIModuleConfig): DynamicModule {
Expand All @@ -17,9 +17,9 @@ export class UserProfileModule {
providers: [
UserProfileService,
{
provide: V2UsersApi,
provide: V2MeApi,
useFactory: () =>
new V2UsersApi(
new V2MeApi(
new Configuration({
fetchApi: fetch,
basePath: config.userProfile.serviceBasePath,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import { Injectable } from '@nestjs/common'
import { Auth, AuthMiddleware, User } from '@island.is/auth-nest-tools'
import { IslyklarApi } from '@island.is/clients/islykill'
import {
UserProfileControllerFindUserProfileClientTypeEnum,
V2UsersApi,
} from '@island.is/clients/user-profile'
import { V2MeApi } from '@island.is/clients/user-profile'
import { isRunningOnEnvironment } from '@island.is/shared/utils'
import {
BaseTemplateAPIModuleConfig,
Expand All @@ -16,18 +13,17 @@ import {
UserProfile,
UserProfileParameters,
} from '@island.is/application/types'
import { getSlugFromType } from '@island.is/application/core'
import { coreErrorMessages, getSlugFromType } from '@island.is/application/core'
import { IdsClientConfig } from '@island.is/nest/config'
import { Inject } from '@nestjs/common'
import { ConfigService, ConfigType } from '@nestjs/config'
import { getConfigValue } from '../../shared.utils'

export const MAX_OUT_OF_DATE_MONTHS = 6
import { TemplateApiError } from '@island.is/nest/problem'

@Injectable()
export class UserProfileService extends BaseTemplateApiService {
constructor(
private readonly userProfileApi: V2UsersApi,
private readonly userProfileApi: V2MeApi,
private readonly islyklarApi: IslyklarApi,
@Inject(IdsClientConfig.KEY)
private idsClientConfig: ConfigType<typeof IdsClientConfig>,
Expand All @@ -37,19 +33,17 @@ export class UserProfileService extends BaseTemplateApiService {
super('UserProfile')
}

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

async userProfile({
application,
auth,
params,
}: TemplateApiModuleActionProps<UserProfileParameters>): Promise<UserProfile> {
const { mobilePhoneNumber, email } = await this.userProfileApiWithAuth(auth)
.userProfileControllerFindUserProfile({
xParamNationalId: auth.nationalId,
clientType:
UserProfileControllerFindUserProfileClientTypeEnum.FirstParty,
})
.meUserProfileControllerFindUserProfile()
.catch((error) => {
if (isRunningOnEnvironment('local')) {
return {
Expand All @@ -59,10 +53,35 @@ export class UserProfileService extends BaseTemplateApiService {
}
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)

if (params?.validateBankInformation && !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 && !email) {
throw new TemplateApiError(
{
title: coreErrorMessages.noEmailFound,
summary: {
...coreErrorMessages.noEmailFoundDescription,
values: { link: this.getIDSLink(application) },
},
},
500,
)
}

return {
mobilePhoneNumber: mobilePhoneNumber ?? undefined,
email: email ?? undefined,
Expand Down

0 comments on commit e75ff7a

Please sign in to comment.