Taichi Masuyama %!s(int64=4) %!d(string=hai) anos
pai
achega
2b1895de7e

+ 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) {
 schema.statics.findAncestorsUsingParentRecursively = async function(pageId: ObjectIdLike, shouldIncludeTarget: boolean) {
   const self = this;
   const self = this;
   const target = await this.findById(pageId);
   const target = await this.findById(pageId);
+  if (target == null) {
+    throw Error('Target not found');
+  }
 
 
   async function findAncestorsRecursively(target, ancestors = shouldIncludeTarget ? [target] : []) {
   async function findAncestorsRecursively(target, ancestors = shouldIncludeTarget ? [target] : []) {
     const parent = await self.findOne({ _id: target.parent });
     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
     // 3. Duplicate target
     const options: PageCreateOptions = {
     const options: PageCreateOptions = {
       grant: page.grant,
       grant: page.grant,
@@ -803,10 +806,7 @@ class PageService {
       duplicatedTarget = await Page.createEmptyPage(newPagePath, parent);
       duplicatedTarget = await Page.createEmptyPage(newPagePath, parent);
     }
     }
     else {
     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)(
       duplicatedTarget = await (Page.create as CreateMethod)(
         newPagePath, copyPage.revision.body, user, options,
         newPagePath, copyPage.revision.body, user, options,
       );
       );
@@ -830,7 +830,7 @@ class PageService {
         pageOp = await PageOperation.create({
         pageOp = await PageOperation.create({
           actionType: PageActionType.Duplicate,
           actionType: PageActionType.Duplicate,
           actionStage: PageActionStage.Main,
           actionStage: PageActionStage.Main,
-          page,
+          page: copyPage,
           user,
           user,
           fromPath: page.path,
           fromPath: page.path,
           toPath: newPagePath,
           toPath: newPagePath,