From 988b02c7d28a3df93099b42964ad1f1ee094809f Mon Sep 17 00:00:00 2001 From: Nathan <70660308+NotARoomba@users.noreply.github.com> Date: Wed, 18 Feb 2026 19:09:19 -0500 Subject: [PATCH] cph --- backend/src/routes/admin.ts | 34 ++++++++++- frontend/src/routes/admin/+page.svelte | 79 +++++++++++++++++++++++++- 2 files changed, 110 insertions(+), 3 deletions(-) diff --git a/backend/src/routes/admin.ts b/backend/src/routes/admin.ts index ee8c11c..fa41dbc 100644 --- a/backend/src/routes/admin.ts +++ b/backend/src/routes/admin.ts @@ -80,15 +80,45 @@ admin.get('/stats', async ({ headers, status }) => { const pendingWeightedGrants = Math.round(pendingHours / 10 * 100) / 100 const inProgressWeightedGrants = Math.round(inProgressHours / 10 * 100) / 100 + // Shop spending stats + const [shopSpending, refinerySpending] = await Promise.all([ + db.select({ + totalSpent: sql`COALESCE(SUM(${shopOrdersTable.totalPrice}), 0)`, + purchaseSpent: sql`COALESCE(SUM(CASE WHEN ${shopOrdersTable.orderType} = 'purchase' THEN ${shopOrdersTable.totalPrice} ELSE 0 END), 0)`, + consolationSpent: sql`COALESCE(SUM(CASE WHEN ${shopOrdersTable.orderType} = 'consolation' THEN ${shopOrdersTable.totalPrice} ELSE 0 END), 0)`, + luckWinSpent: sql`COALESCE(SUM(CASE WHEN ${shopOrdersTable.orderType} = 'luck_win' THEN ${shopOrdersTable.totalPrice} ELSE 0 END), 0)` + }).from(shopOrdersTable), + db.select({ + totalSpent: sql`COALESCE(SUM(${refinerySpendingHistoryTable.cost}), 0)` + }).from(refinerySpendingHistoryTable) + ]) + + const shopTotal = Number(shopSpending[0]?.totalSpent) || 0 + const shopPurchases = Number(shopSpending[0]?.purchaseSpent) || 0 + const shopConsolations = Number(shopSpending[0]?.consolationSpent) || 0 + const shopLuckWins = Number(shopSpending[0]?.luckWinSpent) || 0 + const refineryTotal = Number(refinerySpending[0]?.totalSpent) || 0 + const totalScrapsSpent = shopTotal + refineryTotal + const roundedTotalHours = Math.round(totalHours * 10) / 10 + const costPerHour = roundedTotalHours > 0 ? Math.round(totalScrapsSpent / roundedTotalHours * 100) / 100 : 0 + return { totalUsers, totalProjects, - totalHours: Math.round(totalHours * 10) / 10, + totalHours: roundedTotalHours, weightedGrants, pendingHours: Math.round(pendingHours * 10) / 10, pendingWeightedGrants, inProgressHours: Math.round(inProgressHours * 10) / 10, - inProgressWeightedGrants + inProgressWeightedGrants, + shopStats: { + totalScrapsSpent, + shopPurchases, + shopConsolations, + shopLuckWins, + refineryUpgrades: refineryTotal, + costPerHour + } } }) diff --git a/frontend/src/routes/admin/+page.svelte b/frontend/src/routes/admin/+page.svelte index 80c3e18..1f9b1fd 100644 --- a/frontend/src/routes/admin/+page.svelte +++ b/frontend/src/routes/admin/+page.svelte @@ -1,11 +1,20 @@