Bläddra i källkod

change resumeRenameSubOperation to handle one page operation

yohei0125 3 år sedan
förälder
incheckning
762f70f34c
1 ändrade filer med 18 tillägg och 20 borttagningar
  1. 18 20
      packages/app/src/server/service/page.ts

+ 18 - 20
packages/app/src/server/service/page.ts

@@ -584,36 +584,34 @@ class PageService {
     await PageOperation.findByIdAndDelete(pageOpId);
     await PageOperation.findByIdAndDelete(pageOpId);
   }
   }
 
 
-  async resumeRenamePageOperation(user: any): Promise<void> {
+  async resumeRenameSubOperation(user: any, pageId: ObjectIdLike): Promise<void> {
     if (user == null) {
     if (user == null) {
       throw Error('Guest user cannot execute this operation');
       throw Error('Guest user cannot execute this operation');
     }
     }
 
 
-    const filter = { actionType: PageActionType.Rename, actionStage: PageActionStage.Sub };
-    const pageOps = await PageOperation.find(filter);
-
-    if (pageOps == null || pageOps.length === 0) {
+    // findOne PageOperation
+    const filter = { actionType: PageActionType.Rename, actionStage: PageActionStage.Sub, 'page._id': pageId };
+    const pageOp = await PageOperation.findOne(filter);
+    if (pageOp == null) {
       throw Error('There is nothing to be processed right now');
       throw Error('There is nothing to be processed right now');
     }
     }
 
 
-    const Page = mongoose.model('Page') as unknown as PageModel;
-    // resume multiple rename operations parallelly
-    await Promise.all(pageOps.map(async(pageOp) => {
-      const {
-        page, toPath, options,
-      } = pageOp;
+    const { page, toPath, options } = pageOp;
 
 
-      if (toPath == null) {
-        throw Error(`Property toPath is missing which is needed to resume page operation(${pageOp._id})`);
-      }
+    // check property
+    if (toPath == null) {
+      throw Error(`Property toPath is missing which is needed to resume page operation(${pageOp._id})`);
+    }
 
 
-      const renamedPage = await Page.findOne({ _id: page._id }); // sub operation needs updated page
-      if (renamedPage == null) {
-        throw Error(`Renamed page(${page._id} is not found)`);
-      }
+    const Page = mongoose.model('Page') as unknown as PageModel;
 
 
-      this.renameSubOperation(page, toPath, user, options, renamedPage, pageOp._id);
-    }));
+    // findOne renamed page
+    const renamedPage = await Page.findOne({ _id: page._id }); // sub operation needs renamed page
+    if (renamedPage == null) {
+      throw Error(`Renamed page(${page._id} is not found)`);
+    }
+
+    this.renameSubOperation(page, toPath, user, options, renamedPage, pageOp._id);
 
 
   }
   }