Fix admin dashboard summary nulls

This commit is contained in:
john
2026-06-20 17:04:30 +08:00
parent dae3e2f350
commit a59823d347
2 changed files with 52 additions and 26 deletions
+19 -2
View File
@@ -229,9 +229,26 @@ export function createLocalUserAuth(pool) {
async function getAdminSummary() {
const [[row]] = await pool.execute(
`SELECT COUNT(*) AS total, SUM(CASE WHEN balance_cents < 0 THEN 1 ELSE 0 END) AS lowBalance FROM auth_users`,
`SELECT
COUNT(*) AS total,
SUM(CASE WHEN status = 'active' THEN 1 ELSE 0 END) AS active,
SUM(CASE WHEN balance_cents < 0 THEN 1 ELSE 0 END) AS lowBalance,
SUM(balance_cents) AS totalBalanceCents
FROM auth_users`,
);
return { users: { total: Number(row.total ?? 0), lowBalance: Number(row.lowBalance ?? 0) }, routes: { total: 0, active: 0 } };
return {
users: {
total: Number(row.total ?? 0),
active: Number(row.active ?? 0),
lowBalance: Number(row.lowBalance ?? 0),
totalBalanceCents: Number(row.totalBalanceCents ?? 0),
},
usage24h: { count: 0, costCents: 0 },
lowBalanceUsers: [],
recentUsage: [],
recentLedger: [],
llm: { keyCount: 0, selectedKeyName: null, globalModel: null },
};
}
return {