feat: add validation for documents

This commit is contained in:
Abdalhamid Alhamad
2025-01-13 11:43:28 +03:00
parent 756e947c8a
commit 62621c1a15
12 changed files with 195 additions and 13 deletions

View File

@ -1,5 +1,5 @@
import { BadRequestException, Injectable, Logger } from '@nestjs/common';
import { OciService } from '~/document/services';
import { DocumentService, OciService } from '~/document/services';
import { User } from '~/user/entities';
import { DeviceService } from '~/user/services';
import { UpdateCustomerRequestDto, UpdateNotificationsSettingsRequestDto } from '../dtos/request';
@ -13,6 +13,7 @@ export class CustomerService {
private readonly customerRepository: CustomerRepository,
private readonly ociService: OciService,
private readonly deviceService: DeviceService,
private readonly documentService: DocumentService,
) {}
async updateNotificationSettings(userId: string, data: UpdateNotificationsSettingsRequestDto, deviceId: string) {
this.logger.log(`Updating notification settings for user ${userId}`);
@ -34,6 +35,8 @@ export class CustomerService {
async updateCustomer(userId: string, data: UpdateCustomerRequestDto): Promise<Customer> {
this.logger.log(`Updating customer ${userId}`);
await this.validateProfilePictureForCustomer(userId, data.profilePictureId);
await this.customerRepository.updateCustomer(userId, data);
this.logger.log(`Customer ${userId} updated successfully`);
return this.findCustomerById(userId);
@ -60,4 +63,20 @@ export class CustomerService {
this.logger.log(`Customer ${id} found successfully`);
return customer;
}
private async validateProfilePictureForCustomer(userId: string, profilePictureId?: string) {
if (!profilePictureId) return;
this.logger.log(`Validating profile picture ${profilePictureId}`);
const profilePicture = await this.documentService.findDocumentById(profilePictureId);
if (!profilePicture) {
this.logger.error(`Profile picture ${profilePictureId} not found`);
throw new BadRequestException('DOCUMENT.NOT_FOUND');
}
if (profilePicture.createdById && profilePicture.createdById !== userId) {
}
}
}