A social knowledge tool for researchers built on ATProto

feat: add static eventName property to domain events for type-safe event handling

Co-authored-by: aider (anthropic/claude-sonnet-4-20250514) <aider@aider.chat>

+12 -7
+3 -1
src/modules/cards/domain/events/CardAddedToLibraryEvent.ts
··· 1 - import { IDomainEvent } from '../../../../shared/domain/events/IDomainEvent'; 1 + import { IDomainEvent, IDomainEventClass } from '../../../../shared/domain/events/IDomainEvent'; 2 2 import { UniqueEntityID } from '../../../../shared/domain/UniqueEntityID'; 3 3 import { CardId } from '../value-objects/CardId'; 4 4 import { CuratorId } from '../value-objects/CuratorId'; 5 5 import { CardTypeEnum } from '../value-objects/CardType'; 6 + import { EventNames } from '../../../../shared/infrastructure/events/EventConfig'; 6 7 7 8 export class CardAddedToLibraryEvent implements IDomainEvent { 9 + public static readonly eventName = EventNames.CARD_ADDED_TO_LIBRARY; 8 10 public readonly dateTimeOccurred: Date; 9 11 10 12 constructor(
+4
src/shared/domain/events/IDomainEvent.ts
··· 4 4 dateTimeOccurred: Date; 5 5 getAggregateId(): UniqueEntityID; 6 6 } 7 + 8 + export interface IDomainEventClass { 9 + eventName: string; 10 + }
+5 -6
src/shared/infrastructure/events/BullMQEventPublisher.ts
··· 46 46 } 47 47 48 48 private getEventType(event: IDomainEvent): string { 49 - // Map event constructor names to our centralized event names 50 - switch (event.constructor.name) { 51 - case 'CardAddedToLibraryEvent': 52 - return EventNames.CARD_ADDED_TO_LIBRARY; 53 - default: 54 - throw new Error(`Unknown event type: ${event.constructor.name}`); 49 + // Use the static eventName property from the event class 50 + const eventClass = event.constructor as any; 51 + if (eventClass.eventName) { 52 + return eventClass.eventName; 55 53 } 54 + throw new Error(`Event class ${event.constructor.name} does not have a static eventName property`); 56 55 } 57 56 58 57 async close(): Promise<void> {