mirror of
https://github.com/HamzaSha1/zod-backend.git
synced 2025-08-25 13:49:40 +00:00
feat: add validation for documents
This commit is contained in:
@ -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) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user