export type GetApiTripsSearchArgs = {'search[start_departure_date]'?: string | undefined, 'search[end_departure_date]'?: string | undefined, 'search[is_cts]'?: boolean | undefined, 'search[coach][id]'?: number | undefined, 'search[coach][seat_profile_id]'?: number | undefined, 'search[coach][code]'?: string | undefined, 'search[coach][counter_group_id]'?: number | undefined, 'search[coach][departure_station_id]'?: number | undefined, 'search[coach][arrival_station_id]'?: number | undefined, 'pagination[limit]'?: number | undefined, 'pagination[page]'?: number | undefined, body: {'search[departure_days]'?: (Array<'monday' | 'tuesday' | 'wednesday' | 'thursday' | 'friday' | 'saturday' | 'sunday'>) | undefined, 'search[departure_time]'?: Array | undefined}}; export type GetApiTripsSearchOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; /** * Search trips. (Permission: trip_maintenance) * * GET /trips/search */ export const getApiTripsSearch = async (args: GetApiTripsSearchArgs, options?: GetApiTripsSearchOptions) => { 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['search[start_departure_date]'] != null) query.append("search[start_departure_date]", String(args['search[start_departure_date]'])) if (args['search[end_departure_date]'] != null) query.append("search[end_departure_date]", String(args['search[end_departure_date]'])) if (args['search[is_cts]'] != null) query.append("search[is_cts]", String(args['search[is_cts]'])) if (args['search[coach][id]'] != null) query.append("search[coach][id]", String(args['search[coach][id]'])) if (args['search[coach][seat_profile_id]'] != null) query.append("search[coach][seat_profile_id]", String(args['search[coach][seat_profile_id]'])) if (args['search[coach][code]'] != null) query.append("search[coach][code]", String(args['search[coach][code]'])) if (args['search[coach][counter_group_id]'] != null) query.append("search[coach][counter_group_id]", String(args['search[coach][counter_group_id]'])) if (args['search[coach][departure_station_id]'] != null) query.append("search[coach][departure_station_id]", String(args['search[coach][departure_station_id]'])) if (args['search[coach][arrival_station_id]'] != null) query.append("search[coach][arrival_station_id]", String(args['search[coach][arrival_station_id]'])) if (args['pagination[limit]'] != null) query.append("pagination[limit]", String(args['pagination[limit]'])) if (args['pagination[page]'] != null) query.append("pagination[page]", String(args['pagination[page]'])) const url = `${baseUrl.replace(/\/+$/, '')}/trips/search${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 };