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.ts30
1 files changed, 30 insertions, 0 deletions
diff --git a/src/frontend/app/api/arrivals.ts b/src/frontend/app/api/arrivals.ts
index 8ae6e78..ad99630 100644
--- a/src/frontend/app/api/arrivals.ts
+++ b/src/frontend/app/api/arrivals.ts
@@ -1,6 +1,8 @@
import {
StopArrivalsResponseSchema,
+ StopEstimatesResponseSchema,
type StopArrivalsResponse,
+ type StopEstimatesResponse,
} from "./schema";
export const fetchArrivals = async (
@@ -29,3 +31,31 @@ export const fetchArrivals = async (
throw e;
}
};
+
+export const fetchEstimates = async (
+ stopId: string,
+ routeId: string,
+ viaStopId?: string
+): Promise<StopEstimatesResponse> => {
+ let url = `/api/stops/estimates?stop=${encodeURIComponent(stopId)}&route=${encodeURIComponent(routeId)}`;
+ if (viaStopId) {
+ url += `&via=${encodeURIComponent(viaStopId)}`;
+ }
+
+ const resp = await fetch(url, {
+ headers: { Accept: "application/json" },
+ });
+
+ if (!resp.ok) {
+ throw new Error(`HTTP ${resp.status}: ${resp.statusText}`);
+ }
+
+ const data = await resp.json();
+ try {
+ return StopEstimatesResponseSchema.parse(data);
+ } catch (e) {
+ console.error("Zod parsing failed for estimates:", e);
+ console.log("Received data:", data);
+ throw e;
+ }
+};