主要变更: - 将独立的 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>
49 lines
1.8 KiB
TypeScript
49 lines
1.8 KiB
TypeScript
import { defineEventHandler, getRouterParam, readBody } from '#nitro';
|
|
|
|
import { MOCK_BUDGETS } from '../../../utils/mock-data';
|
|
import { useResponseError, useResponseSuccess } from '../../../utils/response';
|
|
|
|
export default defineEventHandler(async (event) => {
|
|
const id = Number(getRouterParam(event, 'id'));
|
|
const body = await readBody(event);
|
|
|
|
const index = MOCK_BUDGETS.findIndex((b) => b.id === id);
|
|
|
|
if (index === -1) {
|
|
return useResponseError('预算不存在', -1);
|
|
}
|
|
|
|
// 如果是恢复操作
|
|
if (body.isDeleted === false) {
|
|
MOCK_BUDGETS[index] = {
|
|
...MOCK_BUDGETS[index],
|
|
isDeleted: false,
|
|
deletedAt: undefined,
|
|
};
|
|
return useResponseSuccess(MOCK_BUDGETS[index]);
|
|
}
|
|
|
|
// 普通更新
|
|
const updatedBudget = {
|
|
...MOCK_BUDGETS[index],
|
|
category: body.category ?? MOCK_BUDGETS[index].category,
|
|
categoryId: body.categoryId ?? MOCK_BUDGETS[index].categoryId,
|
|
emoji: body.emoji ?? MOCK_BUDGETS[index].emoji,
|
|
limit: body.limit ?? MOCK_BUDGETS[index].limit,
|
|
spent: body.spent ?? MOCK_BUDGETS[index].spent,
|
|
remaining: body.remaining ?? MOCK_BUDGETS[index].remaining,
|
|
percentage: body.percentage ?? MOCK_BUDGETS[index].percentage,
|
|
currency: body.currency ?? MOCK_BUDGETS[index].currency,
|
|
period: body.period ?? MOCK_BUDGETS[index].period,
|
|
alertThreshold: body.alertThreshold ?? MOCK_BUDGETS[index].alertThreshold,
|
|
description: body.description ?? MOCK_BUDGETS[index].description,
|
|
autoRenew: body.autoRenew ?? MOCK_BUDGETS[index].autoRenew,
|
|
overspendAlert: body.overspendAlert ?? MOCK_BUDGETS[index].overspendAlert,
|
|
dailyReminder: body.dailyReminder ?? MOCK_BUDGETS[index].dailyReminder,
|
|
monthlyTrend: body.monthlyTrend ?? MOCK_BUDGETS[index].monthlyTrend,
|
|
};
|
|
|
|
MOCK_BUDGETS[index] = updatedBudget;
|
|
return useResponseSuccess(updatedBudget);
|
|
});
|