feat: 新增账户服务及其相关类型定义,包括账户的增删改查、转账、排序及余额计算功能。
This commit is contained in:
@@ -26,6 +26,12 @@ function mapAccountFromApi(data: Record<string, unknown>): Account {
|
|||||||
lastSyncTime: data.last_sync_time as string | undefined,
|
lastSyncTime: data.last_sync_time as string | undefined,
|
||||||
accountCode: data.account_code as string | undefined,
|
accountCode: data.account_code as string | undefined,
|
||||||
accountType: data.account_type as 'asset' | 'liability' | 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,
|
payment_date: data.paymentDate,
|
||||||
warning_threshold: data.warningThreshold,
|
warning_threshold: data.warningThreshold,
|
||||||
account_code: data.accountCode,
|
account_code: data.accountCode,
|
||||||
|
tag_ids: data.tagIds,
|
||||||
};
|
};
|
||||||
const response = await api.post<ApiResponse<Account>>('/accounts', payload);
|
const response = await api.post<ApiResponse<Account>>('/accounts', payload);
|
||||||
if (!response.data) {
|
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.warningThreshold !== undefined) payload.warning_threshold = data.warningThreshold;
|
||||||
if (data.accountCode !== undefined) payload.account_code = data.accountCode;
|
if (data.accountCode !== undefined) payload.account_code = data.accountCode;
|
||||||
if (data.accountType !== undefined) payload.account_type = data.accountType;
|
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);
|
const response = await api.put<ApiResponse<Account>>(`/accounts/${id}`, payload);
|
||||||
if (!response.data) {
|
if (!response.data) {
|
||||||
|
|||||||
@@ -149,6 +149,7 @@ export interface Account {
|
|||||||
lastSyncTime?: string;
|
lastSyncTime?: string;
|
||||||
accountCode?: string;
|
accountCode?: string;
|
||||||
accountType?: 'asset' | 'liability';
|
accountType?: 'asset' | 'liability';
|
||||||
|
tags?: Tag[];
|
||||||
}
|
}
|
||||||
|
|
||||||
// Budget Interface
|
// Budget Interface
|
||||||
@@ -294,6 +295,7 @@ export interface AccountFormInput {
|
|||||||
warningThreshold?: number;
|
warningThreshold?: number;
|
||||||
accountCode?: string;
|
accountCode?: string;
|
||||||
accountType?: 'asset' | 'liability';
|
accountType?: 'asset' | 'liability';
|
||||||
|
tagIds?: number[];
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface TransferFormInput {
|
export interface TransferFormInput {
|
||||||
|
|||||||
Reference in New Issue
Block a user