aboutsummaryrefslogtreecommitdiff
path: root/src/frontend/app/api/arrivals.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/frontend/app/api/arrivals.ts')
-rw-r--r--src/frontend/app/api/arrivals.ts31
1 files changed, 31 insertions, 0 deletions
diff --git a/src/frontend/app/api/arrivals.ts b/src/frontend/app/api/arrivals.ts
new file mode 100644
index 0000000..8ae6e78
--- /dev/null
+++ b/src/frontend/app/api/arrivals.ts
@@ -0,0 +1,31 @@
+import {
+ StopArrivalsResponseSchema,
+ type StopArrivalsResponse,
+} from "./schema";
+
+export const fetchArrivals = async (
+ stopId: string,
+ reduced: boolean = false
+): Promise<StopArrivalsResponse> => {
+ const resp = await fetch(
+ `/api/stops/arrivals?id=${stopId}&reduced=${reduced}`,
+ {
+ headers: {
+ Accept: "application/json",
+ },
+ }
+ );
+
+ if (!resp.ok) {
+ throw new Error(`HTTP ${resp.status}: ${resp.statusText}`);
+ }
+
+ const data = await resp.json();
+ try {
+ return StopArrivalsResponseSchema.parse(data);
+ } catch (e) {
+ console.error("Zod parsing failed for arrivals:", e);
+ console.log("Received data:", data);
+ throw e;
+ }
+};