feat: update customer profile picture and notifications settings

This commit is contained in:
Abdalhamid Alhamad
2024-12-12 13:15:47 +03:00
parent 4867a5f858
commit 51fa61dbc6
28 changed files with 150 additions and 135 deletions

View File

@ -1,18 +1,20 @@
import { BadRequestException, forwardRef, Inject, Injectable } from '@nestjs/common';
import { BadRequestException, Injectable } from '@nestjs/common';
import { User } from '~/auth/entities';
import { UserService } from '~/auth/services/user.service';
import { OciService } from '~/document/services';
import { UpdateCustomerRequestDto, UpdateNotificationsSettingsRequestDto } from '../dtos/request';
import { Customer } from '../entities';
import { CustomerRepository } from '../repositories/customer.repository';
@Injectable()
export class CustomerService {
constructor(
@Inject(forwardRef(() => UserService)) private readonly userService: UserService,
private readonly customerRepository: CustomerRepository,
) {}
updateNotificationSettings(userId: string, data: UpdateNotificationsSettingsRequestDto) {
return this.userService.updateNotificationSettings(userId, data);
constructor(private readonly customerRepository: CustomerRepository, private readonly ociService: OciService) {}
async updateNotificationSettings(userId: string, data: UpdateNotificationsSettingsRequestDto) {
const customer = await this.findCustomerById(userId);
const notificationSettings = (await this.customerRepository.updateNotificationSettings(customer, data))
.notificationSettings;
return notificationSettings;
}
async updateCustomer(userId: string, data: UpdateCustomerRequestDto): Promise<Customer> {
@ -26,9 +28,14 @@ export class CustomerService {
async findCustomerById(id: string) {
const customer = await this.customerRepository.findOne({ id });
if (!customer) {
throw new BadRequestException('CUSTOMER.NOT_FOUND');
}
if (customer.profilePicture) {
customer.profilePicture.url = await this.ociService.generatePreSignedUrl(customer.profilePicture);
}
return customer;
}
}