fix: register fcm token on enabling push notification

This commit is contained in:
Abdalhamid Alhamad
2024-12-24 13:00:54 +03:00
parent 3719498c2f
commit bb8cc33d53
5 changed files with 31 additions and 13 deletions

View File

@ -1,5 +1,6 @@
import { BadRequestException, Injectable } from '@nestjs/common';
import { BadRequestException, forwardRef, Inject, Injectable } from '@nestjs/common';
import { User } from '~/auth/entities';
import { DeviceService } from '~/auth/services';
import { OciService } from '~/document/services';
import { UpdateCustomerRequestDto, UpdateNotificationsSettingsRequestDto } from '../dtos/request';
import { Customer } from '../entities';
@ -7,13 +8,24 @@ import { CustomerRepository } from '../repositories/customer.repository';
@Injectable()
export class CustomerService {
constructor(private readonly customerRepository: CustomerRepository, private readonly ociService: OciService) {}
async updateNotificationSettings(userId: string, data: UpdateNotificationsSettingsRequestDto) {
constructor(
private readonly customerRepository: CustomerRepository,
private readonly ociService: OciService,
@Inject(forwardRef(() => DeviceService)) private readonly deviceService: DeviceService,
) {}
async updateNotificationSettings(userId: string, data: UpdateNotificationsSettingsRequestDto, deviceId: string) {
const customer = await this.findCustomerById(userId);
const notificationSettings = (await this.customerRepository.updateNotificationSettings(customer, data))
.notificationSettings;
if (data.isPushEnabled && deviceId) {
await this.deviceService.updateDevice(deviceId, {
fcmToken: data.fcmToken,
userId: userId,
});
}
return notificationSettings;
}