ソースを参照

use validation and swagger

itizawa 5 年 前
コミット
3ea9bd446c
1 ファイル変更6 行追加2 行削除
  1. 6 2
      src/server/routes/apiv3/pages.js

+ 6 - 2
src/server/routes/apiv3/pages.js

@@ -145,6 +145,7 @@ module.exports = (crowi) => {
     duplicatePage: [
     duplicatePage: [
       body('pageId').isMongoId().withMessage('pageId is required'),
       body('pageId').isMongoId().withMessage('pageId is required'),
       body('pageNameInput').trim().isLength({ min: 1 }).withMessage('pageNameInput is required'),
       body('pageNameInput').trim().isLength({ min: 1 }).withMessage('pageNameInput is required'),
+      body('isRecursively').if(value => value != null).isBoolean().withMessage('isRecursively must be boolean'),
     ],
     ],
   };
   };
 
 
@@ -502,6 +503,9 @@ module.exports = (crowi) => {
    *                    $ref: '#/components/schemas/Page/properties/_id'
    *                    $ref: '#/components/schemas/Page/properties/_id'
    *                  pageNameInput:
    *                  pageNameInput:
    *                    $ref: '#/components/schemas/Page/properties/path'
    *                    $ref: '#/components/schemas/Page/properties/path'
+   *                  isRecursively:
+   *                    type: boolean
+   *                    description: whether duplicate page with descendants
    *                required:
    *                required:
    *                  - pageId
    *                  - pageId
    *        responses:
    *        responses:
@@ -520,7 +524,7 @@ module.exports = (crowi) => {
    *            description: Internal server error.
    *            description: Internal server error.
    */
    */
   router.post('/duplicate', accessTokenParser, loginRequiredStrictly, csrf, validator.duplicatePage, apiV3FormValidator, async(req, res) => {
   router.post('/duplicate', accessTokenParser, loginRequiredStrictly, csrf, validator.duplicatePage, apiV3FormValidator, async(req, res) => {
-    const { pageId, isDuplicateRecursively } = req.body;
+    const { pageId, isRecursively } = req.body;
 
 
     const newPagePath = pathUtils.normalizePath(req.body.pageNameInput);
     const newPagePath = pathUtils.normalizePath(req.body.pageNameInput);
 
 
@@ -541,7 +545,7 @@ module.exports = (crowi) => {
 
 
     let result;
     let result;
 
 
-    if (isDuplicateRecursively) {
+    if (isRecursively) {
       result = await duplicatePageRecursively(page, newPagePath, req.user);
       result = await duplicatePageRecursively(page, newPagePath, req.user);
     }
     }
     else {
     else {