pass options in search endpoint

This commit is contained in:
2021-05-10 14:02:25 +02:00
parent 36326a2a70
commit 143f8f43fa
2 changed files with 21 additions and 10 deletions

View File

@@ -1,12 +1,23 @@
/*
* Build query string with query and options
*/
const parametersToString = ({ query, options }) => {
let types ='';
options.type.forEach(function(type) {
types += '&type[]=' + type;
});
return 'q=' + query + types + '&uniq=' + options.uniq;
};
/*
* Endpoint chill_person_search
* method GET, get a list of persons
*
* @query string - the query to search for
*/
let searchPersons = ({ query, options }) => {
console.log('options', options);
let url = `/fr/search.json?name=person_regular&q=${query}`;
const searchPersons = ({ query, options }) => {
let queryStr = parametersToString({ query, options });
let url = `/fr/search.json?name=person_regular&${queryStr}`;
return fetch(url)
.then(response => {
if (response.ok) { return response.json(); }
@@ -21,9 +32,9 @@ let searchPersons = ({ query, options }) => {
* NOTE: this is a temporary WIP endpoint, return inconsistent random results
* @query string - the query to search for
*/
let searchPersons_2 = ({ query, options }) => {
console.log('options', options);
let url = `/api/1.0/search.json?q=${query}`
const searchPersons_2 = ({ query, options }) => {
let queryStr = parametersToString({ query, options });
let url = `/api/1.0/search.json?${queryStr}`;
return fetch(url)
.then(response => {
if (response.ok) { return response.json(); }