数据源修改

This commit is contained in:
cheney
2026-08-06 15:24:55 +08:00
parent b10b1c44db
commit ec15f40323
24 changed files with 2289 additions and 131 deletions
+18 -2
View File
@@ -6,10 +6,26 @@ const router = Router()
router.use(authRequired)
// 指标列表: 元数据 + 明细点, 过滤 hidden (数据与脚本保留, 仅不展示)
router.get('/indicators', async (_req, res, next) => {
try {
const rows = await prisma.indicator.findMany({ orderBy: [{ groupName: 'asc' }, { name: 'asc' }] })
res.json({ indicators: rows })
const rows = await prisma.indicator.findMany({
where: { hidden: false },
include: { points: { orderBy: { period: 'asc' } } },
orderBy: [{ groupName: 'asc' }, { name: 'asc' }],
})
// 组装前端友好结构: points 保持从老到新
const indicators = rows.map((r) => ({
id: r.id,
name: r.name,
groupName: r.groupName,
title: r.title,
unit: r.unit,
source: r.source,
frequency: r.frequency,
points: r.points.map((p) => ({ period: p.period, value: p.value })),
}))
res.json({ indicators })
} catch (e) { next(e) }
})