Sfoglia il codice sorgente

fix(syncing-server): publish revision creation request only for notes and files

Karol Sójko 2 anni fa
parent
commit
308662550f

+ 8 - 2
packages/syncing-server/src/Domain/Item/ItemService.spec.ts

@@ -158,7 +158,9 @@ describe('ItemService', () => {
     itemSaveValidator = {} as jest.Mocked<ItemSaveValidatorInterface>
     itemSaveValidator.validate = jest.fn().mockReturnValue({ passed: true })
 
-    newItem = {} as jest.Mocked<Item>
+    newItem = {
+      contentType: ContentType.Note,
+    } as jest.Mocked<Item>
 
     itemFactory = {} as jest.Mocked<ItemFactoryInterface>
     itemFactory.create = jest.fn().mockReturnValue(newItem)
@@ -521,7 +523,11 @@ describe('ItemService', () => {
 
   it('should save new items that are duplicates', async () => {
     itemRepository.findByUuid = jest.fn().mockReturnValue(null)
-    const duplicateItem = { updatedAtTimestamp: 1616164633241570, duplicateOf: '1-2-3' } as jest.Mocked<Item>
+    const duplicateItem = {
+      updatedAtTimestamp: 1616164633241570,
+      duplicateOf: '1-2-3',
+      contentType: ContentType.Note,
+    } as jest.Mocked<Item>
     itemFactory.create = jest.fn().mockReturnValueOnce(duplicateItem)
 
     const result = await createService().saveItems({

+ 10 - 6
packages/syncing-server/src/Domain/Item/ItemService.ts

@@ -255,9 +255,11 @@ export class ItemService implements ItemServiceInterface {
     if (secondsFromLastUpdate >= this.revisionFrequency) {
       await this.revisionService.createRevision(savedItem)
 
-      await this.domainEventPublisher.publish(
-        this.domainEventFactory.createItemRevisionCreationRequested(savedItem.uuid, savedItem.userUuid),
-      )
+      if ([ContentType.Note, ContentType.File].includes(savedItem.contentType as ContentType)) {
+        await this.domainEventPublisher.publish(
+          this.domainEventFactory.createItemRevisionCreationRequested(savedItem.uuid, savedItem.userUuid),
+        )
+      }
     }
 
     if (wasMarkedAsDuplicate) {
@@ -276,9 +278,11 @@ export class ItemService implements ItemServiceInterface {
 
     await this.revisionService.createRevision(savedItem)
 
-    await this.domainEventPublisher.publish(
-      this.domainEventFactory.createItemRevisionCreationRequested(savedItem.uuid, savedItem.userUuid),
-    )
+    if ([ContentType.Note, ContentType.File].includes(savedItem.contentType as ContentType)) {
+      await this.domainEventPublisher.publish(
+        this.domainEventFactory.createItemRevisionCreationRequested(savedItem.uuid, savedItem.userUuid),
+      )
+    }
 
     if (savedItem.duplicateOf) {
       await this.domainEventPublisher.publish(