export type GetApiFinanceAccountsArgs = {payment_method?: ('cash' | 'cashless' | 'credit_card') | undefined, branch_id?: number | undefined, sort?: ('id' | '-id' | 'title' | '-title') | undefined}; export type GetApiFinanceAccountsOptions = {baseUrl?: string | undefined, apiKey?: string | undefined, fetch?: typeof fetch | undefined}; /** * Get Finance Accounts * * GET /finance/accounts */ export const getApiFinanceAccounts = async (args: GetApiFinanceAccountsArgs, options?: GetApiFinanceAccountsOptions) => { const {baseUrl = "https://api.roapp.io/v2", fetch: fetchFn = fetch, apiKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() if (args.payment_method != null) query.append("payment_method", String(args.payment_method)) if (args.branch_id != null) query.append("branch_id", String(args.branch_id)) if (args.sort != null) query.append("sort", String(args.sort)) if (apiKey !== undefined) headers.set('authorization', `Bearer ${apiKey}`) const url = `${baseUrl.replace(/\/+$/, '')}/finance/accounts${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 };