ENCOA-200: Added Master Statistical to Corporate
This commit is contained in:
@@ -49,15 +49,22 @@ async function post(req: NextApiRequest, res: NextApiResponse) {
|
||||
// verify if it's a logged user that is trying to export
|
||||
if (req.session.user) {
|
||||
if (
|
||||
!checkAccess(req.session.user, ["mastercorporate", "developer", "admin"])
|
||||
!checkAccess(req.session.user, ["mastercorporate", "corporate", "developer", "admin"])
|
||||
) {
|
||||
return res.status(401).json({ error: "Unauthorized" });
|
||||
return res.status(403).json({ error: "Unauthorized" });
|
||||
}
|
||||
const { ids, startDate, endDate, searchText } = req.body as {
|
||||
const {
|
||||
ids,
|
||||
startDate,
|
||||
endDate,
|
||||
searchText,
|
||||
displaySelection = true,
|
||||
} = req.body as {
|
||||
ids: string[];
|
||||
startDate?: string;
|
||||
endDate?: string;
|
||||
searchText: string;
|
||||
displaySelection?: boolean;
|
||||
};
|
||||
const startDateParsed = startDate ? new Date(startDate) : undefined;
|
||||
const endDateParsed = endDate ? new Date(endDate) : undefined;
|
||||
@@ -83,7 +90,7 @@ async function post(req: NextApiRequest, res: NextApiResponse) {
|
||||
);
|
||||
|
||||
const getGradingSystemHelper = (
|
||||
exams: {id: string; module: Module; assignee: string}[],
|
||||
exams: { id: string; module: Module; assignee: string }[],
|
||||
assigner: string,
|
||||
user: User,
|
||||
correct: number,
|
||||
@@ -100,15 +107,18 @@ async function post(req: NextApiRequest, res: NextApiResponse) {
|
||||
"level",
|
||||
user.focus
|
||||
);
|
||||
return { label: getGradingLabel(bandScore, gradingSystem?.steps || []), score: bandScore };
|
||||
return {
|
||||
label: getGradingLabel(bandScore, gradingSystem?.steps || []),
|
||||
score: bandScore,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
return { score: -1, label: "N/A" };
|
||||
};
|
||||
|
||||
const tableResults = assignments.reduce(
|
||||
(accmA: TableData[], a: AssignmentWithCorporateId) => {
|
||||
const tableResults = assignments
|
||||
.reduce((accmA: TableData[], a: AssignmentWithCorporateId) => {
|
||||
const userResults = a.assignees.map((assignee) => {
|
||||
const userStats =
|
||||
a.results.find((r) => r.user === assignee)?.stats || [];
|
||||
@@ -124,7 +134,6 @@ async function post(req: NextApiRequest, res: NextApiResponse) {
|
||||
total
|
||||
);
|
||||
|
||||
|
||||
console.log("Level", level);
|
||||
const commonData = {
|
||||
user: userData?.name || "",
|
||||
@@ -145,12 +154,14 @@ async function post(req: NextApiRequest, res: NextApiResponse) {
|
||||
};
|
||||
}
|
||||
|
||||
const partsData = userStats.every((e) => e.module === "level") ? userStats.reduce((acc, e, index) => {
|
||||
return {
|
||||
...acc,
|
||||
[`part${index}`]: `${e.score.correct}/${e.score.total}`
|
||||
}
|
||||
}, {}) : {};
|
||||
const partsData = userStats.every((e) => e.module === "level")
|
||||
? userStats.reduce((acc, e, index) => {
|
||||
return {
|
||||
...acc,
|
||||
[`part${index}`]: `${e.score.correct}/${e.score.total}`,
|
||||
};
|
||||
}, {})
|
||||
: {};
|
||||
|
||||
return {
|
||||
...commonData,
|
||||
@@ -162,9 +173,8 @@ async function post(req: NextApiRequest, res: NextApiResponse) {
|
||||
}) as TableData[];
|
||||
|
||||
return [...accmA, ...userResults];
|
||||
},
|
||||
[]
|
||||
).sort((a,b) => b.score - a.score);
|
||||
}, [])
|
||||
.sort((a, b) => b.score - a.score);
|
||||
|
||||
// Create a new workbook and add a worksheet
|
||||
const workbook = new ExcelJS.Workbook();
|
||||
@@ -179,10 +189,14 @@ async function post(req: NextApiRequest, res: NextApiResponse) {
|
||||
label: "Email",
|
||||
value: (entry: TableData) => entry.email,
|
||||
},
|
||||
{
|
||||
label: "Corporate",
|
||||
value: (entry: TableData) => entry.corporate,
|
||||
},
|
||||
...(displaySelection
|
||||
? [
|
||||
{
|
||||
label: "Corporate",
|
||||
value: (entry: TableData) => entry.corporate,
|
||||
},
|
||||
]
|
||||
: []),
|
||||
{
|
||||
label: "Assignment",
|
||||
value: (entry: TableData) => entry.assignment,
|
||||
|
||||
Reference in New Issue
Block a user