edtech / apps /api /src /services /analytics-service.ts
CognxSafeTrack
fix(security): resolve critical and high technical debt from audit
a8e18d6
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
};
}
}