AccountDeletionRequestedEventHandler.ts 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. import {
  2. AccountDeletionRequestedEvent,
  3. DomainEventHandlerInterface,
  4. DomainEventPublisherInterface,
  5. } from '@standardnotes/domain-events'
  6. import { inject, injectable } from 'inversify'
  7. import TYPES from '../../Bootstrap/Types'
  8. import { DomainEventFactoryInterface } from '../Event/DomainEventFactoryInterface'
  9. import { MarkFilesToBeRemoved } from '../UseCase/MarkFilesToBeRemoved/MarkFilesToBeRemoved'
  10. @injectable()
  11. export class AccountDeletionRequestedEventHandler implements DomainEventHandlerInterface {
  12. constructor(
  13. @inject(TYPES.Files_MarkFilesToBeRemoved) private markFilesToBeRemoved: MarkFilesToBeRemoved,
  14. @inject(TYPES.Files_DomainEventPublisher) private domainEventPublisher: DomainEventPublisherInterface,
  15. @inject(TYPES.Files_DomainEventFactory) private domainEventFactory: DomainEventFactoryInterface,
  16. ) {}
  17. async handle(event: AccountDeletionRequestedEvent): Promise<void> {
  18. if (event.payload.regularSubscriptionUuid === undefined) {
  19. return
  20. }
  21. const result = await this.markFilesToBeRemoved.execute({
  22. ownerUuid: event.payload.userUuid,
  23. })
  24. if (result.isFailed()) {
  25. return
  26. }
  27. const filesRemoved = result.getValue()
  28. for (const fileRemoved of filesRemoved) {
  29. await this.domainEventPublisher.publish(
  30. this.domainEventFactory.createFileRemovedEvent({
  31. regularSubscriptionUuid: event.payload.regularSubscriptionUuid,
  32. ...fileRemoved,
  33. }),
  34. )
  35. }
  36. }
  37. }