export type GetApiItemsArgs = {name?: string | undefined, organization_id?: number | undefined, price?: string | undefined, filters?: Record | undefined, 'sort[asc]'?: ('unit_name' | 'unit_price') | undefined, 'sort[desc]'?: ('unit_name' | 'unit_price') | undefined, page?: number | undefined, per_page?: number | undefined}; export type GetApiItemsOptions = {baseUrl?: string | undefined, passport?: string | undefined, fetch?: typeof fetch | undefined}; /** * List items * * GET /items */ export const getApiItems = async (args: GetApiItemsArgs, options?: GetApiItemsOptions) => { const {baseUrl = "http://localhost/app4legal/api/v2/money", fetch: fetchFn = fetch, passport} = options ?? {} const query = new URLSearchParams() const headers = new Headers() if (args.name != null) query.append("name", String(args.name)) if (args.organization_id != null) query.append("organization_id", String(args.organization_id)) if (args.price != null) query.append("price", String(args.price)) if (args.filters != null) query.append("filters", JSON.stringify(args.filters)) if (args['sort[asc]'] != null) query.append("sort[asc]", String(args['sort[asc]'])) if (args['sort[desc]'] != null) query.append("sort[desc]", String(args['sort[desc]'])) if (args.page != null) query.append("page", String(args.page)) if (args.per_page != null) query.append("per_page", String(args.per_page)) if (passport !== undefined) headers.set('authorization', `Bearer ${passport}`) const url = `${baseUrl.replace(/\/+$/, '')}/items${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 };