|
|
@@ -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 });
|
|
|
|