ENCOA-277, ENCOA-276, ENCOA-282, ENCOA-283

This commit is contained in:
Carlos-Mesquita
2024-12-21 19:23:53 +00:00
parent f6d387ce2d
commit 98a1636d0c
31 changed files with 2513 additions and 194 deletions

View File

@@ -1,6 +1,6 @@
import { collection, getDocs, query, where, setDoc, doc, Firestore, getDoc, and } from "firebase/firestore";
import { groupBy, shuffle } from "lodash";
import { Difficulty, Exam, InstructorGender, SpeakingExam, Variant, WritingExam } from "@/interfaces/exam";
import { CEFRLevels, Difficulty, Exam, InstructorGender, SpeakingExam, Variant, WritingExam } from "@/interfaces/exam";
import { DeveloperUser, Stat, StudentUser, User } from "@/interfaces/user";
import { Module } from "@/interfaces";
import { getCorporateUser } from "@/resources/user";
@@ -128,9 +128,42 @@ const filterByDifficulty = async (db: Db, exams: Exam[], module: Module, userID?
const user = await db.collection("users").findOne<User>({ id: userID });
if (!user) return exams;
const difficulty = user.levels[module] <= 3 ? "easy" : user.levels[module] <= 6 ? "medium" : "hard";
const basicDifficulty = user.levels[module] <= 3 ? "easy" : user.levels[module] <= 6 ? "medium" : "hard";
let CEFRLevel: CEFRLevels;
// Adjust the levels if necessary
switch (user.levels[module]) {
case 1:
case 2:
CEFRLevel = "A1";
break;
case 3:
case 4:
CEFRLevel = "A2";
break;
case 4:
case 5:
CEFRLevel = "B1";
break;
case 6:
CEFRLevel = "B2";
break;
case 7:
case 8:
CEFRLevel = "C1";
break;
case 9:
CEFRLevel = "C2";
break;
default:
CEFRLevel = "B1";
}
const filteredExams = exams.filter((exam) =>
exam.difficulty === basicDifficulty || exam.difficulty === CEFRLevel
);
const filteredExams = exams.filter((exam) => exam.difficulty === difficulty);
return filteredExams.length === 0 ? exams : filteredExams;
};