diff --git a/src/modules/atproto/tests/application/ProcessCardFirehoseEventUseCase.test.ts b/src/modules/atproto/tests/application/ProcessCardFirehoseEventUseCase.test.ts index bfd8ae2f..4e036615 100644 --- a/src/modules/atproto/tests/application/ProcessCardFirehoseEventUseCase.test.ts +++ b/src/modules/atproto/tests/application/ProcessCardFirehoseEventUseCase.test.ts @@ -79,6 +79,7 @@ describe('ProcessCardFirehoseEventUseCase', () => { removeCardFromLibraryUseCase = new RemoveCardFromLibraryUseCase( cardRepository, cardLibraryService, + eventPublisher, ); useCase = new ProcessCardFirehoseEventUseCase( diff --git a/src/modules/atproto/tests/application/ProcessFirehoseEventUseCase.test.ts b/src/modules/atproto/tests/application/ProcessFirehoseEventUseCase.test.ts index 875cf453..5a757276 100644 --- a/src/modules/atproto/tests/application/ProcessFirehoseEventUseCase.test.ts +++ b/src/modules/atproto/tests/application/ProcessFirehoseEventUseCase.test.ts @@ -96,6 +96,7 @@ describe('ProcessFirehoseEventUseCase', () => { removeCardFromLibraryUseCase = new RemoveCardFromLibraryUseCase( cardRepository, cardLibraryService, + eventPublisher, ); // Create use cases for collection processing diff --git a/src/modules/cards/application/useCases/commands/RemoveCardFromLibraryUseCase.ts b/src/modules/cards/application/useCases/commands/RemoveCardFromLibraryUseCase.ts index 93676ffe..de7a2edc 100644 --- a/src/modules/cards/application/useCases/commands/RemoveCardFromLibraryUseCase.ts +++ b/src/modules/cards/application/useCases/commands/RemoveCardFromLibraryUseCase.ts @@ -150,7 +150,8 @@ export class RemoveCardFromLibraryUseCase extends BaseUseCase< } // Publish events for the updated card (events are raised in removeFromLibrary method) - const publishCardResult = await this.publishEventsForAggregate(updatedCard); + const publishCardResult = + await this.publishEventsForAggregate(updatedCard); if (publishCardResult.isErr()) { console.error( 'Failed to publish events for removed card:', diff --git a/src/modules/cards/domain/events/CardRemovedFromLibraryEvent.ts b/src/modules/cards/domain/events/CardRemovedFromLibraryEvent.ts index aa46d9e2..4e79fb1b 100644 --- a/src/modules/cards/domain/events/CardRemovedFromLibraryEvent.ts +++ b/src/modules/cards/domain/events/CardRemovedFromLibraryEvent.ts @@ -29,7 +29,9 @@ export class CardRemovedFromLibraryEvent implements IDomainEvent { curatorId: CuratorId, dateTimeOccurred: Date, ): Result { - return ok(new CardRemovedFromLibraryEvent(cardId, curatorId, dateTimeOccurred)); + return ok( + new CardRemovedFromLibraryEvent(cardId, curatorId, dateTimeOccurred), + ); } getAggregateId(): UniqueEntityID { diff --git a/src/modules/cards/tests/application/RemoveCardFromLibraryUseCase.test.ts b/src/modules/cards/tests/application/RemoveCardFromLibraryUseCase.test.ts index a71df3c6..0b37bd09 100644 --- a/src/modules/cards/tests/application/RemoveCardFromLibraryUseCase.test.ts +++ b/src/modules/cards/tests/application/RemoveCardFromLibraryUseCase.test.ts @@ -9,6 +9,7 @@ import { InMemoryCollectionRepository } from '../utils/InMemoryCollectionReposit import { FakeCollectionPublisher } from '../utils/FakeCollectionPublisher'; import { CardCollectionService } from '../../domain/services/CardCollectionService'; import { CollectionBuilder } from '../utils/builders/CollectionBuilder'; +import { FakeEventPublisher } from '../utils/FakeEventPublisher'; describe('RemoveCardFromLibraryUseCase', () => { let useCase: RemoveCardFromLibraryUseCase; @@ -20,6 +21,7 @@ describe('RemoveCardFromLibraryUseCase', () => { let cardLibraryService: CardLibraryService; let curatorId: CuratorId; let otherCuratorId: CuratorId; + let eventPublisher: FakeEventPublisher; beforeEach(() => { cardRepository = InMemoryCardRepository.getInstance(); @@ -37,10 +39,12 @@ describe('RemoveCardFromLibraryUseCase', () => { collectionRepository, cardCollectionService, ); + eventPublisher = new FakeEventPublisher(); useCase = new RemoveCardFromLibraryUseCase( cardRepository, cardLibraryService, + eventPublisher, ); curatorId = CuratorId.create('did:plc:testcurator').unwrap(); diff --git a/src/modules/notifications/application/sagas/CardNotificationSaga.ts b/src/modules/notifications/application/sagas/CardNotificationSaga.ts index 63b48f0f..5f9e1056 100644 --- a/src/modules/notifications/application/sagas/CardNotificationSaga.ts +++ b/src/modules/notifications/application/sagas/CardNotificationSaga.ts @@ -34,7 +34,10 @@ export class CardNotificationSaga { ) {} async handleCardEvent( - event: CardAddedToLibraryEvent | CardAddedToCollectionEvent | CardRemovedFromLibraryEvent, + event: + | CardAddedToLibraryEvent + | CardAddedToCollectionEvent + | CardRemovedFromLibraryEvent, ): Promise> { // Handle card removal events if (event instanceof CardRemovedFromLibraryEvent) { @@ -57,20 +60,26 @@ export class CardNotificationSaga { } // Find and delete any existing notifications for this card/actor combination - const existingNotificationsResult = await this.notificationRepository.findByCardAndActor( - event.cardId.getStringValue(), - actorUserId.value, - ); + const existingNotificationsResult = + await this.notificationRepository.findByCardAndActor( + event.cardId.getStringValue(), + actorUserId.value, + ); if (existingNotificationsResult.isOk()) { const notifications = existingNotificationsResult.value; for (const notification of notifications) { // Delete any pending notification in the saga state for this specific notification - const aggregationKey = this.createKey(event, notification.recipientUserId.value); + const aggregationKey = this.createKey( + event, + notification.recipientUserId.value, + ); await this.deletePendingNotification(aggregationKey); // Delete the existing notification - const deleteResult = await this.notificationRepository.delete(notification.notificationId); + const deleteResult = await this.notificationRepository.delete( + notification.notificationId, + ); if (deleteResult.isErr()) { console.error('Failed to delete notification:', deleteResult.error); // Continue with other notifications even if one fails @@ -80,7 +89,10 @@ export class CardNotificationSaga { return ok(undefined); } catch (error) { - console.error('Error in CardNotificationSaga handleCardRemovedEvent:', error); + console.error( + 'Error in CardNotificationSaga handleCardRemovedEvent:', + error, + ); return err(error as Error); } } @@ -228,7 +240,10 @@ export class CardNotificationSaga { } private createKey( - event: CardAddedToLibraryEvent | CardAddedToCollectionEvent | CardRemovedFromLibraryEvent, + event: + | CardAddedToLibraryEvent + | CardAddedToCollectionEvent + | CardRemovedFromLibraryEvent, recipientUserId: string, ): string { const cardId = event.cardId.getStringValue(); @@ -237,7 +252,10 @@ export class CardNotificationSaga { } private getActorId( - event: CardAddedToLibraryEvent | CardAddedToCollectionEvent | CardRemovedFromLibraryEvent, + event: + | CardAddedToLibraryEvent + | CardAddedToCollectionEvent + | CardRemovedFromLibraryEvent, ): string { if ('curatorId' in event) { return event.curatorId.value; // CardAddedToLibraryEvent or CardRemovedFromLibraryEvent diff --git a/src/modules/notifications/application/useCases/queries/GetMyNotificationsUseCase.ts b/src/modules/notifications/application/useCases/queries/GetMyNotificationsUseCase.ts index 219f43fe..f89f1fcd 100644 --- a/src/modules/notifications/application/useCases/queries/GetMyNotificationsUseCase.ts +++ b/src/modules/notifications/application/useCases/queries/GetMyNotificationsUseCase.ts @@ -99,7 +99,9 @@ export class GetMyNotificationsUseCase ); if (actorProfileResult.isErr()) { // Delete notification if we can't resolve the actor profile - await this.notificationRepository.delete(notification.notificationId); + await this.notificationRepository.delete( + notification.notificationId, + ); continue; } @@ -110,7 +112,9 @@ export class GetMyNotificationsUseCase ); if (!cardView) { // Delete notification if we can't resolve the card - await this.notificationRepository.delete(notification.notificationId); + await this.notificationRepository.delete( + notification.notificationId, + ); continue; } @@ -120,7 +124,9 @@ export class GetMyNotificationsUseCase ); if (cardAuthorProfileResult.isErr()) { // Delete notification if we can't resolve the card author profile - await this.notificationRepository.delete(notification.notificationId); + await this.notificationRepository.delete( + notification.notificationId, + ); continue; } diff --git a/src/modules/notifications/tests/infrastructure/InMemoryNotificationRepository.ts b/src/modules/notifications/tests/infrastructure/InMemoryNotificationRepository.ts index be16165d..a157b63c 100644 --- a/src/modules/notifications/tests/infrastructure/InMemoryNotificationRepository.ts +++ b/src/modules/notifications/tests/infrastructure/InMemoryNotificationRepository.ts @@ -109,7 +109,9 @@ export class InMemoryNotificationRepository implements INotificationRepository { cardId: string, actorUserId: CuratorId, ): Promise> { - const matchingNotifications = Array.from(this.notifications.values()).filter( + const matchingNotifications = Array.from( + this.notifications.values(), + ).filter( (notification) => notification.metadata.cardId === cardId && notification.actorUserId.equals(actorUserId), diff --git a/src/shared/infrastructure/http/factories/UseCaseFactory.ts b/src/shared/infrastructure/http/factories/UseCaseFactory.ts index 171b9a7d..4c7f2ed5 100644 --- a/src/shared/infrastructure/http/factories/UseCaseFactory.ts +++ b/src/shared/infrastructure/http/factories/UseCaseFactory.ts @@ -383,6 +383,7 @@ export class UseCaseFactory { new RemoveCardFromLibraryUseCase( repositories.cardRepository, services.cardLibraryService, + services.eventPublisher, ), repositories.cardRepository, ), diff --git a/src/shared/infrastructure/processes/InMemoryEventWorkerProcess.ts b/src/shared/infrastructure/processes/InMemoryEventWorkerProcess.ts index 41e666dd..785f8bc7 100644 --- a/src/shared/infrastructure/processes/InMemoryEventWorkerProcess.ts +++ b/src/shared/infrastructure/processes/InMemoryEventWorkerProcess.ts @@ -69,6 +69,7 @@ export class InMemoryEventWorkerProcess implements IProcess { useCases.createNotificationUseCase, services.sagaStateStore, repositories.cardRepository, + repositories.notificationRepository, ); const notificationCardAddedToLibraryHandler = diff --git a/src/shared/infrastructure/processes/NotificationWorkerProcess.ts b/src/shared/infrastructure/processes/NotificationWorkerProcess.ts index 91a0f304..5068701d 100644 --- a/src/shared/infrastructure/processes/NotificationWorkerProcess.ts +++ b/src/shared/infrastructure/processes/NotificationWorkerProcess.ts @@ -53,9 +53,8 @@ export class NotificationWorkerProcess extends BaseWorkerProcess { const cardAddedToCollectionHandler = new CardAddedToCollectionEventHandler( cardNotificationSaga, ); - const cardRemovedFromLibraryHandler = new CardRemovedFromLibraryEventHandler( - cardNotificationSaga, - ); + const cardRemovedFromLibraryHandler = + new CardRemovedFromLibraryEventHandler(cardNotificationSaga); await subscriber.subscribe( EventNames.CARD_ADDED_TO_LIBRARY,