PDF Report titles are now dynamic
This commit is contained in:
@@ -303,12 +303,6 @@ async function post(req: NextApiRequest, res: NextApiResponse) {
|
||||
);
|
||||
const overallResult = overallScore / overallTotal;
|
||||
|
||||
// generate the performance summary based on the overall result
|
||||
const performanceSummary = getPerformanceSummary(
|
||||
"level",
|
||||
overallResult
|
||||
);
|
||||
|
||||
// generate the overall detail report
|
||||
const overallDetail = {
|
||||
module: "Overall",
|
||||
@@ -319,16 +313,32 @@ async function post(req: NextApiRequest, res: NextApiResponse) {
|
||||
const testDetails = [overallDetail, ...finalResults];
|
||||
|
||||
const [stat] = stats;
|
||||
|
||||
// generate the performance summary based on the overall result
|
||||
const performanceSummary = getPerformanceSummary(
|
||||
stat.module,
|
||||
overallResult
|
||||
);
|
||||
|
||||
// level exams have a different report structure than the skill exams
|
||||
const renderDetails = () => {
|
||||
const getCustomData = () => {
|
||||
if (stat.module === "level") {
|
||||
return <LevelExamDetails detail={overallDetail} />;
|
||||
return {
|
||||
title: "ENGLISH LEVEL TEST RESULT REPORT ",
|
||||
details: <LevelExamDetails detail={overallDetail} />,
|
||||
};
|
||||
}
|
||||
|
||||
return <SkillExamDetails testDetails={testDetails} />;
|
||||
return {
|
||||
title: "ENGLISH SKILLS TEST RESULT REPORT",
|
||||
details: <SkillExamDetails testDetails={testDetails} />,
|
||||
};
|
||||
};
|
||||
|
||||
const { title, details } = getCustomData();
|
||||
const pdfStream = await ReactPDF.renderToStream(
|
||||
<PDFReport
|
||||
title={title}
|
||||
date={new Date(stat.date).toLocaleString()}
|
||||
name={user.name}
|
||||
email={user.email}
|
||||
@@ -336,7 +346,7 @@ async function post(req: NextApiRequest, res: NextApiResponse) {
|
||||
gender={user.demographicInformation?.gender}
|
||||
summary={performanceSummary}
|
||||
testDetails={testDetails}
|
||||
renderDetails={renderDetails()}
|
||||
renderDetails={details}
|
||||
logo={"public/logo_title.png"}
|
||||
qrcode={qrcode}
|
||||
/>
|
||||
|
||||
Reference in New Issue
Block a user