|
|
@@ -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
|