feat/working on update card control

This commit is contained in:
Abdalhamid Alhamad
2025-07-14 11:57:51 +03:00
parent 038b8ef6e3
commit 5a780eeb17
15 changed files with 263 additions and 28 deletions

View File

@ -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}`;
}
}