- 优化财务仪表板数据展示 - 增强账户管理功能 - 改进预算和分类管理 - 完善报表和统计分析 - 优化交易管理界面 - 更新Workspace工作区 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
33 lines
954 B
TypeScript
33 lines
954 B
TypeScript
import { readBody } from 'h3';
|
|
import { createTransaction } from '~/utils/finance-repository';
|
|
import { useResponseError, useResponseSuccess } from '~/utils/response';
|
|
|
|
const DEFAULT_CURRENCY = 'CNY';
|
|
|
|
export default defineEventHandler(async (event) => {
|
|
const body = await readBody(event);
|
|
|
|
if (!body?.type || !body?.amount || !body?.transactionDate) {
|
|
return useResponseError('缺少必填字段', -1);
|
|
}
|
|
|
|
const amount = Number(body.amount);
|
|
if (Number.isNaN(amount)) {
|
|
return useResponseError('金额格式不正确', -1);
|
|
}
|
|
|
|
const transaction = createTransaction({
|
|
type: body.type,
|
|
amount,
|
|
currency: body.currency ?? DEFAULT_CURRENCY,
|
|
categoryId: body.categoryId ?? null,
|
|
accountId: body.accountId ?? null,
|
|
transactionDate: body.transactionDate,
|
|
description: body.description ?? '',
|
|
project: body.project ?? null,
|
|
memo: body.memo ?? null,
|
|
});
|
|
|
|
return useResponseSuccess(transaction);
|
|
});
|