From 84b242e4dc94cc93eccd0d7c0ae279f9271ae824 Mon Sep 17 00:00:00 2001 From: Yannick1712 Date: Sun, 28 Aug 2022 16:05:25 +0200 Subject: [PATCH 1/5] [DEV-677] add KYC Mails --- src/shared/i18n/de/mail.json | 5 +++++ src/shared/i18n/en/mail.json | 5 +++++ src/shared/i18n/es/mail.json | 5 +++++ src/shared/i18n/fr/mail.json | 5 +++++ src/shared/i18n/it/mail.json | 5 +++++ src/shared/i18n/pt/mail.json | 5 +++++ src/user/models/kyc/kyc-process.service.ts | 14 +++++++++++--- src/user/models/user-data/user-data.service.ts | 16 ++++++++-------- 8 files changed, 49 insertions(+), 11 deletions(-) diff --git a/src/shared/i18n/de/mail.json b/src/shared/i18n/de/mail.json index ec1071d282..7269b53c1a 100644 --- a/src/shared/i18n/de/mail.json +++ b/src/shared/i18n/de/mail.json @@ -19,6 +19,11 @@ "salutation": "Deine Online-Identifikation ist fehlgeschlagen", "body": "

Wir haben festgestellt, dass die Online-Identifizierung fehlgeschlagen ist. Wir haben jedoch bereits die Video-Identifikation freigeschaltet.
Weiter geht es, indem man auf der Payment Seite (Kaufen, Verkaufen & Staking) auf den Refresh Button (roter Pfeil in Kreisoptik) klickt oder hier.

Mache den letzten Schritt und beginne noch heute deine Reise zur finanziellen Freiheit

Dein DFX Team
Bitcoiners by heart ♥

", "title": "Online Identifikation fehlgeschlagen" + }, + "success": { + "salutation": "Verifikation erfolgreich", + "body": "
Deine Verifikation ist abgeschlossen.
Viel Erfolg beim Traden
Dein freundliches DFX Team
Bitcoiners by heart ♥️
", + "title": "Verifikation erfolgreich" } }, "stakingRef": { diff --git a/src/shared/i18n/en/mail.json b/src/shared/i18n/en/mail.json index 8bfb6f0ea1..7119c473eb 100644 --- a/src/shared/i18n/en/mail.json +++ b/src/shared/i18n/en/mail.json @@ -19,6 +19,11 @@ "salutation": "Your online identification has failed", "body": "

We have noticed that your online identification has failed. However, we have already unlocked video identification for you.
Please continue by clicking on the refresh button in the limit section on the payment page (Buy, Sell & Staking) or here.

Take the final step and start working on your financial freedom today

Your DFX Team
Bitcoiners by heart ♥

", "title": "Online identification failed" + }, + "success": { + "salutation": "Verification successful", + "body": "
Your verification is complete.
Happy Trading
Your DFX Team
Bitcoiners by heart ♥️
", + "title": "Verification successful" } }, "stakingRef": { diff --git a/src/shared/i18n/es/mail.json b/src/shared/i18n/es/mail.json index b5dff3dd69..b73d183065 100644 --- a/src/shared/i18n/es/mail.json +++ b/src/shared/i18n/es/mail.json @@ -19,6 +19,11 @@ "salutation": "Tu identificación online ha fallado", "body": "

Nos hemos dado cuenta de que tu identificación online ha fallado. De todas formas, hemos desbloquado la identificación por video para ti.
Por favor, continúa apretando el botón de refresco en la sección \"límite\" en la página de pago (Compra, Vende y Staking) o aquí.

Da el último paso y empieza a crear tu libertad financiera hoy

Tu Equipo DFX
Bitcoiners de corazón ♥

", "title": "Tu identificación online ha fallado" + }, + "success": { + "salutation": "Verificación exitosa", + "body": "
Su verificación está completa.
¡Que disfrutes al comerciar!
Tu Equipo DFX
Bitcoiners by heart ♥️
", + "title": "Verificación exitosa" } }, "stakingRef": { diff --git a/src/shared/i18n/fr/mail.json b/src/shared/i18n/fr/mail.json index 5ee6325488..7ea41b50a8 100644 --- a/src/shared/i18n/fr/mail.json +++ b/src/shared/i18n/fr/mail.json @@ -19,6 +19,11 @@ "salutation": "Votre identification en ligne a échoué", "body": "

Nous avons remarqué que votre identification en ligne a échoué. Nous avons cependant déjà débloqué l'identification vidéo pour vous.
Veuillez continuer en cliquant sur le bouton d'actualisation dans la section Limites de la page de paiement (Achat, Vente & Staking) ou ici.

Franchissez le dernier pas et développez votre liberté financière dès aujourd'hui

Votre équipe DFX
Bitcoiners de coeur ♥

", "title": "Votre identification en ligne a échoué" + }, + "success": { + "salutation": "Vérification réussie", + "body": "
Votre vérification est terminée.
Bon trading
Votre équipe DFX
Bitcoiners by heart ♥️
", + "title": "Vérification réussie" } }, "stakingRef": { diff --git a/src/shared/i18n/it/mail.json b/src/shared/i18n/it/mail.json index 585f3d9441..6cc4ddf2a3 100644 --- a/src/shared/i18n/it/mail.json +++ b/src/shared/i18n/it/mail.json @@ -19,6 +19,11 @@ "salutation": "La tua identificazione online non è riuscita", "body": "

Abbiamo notato che la sua identificazione online è fallita. Tuttavia, abbiamo già sbloccato l'identificazione video per te.
Si prega di continuare cliccando sul pulsante di aggiornamento nella sezione dei limiti della pagina di pagamento (Compra, Vendi e Staking) o qui.

Fai il passo finale e inizia a lavorare sulla tua libertà finanziaria oggi stesso

Tuo DFX team
Bitcoiners by heart ♥

", "title": "La tua identificazione online non è riuscita" + }, + "success": { + "salutation": "Verifica riuscita", + "body": "
La verifica è stata completata.
Buon trading
Tuo DFX team
Bitcoiners by heart ♥️
", + "title": "Verifica riuscita" } }, "stakingRef": { diff --git a/src/shared/i18n/pt/mail.json b/src/shared/i18n/pt/mail.json index 8bfb6f0ea1..7119c473eb 100644 --- a/src/shared/i18n/pt/mail.json +++ b/src/shared/i18n/pt/mail.json @@ -19,6 +19,11 @@ "salutation": "Your online identification has failed", "body": "

We have noticed that your online identification has failed. However, we have already unlocked video identification for you.
Please continue by clicking on the refresh button in the limit section on the payment page (Buy, Sell & Staking) or here.

Take the final step and start working on your financial freedom today

Your DFX Team
Bitcoiners by heart ♥

", "title": "Online identification failed" + }, + "success": { + "salutation": "Verification successful", + "body": "
Your verification is complete.
Happy Trading
Your DFX Team
Bitcoiners by heart ♥️
", + "title": "Verification successful" } }, "stakingRef": { diff --git a/src/user/models/kyc/kyc-process.service.ts b/src/user/models/kyc/kyc-process.service.ts index 936fe78a9f..2465846134 100644 --- a/src/user/models/kyc/kyc-process.service.ts +++ b/src/user/models/kyc/kyc-process.service.ts @@ -1,5 +1,4 @@ -import { Injectable, ServiceUnavailableException } from '@nestjs/common'; -import { UserRole } from 'src/shared/auth/user-role.enum'; +import { forwardRef, Inject, Injectable, ServiceUnavailableException } from '@nestjs/common'; import { SpiderDataRepository } from 'src/user/models/spider-data/spider-data.repository'; import { KycInProgress, KycState, KycStatus, UserData } from 'src/user/models/user-data/user-data.entity'; import { KycDocument, KycDocuments, InitiateResponse } from '../../services/spider/dto/spider.dto'; @@ -8,14 +7,16 @@ import { MailService } from 'src/shared/services/mail.service'; import { IdentResultDto } from 'src/user/models/ident/dto/ident-result.dto'; import { DocumentState, SpiderService } from 'src/user/services/spider/spider.service'; import { UserDataService } from '../user-data/user-data.service'; +import { UserRole } from 'src/shared/auth/user-role.enum'; @Injectable() export class KycProcessService { constructor( - private readonly userDataService: UserDataService, private readonly spiderDataRepo: SpiderDataRepository, private readonly spiderService: SpiderService, private readonly mailService: MailService, + @Inject(forwardRef(() => UserDataService)) + private readonly userDataService: UserDataService, ) {} // --- GENERAL METHODS --- // @@ -51,6 +52,12 @@ export class KycProcessService { const initiateData = await this.spiderService.initiateIdentification(userData.id, identType); userData.spiderData = await this.updateSpiderData(userData, initiateData); } + if (status === KycStatus.MANUAL) + await this.mailService.sendTranslatedMail({ + userData: userData, + translationKey: 'mail.kyc.success', + params: {}, + }); return this.updateKycStatus(userData, status); } @@ -100,6 +107,7 @@ export class KycProcessService { userData = await this.storeChatbotResult(userData); const isVipUser = await this.userDataService.hasRole(userData.id, UserRole.VIP); + return isVipUser ? await this.goToStatus(userData, KycStatus.VIDEO_ID) : await this.goToStatus(userData, KycStatus.ONLINE_ID); diff --git a/src/user/models/user-data/user-data.service.ts b/src/user/models/user-data/user-data.service.ts index fe523d5ae1..1a32412cb7 100644 --- a/src/user/models/user-data/user-data.service.ts +++ b/src/user/models/user-data/user-data.service.ts @@ -1,6 +1,8 @@ import { BadRequestException, ConflictException, + forwardRef, + Inject, Injectable, NotFoundException, } from '@nestjs/common'; @@ -20,6 +22,7 @@ import { UserRepository } from '../user/user.repository'; import { SpiderApiService } from 'src/user/services/spider/spider-api.service'; import { Util } from 'src/shared/util'; import { Cron, CronExpression } from '@nestjs/schedule'; +import { KycProcessService } from '../kyc/kyc-process.service'; @Injectable() export class UserDataService { @@ -32,6 +35,8 @@ export class UserDataService { private readonly fiatService: FiatService, private readonly spiderService: SpiderService, private readonly spiderApiService: SpiderApiService, + @Inject(forwardRef(() => KycProcessService)) + private readonly kycProcessService: KycProcessService, ) {} async getUserDataByUser(userId: number): Promise { @@ -78,10 +83,6 @@ export class UserDataService { if (!userData.organizationCountry) throw new BadRequestException('Country not found'); } - if (dto.kycStatus && !dto.kycState) { - dto.kycState = KycState.NA; - } - if (dto.mainBankDataId) { userData.mainBankData = await this.bankDataRepo.findOne(dto.mainBankDataId); if (!userData.mainBankData) throw new BadRequestException('Bank data not found'); @@ -104,9 +105,8 @@ export class UserDataService { ); } - if (dto.kycStatus && userData.kycStatus != dto.kycStatus) { - userData.kycStatusChangeDate = new Date(); - } + if (dto.kycStatus && userData.kycStatus != dto.kycStatus) + this.kycProcessService.goToStatus(userData, dto.kycStatus); return await this.userDataRepo.save({ ...userData, ...dto }); } @@ -125,7 +125,7 @@ export class UserDataService { } // update spider - await this.updateSpiderIfNeeded(user, dto) + await this.updateSpiderIfNeeded(user, dto); return this.userDataRepo.save({ ...user, ...dto }); } From f60adeb2f159033a14065c92edf1329692d96348 Mon Sep 17 00:00:00 2001 From: Yannick1712 Date: Mon, 29 Aug 2022 15:09:48 +0200 Subject: [PATCH 2/5] [DEV-677] Refactoring --- src/user/models/kyc/kyc-process.service.ts | 13 ++++++++----- src/user/models/user-data/user-data.service.ts | 5 ----- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/src/user/models/kyc/kyc-process.service.ts b/src/user/models/kyc/kyc-process.service.ts index 2465846134..b62dcf2dc7 100644 --- a/src/user/models/kyc/kyc-process.service.ts +++ b/src/user/models/kyc/kyc-process.service.ts @@ -1,4 +1,4 @@ -import { forwardRef, Inject, Injectable, ServiceUnavailableException } from '@nestjs/common'; +import { Injectable, ServiceUnavailableException } from '@nestjs/common'; import { SpiderDataRepository } from 'src/user/models/spider-data/spider-data.repository'; import { KycInProgress, KycState, KycStatus, UserData } from 'src/user/models/user-data/user-data.entity'; import { KycDocument, KycDocuments, InitiateResponse } from '../../services/spider/dto/spider.dto'; @@ -6,8 +6,8 @@ import { AccountType } from 'src/user/models/user-data/account-type.enum'; import { MailService } from 'src/shared/services/mail.service'; import { IdentResultDto } from 'src/user/models/ident/dto/ident-result.dto'; import { DocumentState, SpiderService } from 'src/user/services/spider/spider.service'; -import { UserDataService } from '../user-data/user-data.service'; import { UserRole } from 'src/shared/auth/user-role.enum'; +import { UserRepository } from '../user/user.repository'; @Injectable() export class KycProcessService { @@ -15,8 +15,7 @@ export class KycProcessService { private readonly spiderDataRepo: SpiderDataRepository, private readonly spiderService: SpiderService, private readonly mailService: MailService, - @Inject(forwardRef(() => UserDataService)) - private readonly userDataService: UserDataService, + private readonly userRepo: UserRepository, ) {} // --- GENERAL METHODS --- // @@ -106,7 +105,7 @@ export class KycProcessService { userData = await this.storeChatbotResult(userData); - const isVipUser = await this.userDataService.hasRole(userData.id, UserRole.VIP); + const isVipUser = await this.hasRole(userData.id, UserRole.VIP); return isVipUser ? await this.goToStatus(userData, KycStatus.VIDEO_ID) @@ -187,6 +186,10 @@ export class KycProcessService { } // --- HELPER METHODS --- // + private async hasRole(userDataId: number, role: UserRole): Promise { + return await this.userRepo.findOne({ where: { userData: { id: userDataId }, role } }).then((u) => u != null); + } + private async updateSpiderData(userData: UserData, initiateData: InitiateResponse) { const sessionData = await this.getSessionData(userData, initiateData); diff --git a/src/user/models/user-data/user-data.service.ts b/src/user/models/user-data/user-data.service.ts index 1a32412cb7..8fb3e60844 100644 --- a/src/user/models/user-data/user-data.service.ts +++ b/src/user/models/user-data/user-data.service.ts @@ -35,7 +35,6 @@ export class UserDataService { private readonly fiatService: FiatService, private readonly spiderService: SpiderService, private readonly spiderApiService: SpiderApiService, - @Inject(forwardRef(() => KycProcessService)) private readonly kycProcessService: KycProcessService, ) {} @@ -203,10 +202,6 @@ export class UserDataService { await this.updateVolumes(slaveId); } - async hasRole(userDataId: number, role: UserRole): Promise { - return await this.userRepo.findOne({ where: { userData: { id: userDataId }, role } }).then((u) => u != null); - } - async getAllUserDataWithEmptyFileId(): Promise { const userDataList = await this.userDataRepo.find({ where: { kycFileId: MoreThan(0) } }); const idList = []; From 1794e2c4569d2b49f929b91616a908b0f1b75042 Mon Sep 17 00:00:00 2001 From: Yannick1712 Date: Mon, 29 Aug 2022 18:29:47 +0200 Subject: [PATCH 3/5] [DEV-677] fix wrong update --- src/user/models/user-data/user-data.service.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/user/models/user-data/user-data.service.ts b/src/user/models/user-data/user-data.service.ts index 8fb3e60844..2598ad301a 100644 --- a/src/user/models/user-data/user-data.service.ts +++ b/src/user/models/user-data/user-data.service.ts @@ -70,7 +70,8 @@ export class UserDataService { let userData = await this.userDataRepo.findOne(userDataId); if (!userData) throw new NotFoundException('User data not found'); - userData = await this.updateUserSettings(userData, dto); + // Is this needed here? + userData = await this.updateUserSettings(userData, {}); if (dto.countryId) { userData.country = await this.countryService.getCountry(dto.countryId); From 59605df63c41429de0bb7bea548464d2407adb26 Mon Sep 17 00:00:00 2001 From: Yannick1712 Date: Tue, 30 Aug 2022 13:02:52 +0200 Subject: [PATCH 4/5] [DEV-677] Refactoring --- src/user/models/user-data/user-data.service.ts | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/src/user/models/user-data/user-data.service.ts b/src/user/models/user-data/user-data.service.ts index 2598ad301a..5667cfc2c9 100644 --- a/src/user/models/user-data/user-data.service.ts +++ b/src/user/models/user-data/user-data.service.ts @@ -1,11 +1,4 @@ -import { - BadRequestException, - ConflictException, - forwardRef, - Inject, - Injectable, - NotFoundException, -} from '@nestjs/common'; +import { BadRequestException, ConflictException, Injectable, NotFoundException } from '@nestjs/common'; import { UpdateUserDataDto } from './dto/update-user-data.dto'; import { UserDataRepository } from './user-data.repository'; import { KycInProgress, KycState, UserData } from './user-data.entity'; @@ -70,8 +63,7 @@ export class UserDataService { let userData = await this.userDataRepo.findOne(userDataId); if (!userData) throw new NotFoundException('User data not found'); - // Is this needed here? - userData = await this.updateUserSettings(userData, {}); + userData = await this.updateSpiderIfNeeded(userData, dto); if (dto.countryId) { userData.country = await this.countryService.getCountry(dto.countryId); @@ -106,7 +98,7 @@ export class UserDataService { } if (dto.kycStatus && userData.kycStatus != dto.kycStatus) - this.kycProcessService.goToStatus(userData, dto.kycStatus); + userData = await this.kycProcessService.goToStatus(userData, dto.kycStatus); return await this.userDataRepo.save({ ...userData, ...dto }); } @@ -130,7 +122,7 @@ export class UserDataService { return this.userDataRepo.save({ ...user, ...dto }); } - async updateSpiderIfNeeded(userData: UserData, dto: UpdateUserDto) { + async updateSpiderIfNeeded(userData: UserData, dto: UpdateUserDto): Promise { if ((dto.phone && dto.phone != userData.phone) || (dto.mail && dto.mail != userData.mail)) { await this.spiderService.updateCustomer(userData.id, { telephones: dto.phone ? [dto.phone.replace('+', '').split(' ').join('')] : undefined, @@ -141,6 +133,8 @@ export class UserDataService { userData.kycState = KycState.FAILED; } } + + return userData; } // --- VOLUMES --- // From bc97b00658834f6b9f856d0187042501f86f218d Mon Sep 17 00:00:00 2001 From: Yannick1712 Date: Wed, 31 Aug 2022 09:55:48 +0200 Subject: [PATCH 5/5] [DEV-677] More refactoring --- src/user/models/kyc/kyc.service.ts | 4 ++-- src/user/models/user-data/user-data.service.ts | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/user/models/kyc/kyc.service.ts b/src/user/models/kyc/kyc.service.ts index 908d6fbaec..cbf6600526 100644 --- a/src/user/models/kyc/kyc.service.ts +++ b/src/user/models/kyc/kyc.service.ts @@ -83,7 +83,7 @@ export class KycService { } async updateKycData(code: string, data: KycUserDataDto, userId?: number): Promise { - const user = await this.getUser(code, userId); + let user = await this.getUser(code, userId); const isPersonalAccount = (data.accountType ?? user.accountType) === AccountType.PERSONAL; // check countries @@ -102,7 +102,7 @@ export class KycService { data.organizationCountry = null; } - await this.userDataService.updateSpiderIfNeeded(user, data); + user = await this.userDataService.updateSpiderIfNeeded(user, data); const updatedUser = await this.userDataRepo.save({ ...user, ...data }); diff --git a/src/user/models/user-data/user-data.service.ts b/src/user/models/user-data/user-data.service.ts index 5667cfc2c9..81bb1c633c 100644 --- a/src/user/models/user-data/user-data.service.ts +++ b/src/user/models/user-data/user-data.service.ts @@ -117,7 +117,7 @@ export class UserDataService { } // update spider - await this.updateSpiderIfNeeded(user, dto); + user = await this.updateSpiderIfNeeded(user, dto); return this.userDataRepo.save({ ...user, ...dto }); }