UNPKG

ruch

Version:

Revolutionary React TypeScript CLI with hexagonal architecture & AI-powered development assistance. Create maintainable, scalable applications with domain-driven design and integrated AI tooling.

87 lines (77 loc) 2.11 kB
/** * Services and business logic for the Notification domain. * @packageDocumentation */ import type { NotificationEntity, NotificationCreationData, NotificationUpdateData } from '../entities/Notification'; import type { NotificationPort } from '../ports/NotificationPort'; export class NotificationError extends Error { constructor( public code: string, message: string, ) { super(message); this.name = 'NotificationError'; } } /** * Service implementation for Notification domain */ export class NotificationService { constructor(private readonly port: NotificationPort) {} /** * Get all notification entities */ async getAll(): Promise<NotificationEntity[]> { try { return await this.port.getAll(); } catch (error) { throw new NotificationError('GET_ALL_ERROR', 'Failed to get all notification entities'); } } /** * Get a notification entity by ID */ async getById(id: string): Promise<NotificationEntity> { try { return await this.port.getById(id); } catch (error) { throw new NotificationError('GET_BY_ID_ERROR', `Failed to get notification entity with id ${id}`); } } /** * Create a new notification entity */ async create(data: NotificationCreationData): Promise<NotificationEntity> { try { return await this.port.create(data); } catch (error) { throw new NotificationError('CREATE_ERROR', 'Failed to create notification entity'); } } /** * Update an existing notification entity */ async update(id: string, data: NotificationUpdateData): Promise<NotificationEntity> { try { return await this.port.update(id, data); } catch (error) { throw new NotificationError('UPDATE_ERROR', `Failed to update notification entity with id ${id}`); } } /** * Delete a notification entity */ async delete(id: string): Promise<void> { try { await this.port.delete(id); } catch (error) { throw new NotificationError('DELETE_ERROR', `Failed to delete notification entity with id ${id}`); } } }