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
2 changes: 1 addition & 1 deletion src/subdomains/generic/kyc/dto/mapper/kyc-info.mapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export class KycInfoMapper {
);

return KycInfoMapper.sortSteps(
userData.kycSteps.filter((s) => s.status !== ReviewStatus.CANCELED).concat(openSteps),
(userData.kycSteps ?? []).filter((s) => s.status !== ReviewStatus.CANCELED).concat(openSteps),
);
}

Expand Down
3 changes: 3 additions & 0 deletions src/subdomains/generic/kyc/entities/kyc-step.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,9 @@ export class KycStep extends IEntity {

case KycStepName.PAYMENT_AGREEMENT:
return { url: `${apiUrl}/data/payment/${this.id}`, type: UrlType.API };

case KycStepName.PHONE_CHANGE:
return { url: '', type: UrlType.NONE };
}
}

Expand Down
1 change: 1 addition & 0 deletions src/subdomains/generic/kyc/enums/kyc-step-name.enum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export enum KycStepName {
// additional features
PAYMENT_AGREEMENT = 'PaymentAgreement',
RECALL_AGREEMENT = 'RecallAgreement',
PHONE_CHANGE = 'PhoneChange',

// external registrations
REALUNIT_REGISTRATION = 'RealUnitRegistration',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,6 @@ export class UserData extends IEntity {

setUserDataSettings(dto: UpdateUserDto): UpdateResult<UserData> {
const update: Partial<UserData> = {
phone: dto.phone ?? this.phone,
language: dto.language ?? this.language,
currency: dto.currency ?? this.currency,
};
Expand Down Expand Up @@ -648,7 +647,7 @@ export class UserData extends IEntity {
}

getStep(stepId: number): KycStep | undefined {
return this.kycSteps.find((s) => s.id === stepId);
return (this.kycSteps ?? []).find((s) => s.id === stepId);
}

getStepOrThrow(stepId: number): KycStep {
Expand All @@ -659,7 +658,7 @@ export class UserData extends IEntity {
}

getStepsWith(name?: KycStepName, type?: KycStepType, sequenceNumber?: number): KycStep[] {
return this.kycSteps.filter(
return (this.kycSteps ?? []).filter(
(s) =>
(!name || s.name === name) &&
(!type || s.type === type) &&
Expand Down Expand Up @@ -687,7 +686,7 @@ export class UserData extends IEntity {
}

get hasStepsInProgress(): boolean {
return this.kycSteps.some((s) => s.isInProgress);
return (this.kycSteps ?? []).some((s) => s.isInProgress);
}

getNextSequenceNumber(stepName: KycStepName, stepType?: KycStepType): number {
Expand Down
55 changes: 40 additions & 15 deletions src/subdomains/generic/user/models/user-data/user-data.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -736,12 +736,45 @@ export class UserDataService {
return userData;
}

// --- SETTINGS UPDATE --- //
async updateUserSettings(userData: UserData, dto: UpdateUserDto): Promise<UserData> {
// check phone KYC is already started
if (userData.kycLevel != KycLevel.LEVEL_0 && (dto.phone === null || dto.phone === ''))
// --- PHONE UPDATE --- //
async updatePhone(userData: UserData, phone: string): Promise<void> {
if (userData.kycLevel !== KycLevel.LEVEL_0 && !phone)
throw new BadRequestException('KYC already started, user data deletion not allowed');

const previousPhone = userData.phone;

await this.userDataRepo.update(userData.id, {
phone,
phoneCallCheckDate: null,
phoneCallIpCheckDate: null,
phoneCallIpCountryCheckDate: null,
});

Object.assign(userData, {
phone,
phoneCallCheckDate: null,
phoneCallIpCheckDate: null,
phoneCallIpCountryCheckDate: null,
});

// update Sift
for (const user of userData.users) {
this.siftService.updateAccount({
$user_id: user.id.toString(),
$time: Date.now(),
$phone: phone,
});
}

// create KYC step
await this.kycService.createCustomKycStep(userData, KycStepName.PHONE_CHANGE, ReviewStatus.COMPLETED, {
phone,
previousPhone,
});
}

// --- SETTINGS UPDATE --- //
async updateUserSettings(userData: UserData, dto: UpdateUserDto): Promise<UserData> {
// check language
if (dto.language) {
dto.language = await this.languageService.getLanguage(dto.language.id);
Expand All @@ -754,17 +787,9 @@ export class UserDataService {
if (!dto.currency) throw new BadRequestException('Currency not found');
}

const phoneChanged = dto.phone && dto.phone !== userData.phone;

const updateSiftAccount: CreateAccount = { $time: Date.now() };

if (phoneChanged) updateSiftAccount.$phone = dto.phone;

if (phoneChanged) {
for (const user of userData.users) {
updateSiftAccount.$user_id = user.id.toString();
this.siftService.updateAccount(updateSiftAccount);
}
// check phone
if (dto.phone && dto.phone !== userData.phone) {
await this.updatePhone(userData, dto.phone);
}

await this.userDataRepo.update(...userData.setUserDataSettings(dto));
Expand Down
Loading