Remove unused columns and simplify schema across database and routes

Drop `parent_id` from categories, remove `ai_category` and
`review_notes` from
transactions, and eliminate category/reviewed filters from transaction
queries.
Clean up code style and formatting.
This commit is contained in:
2026-05-06 22:16:36 +08:00
parent 965ef2058d
commit 08fbde8a39
4 changed files with 50 additions and 112 deletions
+2 -76
View File
@@ -16,8 +16,6 @@ router.get("/", (req, res) => {
end_date,
source_type,
direction,
category,
reviewed,
min_amount,
max_amount,
keyword,
@@ -45,14 +43,6 @@ router.get("/", (req, res) => {
conditions.push("t.direction = ?");
params.push(direction);
}
if (category) {
conditions.push("t.category = ?");
params.push(category);
}
if (reviewed !== undefined) {
conditions.push("t.reviewed = ?");
params.push(parseInt(reviewed));
}
if (min_amount) {
conditions.push("ABS(t.amount) >= ?");
params.push(parseFloat(min_amount));
@@ -63,10 +53,10 @@ router.get("/", (req, res) => {
}
if (keyword) {
conditions.push(
"(t.counterparty LIKE ? OR t.description LIKE ? OR t.notes LIKE ? OR t.ai_description LIKE ?)",
"(t.counterparty LIKE ? OR t.description LIKE ? OR t.notes LIKE ?)",
);
const kw = `%${keyword}%`;
params.push(kw, kw, kw, kw);
params.push(kw, kw, kw);
}
const whereClause =
@@ -244,68 +234,4 @@ router.post("/classify-all", async (req, res) => {
}
});
// GET /api/transactions/stats/summary - 获取汇总统计
router.get("/stats/summary", (req, res) => {
// This is handled by the stats route, but let's keep a simple version here too
const db = getDB();
const { start_date, end_date } = req.query;
const conditions = [];
const params = [];
if (start_date) {
conditions.push("transaction_date >= ?");
params.push(start_date);
}
if (end_date) {
conditions.push("transaction_date <= ?");
params.push(end_date);
}
const where =
conditions.length > 0 ? "WHERE " + conditions.join(" AND ") : "";
const incomeResult = db
.prepare(
`SELECT COALESCE(SUM(amount), 0) as total FROM transactions ${where} AND direction = 'income'`,
)
.get(...params);
const expenseResult = db
.prepare(
`SELECT COALESCE(SUM(ABS(amount)), 0) as total FROM transactions ${where} AND direction = 'expense'`,
)
.get(...params);
const countResult = db
.prepare(`SELECT COUNT(*) as total FROM transactions ${where}`)
.get(...params);
const unreviewedCount = db
.prepare(
`SELECT COUNT(*) as total FROM transactions ${where} AND reviewed = 0 AND ABS(amount) >= 100`,
)
.get(...params);
const categoryBreakdown = db
.prepare(
`
SELECT category, COUNT(*) as count, SUM(ABS(amount)) as total_amount
FROM transactions ${where} AND direction = 'expense'
GROUP BY category
ORDER BY total_amount DESC
`,
)
.all(...params);
res.json({
totalIncome: incomeResult.total,
totalExpense: expenseResult.total,
netAmount: incomeResult.total - expenseResult.total,
totalCount: countResult.total,
unreviewedCount: unreviewedCount.total,
categoryBreakdown,
});
});
module.exports = router;