mirror of
https://github.com/HamzaSha1/zod-backend.git
synced 2026-10-25 13:27:56 +00:00
refactor: remove unsed code
This commit is contained in:
@@ -82,8 +82,6 @@ export class InternalCustomerDetailsResponseDto {
|
||||
this.gender = customer.gender;
|
||||
this.isJunior = customer.isJunior;
|
||||
this.isGuardian = customer.isGuardian;
|
||||
this.civilIdFront = new DocumentMetaResponseDto(customer.civilIdFront);
|
||||
this.civilIdBack = new DocumentMetaResponseDto(customer.civilIdBack);
|
||||
this.profilePicture = customer.profilePicture ? new DocumentMetaResponseDto(customer.profilePicture) : null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -92,20 +92,6 @@ export class Customer extends BaseEntity {
|
||||
@OneToOne(() => Guardian, (guardian) => guardian.customer, { cascade: true })
|
||||
guardian!: Guardian;
|
||||
|
||||
@Column('uuid', { name: 'civil_id_front_id', nullable: true })
|
||||
civilIdFrontId!: string;
|
||||
|
||||
@Column('uuid', { name: 'civil_id_back_id', nullable: true })
|
||||
civilIdBackId!: string;
|
||||
|
||||
@OneToOne(() => Document, (document) => document.customerCivilIdFront, { nullable: true })
|
||||
@JoinColumn({ name: 'civil_id_front_id' })
|
||||
civilIdFront!: Document;
|
||||
|
||||
@OneToOne(() => Document, (document) => document.customerCivilIdBack, { nullable: true })
|
||||
@JoinColumn({ name: 'civil_id_back_id' })
|
||||
civilIdBack!: Document;
|
||||
|
||||
@CreateDateColumn({ type: 'timestamp with time zone', default: () => 'CURRENT_TIMESTAMP', name: 'created_at' })
|
||||
createdAt!: Date;
|
||||
|
||||
|
||||
@@ -61,10 +61,4 @@ export class CustomerRepository {
|
||||
|
||||
return query.getManyAndCount();
|
||||
}
|
||||
|
||||
findCustomerByCivilId(civilIdFrontId: string, civilIdBackId: string) {
|
||||
return this.customerRepository.findOne({
|
||||
where: [{ civilIdFrontId, civilIdBackId }, { civilIdFrontId }, { civilIdBackId }],
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,8 +35,6 @@ export class CustomerService {
|
||||
async createJuniorCustomer(guardianId: string, juniorId: string, body: CreateJuniorRequestDto) {
|
||||
this.logger.log(`Creating junior customer for user ${juniorId}`);
|
||||
|
||||
await this.validateCivilIdForCustomer(guardianId, body.civilIdFrontId, body.civilIdBackId);
|
||||
|
||||
return this.customerRepository.createCustomer(juniorId, body, false);
|
||||
}
|
||||
|
||||
@@ -143,48 +141,9 @@ export class CustomerService {
|
||||
}
|
||||
}
|
||||
|
||||
private async validateCivilIdForCustomer(userId: string, civilIdFrontId: string, civilIdBackId: string) {
|
||||
this.logger.log(`Validating customer documents`);
|
||||
|
||||
if (!civilIdFrontId || !civilIdBackId) {
|
||||
this.logger.error('Civil id front and back are required');
|
||||
throw new BadRequestException('CUSTOMER.CIVIL_ID_REQUIRED');
|
||||
}
|
||||
|
||||
const [civilIdFront, civilIdBack] = await Promise.all([
|
||||
this.documentService.findDocumentById(civilIdFrontId),
|
||||
this.documentService.findDocumentById(civilIdBackId),
|
||||
]);
|
||||
|
||||
if (!civilIdFront || !civilIdBack) {
|
||||
this.logger.error('Civil id front or back not found');
|
||||
throw new BadRequestException('CUSTOMER.CIVIL_ID_REQUIRED');
|
||||
}
|
||||
|
||||
if (civilIdFront.createdById !== userId || civilIdBack.createdById !== userId) {
|
||||
this.logger.error(`Civil id front or back not created by user with id ${userId}`);
|
||||
throw new BadRequestException('CUSTOMER.CIVIL_ID_NOT_CREATED_BY_USER');
|
||||
}
|
||||
|
||||
const customerWithTheSameCivilId = await this.customerRepository.findCustomerByCivilId(
|
||||
civilIdFrontId,
|
||||
civilIdBackId,
|
||||
);
|
||||
|
||||
if (customerWithTheSameCivilId) {
|
||||
this.logger.error(
|
||||
`Customer with civil id front ${civilIdFrontId} and civil id back ${civilIdBackId} already exists`,
|
||||
);
|
||||
throw new BadRequestException('CUSTOMER.CIVIL_ID_ALREADY_EXISTS');
|
||||
}
|
||||
}
|
||||
|
||||
private async prepareCustomerDocuments(customer: Customer) {
|
||||
const promises = [];
|
||||
|
||||
promises.push(this.ociService.generatePreSignedUrl(customer.civilIdFront));
|
||||
promises.push(this.ociService.generatePreSignedUrl(customer.civilIdBack));
|
||||
|
||||
if (customer.profilePicture) {
|
||||
promises.push(this.ociService.generatePreSignedUrl(customer.profilePicture));
|
||||
}
|
||||
@@ -194,8 +153,6 @@ export class CustomerService {
|
||||
customer.profilePicture.url = profilePictureUrl;
|
||||
}
|
||||
|
||||
customer.civilIdFront.url = civilIdFrontUrl;
|
||||
customer.civilIdBack.url = civilIdBackUrl;
|
||||
return customer;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user