wip
This commit is contained in:
@@ -0,0 +1,87 @@
|
||||
/**
|
||||
* Application Use Case: MarkNotificationReadUseCase
|
||||
*
|
||||
* Marks a notification as read.
|
||||
*/
|
||||
|
||||
import type { INotificationRepository } from '../../domain/repositories/INotificationRepository';
|
||||
|
||||
export interface MarkNotificationReadCommand {
|
||||
notificationId: string;
|
||||
recipientId: string; // For validation
|
||||
}
|
||||
|
||||
export class MarkNotificationReadUseCase {
|
||||
constructor(
|
||||
private readonly notificationRepository: INotificationRepository,
|
||||
) {}
|
||||
|
||||
async execute(command: MarkNotificationReadCommand): Promise<void> {
|
||||
const notification = await this.notificationRepository.findById(command.notificationId);
|
||||
|
||||
if (!notification) {
|
||||
throw new Error('Notification not found');
|
||||
}
|
||||
|
||||
if (notification.recipientId !== command.recipientId) {
|
||||
throw new Error('Cannot mark another user\'s notification as read');
|
||||
}
|
||||
|
||||
if (!notification.isUnread()) {
|
||||
return; // Already read, nothing to do
|
||||
}
|
||||
|
||||
const updatedNotification = notification.markAsRead();
|
||||
await this.notificationRepository.update(updatedNotification);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Application Use Case: MarkAllNotificationsReadUseCase
|
||||
*
|
||||
* Marks all notifications as read for a recipient.
|
||||
*/
|
||||
export class MarkAllNotificationsReadUseCase {
|
||||
constructor(
|
||||
private readonly notificationRepository: INotificationRepository,
|
||||
) {}
|
||||
|
||||
async execute(recipientId: string): Promise<void> {
|
||||
await this.notificationRepository.markAllAsReadByRecipientId(recipientId);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Application Use Case: DismissNotificationUseCase
|
||||
*
|
||||
* Dismisses a notification.
|
||||
*/
|
||||
export interface DismissNotificationCommand {
|
||||
notificationId: string;
|
||||
recipientId: string;
|
||||
}
|
||||
|
||||
export class DismissNotificationUseCase {
|
||||
constructor(
|
||||
private readonly notificationRepository: INotificationRepository,
|
||||
) {}
|
||||
|
||||
async execute(command: DismissNotificationCommand): Promise<void> {
|
||||
const notification = await this.notificationRepository.findById(command.notificationId);
|
||||
|
||||
if (!notification) {
|
||||
throw new Error('Notification not found');
|
||||
}
|
||||
|
||||
if (notification.recipientId !== command.recipientId) {
|
||||
throw new Error('Cannot dismiss another user\'s notification');
|
||||
}
|
||||
|
||||
if (notification.isDismissed()) {
|
||||
return; // Already dismissed
|
||||
}
|
||||
|
||||
const updatedNotification = notification.dismiss();
|
||||
await this.notificationRepository.update(updatedNotification);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user