Manuel Bustillo 54be5515e5
Some checks failed
Check usage of free licenses / build-static-assets (pull_request) Successful in 29s
Add copyright notice / copyright_notice (pull_request) Successful in 32s
Playwright Tests / test (pull_request) Failing after 5m1s
Update API routes to target the default tenant
2024-11-30 20:21:19 +01:00

40 lines
1.0 KiB
TypeScript

/* Copyright (C) 2024 Manuel Bustillo*/
import { Expense } from '@/app/lib/definitions';
import { getCsrfToken } from '@/app/lib/utils';
export function loadExpenses(onLoad?: (expenses: Expense[]) => void) {
fetch("/api/default/expenses")
.then((response) => response.json())
.then((data) => {
onLoad && onLoad(data.map((record: any) => {
return ({
id: record.id,
name: record.name,
amount: record.amount,
pricingType: record.pricing_type
});
}));
}, (error) => {
return [];
});
}
export function updateExpense(expense: Expense) {
fetch(`/api/default/expenses/${expense.id}`,
{
method: 'PUT',
body: JSON.stringify({
expense: {
name: expense.name,
amount: expense.amount,
pricing_type: expense.pricingType,
}
}),
headers: {
'Content-Type': 'application/json',
'X-CSRF-TOKEN': getCsrfToken(),
}
})
.catch((error) => console.error(error));
}