export type GetApiCoachesArgs = {'search[seat_profile_id]'?: number | undefined, 'search[code]'?: string | undefined, 'search[counter_group_id]'?: number | undefined, 'search[departure_station_id]'?: number | undefined, 'search[arrival_station_id]'?: number | undefined, 'search[published]'?: (0 | 1) | undefined, q_select?: Array | undefined}; export type GetApiCoachesOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; /** * List * * GET /coaches */ export const getApiCoaches = async (args: GetApiCoachesArgs, options?: GetApiCoachesOptions) => { const {baseUrl = "http://api.gostarmartbus.com/api", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() if (args['search[seat_profile_id]'] != null) query.append("search[seat_profile_id]", String(args['search[seat_profile_id]'])) if (args['search[code]'] != null) query.append("search[code]", String(args['search[code]'])) if (args['search[counter_group_id]'] != null) query.append("search[counter_group_id]", String(args['search[counter_group_id]'])) if (args['search[departure_station_id]'] != null) query.append("search[departure_station_id]", String(args['search[departure_station_id]'])) if (args['search[arrival_station_id]'] != null) query.append("search[arrival_station_id]", String(args['search[arrival_station_id]'])) if (args['search[published]'] != null) query.append("search[published]", String(args['search[published]'])) for (const item of args.q_select ?? []) query.append("q_select", String(item)) const url = `${baseUrl.replace(/\/+$/, '')}/coaches${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 };