blob: 317271a448ea42703b5f290b0c6ab52b15662ac9 (
plain)
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
|
import {
RouteDetailsSchema,
RouteSchema,
type Route,
type RouteDetails,
} from "./schema";
export const fetchRoutes = async (feeds: string[] = []): Promise<Route[]> => {
const params = new URLSearchParams();
feeds.forEach((f) => params.append("feeds", f));
const resp = await fetch(`/api/transit/routes?${params.toString()}`, {
headers: {
Accept: "application/json",
},
});
if (!resp.ok) {
throw new Error(`HTTP ${resp.status}: ${resp.statusText}`);
}
const data = await resp.json();
return RouteSchema.array().parse(data);
};
export const fetchRouteDetails = async (id: string): Promise<RouteDetails> => {
const resp = await fetch(`/api/transit/routes/${encodeURIComponent(id)}`, {
headers: {
Accept: "application/json",
},
});
if (!resp.ok) {
throw new Error(`HTTP ${resp.status}: ${resp.statusText}`);
}
const data = await resp.json();
return RouteDetailsSchema.parse(data);
};
|