diff --git a/libs/application/template-api-modules/src/lib/modules/shared/api/user-profile/user-profile.service.ts b/libs/application/template-api-modules/src/lib/modules/shared/api/user-profile/user-profile.service.ts index 2ea872a220fc..a5be92e41092 100644 --- a/libs/application/template-api-modules/src/lib/modules/shared/api/user-profile/user-profile.service.ts +++ b/libs/application/template-api-modules/src/lib/modules/shared/api/user-profile/user-profile.service.ts @@ -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, @@ -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, @@ -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): Promise { const { mobilePhoneNumber, email } = await this.userProfileApiWithAuth(auth) - .userProfileControllerFindUserProfile({ - xParamNationalId: auth.nationalId, - clientType: - UserProfileControllerFindUserProfileClientTypeEnum.FirstParty, - }) + .meUserProfileControllerFindUserProfile() .catch((error) => { if (isRunningOnEnvironment('local')) { return { @@ -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,