Removed ID and improved unknown user handling

This commit is contained in:
Joao Ramos
2024-01-09 18:25:00 +00:00
parent bdf65a7215
commit f8bf58e57c
2 changed files with 21 additions and 32 deletions

View File

@@ -7,14 +7,14 @@ import {
Text, Text,
Image, Image,
StyleSheet, StyleSheet,
Font,
} from "@react-pdf/renderer"; } from "@react-pdf/renderer";
import { styles } from "./styles"; import { styles } from "./styles";
import TestReportFooter from "./test.report.footer"; import TestReportFooter from "./test.report.footer";
import { ModuleScore } from "@/interfaces/module.scores"; import { ModuleScore } from "@/interfaces/module.scores";
import ProgressBar from "./progress.bar"; import ProgressBar from "./progress.bar";
// import { Font } from "@react-pdf/renderer";
// Font.registerHyphenationCallback((word) => [word]); Font.registerHyphenationCallback((word) => [word]);
interface Props { interface Props {
date: string; date: string;
@@ -220,7 +220,6 @@ const GroupTestReport = ({
<Text style={customStyles.tableCell}>Date of test</Text> <Text style={customStyles.tableCell}>Date of test</Text>
<Text style={customStyles.tableCell}>Result</Text> <Text style={customStyles.tableCell}>Result</Text>
<Text style={customStyles.tableCell}>Level</Text> <Text style={customStyles.tableCell}>Level</Text>
<Text style={customStyles.tableCell}>ID</Text>
</View> </View>
{studentsData.map( {studentsData.map(
({ id, name, email, gender, date, result, level }, index) => ( ({ id, name, email, gender, date, result, level }, index) => (
@@ -239,7 +238,6 @@ const GroupTestReport = ({
<Text style={customStyles.tableCell}>{date}</Text> <Text style={customStyles.tableCell}>{date}</Text>
<Text style={customStyles.tableCell}>{result}</Text> <Text style={customStyles.tableCell}>{result}</Text>
<Text style={customStyles.tableCell}>{level}</Text> <Text style={customStyles.tableCell}>{level}</Text>
<Text style={customStyles.tableCell}>{id}</Text>
</View> </View>
) )
)} )}

View File

@@ -223,36 +223,27 @@ async function post(req: NextApiRequest, res: NextApiResponse) {
return data.assignees.map((id) => { return data.assignees.map((id) => {
const user = users.find((u) => u.id === id); const user = users.find((u) => u.id === id);
if (user) {
const exams = flattenResults.filter((e) => e.user === id); const exams = flattenResults.filter((e) => e.user === id);
return { const date =
id,
name: user.name,
email: user.email,
gender: user.demographicInformation?.gender,
date:
exams.length === 0 exams.length === 0
? "N/A" ? "N/A"
: new Date(exams[0].date).toLocaleDateString(undefined, { : new Date(exams[0].date).toLocaleDateString(undefined, {
year: "numeric", year: "numeric",
month: "numeric", month: "numeric",
day: "numeric", day: "numeric",
}), });
result: const result =
exams.length === 0 exams.length === 0
? "N/A" ? "N/A"
: `${exams[0].score.correct}/${exams[0].score.total}`, : `${exams[0].score.correct}/${exams[0].score.total}`;
};
}
return { return {
id: "N/A", id,
name: "N/A", name: user?.name || "N/A",
email: "N/A", email: user?.email || "N/A",
gender: "N/A", gender: user?.demographicInformation?.gender || "N/A",
date: "N/A", date,
result: "N/A", result,
}; };
}); });
}; };