llm-router / apps /web /src /api /budgets.ts
ClaraSu's picture
Upload folder using huggingface_hub
e481638 verified
Raw History Blame Contribute Delete
1.27 kB
import { apiFetch } from './client'
import type { Budget, CreateBudget, UpdateBudget } from '@llm-router/shared'
export async function listBudgets(): Promise<Budget[]> {
const res = await apiFetch('/v1/expense/budgets')
if (!res.ok) throw new Error('Failed to load budgets')
return res.json() as Promise<Budget[]>
}
export async function createBudget(data: CreateBudget): Promise<Budget> {
const res = await apiFetch('/v1/expense/budgets', {
method: 'POST',
body: JSON.stringify(data),
})
if (!res.ok) {
const err = await res.json() as { error?: string }
throw new Error(err.error ?? 'Failed to create budget')
}
return res.json() as Promise<Budget>
}
export async function updateBudget(id: string, data: UpdateBudget): Promise<Budget> {
const res = await apiFetch(`/v1/expense/budgets/${id}`, {
method: 'PUT',
body: JSON.stringify(data),
})
if (!res.ok) {
const err = await res.json() as { error?: string }
throw new Error(err.error ?? 'Failed to update budget')
}
return res.json() as Promise<Budget>
}
export async function deleteBudget(id: string): Promise<void> {
const res = await apiFetch(`/v1/expense/budgets/${id}`, { method: 'DELETE' })
if (!res.ok) throw new Error('Failed to delete budget')
}