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.
This commit is contained in:
144
frontend-web/src/lib/api/networth.service.ts
Normal file
144
frontend-web/src/lib/api/networth.service.ts
Normal file
@@ -0,0 +1,144 @@
|
||||
/**
|
||||
* 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}`);
|
||||
},
|
||||
};
|
||||
Reference in New Issue
Block a user