Просмотр исходного кода

Modified the code based off the FB

Shunm634-source 3 лет назад
Родитель
Сommit
a609794bd3
2 измененных файлов с 12 добавлено и 12 удалено
  1. 6 6
      packages/app/src/server/service/page.ts
  2. 6 6
      packages/app/test/integration/service/page.test.js

+ 6 - 6
packages/app/src/server/service/page.ts

@@ -169,7 +169,7 @@ class PageService {
 
 
     // Change the parameter of the function into the pages
     // Change the parameter of the function into the pages
     // rename
     // rename
-    this.pageEvent.on('rename', async(page, user, descendantPages) => {
+    this.pageEvent.on('rename', async(page, user, descendantPages?) => {
       const isRecursively = descendantPages != null;
       const isRecursively = descendantPages != null;
       const action = isRecursively ? SUPPORTED_ACTION_TYPE.ACTION_PAGE_RECURSIVELY_RENAME : SUPPORTED_ACTION_TYPE.ACTION_PAGE_RENAME;
       const action = isRecursively ? SUPPORTED_ACTION_TYPE.ACTION_PAGE_RECURSIVELY_RENAME : SUPPORTED_ACTION_TYPE.ACTION_PAGE_RENAME;
       try {
       try {
@@ -191,7 +191,7 @@ class PageService {
     });
     });
 
 
     // delete
     // delete
-    this.pageEvent.on('delete', async(page, user, descendantPages) => {
+    this.pageEvent.on('delete', async(page, user, descendantPages?) => {
       const isRecursively = descendantPages != null;
       const isRecursively = descendantPages != null;
       const action = isRecursively ? SUPPORTED_ACTION_TYPE.ACTION_PAGE_RECURSIVELY_DELETE : SUPPORTED_ACTION_TYPE.ACTION_PAGE_DELETE;
       const action = isRecursively ? SUPPORTED_ACTION_TYPE.ACTION_PAGE_RECURSIVELY_DELETE : SUPPORTED_ACTION_TYPE.ACTION_PAGE_DELETE;
       try {
       try {
@@ -543,7 +543,7 @@ class PageService {
       update.updatedAt = new Date();
       update.updatedAt = new Date();
     }
     }
     const renamedPage = await Page.findByIdAndUpdate(page._id, { $set: update }, { new: true });
     const renamedPage = await Page.findByIdAndUpdate(page._id, { $set: update }, { new: true });
-    this.pageEvent.emit('rename', page, user, null);
+    this.pageEvent.emit('rename', page, user);
 
 
     // create page redirect
     // create page redirect
     if (options.createRedirectPage) {
     if (options.createRedirectPage) {
@@ -689,7 +689,7 @@ class PageService {
       await PageRedirect.create({ fromPath: page.path, toPath: newPagePath });
       await PageRedirect.create({ fromPath: page.path, toPath: newPagePath });
     }
     }
 
 
-    this.pageEvent.emit('rename', page, user, null);
+    this.pageEvent.emit('rename', page, user);
 
 
     return renamedPage;
     return renamedPage;
   }
   }
@@ -1420,7 +1420,7 @@ class PageService {
       this.deleteRecursivelyMainOperation(page, user, pageOp._id);
       this.deleteRecursivelyMainOperation(page, user, pageOp._id);
     }
     }
     else {
     else {
-      this.pageEvent.emit('delete', page, user, null);
+      this.pageEvent.emit('delete', page, user);
     }
     }
 
 
     return deletedPage;
     return deletedPage;
@@ -1508,7 +1508,7 @@ class PageService {
       }
       }
     }
     }
 
 
-    this.pageEvent.emit('delete', page, user, null);
+    this.pageEvent.emit('delete', page, user);
     this.pageEvent.emit('create', deletedPage, user);
     this.pageEvent.emit('create', deletedPage, user);
 
 
     return deletedPage;
     return deletedPage;

+ 6 - 6
packages/app/test/integration/service/page.test.js

@@ -350,7 +350,7 @@ describe('PageService', () => {
 
 
         expect(xssSpy).toHaveBeenCalled();
         expect(xssSpy).toHaveBeenCalled();
 
 
-        expect(pageEventSpy).toHaveBeenCalledWith('rename', parentForRename1, testUser2, null);
+        expect(pageEventSpy).toHaveBeenCalledWith('rename', parentForRename1, testUser2);
 
 
         expect(resultPage.path).toBe('/renamed1');
         expect(resultPage.path).toBe('/renamed1');
         expect(resultPage.updatedAt).toEqual(parentForRename1.updatedAt);
         expect(resultPage.updatedAt).toEqual(parentForRename1.updatedAt);
@@ -363,7 +363,7 @@ describe('PageService', () => {
 
 
         expect(xssSpy).toHaveBeenCalled();
         expect(xssSpy).toHaveBeenCalled();
 
 
-        expect(pageEventSpy).toHaveBeenCalledWith('rename', parentForRename2, testUser2, null);
+        expect(pageEventSpy).toHaveBeenCalledWith('rename', parentForRename2, testUser2);
 
 
         expect(resultPage.path).toBe('/renamed2');
         expect(resultPage.path).toBe('/renamed2');
         expect(resultPage.updatedAt).toEqual(dateToUse);
         expect(resultPage.updatedAt).toEqual(dateToUse);
@@ -375,7 +375,7 @@ describe('PageService', () => {
         const resultPage = await crowi.pageService.renamePage(parentForRename3, '/renamed3', testUser2, { createRedirectPage: true });
         const resultPage = await crowi.pageService.renamePage(parentForRename3, '/renamed3', testUser2, { createRedirectPage: true });
 
 
         expect(xssSpy).toHaveBeenCalled();
         expect(xssSpy).toHaveBeenCalled();
-        expect(pageEventSpy).toHaveBeenCalledWith('rename', parentForRename3, testUser2, null);
+        expect(pageEventSpy).toHaveBeenCalledWith('rename', parentForRename3, testUser2);
 
 
         expect(resultPage.path).toBe('/renamed3');
         expect(resultPage.path).toBe('/renamed3');
         expect(resultPage.updatedAt).toEqual(parentForRename3.updatedAt);
         expect(resultPage.updatedAt).toEqual(parentForRename3.updatedAt);
@@ -388,7 +388,7 @@ describe('PageService', () => {
 
 
         expect(xssSpy).toHaveBeenCalled();
         expect(xssSpy).toHaveBeenCalled();
         expect(renameDescendantsWithStreamSpy).toHaveBeenCalled();
         expect(renameDescendantsWithStreamSpy).toHaveBeenCalled();
-        expect(pageEventSpy).toHaveBeenCalledWith('rename', parentForRename4, testUser2, null);
+        expect(pageEventSpy).toHaveBeenCalledWith('rename', parentForRename4, testUser2);
 
 
         expect(resultPage.path).toBe('/renamed4');
         expect(resultPage.path).toBe('/renamed4');
         expect(resultPage.updatedAt).toEqual(parentForRename4.updatedAt);
         expect(resultPage.updatedAt).toEqual(parentForRename4.updatedAt);
@@ -564,7 +564,7 @@ describe('PageService', () => {
       expect(resultPage.updatedAt).toEqual(parentForDelete1.updatedAt);
       expect(resultPage.updatedAt).toEqual(parentForDelete1.updatedAt);
       expect(resultPage.lastUpdateUser).toEqual(testUser1._id);
       expect(resultPage.lastUpdateUser).toEqual(testUser1._id);
 
 
-      expect(pageEventSpy).toHaveBeenCalledWith('delete', parentForDelete1, testUser2, null);
+      expect(pageEventSpy).toHaveBeenCalledWith('delete', parentForDelete1, testUser2);
       expect(pageEventSpy).toHaveBeenCalledWith('create', resultPage, testUser2);
       expect(pageEventSpy).toHaveBeenCalledWith('create', resultPage, testUser2);
     });
     });
 
 
@@ -581,7 +581,7 @@ describe('PageService', () => {
       expect(resultPage.updatedAt).toEqual(parentForDelete2.updatedAt);
       expect(resultPage.updatedAt).toEqual(parentForDelete2.updatedAt);
       expect(resultPage.lastUpdateUser).toEqual(testUser1._id);
       expect(resultPage.lastUpdateUser).toEqual(testUser1._id);
 
 
-      expect(pageEventSpy).toHaveBeenCalledWith('delete', parentForDelete2, testUser2, null);
+      expect(pageEventSpy).toHaveBeenCalledWith('delete', parentForDelete2, testUser2);
       expect(pageEventSpy).toHaveBeenCalledWith('create', resultPage, testUser2);
       expect(pageEventSpy).toHaveBeenCalledWith('create', resultPage, testUser2);
     });
     });