26 lines
639 B
TypeScript
26 lines
639 B
TypeScript
import { v4 as uuidv4 } from 'uuid';
|
|
|
|
export abstract class DomainEvent {
|
|
readonly eventId: string;
|
|
readonly eventType: string;
|
|
readonly aggregateId: string;
|
|
readonly aggregateType: string;
|
|
readonly occurredAt: Date;
|
|
readonly version: number;
|
|
|
|
constructor(params: {
|
|
aggregateId: string;
|
|
aggregateType: string;
|
|
version?: number;
|
|
}) {
|
|
this.eventId = uuidv4();
|
|
this.eventType = this.constructor.name;
|
|
this.aggregateId = params.aggregateId;
|
|
this.aggregateType = params.aggregateType;
|
|
this.occurredAt = new Date();
|
|
this.version = params.version ?? 1;
|
|
}
|
|
|
|
abstract getPayload(): unknown;
|
|
}
|