itizawa 6 лет назад
Родитель
Сommit
02cbeb84c1
2 измененных файлов с 51 добавлено и 0 удалено
  1. 36 0
      src/client/js/components/Admin/Users/Users.jsx
  2. 15 0
      src/server/routes/apiv3/users.js

+ 36 - 0
src/client/js/components/Admin/Users/Users.jsx

@@ -8,6 +8,8 @@ import InviteUserControl from './InviteUserControl';
 import UserTable from './UserTable';
 
 import { createSubscribedElement } from '../../UnstatedUtils';
+import { toastError } from '../../../util/apiNotification';
+
 import AppContainer from '../../../services/AppContainer';
 import AdminUsersContainer from '../../../services/AdminUsersContainer';
 
@@ -21,6 +23,40 @@ class UserPage extends React.Component {
       pagingLimit: Infinity,
     };
 
+    this.handlePage = this.handlePage.bind(this);
+  }
+
+  async handlePage(selectedPage) {
+    await this.setState({ activePage: selectedPage });
+    await this.syncUserGroupAndRelations();
+  }
+
+  async syncUserGroupAndRelations() {
+    // let userGroups = [];
+    // let userGroupRelations = {};
+    // let totalUserGroups = 0;
+    // let pagingLimit = Infinity;
+
+    try {
+      const params = { page: this.state.activePage };
+      const response = await this.props.appContainer.apiv3.get('/users', params);
+
+      // const [userGroupsRes, userGroupRelationsRes] = responses;
+      // userGroups = userGroupsRes.data.userGroups;
+      // totalUserGroups = userGroupsRes.data.totalUserGroups;
+      // pagingLimit = userGroupsRes.data.pagingLimit;
+      // userGroupRelations = userGroupRelationsRes.data.userGroupRelations;
+
+      // this.setState({
+      //   userGroups,
+      //   userGroupRelations,
+      //   totalUserGroups,
+      //   pagingLimit,
+      // });
+    }
+    catch (err) {
+      toastError(err);
+    }
   }
 
   render() {

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

@@ -32,6 +32,21 @@ module.exports = (crowi) => {
 
   const { ApiV3FormValidator } = crowi.middlewares;
 
+  // TODO writte swagger
+  router.get('/', loginRequiredStrictly, adminRequired, async(req, res) => {
+    try {
+      const page = parseInt(req.query.page) || 1;
+      const result = await User.findUserGroupsWithPagination({ page });
+      const { docs: userGroups, total: totalUserGroups, limit: pagingLimit } = result;
+      return res.apiv3({ userGroups, totalUserGroups, pagingLimit });
+    }
+    catch (err) {
+      const msg = 'Error occurred in fetching user group list';
+      logger.error('Error', err);
+      return res.apiv3Err(new ErrorV3(msg, 'user-group-list-fetch-failed'));
+    }
+  });
+
   validator.inviteEmail = [
     // isEmail prevents line breaks, so use isString
     body('shapedEmailList').custom((value) => {