-
Notifications
You must be signed in to change notification settings - Fork 0
/
api.js
44 lines (40 loc) · 1.04 KB
/
api.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
export async function getVans(id) {
const url = id ? `/api/vans/${id}` : "/api/vans"
const res = await fetch(url)
if (!res.ok) {
throw {
message: "Failed to fetch vans",
statusText: res.statusText,
status: res.status
}
}
const data = await res.json()
return data.vans
}
export async function getHostVans(id) {
const url = id ? `/api/host/vans/${id}` : "/api/host/vans"
const res = await fetch(url)
if (!res.ok) {
throw {
message: "Failed to fetch vans",
statusText: res.statusText,
status: res.status
}
}
const data = await res.json()
return data.vans
}
export async function loginUser(creds) {
const res = await fetch("/api/login",
{ method: "post", body: JSON.stringify(creds) }
)
const data = await res.json()
if (!res.ok) {
throw {
message: data.message,
statusText: res.statusText,
status: res.status
}
}
return data
}