2018-09-28 15:53:07 -07:00
|
|
|
import { getJSON } from 'wherehows-web/utils/api/fetcher';
|
|
|
|
|
import { getApiRoot } from 'wherehows-web/utils/api/shared';
|
|
|
|
|
import buildUrl from 'wherehows-web/utils/build-url';
|
|
|
|
|
import { ISuggestionsApi, ISuggestionsResponse } from 'wherehows-web/typings/app/search/suggestions';
|
|
|
|
|
|
|
|
|
|
/**
|
2018-10-02 14:18:32 -07:00
|
|
|
* Build suggestions url
|
|
|
|
|
* @param {ISuggestionApi} params api contract
|
|
|
|
|
* @return {string} return a url with get paramenters attached
|
2018-09-28 15:53:07 -07:00
|
|
|
*/
|
|
|
|
|
export const suggestionsUrl = (params: ISuggestionsApi): string => {
|
|
|
|
|
return buildUrl(`${getApiRoot()}/autocomplete/datasets`, params);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
2018-10-02 14:18:32 -07:00
|
|
|
* Fetch suggestions from API
|
|
|
|
|
* @param {ISuggestionApi} params api contract
|
|
|
|
|
* @return {Promise<ISuggestionsResponse>} returns a promise of the suggestions api response
|
2018-09-28 15:53:07 -07:00
|
|
|
*/
|
2018-10-02 14:18:32 -07:00
|
|
|
export const readSuggestions = (params: ISuggestionsApi): Promise<ISuggestionsResponse> =>
|
2018-09-28 15:53:07 -07:00
|
|
|
getJSON<ISuggestionsResponse>({ url: suggestionsUrl(params) });
|