Taichi Masuyama 4 лет назад
Родитель
Сommit
2b1895de7e
2 измененных файлов с 8 добавлено и 5 удалено
  1. 3 0
      packages/app/src/server/models/page.ts
  2. 5 5
      packages/app/src/server/service/page.ts

+ 3 - 0
packages/app/src/server/models/page.ts

@@ -478,6 +478,9 @@ schema.statics.recountDescendantCount = async function(id: ObjectIdLike):Promise
 schema.statics.findAncestorsUsingParentRecursively = async function(pageId: ObjectIdLike, shouldIncludeTarget: boolean) {
   const self = this;
   const target = await this.findById(pageId);
+  if (target == null) {
+    throw Error('Target not found');
+  }
 
   async function findAncestorsRecursively(target, ancestors = shouldIncludeTarget ? [target] : []) {
     const parent = await self.findOne({ _id: target.parent });

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

@@ -792,6 +792,9 @@ class PageService {
       }
     }
 
+    // copy & populate (reason why copy: SubOperation only allows non-populated page document)
+    const copyPage = { ...page };
+
     // 3. Duplicate target
     const options: PageCreateOptions = {
       grant: page.grant,
@@ -803,10 +806,7 @@ class PageService {
       duplicatedTarget = await Page.createEmptyPage(newPagePath, parent);
     }
     else {
-      console.log('ははははh?', page);
-      // copy & populate (reason why copy: SubOperation only allows non-populated page document)
-      const copyPage = { ...page };
-      await copyPage.populate({ path: 'revision', model: 'Revision', select: 'body' });
+      await page.populate({ path: 'revision', model: 'Revision', select: 'body' });
       duplicatedTarget = await (Page.create as CreateMethod)(
         newPagePath, copyPage.revision.body, user, options,
       );
@@ -830,7 +830,7 @@ class PageService {
         pageOp = await PageOperation.create({
           actionType: PageActionType.Duplicate,
           actionStage: PageActionStage.Main,
-          page,
+          page: copyPage,
           user,
           fromPath: page.path,
           toPath: newPagePath,