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:
@@ -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
|
||||
`);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user