Added the ability for some exams to be private and not chosen randomly

This commit is contained in:
Tiago Ribeiro
2024-08-28 10:17:01 +01:00
parent 7960e7d8fb
commit 951ca5736e
2 changed files with 20 additions and 24 deletions

View File

@@ -15,6 +15,7 @@ interface ExamBase {
shuffle?: boolean; shuffle?: boolean;
createdBy?: string; // option as it has been added later createdBy?: string; // option as it has been added later
createdAt?: string; // option as it has been added later createdAt?: string; // option as it has been added later
private?: boolean;
} }
export interface ReadingExam extends ExamBase { export interface ReadingExam extends ExamBase {
module: "reading"; module: "reading";
@@ -67,7 +68,7 @@ export interface UserSolution {
}; };
exercise: string; exercise: string;
isDisabled?: boolean; isDisabled?: boolean;
shuffleMaps?: ShuffleMap[] shuffleMaps?: ShuffleMap[];
} }
export interface WritingExam extends ExamBase { export interface WritingExam extends ExamBase {
@@ -103,7 +104,6 @@ export interface Evaluation {
misspelled_pairs?: {correction: string | null; misspelled: string}[]; misspelled_pairs?: {correction: string | null; misspelled: string}[];
} }
type InteractivePerfectAnswerKey = `perfect_answer_${number}`; type InteractivePerfectAnswerKey = `perfect_answer_${number}`;
type InteractiveTranscriptKey = `transcript_${number}`; type InteractiveTranscriptKey = `transcript_${number}`;
type InteractiveFixedTextKey = `fixed_text_${number}`; type InteractiveFixedTextKey = `fixed_text_${number}`;
@@ -112,11 +112,7 @@ type InteractivePerfectAnswerType = { [key in InteractivePerfectAnswerKey]: { an
type InteractiveTranscriptType = {[key in InteractiveTranscriptKey]?: string}; type InteractiveTranscriptType = {[key in InteractiveTranscriptKey]?: string};
type InteractiveFixedTextType = {[key in InteractiveFixedTextKey]?: string}; type InteractiveFixedTextType = {[key in InteractiveFixedTextKey]?: string};
interface InteractiveSpeakingEvaluation extends Evaluation, interface InteractiveSpeakingEvaluation extends Evaluation, InteractivePerfectAnswerType, InteractiveTranscriptType, InteractiveFixedTextType {}
InteractivePerfectAnswerType,
InteractiveTranscriptType,
InteractiveFixedTextType { }
interface SpeakingEvaluation extends CommonEvaluation { interface SpeakingEvaluation extends CommonEvaluation {
perfect_answer_1?: string; perfect_answer_1?: string;
@@ -208,7 +204,7 @@ export interface FillBlanksMCOption {
B: string; B: string;
C: string; C: string;
D: string; D: string;
} };
} }
export interface FillBlanksExercise { export interface FillBlanksExercise {
@@ -306,10 +302,10 @@ export interface ShuffleMap {
questionID: string; questionID: string;
map: { map: {
[key: string]: string; [key: string]: string;
} };
} }
export interface Shuffles { export interface Shuffles {
exerciseID: string; exerciseID: string;
shuffles: ShuffleMap[] shuffles: ShuffleMap[];
} }

View File

@@ -1,4 +1,4 @@
import {collection, getDocs, query, where, setDoc, doc, Firestore, getDoc} from "firebase/firestore"; import {collection, getDocs, query, where, setDoc, doc, Firestore, getDoc, and} from "firebase/firestore";
import {shuffle} from "lodash"; import {shuffle} from "lodash";
import {Difficulty, Exam, InstructorGender, SpeakingExam, Variant, WritingExam} from "@/interfaces/exam"; import {Difficulty, Exam, InstructorGender, SpeakingExam, Variant, WritingExam} from "@/interfaces/exam";
import {DeveloperUser, Stat, StudentUser, User} from "@/interfaces/user"; import {DeveloperUser, Stat, StudentUser, User} from "@/interfaces/user";
@@ -17,7 +17,7 @@ export const getExams = async (
): Promise<Exam[]> => { ): Promise<Exam[]> => {
const moduleRef = collection(db, module); const moduleRef = collection(db, module);
const q = query(moduleRef, where("isDiagnostic", "==", false)); const q = query(moduleRef, and(where("isDiagnostic", "==", false), where("private", "!=", true)));
const snapshot = await getDocs(q); const snapshot = await getDocs(q);
const allExams = shuffle( const allExams = shuffle(