export type GetApiStationsArgs = {q_select?: Array | undefined}; export type GetApiStationsOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; /** * Get all stations. Permission: station_address_maintenance * * GET /stations */ export const getApiStations = async (args: GetApiStationsArgs, options?: GetApiStationsOptions) => { const {baseUrl = "http://api.gostarmartbus.com/api", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() for (const item of args.q_select ?? []) query.append("q_select", String(item)) const url = `${baseUrl.replace(/\/+$/, '')}/stations${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 };