This commit is contained in:
2025-12-11 13:50:38 +01:00
parent e4c1be628d
commit c7e5de40d6
212 changed files with 2965 additions and 763 deletions

View File

@@ -5,10 +5,11 @@
* Immutable entity with factory methods and domain validation.
*/
import type { IEntity } from '@gridpilot/shared/domain';
import { NotificationDomainError } from '../errors/NotificationDomainError';
import { NotificationId } from '../value-objects/NotificationId';
import type { NotificationType } from '../value-objects/NotificationType';
import type { NotificationChannel } from '../value-objects/NotificationChannel';
import type { NotificationType, NotificationChannel } from '../types/NotificationTypes';
export type NotificationStatus = 'unread' | 'read' | 'dismissed' | 'action_required';
@@ -54,7 +55,7 @@ export interface NotificationAction {
}
export interface NotificationProps {
id: string;
id: NotificationId;
/** Driver who receives this notification */
recipientId: string;
/** Type of notification */
@@ -85,15 +86,17 @@ export interface NotificationProps {
respondedAt?: Date;
}
export class Notification {
export class Notification implements IEntity<string> {
private constructor(private readonly props: NotificationProps) {}
static create(props: Omit<NotificationProps, 'status' | 'createdAt' | 'urgency'> & {
static create(props: Omit<NotificationProps, 'id' | 'status' | 'createdAt' | 'urgency'> & {
id: string;
status?: NotificationStatus;
createdAt?: Date;
urgency?: NotificationUrgency;
}): Notification {
if (!props.id) throw new NotificationDomainError('Notification ID is required');
const id = NotificationId.create(props.id);
if (!props.recipientId) throw new NotificationDomainError('Recipient ID is required');
if (!props.type) throw new NotificationDomainError('Notification type is required');
if (!props.title?.trim()) throw new NotificationDomainError('Notification title is required');
@@ -105,13 +108,14 @@ export class Notification {
return new Notification({
...props,
id,
status: props.status ?? defaultStatus,
urgency: props.urgency ?? 'silent',
createdAt: props.createdAt ?? new Date(),
});
}
get id(): string { return this.props.id; }
get id(): string { return this.props.id.value; }
get recipientId(): string { return this.props.recipientId; }
get type(): NotificationType { return this.props.type; }
get title(): string { return this.props.title; }
@@ -210,7 +214,10 @@ export class Notification {
/**
* Convert to plain object for serialization
*/
toJSON(): NotificationProps {
return { ...this.props };
toJSON(): Omit<NotificationProps, 'id'> & { id: string } {
return {
...this.props,
id: this.props.id.value,
};
}
}