From 934394b17fa67d0436cd05da29a4387ca1862f94 Mon Sep 17 00:00:00 2001 From: Joao Ramos Date: Mon, 5 Feb 2024 20:01:50 +0000 Subject: [PATCH 1/3] Added approach to allow versioning of PDFs (Requires env var!) --- src/pages/api/assignments/[id]/export.tsx | 19 ++++++++++++------- src/pages/api/stats/[id]/export.tsx | 13 ++++++++----- 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/src/pages/api/assignments/[id]/export.tsx b/src/pages/api/assignments/[id]/export.tsx index d38be031..91b24506 100644 --- a/src/pages/api/assignments/[id]/export.tsx +++ b/src/pages/api/assignments/[id]/export.tsx @@ -106,18 +106,20 @@ async function post(req: NextApiRequest, res: NextApiResponse) { results: any; exams: {module: Module}[]; startDate: string; - pdf?: string; + pdf: { + path: string, + version: string, + }, }; if (!data) { res.status(400).end(); return; } - if (data.pdf) { + if (data.pdf && data.pdf.path && data.pdf.version === process.env.PDF_VERSION) { // if it does, return the pdf url - const fileRef = ref(storage, data.pdf); + const fileRef = ref(storage, data.pdf.path); const url = await getDownloadURL(fileRef); - res.status(200).end(url); return; } @@ -387,7 +389,10 @@ async function post(req: NextApiRequest, res: NextApiResponse) { // update the stats entries with the pdf url to prevent duplication await updateDoc(docSnap.ref, { - pdf: refName, + pdf: { + path: refName, + version: process.env.PDF_VERSION, + }, }); const url = await getDownloadURL(fileRef); res.status(200).end(url); @@ -419,8 +424,8 @@ async function get(req: NextApiRequest, res: NextApiResponse) { return; } - if (data.pdf) { - const fileRef = ref(storage, data.pdf); + if (data.pdf?.path) { + const fileRef = ref(storage, data.pdf.path); const url = await getDownloadURL(fileRef); return res.redirect(url); } diff --git a/src/pages/api/stats/[id]/export.tsx b/src/pages/api/stats/[id]/export.tsx index 2736bccf..657cb361 100644 --- a/src/pages/api/stats/[id]/export.tsx +++ b/src/pages/api/stats/[id]/export.tsx @@ -125,7 +125,7 @@ async function post(req: NextApiRequest, res: NextApiResponse) { const stats = docsSnap.docs.map((d) => d.data()); // verify if the stats already have a pdf generated - const hasPDF = stats.find((s) => s.pdf); + const hasPDF = stats.find((s) => s.pdf?.path && s.pdf?.version === process.env.PDF_VERSION); // find the user that generated the stats const statIndex = stats.findIndex((s) => s.user); @@ -138,7 +138,7 @@ async function post(req: NextApiRequest, res: NextApiResponse) { if (hasPDF) { // if it does, return the pdf url - const fileRef = ref(storage, hasPDF.pdf); + const fileRef = ref(storage, hasPDF.pdf.path); const url = await getDownloadURL(fileRef); res.status(200).end(url); @@ -305,7 +305,10 @@ async function post(req: NextApiRequest, res: NextApiResponse) { // update the stats entries with the pdf url to prevent duplication docsSnap.docs.forEach(async (doc) => { await updateDoc(doc.ref, { - pdf: refName, + pdf: { + path: refName, + version: process.env.PDF_VERSION, + }, }); }); const url = await getDownloadURL(fileRef); @@ -336,10 +339,10 @@ async function get(req: NextApiRequest, res: NextApiResponse) { const stats = docsSnap.docs.map((d) => d.data()); - const hasPDF = stats.find((s) => s.pdf); + const hasPDF = stats.find((s) => s.pdf?.path); if (hasPDF) { - const fileRef = ref(storage, hasPDF.pdf); + const fileRef = ref(storage, hasPDF.pdf.path); const url = await getDownloadURL(fileRef); return res.redirect(url); } From 044a4f91aa7fcaa69967f0f19167a196674a887c Mon Sep 17 00:00:00 2001 From: Joao Ramos Date: Tue, 6 Feb 2024 19:19:03 +0000 Subject: [PATCH 2/3] Added PDF version to footer --- src/exams/pdf/test.report.footer.tsx | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/src/exams/pdf/test.report.footer.tsx b/src/exams/pdf/test.report.footer.tsx index 1f9f122e..8f6294b7 100644 --- a/src/exams/pdf/test.report.footer.tsx +++ b/src/exams/pdf/test.report.footer.tsx @@ -37,15 +37,7 @@ const TestReportFooter = ({ userId }: Props) => ( - {userId && ( - - - User ID:{" "} - {userId} - - - )} - + Declaration We hereby declare that exam results on our platform, assessed by AI, are @@ -57,6 +49,22 @@ const TestReportFooter = ({ userId }: Props) => ( continuously enhance our system to ensure accuracy and reliability. + + + PDF Version:{" "} + + {process.env.PDF_VERSION} + + + + {userId && ( + + + User ID:{" "} + {userId} + + + )} info@encoach.com https://encoach.com From 870ed57166b516cc29a07f1220b994cf65dec266 Mon Sep 17 00:00:00 2001 From: Joao Ramos Date: Wed, 7 Feb 2024 20:35:30 +0000 Subject: [PATCH 3/3] Swapped the grade for the level on the level display for an exam --- src/exams/Finish.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/exams/Finish.tsx b/src/exams/Finish.tsx index cff00c5a..72190257 100644 --- a/src/exams/Finish.tsx +++ b/src/exams/Finish.tsx @@ -75,7 +75,7 @@ export default function Finish({user, scores, modules, isLoading, onViewResults} const [levelStr, grade] = getLevelScore(level); return (
- {grade} + {levelStr}
); }