ryoji-s 3 лет назад
Родитель
Сommit
902d7ddafd

+ 0 - 16
packages/app/src/server/models/obsolete-page.js

@@ -672,22 +672,6 @@ export const getPageSchema = (crowi) => {
 
   };
 
-  pageSchema.statics.removeByPath = async function(path) {
-    if (path == null) {
-      throw new Error('path is required');
-    }
-
-    // https://regex101.com/r/guaY11/1
-    const regex = new RegExp(`^${path}/.+$`);
-    const deleteManyPromise = this.deleteMany({ path: regex });
-    const findOneAndRemovePromise = this.findOneAndRemove({ path });
-
-    return await Promise.all([
-      deleteManyPromise,
-      findOneAndRemovePromise,
-    ]);
-  };
-
   pageSchema.statics.findListByPathsArray = async function(paths, includeEmpty = false) {
     const queryBuilder = new this.PageQueryBuilder(this.find(), includeEmpty);
     queryBuilder.addConditionToListByPathsArray(paths);

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

@@ -4,6 +4,7 @@ import nodePath from 'path';
 
 import { HasObjectId, pagePathUtils, pathUtils } from '@growi/core';
 import escapeStringRegexp from 'escape-string-regexp';
+import { DeleteResult } from 'mongodb';
 import mongoose, {
   Schema, Model, Document, AnyObject,
 } from 'mongoose';
@@ -954,6 +955,20 @@ schema.statics.findNonEmptyClosestAncestor = async function(path: string): Promi
   return ancestors[0];
 };
 
+schema.statics.removeByPath = async function(
+    userHomePagePath: string,
+): Promise<{ deleteManyResult: DeleteResult, findOneAndRemoveResult: PageDocument & HasObjectId | null }> {
+  // https://regex101.com/r/PY1tI5/1
+  const regex = new RegExp(`^${userHomePagePath}/.+`);
+
+  const [deleteManyResult, findOneAndRemoveResult] = await Promise.all([
+    this.deleteMany({ path: regex }),
+    this.findOneAndRemove({ path: userHomePagePath }),
+  ]);
+
+  return { deleteManyResult, findOneAndRemoveResult };
+};
+
 
 export type PageCreateOptions = {
   format?: string