This commit is contained in:
2025-12-11 11:25:22 +01:00
parent 6a427eab57
commit e4c1be628d
86 changed files with 1222 additions and 736 deletions

View File

@@ -7,7 +7,7 @@
// Use Cases
export * from './use-cases/SendNotificationUseCase';
export * from './use-cases/MarkNotificationReadUseCase';
export * from './use-cases/GetUnreadNotificationsQuery';
export * from './use-cases/GetUnreadNotificationsUseCase';
export * from './use-cases/NotificationPreferencesUseCases';
// Ports

View File

@@ -1,5 +1,5 @@
/**
* Application Query: GetUnreadNotificationsQuery
* Application Use Case: GetUnreadNotificationsUseCase
*
* Retrieves unread notifications for a recipient.
*/
@@ -12,7 +12,7 @@ export interface UnreadNotificationsResult {
totalCount: number;
}
export class GetUnreadNotificationsQuery {
export class GetUnreadNotificationsUseCase {
constructor(
private readonly notificationRepository: INotificationRepository,
) {}
@@ -28,6 +28,6 @@ export class GetUnreadNotificationsQuery {
}
/**
* Additional notification query use cases (e.g., listing or counting notifications)
* Additional notification query/use case types (e.g., listing or counting notifications)
* can be added here in the future as needed.
*/

View File

@@ -5,6 +5,7 @@
*/
import type { INotificationRepository } from '../../domain/repositories/INotificationRepository';
import { NotificationDomainError } from '../../domain/errors/NotificationDomainError';
export interface MarkNotificationReadCommand {
notificationId: string;
@@ -20,11 +21,11 @@ export class MarkNotificationReadUseCase {
const notification = await this.notificationRepository.findById(command.notificationId);
if (!notification) {
throw new Error('Notification not found');
throw new NotificationDomainError('Notification not found');
}
if (notification.recipientId !== command.recipientId) {
throw new Error('Cannot mark another user\'s notification as read');
throw new NotificationDomainError('Cannot mark another user\'s notification as read');
}
if (!notification.isUnread()) {
@@ -70,11 +71,11 @@ export class DismissNotificationUseCase {
const notification = await this.notificationRepository.findById(command.notificationId);
if (!notification) {
throw new Error('Notification not found');
throw new NotificationDomainError('Notification not found');
}
if (notification.recipientId !== command.recipientId) {
throw new Error('Cannot dismiss another user\'s notification');
throw new NotificationDomainError('Cannot dismiss another user\'s notification');
}
if (notification.isDismissed()) {

View File

@@ -82,10 +82,10 @@ export class UpdateQuietHoursUseCase {
async execute(command: UpdateQuietHoursCommand): Promise<void> {
// Validate hours if provided
if (command.startHour !== undefined && (command.startHour < 0 || command.startHour > 23)) {
throw new Error('Start hour must be between 0 and 23');
throw new NotificationDomainError('Start hour must be between 0 and 23');
}
if (command.endHour !== undefined && (command.endHour < 0 || command.endHour > 23)) {
throw new Error('End hour must be between 0 and 23');
throw new NotificationDomainError('End hour must be between 0 and 23');
}
const preferences = await this.preferenceRepository.getOrCreateDefault(command.driverId);
@@ -110,7 +110,7 @@ export class SetDigestModeUseCase {
async execute(command: SetDigestModeCommand): Promise<void> {
if (command.frequencyHours !== undefined && command.frequencyHours < 1) {
throw new Error('Digest frequency must be at least 1 hour');
throw new NotificationDomainError('Digest frequency must be at least 1 hour');
}
const preferences = await this.preferenceRepository.getOrCreateDefault(command.driverId);