export type GetApiCtsRoutesArgs = {name?: string | undefined, coach_id?: number | undefined, departure_counter_ids?: string | undefined, arrival_counter_ids?: string | undefined}; export type GetApiCtsRoutesOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; /** * Search CTS routes * * GET /cts/routes */ export const getApiCtsRoutes = async (args: GetApiCtsRoutesArgs, options?: GetApiCtsRoutesOptions) => { const {baseUrl = "http://api.gostarmartbus.com/api", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() if (args.name != null) query.append("name", String(args.name)) if (args.coach_id != null) query.append("coach_id", String(args.coach_id)) if (args.departure_counter_ids != null) query.append("departure_counter_ids", String(args.departure_counter_ids)) if (args.arrival_counter_ids != null) query.append("arrival_counter_ids", String(args.arrival_counter_ids)) const url = `${baseUrl.replace(/\/+$/, '')}/cts/routes${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 };