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

Merge pull request #1052 from weseek/imprv/reactify-admin-brushup

Imprv/reactify admin brushup
Shin Oka 6 лет назад
Родитель
Сommit
af429192c2
2 измененных файлов с 148 добавлено и 0 удалено
  1. 25 0
      src/server/routes/apiv3/user-group-relation.js
  2. 123 0
      src/server/routes/apiv3/user-group.js

+ 25 - 0
src/server/routes/apiv3/user-group-relation.js

@@ -11,10 +11,35 @@ const {
   adminRequired,
   adminRequired,
 } = require('../../util/middlewares');
 } = require('../../util/middlewares');
 
 
+/**
+ * @swagger
+ *  tags:
+ *    name: UserGroupRelation
+ */
 
 
 module.exports = (crowi) => {
 module.exports = (crowi) => {
   const { ErrorV3, UserGroup, UserGroupRelation } = crowi.models;
   const { ErrorV3, UserGroup, UserGroupRelation } = crowi.models;
 
 
+  /**
+   * @swagger
+   *  paths:
+   *    /_api/v3/user-group-relations:
+   *      get:
+   *        tags: [UserGroupRelation]
+   *        description: Gets the user group relations
+   *        produces:
+   *          - application/json
+   *        responses:
+   *          200:
+   *            description: user group relations are fetched
+   *            content:
+   *              application/json:
+   *                schema:
+   *                  properties:
+   *                    userGroupRelations:
+   *                      type: object
+   *                      description: contains arrays user objects related
+   */
   router.get('/', loginRequired(crowi), adminRequired(), async(req, res) => {
   router.get('/', loginRequired(crowi), adminRequired(), async(req, res) => {
     // TODO: filter with querystring? or body
     // TODO: filter with querystring? or body
     try {
     try {

+ 123 - 0
src/server/routes/apiv3/user-group.js

@@ -16,10 +16,37 @@ const {
 
 
 const validator = {};
 const validator = {};
 
 
+/**
+ * @swagger
+ *  tags:
+ *    name: UserGroup
+ */
+
 module.exports = (crowi) => {
 module.exports = (crowi) => {
   const { ErrorV3, UserGroup, UserGroupRelation } = crowi.models;
   const { ErrorV3, UserGroup, UserGroupRelation } = crowi.models;
   const { ApiV3FormValidator } = crowi.middlewares;
   const { ApiV3FormValidator } = crowi.middlewares;
 
 
+  /**
+   * @swagger
+   *
+   *  paths:
+   *    /_api/v3/user-groups:
+   *      get:
+   *        tags: [UserGroup]
+   *        description: Gets usergroups
+   *        produces:
+   *          - application/json
+   *        responses:
+   *          200:
+   *            description: usergroups are fetched
+   *            content:
+   *              application/json:
+   *                schema:
+   *                  properties:
+   *                    userGroups:
+   *                      type: object
+   *                      description: a result of `UserGroup.find`
+   */
   router.get('/', loginRequired(crowi), adminRequired(), async(req, res) => {
   router.get('/', loginRequired(crowi), adminRequired(), async(req, res) => {
     // TODO: filter with querystring
     // TODO: filter with querystring
     try {
     try {
@@ -37,6 +64,36 @@ module.exports = (crowi) => {
     body('name', 'Group name is required').trim().exists(),
     body('name', 'Group name is required').trim().exists(),
   ];
   ];
 
 
+  /**
+   * @swagger
+   *
+   *  paths:
+   *    /_api/v3/user-groups:
+   *      post:
+   *        tags: [UserGroup]
+   *        description: Adds userGroup
+   *        produces:
+   *          - application/json
+   *        requestBody:
+   *          required: true
+   *          content:
+   *            application/json:
+   *              schema:
+   *                properties:
+   *                  name:
+   *                    type: string
+   *                    description: name of the userGroup trying to be added
+   *        responses:
+   *          200:
+   *            description: userGroup is added
+   *            content:
+   *              application/json:
+   *                schema:
+   *                  properties:
+   *                    userGroup:
+   *                      type: object
+   *                      description: A result of `UserGroup.createGroupByName`
+   */
   router.post('/', loginRequired(crowi), adminRequired(), csrfVerify(crowi), validator.create, ApiV3FormValidator, async(req, res) => {
   router.post('/', loginRequired(crowi), adminRequired(), csrfVerify(crowi), validator.create, ApiV3FormValidator, async(req, res) => {
     const { name } = req.body;
     const { name } = req.body;
 
 
@@ -59,6 +116,43 @@ module.exports = (crowi) => {
     query('transferToUserGroupId').trim(),
     query('transferToUserGroupId').trim(),
   ];
   ];
 
 
+  /**
+   * @swagger
+   *
+   *  paths:
+   *    /_api/v3/user-groups/{:id}:
+   *      delete:
+   *        tags: [UserGroup]
+   *        description: Deletes userGroup
+   *        produces:
+   *          - application/json
+   *        parameters:
+   *          - name: deleteGroupId
+   *            in: path
+   *            description: id of userGroup
+   *            schema:
+   *              type: ObjectId
+   *          - name: actionName
+   *            in: query
+   *            description: name of action
+   *            schema:
+   *              type: string
+   *          - name: transferToUserGroupId
+   *            in: query
+   *            description: userGroup id that will be transferred to
+   *            schema:
+   *              type: ObjectId
+   *        responses:
+   *          200:
+   *            description: userGroup is removed
+   *            content:
+   *              application/json:
+   *                schema:
+   *                  properties:
+   *                    userGroups:
+   *                      type: object
+   *                      description: A result of `UserGroup.removeCompletelyById`
+   */
   router.delete('/:id', loginRequired(crowi), adminRequired(), csrfVerify(crowi), validator.delete, ApiV3FormValidator, async(req, res) => {
   router.delete('/:id', loginRequired(crowi), adminRequired(), csrfVerify(crowi), validator.delete, ApiV3FormValidator, async(req, res) => {
     const { id: deleteGroupId } = req.params;
     const { id: deleteGroupId } = req.params;
     const { actionName, transferToUserGroupId } = req.query;
     const { actionName, transferToUserGroupId } = req.query;
@@ -83,6 +177,35 @@ module.exports = (crowi) => {
   // router.put('/:id/update', async(req, res) => {
   // router.put('/:id/update', async(req, res) => {
   // });
   // });
 
 
+  /**
+   * @swagger
+   *
+   *  paths:
+   *    /_api/v3/user-groups/{:id/users}:
+   *      get:
+   *        tags: [UserGroup]
+   *        description: Gets the users related to the userGroup
+   *        produces:
+   *          - application/json
+   *        parameters:
+   *          - name: id
+   *            in: path
+   *            description: id of userGroup
+   *            schema:
+   *              type: ObjectId
+   *        responses:
+   *          200:
+   *            description: users are fetched
+   *            content:
+   *              application/json:
+   *                schema:
+   *                  properties:
+   *                    users:
+   *                      type: array
+   *                      items:
+   *                        type: object
+   *                      description: user objects
+   */
   router.get('/:id/users', loginRequired(crowi), adminRequired(), async(req, res) => {
   router.get('/:id/users', loginRequired(crowi), adminRequired(), async(req, res) => {
     const { id } = req.params;
     const { id } = req.params;