refactor: handle kyc journey for customers

This commit is contained in:
Abdalhamid Alhamad
2025-02-20 16:18:06 +03:00
parent 270753cfd7
commit dae9cb6323
74 changed files with 1116 additions and 477 deletions

View File

@ -7,8 +7,8 @@ import { ArrayContains } from 'typeorm';
import { CacheService } from '~/common/modules/cache/services';
import { OtpScope, OtpType } from '~/common/modules/otp/enums';
import { OtpService } from '~/common/modules/otp/services';
import { JuniorTokenService } from '~/junior/services';
import { DeviceService, UserService } from '~/user/services';
import { UserType } from '~/user/enums';
import { DeviceService, UserService, UserTokenService } from '~/user/services';
import { User } from '../../user/entities';
import { PASSCODE_REGEX } from '../constants';
import {
@ -39,7 +39,7 @@ export class AuthService {
private readonly configService: ConfigService,
private readonly userService: UserService,
private readonly deviceService: DeviceService,
private readonly juniorTokenService: JuniorTokenService,
private readonly userTokenService: UserTokenService,
private readonly cacheService: CacheService,
private readonly oauth2Service: Oauth2Service,
) {}
@ -91,13 +91,15 @@ export class AuthService {
return [tokens, user];
}
const updatedUser = await this.userService.verifyUserAndCreateCustomer(user.id);
await this.userService.verifyPhoneNumber(user.id);
const tokens = await this.generateAuthToken(updatedUser);
await user.reload();
const tokens = await this.generateAuthToken(user);
this.logger.log(
`User with phone number ${verifyUserDto.countryCode + verifyUserDto.phoneNumber} verified successfully`,
);
return [tokens, updatedUser];
return [tokens, user];
}
async setEmail(userId: string, { email }: SetEmailRequestDto) {
@ -293,11 +295,11 @@ export class AuthService {
async setJuniorPasscode(body: setJuniorPasswordRequestDto) {
this.logger.log(`Setting passcode for junior with qrToken ${body.qrToken}`);
const juniorId = await this.juniorTokenService.validateToken(body.qrToken);
const juniorId = await this.userTokenService.validateToken(body.qrToken, UserType.JUNIOR);
const salt = bcrypt.genSaltSync(SALT_ROUNDS);
const hashedPasscode = bcrypt.hashSync(body.passcode, salt);
await this.userService.setPasscode(juniorId, hashedPasscode, salt);
await this.juniorTokenService.invalidateToken(body.qrToken);
await this.userService.setPasscode(juniorId!, hashedPasscode, salt);
await this.userTokenService.invalidateToken(body.qrToken);
this.logger.log(`Passcode set successfully for junior with id ${juniorId}`);
}