add searchEvents utils function to call the events/search route
This commit is contained in:
1 parent
f63eb6ce2f
commit
adcd0933d2
1 file changed
+22
@@ -0,0 +1,22 @@
|
|||||||
|
export default async function searchEvents(query) {
|
||||||
|
try {
|
||||||
|
const encodedQuery = encodeURIComponent(query);
|
||||||
|
const response = await fetch(
|
||||||
|
`http://localhost:80/api/events/search?query=${encodedQuery}`,
|
||||||
|
{
|
||||||
|
method: 'GET',
|
||||||
|
credentials: 'include',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
'Accept': 'application/json'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
const data = await response.json();
|
||||||
|
return data.hits.map(hit => hit.document);
|
||||||
|
|
||||||
|
} catch (err) {
|
||||||
|
console.error("Erreur :", err);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in new issue
Block a user