diff --git a/src/subdomains/generic/kyc/controllers/kyc.controller.ts b/src/subdomains/generic/kyc/controllers/kyc.controller.ts index 36b92ea510..c0c7aa4332 100644 --- a/src/subdomains/generic/kyc/controllers/kyc.controller.ts +++ b/src/subdomains/generic/kyc/controllers/kyc.controller.ts @@ -214,7 +214,7 @@ export class KycController { @Param('id') id: string, @Body() data: KycNationalityData, ): Promise { - return this.kycService.updateKycStep(code, +id, data, ReviewStatus.INTERNAL_REVIEW); + return this.kycService.updateNationalityStep(code, +id, data); } @Put('data/recommendation/:id') diff --git a/src/subdomains/generic/kyc/services/kyc.service.ts b/src/subdomains/generic/kyc/services/kyc.service.ts index 3626acc275..3a69baf122 100644 --- a/src/subdomains/generic/kyc/services/kyc.service.ts +++ b/src/subdomains/generic/kyc/services/kyc.service.ts @@ -176,22 +176,7 @@ export class KycService { const result = entity.getResult(); const nationality = await this.countryService.getCountry(result.nationality.id); - //Skip nationalities which needs a residencePermit first - if (Config.kyc.residencePermitCountries.includes(nationality.symbol)) continue; - - const errors = this.getNationalityErrors(entity, nationality); - const comment = errors.join(';'); - - if (errors.some((e) => KycStepIgnoringErrors.includes(e))) { - await this.kycStepRepo.update(...entity.ignored(comment)); - } else if (errors.length > 0) { - await this.kycStepRepo.update(...entity.manualReview(comment)); - } else { - await this.kycStepRepo.update(...entity.complete()); - await this.checkDfxApproval(entity); - } - - await this.createStepLog(entity.userData, entity); + await this.reviewNationalityData(entity, entity.userData, nationality); } catch (e) { this.logger.error(`Failed to auto review nationality step ${entity.id}:`, e); } @@ -560,21 +545,33 @@ export class KycService { data: Partial, reviewStatus: ReviewStatus, ): Promise { - let user = await this.getUser(kycHash); + const user = await this.getUser(kycHash); const kycStep = user.getPendingStepOrThrow(stepId); - if (data.nationality) { - const nationality = await this.countryService.getCountry(data.nationality.id); - if (!nationality) throw new BadRequestException('Nationality not found'); - - Object.assign(data.nationality, { id: nationality.id, symbol: nationality.symbol }); - } else { - user = await this.userDataService.updateUserDataInternal(user, data); - } + await this.userDataService.updateUserDataInternal(user, data); return this.updateKycStepAndLog(kycStep, user, data, reviewStatus); } + async updateNationalityStep(kycHash: string, stepId: number, data: KycNationalityData): Promise { + const user = await this.getUser(kycHash); + const kycStep = user.getPendingStepOrThrow(stepId); + + const nationality = await this.countryService.getCountry(data.nationality.id); + if (!nationality) throw new BadRequestException('Nationality not found'); + + Object.assign(data.nationality, { id: nationality.id, symbol: nationality.symbol }); + + await this.kycStepRepo.update(...kycStep.update(ReviewStatus.INTERNAL_REVIEW, data)); + await this.createStepLog(user, kycStep); + + await this.reviewNationalityData(kycStep, user, nationality); + + await this.updateProgress(user, false); + + return KycStepMapper.toStepBase(kycStep); + } + async updateBeneficialOwnerData(kycHash: string, stepId: number, data: KycBeneficialData): Promise { const user = await this.getUser(kycHash); const kycStep = user.getPendingStepOrThrow(stepId); @@ -1373,6 +1370,24 @@ export class KycService { return errors; } + private async reviewNationalityData(kycStep: KycStep, user: UserData, nationality: Country): Promise { + if (Config.kyc.residencePermitCountries.includes(nationality.symbol)) return; + + const errors = this.getNationalityErrors(kycStep, nationality); + const comment = errors.join(';'); + + if (errors.some((e) => KycStepIgnoringErrors.includes(e))) { + await this.kycStepRepo.update(...kycStep.ignored(comment)); + } else if (errors.length > 0) { + await this.kycStepRepo.update(...kycStep.manualReview(comment)); + } else { + await this.kycStepRepo.update(...kycStep.complete()); + await this.checkDfxApproval(kycStep); + } + + await this.createStepLog(user, kycStep); + } + private getFinancialDataErrors(entity: KycStep): KycError[] { const errors = this.getStepDefaultErrors(entity); const financialStepResult = entity.getResult();