Merged in feature-pdf-version (pull request #31)
PDF Versioning Approved-by: Tiago Ribeiro
This commit is contained in:
@@ -37,15 +37,7 @@ const TestReportFooter = ({ userId }: Props) => (
|
|||||||
</Text>
|
</Text>
|
||||||
</View>
|
</View>
|
||||||
</View>
|
</View>
|
||||||
{userId && (
|
|
||||||
<View>
|
<View>
|
||||||
<Text style={styles.textBold}>
|
|
||||||
User ID:{" "}
|
|
||||||
<Text style={[styles.textFont, styles.textNormal]}>{userId}</Text>
|
|
||||||
</Text>
|
|
||||||
</View>
|
|
||||||
)}
|
|
||||||
<View style={{ paddingTop: 4 }}>
|
|
||||||
<Text style={styles.textBold}>Declaration</Text>
|
<Text style={styles.textBold}>Declaration</Text>
|
||||||
<Text style={{ paddingTop: 5 }}>
|
<Text style={{ paddingTop: 5 }}>
|
||||||
We hereby declare that exam results on our platform, assessed by AI, are
|
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.
|
continuously enhance our system to ensure accuracy and reliability.
|
||||||
</Text>
|
</Text>
|
||||||
</View>
|
</View>
|
||||||
|
<View style={{ paddingTop: 4 }}>
|
||||||
|
<Text style={styles.textBold}>
|
||||||
|
PDF Version:{" "}
|
||||||
|
<Text style={[styles.textFont, styles.textNormal]}>
|
||||||
|
{process.env.PDF_VERSION}
|
||||||
|
</Text>
|
||||||
|
</Text>
|
||||||
|
</View>
|
||||||
|
{userId && (
|
||||||
|
<View>
|
||||||
|
<Text style={styles.textBold}>
|
||||||
|
User ID:{" "}
|
||||||
|
<Text style={[styles.textFont, styles.textNormal]}>{userId}</Text>
|
||||||
|
</Text>
|
||||||
|
</View>
|
||||||
|
)}
|
||||||
<View style={[styles.textColor, { paddingTop: 5 }]}>
|
<View style={[styles.textColor, { paddingTop: 5 }]}>
|
||||||
<Text style={styles.textUnderline}>info@encoach.com</Text>
|
<Text style={styles.textUnderline}>info@encoach.com</Text>
|
||||||
<Text>https://encoach.com</Text>
|
<Text>https://encoach.com</Text>
|
||||||
|
|||||||
@@ -106,18 +106,20 @@ async function post(req: NextApiRequest, res: NextApiResponse) {
|
|||||||
results: any;
|
results: any;
|
||||||
exams: {module: Module}[];
|
exams: {module: Module}[];
|
||||||
startDate: string;
|
startDate: string;
|
||||||
pdf?: string;
|
pdf: {
|
||||||
|
path: string,
|
||||||
|
version: string,
|
||||||
|
},
|
||||||
};
|
};
|
||||||
if (!data) {
|
if (!data) {
|
||||||
res.status(400).end();
|
res.status(400).end();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (data.pdf) {
|
if (data.pdf && data.pdf.path && data.pdf.version === process.env.PDF_VERSION) {
|
||||||
// if it does, return the pdf url
|
// 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);
|
const url = await getDownloadURL(fileRef);
|
||||||
|
|
||||||
res.status(200).end(url);
|
res.status(200).end(url);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -387,7 +389,10 @@ async function post(req: NextApiRequest, res: NextApiResponse) {
|
|||||||
|
|
||||||
// update the stats entries with the pdf url to prevent duplication
|
// update the stats entries with the pdf url to prevent duplication
|
||||||
await updateDoc(docSnap.ref, {
|
await updateDoc(docSnap.ref, {
|
||||||
pdf: refName,
|
pdf: {
|
||||||
|
path: refName,
|
||||||
|
version: process.env.PDF_VERSION,
|
||||||
|
},
|
||||||
});
|
});
|
||||||
const url = await getDownloadURL(fileRef);
|
const url = await getDownloadURL(fileRef);
|
||||||
res.status(200).end(url);
|
res.status(200).end(url);
|
||||||
@@ -419,8 +424,8 @@ async function get(req: NextApiRequest, res: NextApiResponse) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (data.pdf) {
|
if (data.pdf?.path) {
|
||||||
const fileRef = ref(storage, data.pdf);
|
const fileRef = ref(storage, data.pdf.path);
|
||||||
const url = await getDownloadURL(fileRef);
|
const url = await getDownloadURL(fileRef);
|
||||||
return res.redirect(url);
|
return res.redirect(url);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -125,7 +125,7 @@ async function post(req: NextApiRequest, res: NextApiResponse) {
|
|||||||
|
|
||||||
const stats = docsSnap.docs.map((d) => d.data());
|
const stats = docsSnap.docs.map((d) => d.data());
|
||||||
// verify if the stats already have a pdf generated
|
// 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
|
// find the user that generated the stats
|
||||||
const statIndex = stats.findIndex((s) => s.user);
|
const statIndex = stats.findIndex((s) => s.user);
|
||||||
|
|
||||||
@@ -138,7 +138,7 @@ async function post(req: NextApiRequest, res: NextApiResponse) {
|
|||||||
|
|
||||||
if (hasPDF) {
|
if (hasPDF) {
|
||||||
// if it does, return the pdf url
|
// 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);
|
const url = await getDownloadURL(fileRef);
|
||||||
|
|
||||||
res.status(200).end(url);
|
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
|
// update the stats entries with the pdf url to prevent duplication
|
||||||
docsSnap.docs.forEach(async (doc) => {
|
docsSnap.docs.forEach(async (doc) => {
|
||||||
await updateDoc(doc.ref, {
|
await updateDoc(doc.ref, {
|
||||||
pdf: refName,
|
pdf: {
|
||||||
|
path: refName,
|
||||||
|
version: process.env.PDF_VERSION,
|
||||||
|
},
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
const url = await getDownloadURL(fileRef);
|
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 stats = docsSnap.docs.map((d) => d.data());
|
||||||
|
|
||||||
const hasPDF = stats.find((s) => s.pdf);
|
const hasPDF = stats.find((s) => s.pdf?.path);
|
||||||
|
|
||||||
if (hasPDF) {
|
if (hasPDF) {
|
||||||
const fileRef = ref(storage, hasPDF.pdf);
|
const fileRef = ref(storage, hasPDF.pdf.path);
|
||||||
const url = await getDownloadURL(fileRef);
|
const url = await getDownloadURL(fileRef);
|
||||||
return res.redirect(url);
|
return res.redirect(url);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user