feat(SW-1012): Added possibility for multiple include params for hotels

This commit is contained in:
Erik Tiekstra
2024-11-26 11:07:47 +01:00
committed by Fredrik Thorsson
parent 92bbfcf533
commit 05006506f0
17 changed files with 218 additions and 57 deletions

View File

@@ -30,11 +30,20 @@ const wrappedFetch = fetchRetry(fetch, {
export async function get(
endpoint: Endpoint,
options: RequestOptionsWithOutBody,
params = {}
params: Record<string, any> = {}
) {
const url = new URL(env.API_BASEURL)
url.pathname = endpoint
url.search = new URLSearchParams(params).toString()
const searchParams = new URLSearchParams()
Object.entries(params).forEach(([key, value]) => {
if (Array.isArray(value)) {
value.forEach((val) => searchParams.append(key, val))
} else {
searchParams.set(key, value)
}
})
url.search = searchParams.toString()
return wrappedFetch(
url,
merge.all([defaultOptions, { method: "GET" }, options])