diff --git a/src/pages/assignments/[id].tsx b/src/pages/assignments/[id].tsx index 6ce4e703..e40a0ab6 100644 --- a/src/pages/assignments/[id].tsx +++ b/src/pages/assignments/[id].tsx @@ -2,32 +2,32 @@ import Button from "@/components/Low/Button"; import ProgressBar from "@/components/Low/ProgressBar"; import Modal from "@/components/Modal"; import useUsers from "@/hooks/useUsers"; -import {Module} from "@/interfaces"; -import {Assignment} from "@/interfaces/results"; -import {Group, Stat, User} from "@/interfaces/user"; +import { Module } from "@/interfaces"; +import { Assignment } from "@/interfaces/results"; +import { Group, Stat, User } from "@/interfaces/user"; import useExamStore from "@/stores/examStore"; -import {getExamById} from "@/utils/exams"; -import {sortByModule} from "@/utils/moduleUtils"; -import {calculateBandScore} from "@/utils/score"; -import {convertToUserSolutions} from "@/utils/stats"; -import {getUserName} from "@/utils/users"; +import { getExamById } from "@/utils/exams"; +import { sortByModule } from "@/utils/moduleUtils"; +import { calculateBandScore } from "@/utils/score"; +import { convertToUserSolutions } from "@/utils/stats"; +import { getUserName } from "@/utils/users"; import axios from "axios"; import clsx from "clsx"; -import {capitalize, uniqBy} from "lodash"; +import { capitalize, uniqBy } from "lodash"; import moment from "moment"; -import {useRouter} from "next/router"; -import {BsBook, BsBuilding, BsChevronLeft, BsClipboard, BsHeadphones, BsMegaphone, BsPen} from "react-icons/bs"; -import {toast} from "react-toastify"; -import {futureAssignmentFilter} from "@/utils/assignments"; -import {withIronSessionSsr} from "iron-session/next"; -import {checkAccess, doesEntityAllow} from "@/utils/permissions"; -import {mapBy, redirect, serialize} from "@/utils"; -import {getAssignment} from "@/utils/assignments.be"; -import {getEntitiesUsers, getEntityUsers, getUsers} from "@/utils/users.be"; -import {getEntitiesWithRoles, getEntityWithRoles} from "@/utils/entities.be"; -import {getGroups, getGroupsByEntities, getGroupsByEntity} from "@/utils/groups.be"; -import {sessionOptions} from "@/lib/session"; -import {EntityWithRoles} from "@/interfaces/entity"; +import { useRouter } from "next/router"; +import { BsBook, BsBuilding, BsChevronLeft, BsClipboard, BsHeadphones, BsMegaphone, BsPen } from "react-icons/bs"; +import { toast } from "react-toastify"; +import { futureAssignmentFilter } from "@/utils/assignments"; +import { withIronSessionSsr } from "iron-session/next"; +import { checkAccess, doesEntityAllow } from "@/utils/permissions"; +import { mapBy, redirect, serialize } from "@/utils"; +import { getAssignment } from "@/utils/assignments.be"; +import { getEntitiesUsers, getEntityUsers, getUsers } from "@/utils/users.be"; +import { getEntitiesWithRoles, getEntityWithRoles } from "@/utils/entities.be"; +import { getGroups, getGroupsByEntities, getGroupsByEntity } from "@/utils/groups.be"; +import { sessionOptions } from "@/lib/session"; +import { EntityWithRoles } from "@/interfaces/entity"; import Head from "next/head"; import Layout from "@/components/High/Layout"; import Separator from "@/components/Low/Separator"; @@ -35,7 +35,7 @@ import Link from "next/link"; import { requestUser } from "@/utils/api"; import { useEntityPermission } from "@/hooks/useEntityPermissions"; -export const getServerSideProps = withIronSessionSsr(async ({req, res, params}) => { +export const getServerSideProps = withIronSessionSsr(async ({ req, res, params }) => { const user = await requestUser(req, res) if (!user) return redirect("/login") @@ -44,22 +44,22 @@ export const getServerSideProps = withIronSessionSsr(async ({req, res, params}) res.setHeader("Cache-Control", "public, s-maxage=10, stale-while-revalidate=59"); - const {id} = params as {id: string}; + const { id } = params as { id: string }; const assignment = await getAssignment(id); if (!assignment) return redirect("/assignments") const entity = await getEntityWithRoles(assignment.entity || "") - if (!entity){ + if (!entity) { const users = await getUsers() - return {props: serialize({user, users, assignment})}; + return { props: serialize({ user, users, assignment }) }; } if (!doesEntityAllow(user, entity, 'view_assignments')) return redirect("/assignments") const users = await (checkAccess(user, ["developer", "admin"]) ? getUsers() : getEntityUsers(entity.id)); - return {props: serialize({user, users, entity, assignment})}; + return { props: serialize({ user, users, entity, assignment }) }; }, sessionOptions); interface Props { @@ -69,7 +69,7 @@ interface Props { entity?: EntityWithRoles } -export default function AssignmentView({user, users, entity, assignment}: Props) { +export default function AssignmentView({ user, users, entity, assignment }: Props) { const canDeleteAssignment = useEntityPermission(user, entity, 'delete_assignment') const canStartAssignment = useEntityPermission(user, entity, 'start_assignment') @@ -128,9 +128,9 @@ export default function AssignmentView({user, users, entity, assignment}: Props) return resultModuleBandScores.length === 0 ? -1 : resultModuleBandScores.reduce((acc, curr) => acc + curr, 0) / assignment.results.length; }; - const aggregateScoresByModule = (stats: Stat[]): {module: Module; total: number; missing: number; correct: number}[] => { + const aggregateScoresByModule = (stats: Stat[]): { module: Module; total: number; missing: number; correct: number }[] => { const scores: { - [key in Module]: {total: number; missing: number; correct: number}; + [key in Module]: { total: number; missing: number; correct: number }; } = { reading: { total: 0, @@ -159,7 +159,7 @@ export default function AssignmentView({user, users, entity, assignment}: Props) }, }; - stats.forEach((x) => { + stats.filter(x => !x.isPractice).forEach((x) => { scores[x.module!] = { total: scores[x.module!].total + x.score.total, correct: scores[x.module!].correct + x.score.correct, @@ -169,7 +169,7 @@ export default function AssignmentView({user, users, entity, assignment}: Props) return Object.keys(scores) .filter((x) => scores[x as Module].total > 0) - .map((x) => ({module: x as Module, ...scores[x as Module]})); + .map((x) => ({ module: x as Module, ...scores[x as Module] })); }; const customContent = (stats: Stat[], user: string, focus: "academic" | "general") => { @@ -228,7 +228,7 @@ export default function AssignmentView({user, users, entity, assignment}: Props)