From 63613855fd1c49a449873c305d4726e865501f6d Mon Sep 17 00:00:00 2001 From: John Angel Date: Wed, 11 Mar 2026 14:59:40 +0100 Subject: [PATCH] fix: Count only appointments that were actually attended --- common/certificate/index.ts | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/common/certificate/index.ts b/common/certificate/index.ts index 438254d55..a06380ff8 100644 --- a/common/certificate/index.ts +++ b/common/certificate/index.ts @@ -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: { @@ -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: {