mirror of
https://github.com/Memo-2023/mana-monorepo.git
synced 2026-05-17 18:29:39 +02:00
- Move finance, mail, moodlit to apps-archived for later development - Rename games/voxel-lava to games/voxelava 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
49 lines
1.4 KiB
TypeScript
49 lines
1.4 KiB
TypeScript
import { apiClient } from './client';
|
|
import type {
|
|
Transaction,
|
|
CreateTransactionInput,
|
|
UpdateTransactionInput,
|
|
TransactionFilters,
|
|
} from '@finance/shared';
|
|
|
|
interface PaginatedTransactions {
|
|
data: Transaction[];
|
|
total: number;
|
|
limit: number;
|
|
offset: number;
|
|
}
|
|
|
|
export const transactionsApi = {
|
|
getAll: (filters?: TransactionFilters) => {
|
|
const params = new URLSearchParams();
|
|
if (filters) {
|
|
Object.entries(filters).forEach(([key, value]) => {
|
|
if (value !== undefined && value !== null && value !== '') {
|
|
params.append(key, String(value));
|
|
}
|
|
});
|
|
}
|
|
const query = params.toString();
|
|
return apiClient.get<PaginatedTransactions>(`/transactions${query ? `?${query}` : ''}`);
|
|
},
|
|
|
|
getRecent: (limit = 10) => apiClient.get<Transaction[]>(`/transactions/recent?limit=${limit}`),
|
|
|
|
getSummary: (startDate: string, endDate: string) =>
|
|
apiClient.get<{
|
|
income: number;
|
|
expense: number;
|
|
net: number;
|
|
incomeCount: number;
|
|
expenseCount: number;
|
|
}>(`/transactions/summary?startDate=${startDate}&endDate=${endDate}`),
|
|
|
|
getOne: (id: string) => apiClient.get<Transaction>(`/transactions/${id}`),
|
|
|
|
create: (data: CreateTransactionInput) => apiClient.post<Transaction>('/transactions', data),
|
|
|
|
update: (id: string, data: UpdateTransactionInput) =>
|
|
apiClient.put<Transaction>(`/transactions/${id}`, data),
|
|
|
|
delete: (id: string) => apiClient.delete<{ success: boolean }>(`/transactions/${id}`),
|
|
};
|