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

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