export type GetApiTripTemplatesArgs = {'coach[id]'?: number | undefined, 'coach[code]'?: string | undefined, 'coach[seat_profile_id]'?: number | undefined, 'coach[counter_group_id]'?: number | undefined, 'coach[departure_station_id]'?: number | undefined, 'coach[arrival_station_id]'?: number | undefined, list_type?: ('simple' | 'full') | undefined, body: {departure_days?: (Array<'monday' | 'tuesday' | 'wednesday' | 'thursday' | 'friday' | 'saturday' | 'sunday'>) | undefined, departure_time?: Array | undefined}}; export type GetApiTripTemplatesOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; /** * Search trip templates * * GET /trip_templates */ export const getApiTripTemplates = async (args: GetApiTripTemplatesArgs, options?: GetApiTripTemplatesOptions) => { const {baseUrl = "http://api.gostarmartbus.com/api", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/x-www-form-urlencoded") if (args['coach[id]'] != null) query.append("coach[id]", String(args['coach[id]'])) if (args['coach[code]'] != null) query.append("coach[code]", String(args['coach[code]'])) if (args['coach[seat_profile_id]'] != null) query.append("coach[seat_profile_id]", String(args['coach[seat_profile_id]'])) if (args['coach[counter_group_id]'] != null) query.append("coach[counter_group_id]", String(args['coach[counter_group_id]'])) if (args['coach[departure_station_id]'] != null) query.append("coach[departure_station_id]", String(args['coach[departure_station_id]'])) if (args['coach[arrival_station_id]'] != null) query.append("coach[arrival_station_id]", String(args['coach[arrival_station_id]'])) if (args.list_type != null) query.append("list_type", String(args.list_type)) const url = `${baseUrl.replace(/\/+$/, '')}/trip_templates${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers, body: new URLSearchParams(Object.entries(args.body).flatMap(([key, value]) => (value == null ? [] : [[key, String(value)]])))}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return undefined };