Sfoglia il codice sorgente

addConditionToListOnly* methods to exclude {path} self

Yuki Takei 3 anni fa
parent
commit
94d7bc8e25
1 ha cambiato i file con 15 aggiunte e 9 eliminazioni
  1. 15 9
      packages/app/src/server/models/page.ts

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

@@ -196,10 +196,11 @@ export class PageQueryBuilder {
 
 
   /**
   /**
    * generate the query to find the pages '{path}/*' (exclude '{path}' self).
    * generate the query to find the pages '{path}/*' (exclude '{path}' self).
-   * If top page, return without doing anything.
    */
    */
-  addConditionToListOnlyDescendants(path, option): PageQueryBuilder {
-    // No request is set for the top page
+  addConditionToListOnlyDescendants(path: string, option): PageQueryBuilder {
+    // exclude the target page
+    this.query = this.query.and({ path: { $ne: path } });
+
     if (isTopPage(path)) {
     if (isTopPage(path)) {
       return this;
       return this;
     }
     }
@@ -209,22 +210,27 @@ export class PageQueryBuilder {
     const startsPattern = escapeStringRegexp(pathWithTrailingSlash);
     const startsPattern = escapeStringRegexp(pathWithTrailingSlash);
 
 
     this.query = this.query
     this.query = this.query
-      .and({ path: new RegExp(`^${startsPattern}`) });
+      .and(
+        { path: new RegExp(`^${startsPattern}`) },
+      );
 
 
     return this;
     return this;
 
 
   }
   }
 
 
-  addConditionToListOnlyAncestors(path): PageQueryBuilder {
+  addConditionToListOnlyAncestors(path: string): PageQueryBuilder {
     const pathNormalized = pathUtils.normalizePath(path);
     const pathNormalized = pathUtils.normalizePath(path);
     const ancestorsPaths = extractToAncestorsPaths(pathNormalized);
     const ancestorsPaths = extractToAncestorsPaths(pathNormalized);
 
 
     this.query = this.query
     this.query = this.query
-      .and({
-        path: {
-          $in: ancestorsPaths,
+      .and(
+        { path: { $ne: path } }, // exclude the target page
+        {
+          path: {
+            $in: ancestorsPaths,
+          },
         },
         },
-      });
+      );
 
 
     return this;
     return this;