Răsfoiți Sursa

Implemented findEmptyPageByPath and findNotEmptyParentRecursively method on the page model

Taichi Masuyama 3 ani în urmă
părinte
comite
7f5c509d5d
1 a modificat fișierele cu 16 adăugiri și 0 ștergeri
  1. 16 0
      packages/app/src/server/models/page.ts

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

@@ -999,6 +999,22 @@ schema.statics.removeEmptyPages = async function(pageIdsToNotRemove: ObjectIdLik
   });
 };
 
+schema.statics.findEmptyPageByPath = async function(path: string): Promise<PageDocument | null> {
+  return this.findOne({ path, isEmpty: true });
+};
+
+schema.statics.findNotEmptyParentRecursively = async function(target: PageDocument): Promise<PageDocument | null> {
+  const parent = await this.findById(target.parent);
+
+  const shouldContinue = parent != null && parent.isEmpty;
+
+  if (shouldContinue) {
+    return this.findNotEmptyParentRecursively(parent);
+  }
+
+  return target;
+};
+
 schema.statics.PageQueryBuilder = PageQueryBuilder as any; // mongoose does not support constructor type as statics attrs type
 
 export function generateGrantCondition(