Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Instant Certs: only count lectures that are in the past, add date variable, friendly date formatting #1185

Merged
merged 5 commits into from
Jan 17, 2025
Merged
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
10 changes: 7 additions & 3 deletions common/certificate/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ 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: { match: { studentId: requester.id } } });
const matchAppointmentsCountPromise = prisma.lecture.count({ where: { match: { studentId: requester.id }, start: { lt: new Date() } } });
const uniqueCourseParticipantsPromise = prisma.subcourse_participants_pupil.groupBy({
by: ['pupilId'],
where: {
Expand All @@ -103,10 +103,12 @@ export async function createInstantCertificate(requester: Student, lang: Languag
cancelled: false,
subcourse_instructors_student: { some: { studentId: requester.id } },
},
start: { lt: new Date() },
},
});
const totalAppointmentsDurationPromise = prisma.lecture.aggregate({
where: {
start: { lt: new Date() },
OR: [
{
subcourse: {
Expand Down Expand Up @@ -251,12 +253,13 @@ export async function getConfirmationPage(certificateId: string, lang: Language,
const verificationTemplate = loadTemplate('verifiedInstantCertificatePage', lang);
return verificationTemplate({
NAMESTUDENT: certificate.student?.firstname + ' ' + certificate.student?.lastname,
STARTDATE: certificate.startDate,
STARTDATE: moment(certificate.startDate).format('D.M.YYYY'),
MATCHES_COUNT: certificate.matchesCount,
MATCH_APPOINTMENTS_COUNT: certificate.matchAppointmentsCount,
COURSE_PARTICIPANTS_COUNT: certificate.courseParticipantsCount,
COURSE_APPOINTMENTS_COUNT: certificate.courseAppointmentsCount,
TOTAL_APPOINTMENTS_DURATION: certificate.totalAppointmentsDuration,
DATUMHEUTE: moment(certificate.createdAt).format('D.M.YYYY'),
});
}
}
Expand Down Expand Up @@ -456,12 +459,13 @@ async function createInstantPDFBinary(certificate: InstantCertificate & { studen
}
const result = template({
NAMESTUDENT: name,
STARTDATE: certificate.startDate,
STARTDATE: moment(certificate.startDate).format('D.M.YYYY'),
MATCHES_COUNT: certificate.matchesCount,
MATCH_APPOINTMENTS_COUNT: certificate.matchAppointmentsCount,
COURSE_PARTICIPANTS_COUNT: certificate.courseParticipantsCount,
COURSE_APPOINTMENTS_COUNT: certificate.courseAppointmentsCount,
TOTAL_APPOINTMENTS_DURATION: certificate.totalAppointmentsDuration,
DATUMHEUTE: moment().format('D.M.YYYY'),
QR_CODE: await QRCode.toDataURL(link),
});
return await generatePDFFromHTML(result, {
Expand Down
Loading