-
Notifications
You must be signed in to change notification settings - Fork 224
Expand file tree
/
Copy pathaccounts.ts
More file actions
71 lines (59 loc) · 1.86 KB
/
accounts.ts
File metadata and controls
71 lines (59 loc) · 1.86 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
import { api } from './client';
export type AccountType = 'BANK' | 'CREDIT' | 'INVESTMENT' | 'CASH';
export type Account = {
id: number;
name: string;
account_type: AccountType;
institution: string | null;
balance: number;
currency: string;
color: string;
active: boolean;
created_at: string | null;
};
export type AccountCreate = {
name: string;
account_type?: AccountType;
institution?: string;
balance?: number;
currency?: string;
color?: string;
};
export type AccountUpdate = Partial<AccountCreate> & { active?: boolean };
export type TypeBreakdown = {
type: AccountType;
total: number;
count: number;
accounts: Account[];
};
export type AccountsOverview = {
total_balance: number;
net_worth: number;
total_assets: number;
total_liabilities: number;
account_count: number;
type_breakdown: TypeBreakdown[];
};
export async function listAccounts(params?: {
include_inactive?: boolean;
}): Promise<Account[]> {
const qs = new URLSearchParams();
if (params?.include_inactive) qs.set('include_inactive', 'true');
const path = '/accounts' + (qs.toString() ? `?${qs.toString()}` : '');
return api<Account[]>(path);
}
export async function getAccount(id: number): Promise<Account> {
return api<Account>(`/accounts/${id}`);
}
export async function createAccount(payload: AccountCreate): Promise<Account> {
return api<Account>('/accounts', { method: 'POST', body: payload });
}
export async function updateAccount(id: number, payload: AccountUpdate): Promise<Account> {
return api<Account>(`/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');
}