Files
negareh-api/src/modules/notification/services/notification-preference.service.ts
T
2026-01-14 11:29:24 +03:30

85 lines
2.7 KiB
TypeScript

import { Injectable, NotFoundException } from '@nestjs/common';
import { EntityManager } from '@mikro-orm/postgresql';
import { NotificationPreference } from '../entities/notification-preference.entity';
import { CreatePreferenceDto } from '../dto/create-preference.dto';
import { UpdatePreferenceDto } from '../dto/update-preference.dto';
import { NotifTitleEnum } from '../interfaces/notification.interface';
@Injectable()
export class NotificationPreferenceService {
constructor(private readonly em: EntityManager) { }
// async create( dto: CreatePreferenceDto): Promise<NotificationPreference> {
// const restaurant = await this.em.findOne(Restaurant, { id: });
// if (!restaurant) {
// throw new NotFoundException('Restaurant not found');
// }
// const preference = this.em.create(NotificationPreference, {
// restaurant,
// channels: dto.channels,
// title: dto.title,
// });
// await this.em.persistAndFlush(preference);
// return preference;
// }
// async findByRestaurant(: string): Promise<NotificationPreference[]> {
// return this.em.find(NotificationPreference, {
// restaurant: { id: },
// });
// }
// async findByRestaurantAndType(: string, title: NotifTitleEnum): Promise<NotificationPreference | null> {
// return this.em.findOne(NotificationPreference, {
// restaurant: { id: },
// title,
// });
// }
// async updateEnabled(
// : string,
// notificationType: string,
// enabled: boolean,
// ): Promise<NotificationPreference> {
// const preference = await this.findByRestaurantAndType(, notificationType);
// if (!preference) {
// throw new NotFoundException('Notification preference not found');
// }
// preference.enabled = enabled;
// await this.em.persistAndFlush(preference);
// return preference;
// }
// async updatePreference(
// preferenceId: string,
// : string,
// dto: UpdatePreferenceDto,
// ): Promise<NotificationPreference> {
// const preference = await this.em.findOne(NotificationPreference, {
// id: preferenceId,
// restaurant: { id: },
// });
// if (!preference) {
// throw new NotFoundException('Notification preference not found');
// }
// this.em.assign(preference, dto);
// await this.em.persistAndFlush(preference);
// return preference;
// }
// async delete(: string, preferenceId: string): Promise<void> {
// const preference = await this.em.findOne(NotificationPreference, {
// restaurant: { id: },
// id: preferenceId,
// });
// if (!preference) {
// throw new NotFoundException('Notification preference not found');
// }
// await this.em.removeAndFlush(preference);
// }
}