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

+ 11 - 7
src/server/routes/apiv3/page.js

@@ -256,22 +256,26 @@ module.exports = (crowi) => {
     return stream.pipe(res);
   });
 
-  router.get('/duplication-path', async(req, res) => {
+  router.get('/exist-paths', loginRequired, validator.exist, async(req, res) => {
     const { path, toPaths } = req.query;
 
     try {
       const pageData = await Page.findByPath(path);
       const descendantsPath = await Page.findManageableListWithDescendants(pageData, req.user);
-      console.log(req.user);
-      const duplicationPaths = descendantsPath.forEach((page) => {
-        if (toPaths.some(toPath => toPath === page.path)) {
-          duplicationPaths.push(page.path);
+
+      const duplicationPaths = descendantsPath.map((page) => {
+        if (toPaths.includes(page.path)) {
+          return page.path;
         }
+        return null;
       });
-      return res.apiv3({ duplicationPaths });
+      const existPaths = duplicationPaths.filter(path => path !== null);
+
+      return res.apiv3({ existPaths });
+
     }
     catch (err) {
-      logger.error('Failed to get duplication path', err);
+      logger.error('Failed to get exist path', err);
       return res.apiv3Err(err, 500);
     }