itizawa 6 лет назад
Родитель
Сommit
d6d72777cc

+ 6 - 2
src/client/js/components/Admin/UserGroupDetail/UserGroupUserFormByInput.jsx

@@ -65,8 +65,12 @@ class UserGroupUserFormByInput extends React.Component {
   }
 
   searhApplicableUsers() {
-    this.props.userGroupDetailContainer.searhApplicableUsers();
-
+    try {
+      this.props.userGroupDetailContainer.fetchApplicableUsers(this.state.input);
+    }
+    catch (err) {
+      toastError(err);
+    }
   }
 
   /**

+ 11 - 2
src/client/js/services/UserGroupDetailContainer.js

@@ -105,8 +105,17 @@ export default class UserGroupDetailContainer extends Container {
    * search user for invitation
    * @param {string} username username of the user to be searched
    */
-  async fetchApplicableUsers() {
-    console.log('ここはサーチ');
+  async fetchApplicableUsers(searchWord) {
+    const res = await this.appContainer.apiv3.get(`/user-groups/${this.state.userGroup._id}/unrelated-users`, {
+      searchWord,
+      // TODO switch value
+      isForwardMatch: false,
+      isAlsoNameSearched: false,
+      isAlsoMailSearched: false,
+    });
+
+    const { users } = res.data;
+    return users;
   }
 
 

+ 14 - 0
src/server/models/user-group-relation.js

@@ -209,6 +209,20 @@ class UserGroupRelation {
       });
   }
 
+  /**
+   * find all "not" related user for UserGroup
+   *
+   * @static
+   * @param {UserGroup} userGroup for find users not related
+   * @returns {Promise<User>}
+   * @memberof UserGroupRelation
+   */
+  static queryUserByNotRelatedGroup(userGroup, query) {
+
+    console.log('relation');
+
+  }
+
   /**
    * get if the user has relation for group
    *

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

@@ -318,12 +318,14 @@ module.exports = (crowi) => {
    *                        type: object
    *                      description: user objects
    */
+  // TODO rewrite swagger
   router.get('/:id/unrelated-users', loginRequiredStrictly, adminRequired, async(req, res) => {
     const { id } = req.params;
+    const { searchWord } = req.query;
 
     try {
       const userGroup = await UserGroup.findById(id);
-      const users = await UserGroupRelation.findUserByNotRelatedGroup(userGroup);
+      const users = await UserGroupRelation.findUserByNotRelatedGroup(userGroup, searchWord);
 
       return res.apiv3({ users });
     }