Added level to table
This commit is contained in:
@@ -19,11 +19,11 @@ import { ref, uploadBytes } from "firebase/storage";
|
||||
import { Stat } from "@/interfaces/user";
|
||||
import { User } from "@/interfaces/user";
|
||||
import { Module } from "@/interfaces";
|
||||
import { ModuleScore } from "@/interfaces/module.scores";
|
||||
import { ModuleScore, StudentData } from "@/interfaces/module.scores";
|
||||
import qrcode from "qrcode";
|
||||
import { SkillExamDetails } from "@/exams/pdf/details/skill.exam";
|
||||
import { LevelExamDetails } from "@/exams/pdf/details/level.exam";
|
||||
import { calculateBandScore } from "@/utils/score";
|
||||
import { calculateBandScore, getLevelScore } from "@/utils/score";
|
||||
import axios from "axios";
|
||||
import { moduleLabels } from "@/utils/moduleUtils";
|
||||
import {
|
||||
@@ -99,6 +99,17 @@ const getScoreAndTotal = (stats: Stat[]) => {
|
||||
);
|
||||
};
|
||||
|
||||
const getLevelScoreForUserExams = (
|
||||
correct: number,
|
||||
total: number,
|
||||
module: Module,
|
||||
focus: "academic" | "general"
|
||||
) => {
|
||||
const bandScore = calculateBandScore(correct, total, module, focus);
|
||||
const [level] = getLevelScore(bandScore);
|
||||
return level;
|
||||
};
|
||||
|
||||
async function post(req: NextApiRequest, res: NextApiResponse) {
|
||||
// verify if it's a logged user that is trying to export
|
||||
if (req.session.user) {
|
||||
@@ -189,9 +200,11 @@ async function post(req: NextApiRequest, res: NextApiResponse) {
|
||||
overallResult
|
||||
);
|
||||
|
||||
const showLevel = baseStat.module === "level";
|
||||
|
||||
// level exams have a different report structure than the skill exams
|
||||
const getCustomData = () => {
|
||||
if (baseStat.module === "level") {
|
||||
if (showLevel) {
|
||||
return {
|
||||
title: "GROUP ENGLISH LEVEL TEST RESULT REPORT ",
|
||||
details: <LevelExamDetails detail={overallDetail} />,
|
||||
@@ -208,7 +221,7 @@ async function post(req: NextApiRequest, res: NextApiResponse) {
|
||||
|
||||
const numberOfStudents = data.assignees.length;
|
||||
|
||||
const getStudentsData = async () => {
|
||||
const getStudentsData = async (): Promise<StudentData[]> => {
|
||||
// const usersCol = collection(db, "users");
|
||||
const docsSnap = await getDocs(
|
||||
query(
|
||||
@@ -232,10 +245,10 @@ async function post(req: NextApiRequest, res: NextApiResponse) {
|
||||
month: "numeric",
|
||||
day: "numeric",
|
||||
});
|
||||
const result =
|
||||
exams.length === 0
|
||||
? "N/A"
|
||||
: `${exams[0].score.correct}/${exams[0].score.total}`;
|
||||
|
||||
const { correct, total } = getScoreAndTotal(exams);
|
||||
|
||||
const result = exams.length === 0 ? "N/A" : `${correct}/${total}`;
|
||||
|
||||
return {
|
||||
id,
|
||||
@@ -244,6 +257,14 @@ async function post(req: NextApiRequest, res: NextApiResponse) {
|
||||
gender: user?.demographicInformation?.gender || "N/A",
|
||||
date,
|
||||
result,
|
||||
level: showLevel
|
||||
? getLevelScoreForUserExams(
|
||||
correct,
|
||||
total,
|
||||
baseStat.module,
|
||||
user?.focus || "academic"
|
||||
)
|
||||
: "",
|
||||
};
|
||||
});
|
||||
};
|
||||
@@ -266,6 +287,7 @@ async function post(req: NextApiRequest, res: NextApiResponse) {
|
||||
numberOfStudents={numberOfStudents}
|
||||
institution="TODO: PLACEHOLDER"
|
||||
studentsData={studentsData}
|
||||
showLevel={showLevel}
|
||||
/>
|
||||
);
|
||||
|
||||
@@ -290,6 +312,7 @@ async function post(req: NextApiRequest, res: NextApiResponse) {
|
||||
res.status(401).json({ ok: false });
|
||||
return;
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
res.status(500).json({ ok: false });
|
||||
return;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user