feat(expenses): add monthly totals and pagination support for expenses
This commit is contained in:
@@ -158,9 +158,41 @@ export function generateMonthlyExpense(id: number): Promise<Expense> {
|
||||
return mutator<Expense>(`/api/periodic-expenses/${id}/generate-month`, "POST");
|
||||
}
|
||||
|
||||
export function getExpenses(status?: string): Promise<Expense[]> {
|
||||
const params = status ? `?status=${status}` : "";
|
||||
return fetcher<Expense[]>(`/api/expenses${params}`);
|
||||
export type MonthlyExpensesTotal = { total: number };
|
||||
|
||||
export function getMonthlyPayedTotal(year?: number, month?: number): Promise<MonthlyExpensesTotal> {
|
||||
const params = new URLSearchParams();
|
||||
if (year) params.set("year", String(year));
|
||||
if (month) params.set("month", String(month));
|
||||
return fetcher<MonthlyExpensesTotal>(`/api/expenses/monthly-total?${params}`);
|
||||
}
|
||||
|
||||
export type PaginatedResponse<T> = {
|
||||
data: T[];
|
||||
total: number;
|
||||
page: number;
|
||||
pageSize: number;
|
||||
};
|
||||
|
||||
export type MonthlyTotals = {
|
||||
payed: number;
|
||||
pending: number;
|
||||
};
|
||||
|
||||
export function getExpenses(status?: string, page?: number, pageSize?: number): Promise<PaginatedResponse<Expense>> {
|
||||
const params = new URLSearchParams();
|
||||
if (status) params.set("status", status);
|
||||
if (page) params.set("page", String(page));
|
||||
if (pageSize) params.set("pageSize", String(pageSize));
|
||||
const qs = params.toString();
|
||||
return fetcher<PaginatedResponse<Expense>>(`/api/expenses${qs ? `?${qs}` : ""}`);
|
||||
}
|
||||
|
||||
export function getMonthlyTotals(year?: number, month?: number): Promise<MonthlyTotals> {
|
||||
const params = new URLSearchParams();
|
||||
if (year) params.set("year", String(year));
|
||||
if (month) params.set("month", String(month));
|
||||
return fetcher<MonthlyTotals>(`/api/expenses/totals?${params}`);
|
||||
}
|
||||
|
||||
export function createNonPeriodicExpense(data: CreateNonPeriodicExpenseInput): Promise<Expense> {
|
||||
|
||||
Reference in New Issue
Block a user