diff --git a/src/dashboards/Corporate/MasterStatisticalPage.tsx b/src/dashboards/Corporate/MasterStatisticalPage.tsx
new file mode 100644
index 00000000..14420ae4
--- /dev/null
+++ b/src/dashboards/Corporate/MasterStatisticalPage.tsx
@@ -0,0 +1,45 @@
+import useUsers, {userHashStudent, userHashTeacher} from "@/hooks/useUsers";
+import {CorporateUser, User} from "@/interfaces/user";
+import {useRouter} from "next/router";
+import {useMemo} from "react";
+import {BsArrowLeft} from "react-icons/bs";
+import MasterStatistical from "../MasterCorporate/MasterStatistical";
+
+interface Props {
+ user: CorporateUser;
+}
+
+const MasterStatisticalPage = ({user}: Props) => {
+ const {users: students} = useUsers(userHashStudent);
+ const {users: teachers} = useUsers(userHashTeacher);
+
+ // this workaround will allow us toreuse the master statistical due to master corporate restraints
+ // while still being able to use the corporate user
+ const groupedByNameCorporateIds = useMemo(
+ () => ({
+ [user.corporateInformation?.companyInformation?.name || user.name]: [user.id],
+ }),
+ [user],
+ );
+
+ const teachersAndStudents = useMemo(() => [...students, ...teachers], [students, teachers]);
+
+ const router = useRouter();
+
+ return (
+ <>
+
diff --git a/src/pages/api/assignments/statistical/excel.ts b/src/pages/api/assignments/statistical/excel.ts
index dcb406c2..7eed838d 100644
--- a/src/pages/api/assignments/statistical/excel.ts
+++ b/src/pages/api/assignments/statistical/excel.ts
@@ -46,15 +46,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;
@@ -80,7 +87,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,
@@ -97,15 +104,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 || [];
@@ -121,7 +131,6 @@ async function post(req: NextApiRequest, res: NextApiResponse) {
total
);
-
console.log("Level", level);
const commonData = {
user: userData?.name || "",
@@ -142,12 +151,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,
@@ -159,9 +170,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();
@@ -176,10 +186,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,