|
|
@@ -672,11 +672,20 @@ export const getPageSchema = (crowi) => {
|
|
|
|
|
|
};
|
|
|
|
|
|
- pageSchema.statics.removeByPath = function(path) {
|
|
|
+ pageSchema.statics.removeByPath = async function(path) {
|
|
|
if (path == null) {
|
|
|
throw new Error('path is required');
|
|
|
}
|
|
|
- return this.findOneAndRemove({ path }).exec();
|
|
|
+
|
|
|
+ // 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) {
|