Initial commit: FL-Akademie LMS mit Docker, Admin, Portal und Dokumentation.
Made-with: Cursor
This commit is contained in:
28
lib/course-progress.ts
Normal file
28
lib/course-progress.ts
Normal file
@@ -0,0 +1,28 @@
|
||||
import { prisma } from "@/lib/prisma";
|
||||
|
||||
export async function getCourseLessonStats(courseId: string) {
|
||||
const lessons = await prisma.lesson.count({
|
||||
where: { published: true, module: { courseId } },
|
||||
});
|
||||
return { totalLessons: lessons };
|
||||
}
|
||||
|
||||
export async function getUserCourseProgress(userId: string, courseId: string) {
|
||||
const lessons = await prisma.lesson.findMany({
|
||||
where: { published: true, module: { courseId } },
|
||||
select: { id: true },
|
||||
});
|
||||
const total = lessons.length;
|
||||
if (total === 0) return { total: 0, completed: 0, percent: 0 };
|
||||
|
||||
const completed = await prisma.lessonProgress.count({
|
||||
where: {
|
||||
userId,
|
||||
completedAt: { not: null },
|
||||
lessonId: { in: lessons.map((l) => l.id) },
|
||||
},
|
||||
});
|
||||
|
||||
const percent = Math.round((completed / total) * 100);
|
||||
return { total, completed, percent };
|
||||
}
|
||||
Reference in New Issue
Block a user