import { Injectable, NotFoundException, Logger } from '@nestjs/common'; import { NotificationsRepository } from './notifications.repository'; @Injectable() export class NotificationsService { private readonly logger = new Logger(NotificationsService.name); constructor(private readonly repository: NotificationsRepository) {} async list(userId: string) { return this.repository.findAll(userId); } async markRead(id: string) { try { return await this.repository.markRead(id); } catch { throw new NotFoundException(`Notification ${id} not found`); } } async send(data: { userId: string; type: string; title: string; body: string }) { const notification = await this.repository.create(data); this.logger.log(`Notification ${notification.id} sent to user ${data.userId}`); return notification; } }