|
@@ -2,6 +2,7 @@
|
|
|
|
|
|
|
|
import { withSuperAdmin } from '@/lib/with-super-admin'
|
|
import { withSuperAdmin } from '@/lib/with-super-admin'
|
|
|
import { db } from '@/lib/db'
|
|
import { db } from '@/lib/db'
|
|
|
|
|
+import { monthlyPlanPrice } from '@/lib/plan-pricing'
|
|
|
|
|
|
|
|
export async function getAdminStats() {
|
|
export async function getAdminStats() {
|
|
|
return withSuperAdmin(async () => {
|
|
return withSuperAdmin(async () => {
|
|
@@ -12,11 +13,16 @@ export async function getAdminStats() {
|
|
|
db.subscription.count({ where: { status: 'active' } }),
|
|
db.subscription.count({ where: { status: 'active' } }),
|
|
|
db.subscription.findMany({
|
|
db.subscription.findMany({
|
|
|
where: { status: 'active' },
|
|
where: { status: 'active' },
|
|
|
- select: { plan: { select: { price: true } } },
|
|
|
|
|
|
|
+ select: { plan: { select: { price: true, interval: true } } },
|
|
|
}),
|
|
}),
|
|
|
])
|
|
])
|
|
|
|
|
|
|
|
- const totalRevenue = activeSubscriptions.reduce((sum, sub) => sum + sub.plan.price, 0)
|
|
|
|
|
|
|
+ // Yearly plans are the common case, so their price has to come down to a
|
|
|
|
|
+ // month before it can be added to the monthly total.
|
|
|
|
|
+ const totalRevenue = activeSubscriptions.reduce(
|
|
|
|
|
+ (sum, sub) => sum + monthlyPlanPrice(sub.plan.price, sub.plan.interval),
|
|
|
|
|
+ 0
|
|
|
|
|
+ )
|
|
|
|
|
|
|
|
return {
|
|
return {
|
|
|
totalUsers,
|
|
totalUsers,
|