Explorar el Código

refactor canOperate

yohei0125 hace 3 años
padre
commit
37373a6559
Se han modificado 1 ficheros con 5 adiciones y 30 borrados
  1. 5 30
      packages/app/src/server/service/page-operation.ts

+ 5 - 30
packages/app/src/server/service/page-operation.ts

@@ -33,51 +33,26 @@ class PageOperationService {
 
     const fromPaths = pageOperations.map(op => op.fromPath).filter((p): p is string => p != null);
     const toPaths = pageOperations.map(op => op.toPath).filter((p): p is string => p != null);
+    const fromAndToPaths = [...fromPaths, ...toPaths];
 
     if (isRecursively) {
-      // fromPaths
       if (fromPathToOp != null && !isTrashPage(fromPathToOp)) {
-        const flag = fromPaths.some(p => isEitherOfPathAreaOverlap(p, fromPathToOp));
+        const flag = fromAndToPaths.some(p => isEitherOfPathAreaOverlap(p, fromPathToOp));
         if (flag) return false;
       }
-      // toPaths
-      if (fromPathToOp != null && !isTrashPage(fromPathToOp)) {
-        const flag = toPaths.some(p => isEitherOfPathAreaOverlap(p, fromPathToOp));
-        if (flag) return false;
-      }
-
-      // fromPaths
-      if (toPathToOp != null && !isTrashPage(toPathToOp)) {
-        const flag = fromPaths.some(p => isPathAreaOverlap(p, toPathToOp));
-        if (flag) return false;
-      }
-      // toPaths
       if (toPathToOp != null && !isTrashPage(toPathToOp)) {
-        const flag = toPaths.some(p => isPathAreaOverlap(p, toPathToOp));
+        const flag = fromAndToPaths.some(p => isPathAreaOverlap(p, toPathToOp));
         if (flag) return false;
       }
 
     }
     else {
-      // fromPaths
       if (fromPathToOp != null && !isTrashPage(fromPathToOp)) {
-        const flag = fromPaths.some(p => isPathAreaOverlap(p, fromPathToOp));
-        if (flag) return false;
-      }
-      // toPaths
-      if (fromPathToOp != null && !isTrashPage(fromPathToOp)) {
-        const flag = toPaths.some(p => isPathAreaOverlap(p, fromPathToOp));
-        if (flag) return false;
-      }
-
-      // fromPaths
-      if (toPathToOp != null && !isTrashPage(toPathToOp)) {
-        const flag = fromPaths.some(p => isPathAreaOverlap(p, toPathToOp));
+        const flag = fromAndToPaths.some(p => isPathAreaOverlap(p, fromPathToOp));
         if (flag) return false;
       }
-      // toPaths
       if (toPathToOp != null && !isTrashPage(toPathToOp)) {
-        const flag = toPaths.some(p => isPathAreaOverlap(p, toPathToOp));
+        const flag = fromAndToPaths.some(p => isPathAreaOverlap(p, toPathToOp));
         if (flag) return false;
       }
     }