Просмотр исходного кода

Improve update content-width route

https://youtrack.weseek.co.jp/issue/GW-7828
- Add pageId as params to content-width update route
- Update implementation of content-width update route
- Remove pageId from contentWidth validation
mudana 3 лет назад
Родитель
Сommit
e4d8a839f1

+ 1 - 1
packages/app/src/client/services/page-operation.ts

@@ -39,7 +39,7 @@ export const toggleBookmark = async(pageId: string, currentValue?: boolean): Pro
 
 export const toggleContentWidth = async(pageId: string, currentValue: boolean): Promise<void> => {
   try {
-    await apiv3Put('/page/content-width', { pageId, isContainerFluid: !currentValue });
+    await apiv3Put(`/page/${pageId}/content-width`, { isContainerFluid: !currentValue });
   }
   catch (err) {
     toastError(err);

+ 13 - 12
packages/app/src/server/routes/apiv3/page.js

@@ -223,7 +223,6 @@ module.exports = (crowi) => {
       query('pageId').isString(),
     ],
     contentWidth: [
-      body('pageId').isString(),
       body('isContainerFluid').isBoolean(),
     ],
   };
@@ -797,18 +796,20 @@ module.exports = (crowi) => {
   });
 
 
-  router.put('/content-width', apiLimiter, accessTokenParser, loginRequiredStrictly, csrf, validator.contentWidth, apiV3FormValidator, async(req, res) => {
-    const { pageId, isContainerFluid } = req.body;
+  router.put('/:pageId/content-width', apiLimiter, accessTokenParser, loginRequiredStrictly, csrf,
+    validator.contentWidth, apiV3FormValidator, async(req, res) => {
+      const { pageId } = req.params;
+      const { isContainerFluid } = req.body;
 
-    try {
-      const page = await Page.updateOne({ _id: pageId }, { $set: { isContainerFluid } });
-      return res.apiv3({ page });
-    }
-    catch (err) {
-      logger.error('update-content-width-failed', err);
-      return res.apiv3Err(err, 500);
-    }
-  });
+      try {
+        const page = await Page.updateOne({ _id: pageId }, { $set: { isContainerFluid } });
+        return res.apiv3({ page });
+      }
+      catch (err) {
+        logger.error('update-content-width-failed', err);
+        return res.apiv3Err(err, 500);
+      }
+    });
 
   return router;
 };