export type Expense = {amount?: number | undefined, category?: string | undefined, categoryID?: (string | null) | undefined, date?: string | undefined, description?: string | undefined, documents?: (Array<{digest: string, name: string, path: string, size: number, type?: 'CloudFile' | undefined, uploadDate?: (string | null) | undefined, url?: (string | null) | undefined}>) | undefined, id?: string | undefined, isPaid?: boolean | undefined, originalAmount?: (number | null) | undefined, originalCurrency?: (string | null) | undefined, paymentMethod?: string | undefined, paymentMethodID?: (string | null) | undefined, vatRate?: number | undefined, withholdingTax?: boolean | undefined}; export type CreateApiExpensesCreateArgs = {body: {expense: Expense} | Expense}; export type CreateApiExpensesCreateOptions = {baseUrl: string, ApiKeyHeader?: string | undefined, fetch?: typeof fetch | undefined}; /** * Create an expense * * POST /expenses/create * * Also accepts auth: FirebaseIdToken */ export const createApiExpensesCreate = async (args: CreateApiExpensesCreateArgs, options: CreateApiExpensesCreateOptions) => { const {baseUrl, fetch: fetchFn = fetch, ApiKeyHeader} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (ApiKeyHeader !== undefined) headers.set("X-API-Key", ApiKeyHeader) const url = `${baseUrl.replace(/\/+$/, '')}/expenses/create${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return (await res.json()) as unknown };