Taichi Masuyama 4 лет назад
Родитель
Сommit
89624f6a02

+ 1 - 1
packages/app/src/interfaces/page.ts

@@ -5,7 +5,7 @@ import { ITag } from './tag';
 import { HasObjectId } from './has-object-id';
 
 
-export type IPage = {
+export interface IPage {
   path: string,
   status: string,
   revision: Ref<IRevision>,

+ 4 - 5
packages/app/src/server/models/page.ts

@@ -139,7 +139,9 @@ schema.statics.createEmptyPagesByPaths = async function(paths: string[], publicO
   }
 };
 
-schema.statics.createEmptyPage = async function(path: string, parent) {
+schema.statics.createEmptyPage = async function(
+    path: string, parent: any, // TODO: improve type including IPage
+): Promise<PageDocument & { _id: any }> {
   if (parent == null) {
     throw Error('parent must not be null');
   }
@@ -160,7 +162,7 @@ schema.statics.createEmptyPage = async function(path: string, parent) {
  * @param pageToReplaceWith (optional) a page document to replace with
  * @returns Promise<void>
  */
-schema.statics.replaceTargetEmptyPage = async function(exPage, pageToReplaceWith?): Promise<void> {
+schema.statics.replaceTargetWithPage = async function(exPage, pageToReplaceWith?): Promise<void> {
   // find parent
   const parent = await this.findOne({ _id: exPage.parent });
   if (parent == null) {
@@ -249,9 +251,6 @@ schema.statics.getParentAndFillAncestors = async function(path: string): Promise
 
   const createdParent = ancestorsMap.get(parentPath);
 
-  if (createdParent == null) {
-    throw Error('createdParent must not be null');
-  }
   return createdParent;
 };
 

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

@@ -193,11 +193,11 @@ class PageService {
   }
 
   // TODO: implement recursive rename
-  async renamePage(page, newPagePath, user, options, isRecursively = false) {
+  async renamePage(page, newPagePath, user, options) {
     // v4 compatible process
     const isV5Compatible = this.crowi.configManager.getConfig('crowi', 'app:isV5Compatible');
     if (!isV5Compatible) {
-      return this.renamePageV4(page, newPagePath, user, options, isRecursively);
+      return this.renamePageV4(page, newPagePath, user, options);
     }
 
     const Page = this.crowi.model('Page');
@@ -229,10 +229,8 @@ class PageService {
       }
     }
 
-    // create descendants first
-    if (isRecursively) {
-      await this.renameDescendantsWithStream(page, newPagePath, user, options);
-    }
+    // update descendants first
+    await this.renameDescendantsWithStream(page, newPagePath, user, options);
 
     /*
      * replace target