add
This commit is contained in:
parent
a47401971e
commit
18d9b5e33c
|
@ -1,39 +1,39 @@
|
||||||
import { db, Lecture } from "@nice/common"
|
import { db, Lecture } from '@nice/common';
|
||||||
|
|
||||||
export async function updateSectionLectureStats(sectionId: string) {
|
export async function updateSectionLectureStats(sectionId: string) {
|
||||||
const sectionStats = await db.lecture.aggregate({
|
const sectionStats = await db.lecture.aggregate({
|
||||||
where: {
|
where: {
|
||||||
sectionId,
|
sectionId,
|
||||||
deletedAt: null
|
deletedAt: null,
|
||||||
},
|
},
|
||||||
_count: { _all: true },
|
_count: { _all: true },
|
||||||
_sum: { duration: true }
|
_sum: { duration: true },
|
||||||
});
|
});
|
||||||
|
|
||||||
await db.section.update({
|
await db.section.update({
|
||||||
where: { id: sectionId },
|
where: { id: sectionId },
|
||||||
data: {
|
data: {
|
||||||
totalLectures: sectionStats._count._all,
|
// totalLectures: sectionStats._count._all,
|
||||||
totalDuration: sectionStats._sum.duration || 0
|
// totalDuration: sectionStats._sum.duration || 0,
|
||||||
}
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function updateCourseLectureStats(courseId: string) {
|
export async function updateCourseLectureStats(courseId: string) {
|
||||||
const courseStats = await db.lecture.aggregate({
|
const courseStats = await db.lecture.aggregate({
|
||||||
where: {
|
where: {
|
||||||
courseId,
|
courseId,
|
||||||
deletedAt: null
|
deletedAt: null,
|
||||||
},
|
},
|
||||||
_count: { _all: true },
|
_count: { _all: true },
|
||||||
_sum: { duration: true }
|
_sum: { duration: true },
|
||||||
});
|
});
|
||||||
|
|
||||||
await db.course.update({
|
await db.course.update({
|
||||||
where: { id: courseId },
|
where: { id: courseId },
|
||||||
data: {
|
data: {
|
||||||
totalLectures: courseStats._count._all,
|
//totalLectures: courseStats._count._all,
|
||||||
totalDuration: courseStats._sum.duration || 0
|
//totalDuration: courseStats._sum.duration || 0,
|
||||||
}
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue