fix(api): fix api endpoint logic #6

This commit is contained in:
Dacca Retro
2025-08-18 17:48:32 +06:00
parent 58d4d14a51
commit d74b81e962
5 changed files with 306 additions and 206 deletions

77
types/exam.d.ts vendored
View File

@ -1,55 +1,62 @@
export interface Question {
id: string;
question: string;
options?: Record<string, string>;
type: "multiple-choice" | "text" | "boolean" | undefined;
correctAnswer: string | undefined;
solution?: string | undefined;
export type Metadata = {
test_id: string;
total_possible_score: number;
deduction: number;
num_questions: number;
name: string;
start_time: Date;
time_limit_minutes: number;
}
export interface Exam {
id: string;
title: string;
description: string;
export type Question = {
question_id: string;
question: string;
options: string[];
type: string;
}
export interface Test {
metadata: Metadata;
questions: Question[];
timeLimit?: number;
passingScore?: number;
}
export interface ExamAnswer {
questionId: string;
answer: string;
timestamp: Date;
}
type Answers = number | null;
export interface ExamAttempt {
examId: string;
exam: Exam;
answers: ExamAnswer[];
startTime: Date;
endTime?: Date;
score: number;
passed?: boolean;
apiResponse?: any;
totalQuestions: number;
export interface TestAttempt {
user_id: string;
test_id: string;
attempt_id: string;
start_time: Date;
end_time: Date;
user_questions: {
question_id: string;
question: string;
options: string[];
type: string;
};
user_answers: Record<string, Answers>;
correct_answers: Record<string, Answers>;
correct_answers_count: number;
wrong_answers_count: number;
skipped_questions_count: number;
}
export interface ExamContextType {
currentExam: Exam | null;
currentAttempt: ExamAttempt | null;
currentExam: Test | null;
currentAttempt: TestAttempt | null;
isHydrated: boolean;
isInitialized: boolean;
// Actions
setCurrentExam: (exam: Exam) => void;
startExam: (exam?: Exam) => void;
setAnswer: (questionId: string, answer: any) => void;
submitExam: () => ExamAttempt | null;
setCurrentExam: (exam: Test) => void;
startExam: (exam?: Test) => void;
setAnswer: (questionId: string, answer: Answers) => void;
submitExam: () => TestAttempt | null;
clearExam: () => void;
setApiResponse: (response: any) => void;
// Getters
getAnswer: (questionId: string) => any;
getAnswer: (questionId: string) => Answers;
getProgress: () => number;
isExamStarted: () => boolean;
isExamCompleted: () => boolean;