mirror of
https://github.com/HamzaSha1/zod-backend.git
synced 2025-08-25 13:49:40 +00:00
feat/working on update card control
This commit is contained in:
@ -1,8 +1,11 @@
|
||||
import { BadRequestException, Injectable, Logger } from '@nestjs/common';
|
||||
import moment from 'moment';
|
||||
import { Transactional } from 'typeorm-transactional';
|
||||
import { CountryIso } from '~/common/enums';
|
||||
import { DocumentService, OciService } from '~/document/services';
|
||||
import { GuardianService } from '~/guardian/services';
|
||||
import { CreateJuniorRequestDto } from '~/junior/dtos/request';
|
||||
import { User } from '~/user/entities';
|
||||
import {
|
||||
CreateCustomerRequestDto,
|
||||
CustomerFiltersRequestDto,
|
||||
@ -10,7 +13,7 @@ import {
|
||||
UpdateCustomerRequestDto,
|
||||
} from '../dtos/request';
|
||||
import { Customer } from '../entities';
|
||||
import { KycStatus } from '../enums';
|
||||
import { Gender, KycStatus } from '../enums';
|
||||
import { CustomerRepository } from '../repositories/customer.repository';
|
||||
|
||||
@Injectable()
|
||||
@ -125,6 +128,33 @@ export class CustomerService {
|
||||
this.logger.log(`KYC rejected for customer ${customerId}`);
|
||||
}
|
||||
|
||||
// this function is for testing only and will be removed
|
||||
@Transactional()
|
||||
async updateKyc(userId: string) {
|
||||
this.logger.log(`Updating KYC for customer ${userId}`);
|
||||
await this.customerRepository.updateCustomer(userId, {
|
||||
kycStatus: KycStatus.APPROVED,
|
||||
gender: Gender.MALE,
|
||||
nationalId: '1089055972',
|
||||
nationalIdExpiry: moment('2031-09-17').toDate(),
|
||||
countryOfResidence: CountryIso.SAUDI_ARABIA,
|
||||
country: CountryIso.SAUDI_ARABIA,
|
||||
region: 'Mecca',
|
||||
city: 'AT Taif',
|
||||
neighborhood: 'Al Faisaliah',
|
||||
street: 'Al Faisaliah Street',
|
||||
building: '4',
|
||||
});
|
||||
|
||||
await User.update(userId, {
|
||||
phoneNumber: this.generateSaudiPhoneNumber(),
|
||||
countryCode: '+966',
|
||||
});
|
||||
|
||||
this.logger.log(`KYC updated for customer ${userId}`);
|
||||
return this.findCustomerById(userId);
|
||||
}
|
||||
|
||||
private async validateProfilePictureForCustomer(userId: string, profilePictureId?: string) {
|
||||
if (!profilePictureId) return;
|
||||
|
||||
@ -202,4 +232,15 @@ export class CustomerService {
|
||||
async findAnyCustomer() {
|
||||
return this.customerRepository.findOne({ isGuardian: true });
|
||||
}
|
||||
|
||||
// TO BE REMOVED: This function is for testing only and will be removed
|
||||
private generateSaudiPhoneNumber(): string {
|
||||
// Saudi mobile numbers are 9 digits, always starting with '5'
|
||||
const firstDigit = '5';
|
||||
let rest = '';
|
||||
for (let i = 0; i < 8; i++) {
|
||||
rest += Math.floor(Math.random() * 10);
|
||||
}
|
||||
return `${firstDigit}${rest}`;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user