itizawa 5 лет назад
Родитель
Сommit
5b19b6f9df

+ 2 - 2
src/server/routes/apiv3/notification-setting.js

@@ -229,7 +229,7 @@ module.exports = (crowi) => {
         createdUser: await UpdatePost.create(pathPattern, channel, req.user),
         userNotifications: await UpdatePost.findAll(),
       };
-      return res.apiv3({ responseParams });
+      return res.apiv3({ responseParams }, 201);
     }
     catch (err) {
       const msg = 'Error occurred in updating user notification';
@@ -326,7 +326,7 @@ module.exports = (crowi) => {
 
     try {
       const createdNotification = await notification.save();
-      return res.apiv3({ createdNotification });
+      return res.apiv3({ createdNotification }, 200);
     }
     catch (err) {
       const msg = 'Error occurred in updating global notification';

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

@@ -157,7 +157,7 @@ module.exports = (crowi) => {
    *                  - body
    *                  - path
    *        responses:
-   *          200:
+   *          201:
    *            description: Succeeded to create page.
    *            content:
    *              application/json:
@@ -229,7 +229,7 @@ module.exports = (crowi) => {
       }
     }
 
-    return res.apiv3(result);
+    return res.apiv3(result, 201);
   });
 
   /**

+ 2 - 2
src/server/routes/apiv3/response.js

@@ -4,13 +4,13 @@ const ErrorV3 = require('../../models/vo/error-apiv3');
 
 const addCustomFunctionToResponse = (express, crowi) => {
 
-  express.response.apiv3 = function(obj = {}) { // not arrow function
+  express.response.apiv3 = function(obj = {}, status = 200) { // not arrow function
     // obj must be object
     if (typeof obj !== 'object' || obj instanceof Array) {
       throw new Error('invalid value supplied to res.apiv3');
     }
 
-    this.json({ data: obj });
+    this.status(status).json({ data: obj });
   };
 
   express.response.apiv3Err = function(_err, status = 400, info) { // not arrow function

+ 1 - 1
src/server/routes/apiv3/share-links.js

@@ -107,7 +107,7 @@ module.exports = (crowi) => {
 
     try {
       const postedShareLink = await ShareLink.create({ relatedPage, expiredAt, description });
-      return res.apiv3(postedShareLink);
+      return res.apiv3(postedShareLink, 201);
     }
     catch (err) {
       const msg = 'Error occured in post share link';

+ 1 - 1
src/server/routes/apiv3/user-group.js

@@ -116,7 +116,7 @@ module.exports = (crowi) => {
       const userGroupName = crowi.xss.process(name);
       const userGroup = await UserGroup.createGroupByName(userGroupName);
 
-      return res.apiv3({ userGroup });
+      return res.apiv3({ userGroup }, 201);
     }
     catch (err) {
       const msg = 'Error occurred in creating a user group';

+ 1 - 1
src/server/routes/apiv3/users.js

@@ -244,7 +244,7 @@ module.exports = (crowi) => {
   router.post('/invite', loginRequiredStrictly, adminRequired, csrf, validator.inviteEmail, apiV3FormValidator, async(req, res) => {
     try {
       const invitedUserList = await User.createUsersByInvitation(req.body.shapedEmailList, req.body.sendEmail);
-      return res.apiv3({ invitedUserList });
+      return res.apiv3({ invitedUserList }, 201);
     }
     catch (err) {
       logger.error('Error', err);