Last active
August 29, 2018 02:43
-
-
Save VitorLuizC/3893c05cfc3b052e71baab93f1123332 to your computer and use it in GitHub Desktop.
Módulo que controla a pesquisa de usuários.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import request from './request'; | |
| import SearchUsers from './SearchUsers.graphql'; | |
| import GetSearchUsersTypes from './GetSearchUsersTypes.graphql'; | |
| /** | |
| * Obtém os tipos de pesquisa a partir do enum "SearchUserTypes". | |
| * @returns {Promise.<{ value: string, label: string }[]>} | |
| */ | |
| export const getTypes = async () => { | |
| const response = await request(GetSearchUsersTypes); | |
| const types = response.enum.values; | |
| return types; | |
| }; | |
| /** | |
| * Pesquisa usuários com o termo pesquisado e o tipo da pesquisa. | |
| * @param {{ term: string, type: string }} params | |
| * @returns {Promise.<{ id: string, name: string, email: string, position: string }[]>} | |
| */ | |
| export default async ({ term, type } = {}) => { | |
| if (!term || !type) | |
| throw new Error('Can\'t search without term and type.'); | |
| const response = await request(SearchUsers, { term, type }); | |
| const users = response.users || []; | |
| return users; | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment