mirror of
https://github.com/HamzaSha1/zod-backend.git
synced 2025-08-25 13:49:40 +00:00
fix: register fcm token on enabling push notification
This commit is contained in:
@ -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;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user