- Added the ability for a student/developer to choose a gender for a speaking instructor;
- Made it so, if chosen, the user will only get speaking exams with their chosen gender; - Added the ability for speaking exams to select a gender when generating;
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import {collection, getDocs, query, where, setDoc, doc, Firestore} from "firebase/firestore";
|
||||
import {shuffle} from "lodash";
|
||||
import {Exam, Variant} from "@/interfaces/exam";
|
||||
import {Exam, InstructorGender, Variant} from "@/interfaces/exam";
|
||||
import {Stat} from "@/interfaces/user";
|
||||
|
||||
export const getExams = async (
|
||||
@@ -12,22 +12,23 @@ export const getExams = async (
|
||||
// by the teacher that performed the request
|
||||
userId: string | undefined,
|
||||
variant?: Variant,
|
||||
instructorGender?: InstructorGender,
|
||||
): Promise<Exam[]> => {
|
||||
const moduleRef = collection(db, module);
|
||||
|
||||
const q = query(moduleRef, where("isDiagnostic", "==", false));
|
||||
const snapshot = await getDocs(q);
|
||||
|
||||
const exams: Exam[] = filterByVariant(
|
||||
shuffle(
|
||||
snapshot.docs.map((doc) => ({
|
||||
id: doc.id,
|
||||
...doc.data(),
|
||||
module,
|
||||
})),
|
||||
) as Exam[],
|
||||
variant,
|
||||
);
|
||||
const allExams = shuffle(
|
||||
snapshot.docs.map((doc) => ({
|
||||
id: doc.id,
|
||||
...doc.data(),
|
||||
module,
|
||||
})),
|
||||
) as Exam[];
|
||||
|
||||
const variantExams: Exam[] = filterByVariant(allExams, variant);
|
||||
const genderedExams: Exam[] = filterByInstructorGender(variantExams, instructorGender);
|
||||
|
||||
if (avoidRepeated === "true") {
|
||||
const statsQ = query(collection(db, "stats"), where("user", "==", userId));
|
||||
@@ -37,12 +38,18 @@ export const getExams = async (
|
||||
id: doc.id,
|
||||
...doc.data(),
|
||||
})) as unknown as Stat[];
|
||||
const filteredExams = exams.filter((x) => !stats.map((s) => s.exam).includes(x.id));
|
||||
const filteredExams = genderedExams.filter((x) => !stats.map((s) => s.exam).includes(x.id));
|
||||
|
||||
return filteredExams.length > 0 ? filteredExams : exams;
|
||||
return filteredExams.length > 0 ? filteredExams : genderedExams;
|
||||
}
|
||||
|
||||
return exams;
|
||||
return genderedExams;
|
||||
};
|
||||
|
||||
const filterByInstructorGender = (exams: Exam[], instructorGender?: InstructorGender) => {
|
||||
if (!instructorGender || instructorGender === "varied") return exams;
|
||||
|
||||
return exams.filter((e) => (e.module === "speaking" ? e.instructorGender === instructorGender : true));
|
||||
};
|
||||
|
||||
const filterByVariant = (exams: Exam[], variant?: Variant) => {
|
||||
|
||||
Reference in New Issue
Block a user