Files
personal-finance/frontend-web/src/lib/api/networth.service.ts
Alexander Zinn 40210c454e Add lock files for package management and update architecture documentation
- Introduced bun.lock and package-lock.json to manage dependencies for the project.
- Enhanced backend API architecture documentation with additional security and documentation guidelines.
- Made minor formatting adjustments across various files for consistency and clarity.
2025-12-11 02:11:43 -05:00

145 lines
3.8 KiB
TypeScript

/**
* Net Worth Service
*/
import {apiClient} from './client';
export interface Asset {
id: string;
name: string;
type: 'CASH' | 'INVESTMENT' | 'PROPERTY' | 'VEHICLE' | 'OTHER';
value: number;
createdAt?: string;
updatedAt?: string;
}
export interface CreateAssetRequest {
name: string;
type: 'CASH' | 'INVESTMENT' | 'PROPERTY' | 'VEHICLE' | 'OTHER';
value: number;
}
export interface UpdateAssetRequest {
name?: string;
type?: 'CASH' | 'INVESTMENT' | 'PROPERTY' | 'VEHICLE' | 'OTHER';
value?: number;
}
export interface Liability {
id: string;
name: string;
type: 'CREDIT_CARD' | 'LOAN' | 'MORTGAGE' | 'OTHER';
currentBalance: number;
interestRate?: number;
minimumPayment?: number;
dueDate?: string;
creditor?: string;
notes?: string;
createdAt?: string;
updatedAt?: string;
}
export interface CreateLiabilityRequest {
name: string;
type: 'CREDIT_CARD' | 'LOAN' | 'MORTGAGE' | 'OTHER';
currentBalance: number;
interestRate?: number;
minimumPayment?: number;
dueDate?: string;
creditor?: string;
notes?: string;
}
export interface UpdateLiabilityRequest {
name?: string;
type?: 'CREDIT_CARD' | 'LOAN' | 'MORTGAGE' | 'OTHER';
currentBalance?: number;
interestRate?: number;
minimumPayment?: number;
dueDate?: string;
creditor?: string;
notes?: string;
}
export interface NetWorthSnapshot {
id: string;
date: string;
totalAssets: number;
totalLiabilities: number;
netWorth: number;
notes?: string;
createdAt?: string;
}
export const assetService = {
async getAll(): Promise<{assets: Asset[]}> {
return apiClient.get<{assets: Asset[]}>('/assets');
},
async getById(id: string): Promise<{asset: Asset}> {
return apiClient.get<{asset: Asset}>(`/assets/${id}`);
},
async create(data: CreateAssetRequest): Promise<{asset: Asset}> {
return apiClient.post<{asset: Asset}>('/assets', data);
},
async update(id: string, data: UpdateAssetRequest): Promise<{asset: Asset}> {
return apiClient.put<{asset: Asset}>(`/assets/${id}`, data);
},
async delete(id: string): Promise<void> {
return apiClient.delete<void>(`/assets/${id}`);
},
};
export const liabilityService = {
async getAll(): Promise<{liabilities: Liability[]}> {
return apiClient.get<{liabilities: Liability[]}>('/liabilities');
},
async getById(id: string): Promise<{liability: Liability}> {
return apiClient.get<{liability: Liability}>(`/liabilities/${id}`);
},
async create(data: CreateLiabilityRequest): Promise<{liability: Liability}> {
return apiClient.post<{liability: Liability}>('/liabilities', data);
},
async update(id: string, data: UpdateLiabilityRequest): Promise<{liability: Liability}> {
return apiClient.put<{liability: Liability}>(`/liabilities/${id}`, data);
},
async delete(id: string): Promise<void> {
return apiClient.delete<void>(`/liabilities/${id}`);
},
};
export const snapshotService = {
async getAll(): Promise<{snapshots: NetWorthSnapshot[]}> {
return apiClient.get<{snapshots: NetWorthSnapshot[]}>('/networth/snapshots');
},
async getById(id: string): Promise<{snapshot: NetWorthSnapshot}> {
return apiClient.get<{snapshot: NetWorthSnapshot}>(`/networth/snapshots/${id}`);
},
async create(data: {
date: string;
totalAssets: number;
totalLiabilities: number;
netWorth: number;
notes?: string;
}): Promise<{snapshot: NetWorthSnapshot}> {
return apiClient.post<{snapshot: NetWorthSnapshot}>('/networth/snapshots', data);
},
async createFromCurrent(notes?: string): Promise<{snapshot: NetWorthSnapshot}> {
return apiClient.post<{snapshot: NetWorthSnapshot}>('/networth/snapshots/record', {notes});
},
async delete(id: string): Promise<void> {
return apiClient.delete<void>(`/networth/snapshots/${id}`);
},
};