Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 12 additions & 10 deletions common/certificate/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,9 @@ export async function getCertificatePDF(certificateId: string, requestor: Studen

export async function createInstantCertificate(requester: Student, lang: Language): Promise<{ pdf: Buffer; certificate: InstantCertificate }> {
const matchesCountPromise = prisma.match.count({ where: { studentId: requester.id } });
const matchAppointmentsCountPromise = prisma.lecture.count({ where: { isCanceled: false, match: { studentId: requester.id }, start: { lt: new Date() } } });
const matchAppointmentsCountPromise = prisma.lecture.findMany({
where: { isCanceled: false, match: { studentId: requester.id }, start: { lt: new Date() }, joinedBy: { has: userForStudent(requester).userID } },
});
const uniqueCourseParticipantsPromise = prisma.subcourse_participants_pupil.groupBy({
by: ['pupilId'],
where: {
Expand Down Expand Up @@ -134,16 +136,16 @@ export async function createInstantCertificate(requester: Student, lang: Languag
_sum: { duration: true },
});

const [matchesCount, matchAppointmentsCount, courseParticipants, courseAppointmentsCount, totalAppointmentsDuration, homeworkHelpDuration] =
await Promise.all([
matchesCountPromise,
matchAppointmentsCountPromise,
uniqueCourseParticipantsPromise,
courseAppointmentsCountPromise,
totalAppointmentsDurationPromise,
homeworkHelpDurationPromise,
]);
const [matchesCount, matchAppointments, courseParticipants, courseAppointmentsCount, totalAppointmentsDuration, homeworkHelpDuration] = await Promise.all([
matchesCountPromise,
matchAppointmentsCountPromise,
uniqueCourseParticipantsPromise,
courseAppointmentsCountPromise,
totalAppointmentsDurationPromise,
homeworkHelpDurationPromise,
]);
const courseParticipantsCount = courseParticipants.length;
const matchAppointmentsCount = matchAppointments.filter((lecture) => lecture.joinedBy.length > 1).length;

const certificate = await prisma.instant_certificate.create({
data: {
Expand Down
Loading