export type GetApiSalesSessionsArgs = {user_id: string, closed_at: string}; export type GetApiSalesSessionsOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; /** * Get list of sales sessions closed during the day * * GET /sales_sessions */ export const getApiSalesSessions = async (args: GetApiSalesSessionsArgs, options?: GetApiSalesSessionsOptions) => { const {baseUrl = "http://api.gostarmartbus.com/api", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() if (args.user_id != null) query.append("user_id", String(args.user_id)) if (args.closed_at != null) query.append("closed_at", String(args.closed_at)) const url = `${baseUrl.replace(/\/+$/, '')}/sales_sessions${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 };