Fix dashboard SQL: use tier_level and mrr_value columns

The subscriptions table uses:
- tier_level (integer) not tier_id
- mrr_value (pre-calculated) not joined to subscription_tiers
- is_lifetime (boolean) not status='lifetime'

Chronicler #69
This commit is contained in:
Claude
2026-04-08 08:24:08 +00:00
parent 91eea2c5ff
commit d121bd21f6

View File

@@ -34,12 +34,8 @@ router.get('/dashboard', async (req, res) => {
// Fetch subscriber stats from database
const { rows: subStats } = await db.query(`
SELECT
COUNT(*) FILTER (WHERE status IN ('active', 'grace_period', 'lifetime')) as active_count,
COALESCE(SUM(CASE
WHEN status = 'active' AND tier_id IS NOT NULL THEN
(SELECT price FROM subscription_tiers WHERE id = tier_id)
ELSE 0
END), 0) as mrr
COUNT(*) FILTER (WHERE status IN ('active', 'grace_period') OR is_lifetime = true) as active_count,
COALESCE(SUM(mrr_value) FILTER (WHERE status = 'active'), 0) as mrr
FROM subscriptions
`);