takeru0001 5 лет назад
Родитель
Сommit
ac20796515
1 измененных файлов с 13 добавлено и 9 удалено
  1. 13 9
      src/server/routes/apiv3/page.js

+ 13 - 9
src/server/routes/apiv3/page.js

@@ -7,6 +7,7 @@ const { body, query } = require('express-validator');
 
 const router = express.Router();
 
+const { convertToNewAffiliationPath } = require('../../../lib/util/path-utils');
 const ErrorV3 = require('../../models/vo/error-apiv3');
 
 /**
@@ -139,7 +140,8 @@ module.exports = (crowi) => {
       body('hierarchyValue').isNumeric(),
     ],
     exist: [
-      query('newParentPath').isString(),
+      query('fromPath').isString(),
+      query('toPath').isString(),
     ],
   };
 
@@ -290,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 });