- Adjusted formatting in .prettierrc for consistent newline handling. - Enhanced API documentation in BACKEND_PROMPT.md for better readability and structure. - Updated docker-compose.yml to standardize quotes and improve health check commands. - Refactored ESLint configuration for better readability and consistency. - Made minor formatting adjustments in various frontend components for improved user experience and code clarity.
139 lines
3.7 KiB
TypeScript
139 lines
3.7 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}`);
|
|
}
|
|
};
|