diff --git a/services/arbiter-3.0/src/routes/admin/index.js b/services/arbiter-3.0/src/routes/admin/index.js index c41f154..2c263cc 100644 --- a/services/arbiter-3.0/src/routes/admin/index.js +++ b/services/arbiter-3.0/src/routes/admin/index.js @@ -1,6 +1,8 @@ const express = require('express'); const router = express.Router(); const { requireTrinityAccess } = require('./middleware'); +const { getMinecraftServers } = require('../../panel/discovery'); +const db = require('../../database'); // Sub-routers const playersRouter = require('./players'); @@ -23,8 +25,43 @@ router.get('/', (req, res) => { res.redirect('/admin/dashboard'); }); -router.get('/dashboard', (req, res) => { - res.render('admin/dashboard', { title: 'Command Bridge' }); +router.get('/dashboard', async (req, res) => { + try { + // Fetch server count from Pterodactyl + const servers = await getMinecraftServers(); + const serversOnline = servers.length; + + // 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 + FROM subscriptions + `); + + const activeSubscribers = parseInt(subStats[0]?.active_count || 0); + const totalMRR = parseFloat(subStats[0]?.mrr || 0); + + res.render('admin/dashboard', { + title: 'Command Bridge', + serversOnline, + activeSubscribers, + totalMRR + }); + } catch (error) { + console.error('Dashboard data fetch error:', error); + // Fallback to zeros on error + res.render('admin/dashboard', { + title: 'Command Bridge', + serversOnline: 0, + activeSubscribers: 0, + totalMRR: 0 + }); + } }); router.use('/players', playersRouter); diff --git a/services/arbiter-3.0/src/views/admin/dashboard.ejs b/services/arbiter-3.0/src/views/admin/dashboard.ejs index e219ca2..3e23e6c 100644 --- a/services/arbiter-3.0/src/views/admin/dashboard.ejs +++ b/services/arbiter-3.0/src/views/admin/dashboard.ejs @@ -1,15 +1,15 @@