Przeglądaj źródła

add endpoint for update user with creating ImageUrlCache

yusuketk 6 lat temu
rodzic
commit
b027bde46b

+ 1 - 1
src/client/js/services/AppContainer.js

@@ -163,7 +163,7 @@ export default class AppContainer extends Container {
     if (this.willUpdateImageUrlCacheUserIds.length === 0) {
       return;
     }
-    const res = await this.apiv3Post('/user/update.imageUrlCache', { userIds: this.willUpdateImageUrlCacheUserIds });
+    const res = await this.apiv3Put('/users/update.imageUrlCache', { userIds: this.willUpdateImageUrlCacheUserIds });
     console.log(res);
     this.willUpdateImageUrlCacheUserIds = [];
   }

+ 37 - 0
src/server/routes/apiv3/users.js

@@ -544,5 +544,42 @@ module.exports = (crowi) => {
       return res.apiv3Err(new ErrorV3(msg + err.message, 'extenral-account-delete-failed'));
     }
   });
+
+  /**
+   * @swagger
+   *
+   *  paths:
+   *    /users/update.imageUrlCache:
+   *      put:
+   *        tags: [Users]
+   *        operationId: update.imageUrlCache
+   *        summary: /users/update.imageUrlCache
+   *        description: update imageUrlCache
+   *        parameters:
+   *          - userIds: user id list
+   *        responses:
+   *          200:
+   *            description: success creating imageUrlCached
+   *            content:
+   *              application/json:
+   *                schema:
+   *                  properties:
+   *                    userData:
+   *                      type: object
+   *                      description: users updated with imageUrlCached
+   */
+  router.put('/update.imageUrlCache', loginRequiredStrictly, adminRequired, csrf, async(req, res) => {
+    try {
+      const userIds = req.body.userIds;
+      // [TODO] update cache
+      const updatedUsers = await User.find({ _id: { $in: userIds } });
+      return res.apiv3({ updatedUsers });
+    }
+    catch (err) {
+      logger.error('Error', err);
+      return res.apiv3Err(new ErrorV3(err));
+    }
+  });
+
   return router;
 };