takeru0001 před 5 roky
rodič
revize
80190f1d7d
1 změnil soubory, kde provedl 10 přidání a 8 odebrání
  1. 10 8
      src/server/routes/apiv3/page.js

+ 10 - 8
src/server/routes/apiv3/page.js

@@ -292,18 +292,20 @@ module.exports = (crowi) => {
    *            description: Internal server error.
    */
   router.get('/exist-paths', loginRequired, validator.exist, apiV3FormValidator, async(req, res) => {
-    const { newParentPath, toPaths } = req.query;
+    const { fromPath, toPath } = req.query;
 
     try {
-      const { pages } = await Page.findListByStartWith(newParentPath, req.user);
+      const fromPage = await Page.findByPath(fromPath);
+      const fromPageDescendants = await Page.findManageableListWithDescendants(fromPage, req.user);
 
-      const duplicationPaths = pages.map((page) => {
-        if (toPaths.includes(page.path)) {
-          return page.path;
-        }
-        return null;
+      const fromPathDescendantsArray = fromPageDescendants.map((subordinatedPage) => {
+        return convertToNewAffiliationPath(fromPath, toPath, subordinatedPage.path);
       });
-      const existPaths = duplicationPaths.filter(path => path != null);
+
+      const toPageDescendants = await Page.findListByStartWith(toPath, req.user);
+      const toPathDescendantsArray = toPageDescendants.pages.map(page => page.path);
+
+      const existPaths = fromPathDescendantsArray.filter(i => toPathDescendantsArray.indexOf(i) !== -1);
 
       return res.apiv3({ existPaths });