-
Notifications
You must be signed in to change notification settings - Fork 145
Expand file tree
/
Copy pathaccounts.ts
More file actions
75 lines (64 loc) · 1.94 KB
/
accounts.ts
File metadata and controls
75 lines (64 loc) · 1.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import { api } from './client';
export type AccountType = 'CHECKING' | 'SAVINGS' | 'CREDIT_CARD' | 'CASH' | 'INVESTMENT' | 'OTHER';
export type FinancialAccount = {
id: number;
name: string;
account_type: AccountType;
balance: number;
currency: string;
institution: string | null;
active: boolean;
created_at: string | null;
};
export type AccountCreate = {
name: string;
account_type?: AccountType;
balance?: number;
currency?: string;
institution?: string;
};
export type AccountUpdate = Partial<AccountCreate> & {
active?: boolean;
};
export type AccountsOverview = {
accounts: FinancialAccount[];
total_balance: number;
totals_by_currency: Record<string, number>;
account_count: number;
recent_expenses: {
id: number;
amount: number;
currency: string;
description: string;
date: string;
}[];
upcoming_bills: {
id: number;
name: string;
amount: number;
currency: string;
next_due_date: string;
}[];
};
export async function listAccounts(includeInactive = false): Promise<FinancialAccount[]> {
const qs = includeInactive ? '?include_inactive=true' : '';
return api<FinancialAccount[]>(`/accounts${qs}`);
}
export async function getAccount(id: number): Promise<FinancialAccount> {
return api<FinancialAccount>(`/accounts/${id}`);
}
export async function createAccount(payload: AccountCreate): Promise<FinancialAccount> {
return api<FinancialAccount>('/accounts', { method: 'POST', body: payload });
}
export async function updateAccount(
id: number,
payload: AccountUpdate,
): Promise<FinancialAccount> {
return api<FinancialAccount>(`/accounts/${id}`, { method: 'PATCH', body: payload });
}
export async function deleteAccount(id: number): Promise<{ message: string }> {
return api<{ message: string }>(`/accounts/${id}`, { method: 'DELETE' });
}
export async function getAccountsOverview(): Promise<AccountsOverview> {
return api<AccountsOverview>('/accounts/overview');
}