Skip to content

Instantly share code, notes, and snippets.

@VitorLuizC
Last active August 29, 2018 02:43
Show Gist options
  • Select an option

  • Save VitorLuizC/3893c05cfc3b052e71baab93f1123332 to your computer and use it in GitHub Desktop.

Select an option

Save VitorLuizC/3893c05cfc3b052e71baab93f1123332 to your computer and use it in GitHub Desktop.
Módulo que controla a pesquisa de usuários.
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