collect-system/apps/server/src/models/lecture/utils.ts

40 lines
913 B
TypeScript
Raw Normal View History

2025-01-27 22:43:22 +08:00
import { db, Lecture } from '@nice/common';
2025-01-03 09:24:46 +08:00
export async function updateSectionLectureStats(sectionId: string) {
2025-01-27 22:43:22 +08:00
const sectionStats = await db.lecture.aggregate({
where: {
sectionId,
deletedAt: null,
},
_count: { _all: true },
_sum: { duration: true },
});
2025-01-03 09:24:46 +08:00
2025-01-27 22:43:22 +08:00
await db.section.update({
where: { id: sectionId },
data: {
// totalLectures: sectionStats._count._all,
// totalDuration: sectionStats._sum.duration || 0,
},
});
2025-01-03 09:24:46 +08:00
}
export async function updateCourseLectureStats(courseId: string) {
2025-01-27 22:43:22 +08:00
const courseStats = await db.lecture.aggregate({
where: {
courseId,
deletedAt: null,
},
_count: { _all: true },
_sum: { duration: true },
});
2025-01-03 09:24:46 +08:00
2025-01-27 22:43:22 +08:00
await db.course.update({
where: { id: courseId },
data: {
//totalLectures: courseStats._count._all,
//totalDuration: courseStats._sum.duration || 0,
},
});
}