Files
standardnotes-server/packages/syncing-server/src/Domain/Handler/ItemRevisionCreationRequestedEventHandler.ts
T
Karol SójkoandGitHub 993d31167b feat(syncing-server): refactor container config into server and worker (#443)
* feat(syncing-server): refactor container config into server and worker

* fix(syncing-server): yarn lock

* fix(api-gateway): add client update response on v1 revision endpoints

* fix(syncing-server): linter issue
2023-02-13 10:12:32 +01:00

33 lines
1.2 KiB
TypeScript

import {
ItemRevisionCreationRequestedEvent,
DomainEventHandlerInterface,
DomainEventPublisherInterface,
} from '@standardnotes/domain-events'
import { DomainEventFactoryInterface } from '../Event/DomainEventFactoryInterface'
import { ItemBackupServiceInterface } from '../Item/ItemBackupServiceInterface'
import { ItemRepositoryInterface } from '../Item/ItemRepositoryInterface'
export class ItemRevisionCreationRequestedEventHandler implements DomainEventHandlerInterface {
constructor(
private itemRepository: ItemRepositoryInterface,
private itemBackupService: ItemBackupServiceInterface,
private domainEventFactory: DomainEventFactoryInterface,
private domainEventPublisher: DomainEventPublisherInterface,
) {}
async handle(event: ItemRevisionCreationRequestedEvent): Promise<void> {
const item = await this.itemRepository.findByUuid(event.payload.itemUuid)
if (item === null) {
return
}
const fileDumpPath = await this.itemBackupService.dump(item)
if (fileDumpPath) {
await this.domainEventPublisher.publish(
this.domainEventFactory.createItemDumpedEvent(fileDumpPath, event.meta.correlation.userIdentifier),
)
}
}
}