feat: improve handling of stays
This commit is contained in:
committed by
Michael Zetterberg
parent
e733ce283a
commit
f46207a308
@@ -7,7 +7,7 @@ import type {
|
||||
RequestOptionsWithJSONBody,
|
||||
RequestOptionsWithOutBody,
|
||||
} from "@/types/fetch"
|
||||
import type { Endpoint, endpoints } from "./endpoints"
|
||||
import type { Endpoint } from "./endpoints"
|
||||
|
||||
export { endpoints } from "./endpoints"
|
||||
|
||||
@@ -26,13 +26,13 @@ const fetch = fetchRetry(global.fetch, {
|
||||
return Math.pow(2, attempt) * 150 // 150, 300, 600
|
||||
},
|
||||
})
|
||||
const url = new URL(env.API_BASEURL)
|
||||
|
||||
export async function get(
|
||||
endpoint: Endpoint | `${Endpoint}/${string}`,
|
||||
options: RequestOptionsWithOutBody,
|
||||
params = {}
|
||||
) {
|
||||
const url = new URL(env.API_BASEURL)
|
||||
url.pathname = endpoint
|
||||
const searchParams = new URLSearchParams(params)
|
||||
if (searchParams.size) {
|
||||
@@ -50,6 +50,7 @@ export async function patch(
|
||||
params = {}
|
||||
) {
|
||||
const { body, ...requestOptions } = options
|
||||
const url = new URL(env.API_BASEURL)
|
||||
url.pathname = endpoint
|
||||
const searchParams = new URLSearchParams(params)
|
||||
if (searchParams.size) {
|
||||
@@ -71,9 +72,10 @@ export async function patch(
|
||||
export async function post(
|
||||
endpoint: Endpoint | `${Endpoint}/${string}`,
|
||||
options: RequestOptionsWithJSONBody,
|
||||
params = {},
|
||||
params = {}
|
||||
) {
|
||||
const { body, ...requestOptions } = options
|
||||
const url = new URL(env.API_BASEURL)
|
||||
url.pathname = endpoint
|
||||
const searchParams = new URLSearchParams(params)
|
||||
if (searchParams.size) {
|
||||
@@ -95,8 +97,9 @@ export async function post(
|
||||
export async function remove(
|
||||
endpoint: Endpoint | `${Endpoint}/${string}`,
|
||||
options: RequestOptionsWithOutBody,
|
||||
params = {},
|
||||
params = {}
|
||||
) {
|
||||
const url = new URL(env.API_BASEURL)
|
||||
url.pathname = endpoint
|
||||
const searchParams = new URLSearchParams(params)
|
||||
if (searchParams.size) {
|
||||
|
||||
Reference in New Issue
Block a user