feat: 新增账户服务及其相关类型定义,包括账户的增删改查、转账、排序及余额计算功能。

This commit is contained in:
2026-01-29 21:43:20 +08:00
parent 0b3a7b1d79
commit 6087b35ce5
2 changed files with 10 additions and 0 deletions

View File

@@ -26,6 +26,12 @@ function mapAccountFromApi(data: Record<string, unknown>): Account {
lastSyncTime: data.last_sync_time as string | undefined,
accountCode: data.account_code as string | undefined,
accountType: data.account_type as 'asset' | 'liability' | undefined,
tags: (data.tags as { id: number; name: string; color: string; created_at: string }[] | undefined)?.map(t => ({
id: t.id,
name: t.name,
color: t.color,
createdAt: t.created_at,
})),
};
}
@@ -66,6 +72,7 @@ export async function createAccount(data: AccountFormInput): Promise<Account> {
payment_date: data.paymentDate,
warning_threshold: data.warningThreshold,
account_code: data.accountCode,
tag_ids: data.tagIds,
};
const response = await api.post<ApiResponse<Account>>('/accounts', payload);
if (!response.data) {
@@ -91,6 +98,7 @@ export async function updateAccount(id: number, data: Partial<AccountFormInput>)
if (data.warningThreshold !== undefined) payload.warning_threshold = data.warningThreshold;
if (data.accountCode !== undefined) payload.account_code = data.accountCode;
if (data.accountType !== undefined) payload.account_type = data.accountType;
if (data.tagIds !== undefined) payload.tag_ids = data.tagIds;
const response = await api.put<ApiResponse<Account>>(`/accounts/${id}`, payload);
if (!response.data) {

View File

@@ -149,6 +149,7 @@ export interface Account {
lastSyncTime?: string;
accountCode?: string;
accountType?: 'asset' | 'liability';
tags?: Tag[];
}
// Budget Interface
@@ -294,6 +295,7 @@ export interface AccountFormInput {
warningThreshold?: number;
accountCode?: string;
accountType?: 'asset' | 'liability';
tagIds?: number[];
}
export interface TransferFormInput {