Skip to content
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
8 changes: 7 additions & 1 deletion src/subdomains/generic/kyc/entities/kyc-step.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { IdNowResult } from '../dto/ident-result.dto';
import { ManualIdentResult } from '../dto/manual-ident-result.dto';
import { KycSessionInfoDto } from '../dto/output/kyc-info.dto';
import { IdDocTypeMap, ReviewAnswer, SumsubResult } from '../dto/sum-sub.dto';
import { KycStepName } from '../enums/kyc-step-name.enum';
import { KycStepIdentRequiredForReview, KycStepName } from '../enums/kyc-step-name.enum';
import { KycStepType, UrlType } from '../enums/kyc.enum';
import { ReviewStatus } from '../enums/review-status.enum';
import { SumsubService } from '../services/integration/sum-sub.service';
Expand Down Expand Up @@ -369,6 +369,12 @@ export class KycStep extends IEntity {
return [this.comment, comment].filter((c) => c).join(';');
}

reviewStatusForIdentLevel(fallback: ReviewStatus): ReviewStatus {
return KycStepIdentRequiredForReview.includes(this.name) && this.userData.kycLevel < KycLevel.LEVEL_30
Comment thread
Yannick1712 marked this conversation as resolved.
? ReviewStatus.INTERNAL_REVIEW
: fallback;
}

get resultData(): IdentResultData {
if (!this.result) return undefined;

Expand Down
9 changes: 9 additions & 0 deletions src/subdomains/generic/kyc/enums/kyc-step-name.enum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,15 @@ export enum KycStepName {
}

export const KycStepCancelable = [KycStepName.ADDRESS_CHANGE, KycStepName.PHONE_CHANGE, KycStepName.NAME_CHANGE];
export const KycStepIdentRequiredForReview = [
KycStepName.LEGAL_ENTITY,
KycStepName.SOLE_PROPRIETORSHIP_CONFIRMATION,
KycStepName.AUTHORITY,
KycStepName.OWNER_DIRECTORY,
KycStepName.SIGNATORY_POWER,
KycStepName.BENEFICIAL_OWNER,
KycStepName.OPERATIONAL_ACTIVITY,
];
export const KycStepRepeatable = [
KycStepName.ADDRESS_CHANGE,
KycStepName.PHONE_CHANGE,
Expand Down
33 changes: 27 additions & 6 deletions src/subdomains/generic/kyc/services/kyc.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ import {
import { KycStep, KycStepResult } from '../entities/kyc-step.entity';
import { ContentType } from '../enums/content-type.enum';
import { FileCategory } from '../enums/file-category.enum';
import { KycStepCancelable, KycStepName } from '../enums/kyc-step-name.enum';
import { KycStepCancelable, KycStepIdentRequiredForReview, KycStepName } from '../enums/kyc-step-name.enum';
import { KycLogType, KycStepType, getIdentificationType, requiredKycSteps } from '../enums/kyc.enum';
import { ReviewStatus } from '../enums/review-status.enum';
import { KycStepRepository } from '../repositories/kyc-step.repository';
Expand Down Expand Up @@ -624,7 +624,7 @@ export class KycService {

await this.userDataService.updateUserDataInternal(user, data);

return this.updateKycStepAndLog(kycStep, user, data, reviewStatus);
return this.updateKycStepAndLog(kycStep, user, data, kycStep.reviewStatusForIdentLevel(reviewStatus));
}

async updateNationalityStep(kycHash: string, stepId: number, data: KycNationalityData): Promise<KycStepBase> {
Expand Down Expand Up @@ -673,14 +673,14 @@ export class KycService {
allBeneficialOwnersDomicile: allBeneficialOwnersDomicile.join('\n'),
});

return this.updateKycStepAndLog(kycStep, user, data, ReviewStatus.MANUAL_REVIEW);
return this.updateKycStepAndLog(kycStep, user, data, kycStep.reviewStatusForIdentLevel(ReviewStatus.MANUAL_REVIEW));
}

async updateOperationActivityData(kycHash: string, stepId: number, data: KycOperationalData): Promise<KycStepBase> {
const user = await this.getUser(kycHash);
const kycStep = user.getPendingStepOrThrow(stepId, KycStepName.OPERATIONAL_ACTIVITY);

return this.updateKycStepAndLog(kycStep, user, data, ReviewStatus.MANUAL_REVIEW);
return this.updateKycStepAndLog(kycStep, user, data, kycStep.reviewStatusForIdentLevel(ReviewStatus.MANUAL_REVIEW));
}

async updateRecommendationData(kycHash: string, stepId: number, data: KycRecommendationData) {
Expand Down Expand Up @@ -720,7 +720,11 @@ export class KycService {
kycStep,
);

await this.kycStepRepo.update(...kycStep.manualReview(undefined, urlAsJson ? { url } : url));
const result = urlAsJson ? { url } : url;

await this.kycStepRepo.update(
...kycStep.update(kycStep.reviewStatusForIdentLevel(ReviewStatus.MANUAL_REVIEW), result),
);
await this.createStepLog(user, kycStep);
await this.updateProgress(user, false);

Expand All @@ -743,7 +747,13 @@ export class KycService {
kycStep,
);

await this.kycStepRepo.update(...kycStep.manualReview(undefined, { url, legalEntity: data.legalEntity }));
const result = { url, legalEntity: data.legalEntity };

await this.kycStepRepo.update(
...(KycStepIdentRequiredForReview.includes(KycStepName.LEGAL_ENTITY) && user.kycLevel < 30
? kycStep.internalReview(result)
: kycStep.manualReview(undefined, result)),
);

await this.createStepLog(user, kycStep);
await this.updateProgress(user, false);
Expand Down Expand Up @@ -1498,6 +1508,17 @@ export class KycService {
nationality,
});

if (userData.kycLevel >= KycLevel.LEVEL_30) {
await this.kycStepRepo.update(
{
name: In(KycStepIdentRequiredForReview),
status: ReviewStatus.INTERNAL_REVIEW,
userData: { id: kycStep.userData.id },
},
{ status: ReviewStatus.MANUAL_REVIEW },
);
}

if (kycStep.isValidCreatingBankData && !DisabledProcess(Process.AUTO_CREATE_BANK_DATA))
await this.bankDataService.createBankDataInternal(kycStep.userData, {
name: kycStep.userName,
Expand Down