-
Notifications
You must be signed in to change notification settings - Fork 222
Expand file tree
/
Copy pathsavings.ts
More file actions
71 lines (59 loc) · 1.97 KB
/
savings.ts
File metadata and controls
71 lines (59 loc) · 1.97 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 SavingsGoalStatus = 'ACTIVE' | 'COMPLETED' | 'PAUSED';
export type SavingsGoal = {
id: number;
name: string;
target_amount: number;
current_amount: number;
currency: string;
deadline?: string | null;
notes?: string | null;
status: SavingsGoalStatus;
progress_pct: number;
milestones_reached: number[];
next_milestone_pct: number | null;
created_at: string;
};
export type SavingsDeposit = {
id: number;
amount: number;
note?: string | null;
deposited_at: string;
created_at: string;
};
export type SavingsGoalCreate = {
name: string;
target_amount: number;
currency?: string;
deadline?: string | null;
notes?: string | null;
initial_amount?: number;
};
export type SavingsGoalUpdate = Partial<Omit<SavingsGoalCreate, 'initial_amount'>> & {
status?: SavingsGoalStatus;
};
export async function listGoals(status?: string): Promise<SavingsGoal[]> {
const qs = status ? `?status=${status}` : '';
return api<SavingsGoal[]>(`/savings${qs}`);
}
export async function createGoal(payload: SavingsGoalCreate): Promise<SavingsGoal> {
return api<SavingsGoal>('/savings', { method: 'POST', body: payload });
}
export async function getGoal(id: number): Promise<SavingsGoal> {
return api<SavingsGoal>(`/savings/${id}`);
}
export async function updateGoal(id: number, payload: SavingsGoalUpdate): Promise<SavingsGoal> {
return api<SavingsGoal>(`/savings/${id}`, { method: 'PATCH', body: payload });
}
export async function deleteGoal(id: number): Promise<{ message: string }> {
return api(`/savings/${id}`, { method: 'DELETE' });
}
export async function addDeposit(
goalId: number,
payload: { amount: number; note?: string; deposited_at?: string },
): Promise<SavingsGoal> {
return api<SavingsGoal>(`/savings/${goalId}/deposits`, { method: 'POST', body: payload });
}
export async function listDeposits(goalId: number): Promise<SavingsDeposit[]> {
return api<SavingsDeposit[]>(`/savings/${goalId}/deposits`);
}