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

Merge branch 'imprv/rename-testcode-and-interface' into imprv/rename-descendants

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

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

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

+ 3 - 4
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) {
   if (parent == null) {
     throw Error('parent must not be null');
     throw Error('parent must not be null');
   }
   }
@@ -251,9 +253,6 @@ schema.statics.getParentAndFillAncestors = async function(path: string): Promise
 
 
   const createdParent = ancestorsMap.get(parentPath);
   const createdParent = ancestorsMap.get(parentPath);
 
 
-  if (createdParent == null) {
-    throw Error('createdParent must not be null');
-  }
   return createdParent;
   return createdParent;
 };
 };
 
 

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

@@ -192,11 +192,11 @@ class PageService {
   }
   }
 
 
   // TODO: implement recursive rename
   // TODO: implement recursive rename
-  async renamePage(page, newPagePath, user, options, isRecursively = false) {
+  async renamePage(page, newPagePath, user, options) {
     // v4 compatible process
     // v4 compatible process
     const isV5Compatible = this.crowi.configManager.getConfig('crowi', 'app:isV5Compatible') && page.parent != null;
     const isV5Compatible = this.crowi.configManager.getConfig('crowi', 'app:isV5Compatible') && page.parent != null;
     if (!isV5Compatible) {
     if (!isV5Compatible) {
-      return this.renamePageV4(page, newPagePath, user, options, isRecursively);
+      return this.renamePageV4(page, newPagePath, user, options);
     }
     }
 
 
     const Page = this.crowi.model('Page');
     const Page = this.crowi.model('Page');
@@ -228,10 +228,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
      * replace target