A social knowledge tool for researchers built on ATProto
1import { IDomainEvent } from '../../../../shared/domain/events/IDomainEvent';
2import { UniqueEntityID } from '../../../../shared/domain/UniqueEntityID';
3import { CardId } from '../value-objects/CardId';
4import { CollectionId } from '../value-objects/CollectionId';
5import { CuratorId } from '../value-objects/CuratorId';
6import { EventNames } from '../../../../shared/infrastructure/events/EventConfig';
7import { Result, ok } from '../../../../shared/core/Result';
8
9export class CardAddedToCollectionEvent implements IDomainEvent {
10 public readonly eventName = EventNames.CARD_ADDED_TO_COLLECTION;
11 public readonly dateTimeOccurred: Date;
12
13 private constructor(
14 public readonly cardId: CardId,
15 public readonly collectionId: CollectionId,
16 public readonly addedBy: CuratorId,
17 dateTimeOccurred?: Date,
18 ) {
19 this.dateTimeOccurred = dateTimeOccurred || new Date();
20 }
21
22 public static create(
23 cardId: CardId,
24 collectionId: CollectionId,
25 addedBy: CuratorId,
26 ): Result<CardAddedToCollectionEvent> {
27 return ok(new CardAddedToCollectionEvent(cardId, collectionId, addedBy));
28 }
29
30 public static reconstruct(
31 cardId: CardId,
32 collectionId: CollectionId,
33 addedBy: CuratorId,
34 dateTimeOccurred: Date,
35 ): Result<CardAddedToCollectionEvent> {
36 return ok(
37 new CardAddedToCollectionEvent(
38 cardId,
39 collectionId,
40 addedBy,
41 dateTimeOccurred,
42 ),
43 );
44 }
45
46 getAggregateId(): UniqueEntityID {
47 return this.collectionId.getValue();
48 }
49}