Files
kt-financial-system/apps/backend/api/finance/transactions.post.ts
woshiqp465 1e42191296 refactor: 整合财务系统到主应用并重构后端架构
主要变更:
- 将独立的 web-finance 应用整合到 web-antd 主应用中
- 重命名 backend-mock 为 backend,增强后端功能
- 新增财务模块 API 端点(账户、预算、类别、交易)
- 增强财务仪表板和报表功能
- 添加 SQLite 数据存储支持和财务数据导入脚本
- 优化路由结构,删除冗余的 finance-system 模块

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-04 21:14:21 +08:00

34 lines
955 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);
});