export type GetApiDeparturePlansExportArgs = {departure_date: string, station_id: number, exclude_station_codes?: string | undefined}; export type GetApiDeparturePlansExportOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; /** * Export departure plan to .html, .pdf or .xls * * GET /departure_plans/export */ export const getApiDeparturePlansExport = async (args: GetApiDeparturePlansExportArgs, options?: GetApiDeparturePlansExportOptions) => { const {baseUrl = "http://api.gostarmartbus.com/api", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() if (args.departure_date != null) query.append("departure_date", String(args.departure_date)) if (args.station_id != null) query.append("station_id", String(args.station_id)) if (args.exclude_station_codes != null) query.append("exclude_station_codes", String(args.exclude_station_codes)) const url = `${baseUrl.replace(/\/+$/, '')}/departure_plans/export${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return undefined };