mirror of
https://github.com/standardnotes/server
synced 2026-08-01 17:17:00 -04:00
* 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
48 lines
1.5 KiB
TypeScript
48 lines
1.5 KiB
TypeScript
import {
|
|
DomainEventHandlerInterface,
|
|
DomainEventPublisherInterface,
|
|
DuplicateItemSyncedEvent,
|
|
} from '@standardnotes/domain-events'
|
|
import { Logger } from 'winston'
|
|
import { DomainEventFactoryInterface } from '../Event/DomainEventFactoryInterface'
|
|
import { ItemRepositoryInterface } from '../Item/ItemRepositoryInterface'
|
|
|
|
export class DuplicateItemSyncedEventHandler implements DomainEventHandlerInterface {
|
|
constructor(
|
|
private itemRepository: ItemRepositoryInterface,
|
|
private domainEventFactory: DomainEventFactoryInterface,
|
|
private domainEventPublisher: DomainEventPublisherInterface,
|
|
private logger: Logger,
|
|
) {}
|
|
|
|
async handle(event: DuplicateItemSyncedEvent): Promise<void> {
|
|
const item = await this.itemRepository.findByUuidAndUserUuid(event.payload.itemUuid, event.payload.userUuid)
|
|
|
|
if (item === null) {
|
|
this.logger.warn(`Could not find item with uuid ${event.payload.itemUuid}`)
|
|
|
|
return
|
|
}
|
|
|
|
if (!item.duplicateOf) {
|
|
this.logger.warn(`Item ${event.payload.itemUuid} does not point to any duplicate`)
|
|
|
|
return
|
|
}
|
|
|
|
const existingOriginalItem = await this.itemRepository.findByUuidAndUserUuid(
|
|
item.duplicateOf,
|
|
event.payload.userUuid,
|
|
)
|
|
|
|
if (existingOriginalItem !== null) {
|
|
await this.domainEventPublisher.publish(
|
|
this.domainEventFactory.createRevisionsCopyRequestedEvent(event.payload.userUuid, {
|
|
originalItemUuid: existingOriginalItem.uuid,
|
|
newItemUuid: item.uuid,
|
|
}),
|
|
)
|
|
}
|
|
}
|
|
}
|