diff --git a/services/arbiter-3.0/src/routes/admin/index.js b/services/arbiter-3.0/src/routes/admin/index.js index dd19f0d..558bbbc 100644 --- a/services/arbiter-3.0/src/routes/admin/index.js +++ b/services/arbiter-3.0/src/routes/admin/index.js @@ -53,12 +53,45 @@ router.get('/dashboard', async (req, res) => { `); const lastSyncTime = syncRows[0]?.last_sync || null; + // Fetch social stats across all platforms + const { rows: socialStats } = await db.query(` + SELECT + platform, + COUNT(*) as post_count, + COALESCE(SUM(views), 0) as total_views, + COALESCE(SUM(likes), 0) as total_likes, + COALESCE(SUM(comments), 0) as total_comments + FROM social_posts + GROUP BY platform + `); + + const socialTotals = { + posts: 0, + views: 0, + likes: 0, + comments: 0, + platforms: {} + }; + + for (const row of socialStats) { + socialTotals.posts += parseInt(row.post_count); + socialTotals.views += parseInt(row.total_views); + socialTotals.likes += parseInt(row.total_likes); + socialTotals.comments += parseInt(row.total_comments); + socialTotals.platforms[row.platform] = { + posts: parseInt(row.post_count), + views: parseInt(row.total_views), + likes: parseInt(row.total_likes) + }; + } + res.render('admin/dashboard', { title: 'Command Bridge', serversOnline, activeSubscribers, totalMRR, - lastSyncTime + lastSyncTime, + socialTotals }); } catch (error) { console.error('Dashboard data fetch error:', error); @@ -68,7 +101,8 @@ router.get('/dashboard', async (req, res) => { serversOnline: 0, activeSubscribers: 0, totalMRR: 0, - lastSyncTime: null + lastSyncTime: null, + socialTotals: { posts: 0, views: 0, likes: 0, comments: 0, platforms: {} } }); } });