Skip to content
Open
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
2 changes: 1 addition & 1 deletion src/subdomains/generic/kyc/controllers/kyc.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ export class KycController {
@Param('id') id: string,
@Body() data: KycNationalityData,
): Promise<KycStepBase> {
return this.kycService.updateKycStep(code, +id, data, ReviewStatus.INTERNAL_REVIEW);
return this.kycService.updateNationalityStep(code, +id, data);
}

@Put('data/recommendation/:id')
Expand Down
65 changes: 40 additions & 25 deletions src/subdomains/generic/kyc/services/kyc.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,22 +176,7 @@ export class KycService {
const result = entity.getResult<KycNationalityData>();
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);
}
Expand Down Expand Up @@ -560,21 +545,33 @@ export class KycService {
data: Partial<UserData>,
reviewStatus: ReviewStatus,
): Promise<KycStepBase> {
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<KycStepBase> {
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<KycStepBase> {
const user = await this.getUser(kycHash);
const kycStep = user.getPendingStepOrThrow(stepId);
Expand Down Expand Up @@ -1373,6 +1370,24 @@ export class KycService {
return errors;
}

private async reviewNationalityData(kycStep: KycStep, user: UserData, nationality: Country): Promise<void> {
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<KycFinancialResponse[]>();
Expand Down
Loading