File size: 930 Bytes
6dd9bad a8e18d6 6dd9bad | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | import { prisma } from './prisma';
export class AnalyticsService {
static async getDashboardStats(organizationId: string) {
const [totalUsers, activeEnrollments, completedEnrollments, totalTracks, totalRevenue] = await Promise.all([
prisma.user.count({ where: { organizationId, deletedAt: null } }),
prisma.enrollment.count({ where: { status: 'ACTIVE', organizationId, deletedAt: null } }),
prisma.enrollment.count({ where: { status: 'COMPLETED', organizationId, deletedAt: null } }),
prisma.track.count({ where: { organizationId } }),
prisma.payment.aggregate({ where: { status: 'COMPLETED', organizationId }, _sum: { amount: true } }),
]);
return {
totalUsers,
activeEnrollments,
completedEnrollments,
totalTracks,
totalRevenue: totalRevenue._sum.amount || 0
};
}
}
|