fix(api): fix exam screen api logic

This commit is contained in:
shafin-r
2025-08-27 23:45:37 +06:00
parent 84bc192e02
commit 08a560abe5
4 changed files with 143 additions and 203 deletions

55
types/exam.d.ts vendored
View File

@ -1,32 +1,20 @@
export interface Metadata {
attempt_id: string;
test_id: string;
type: string;
total_possible_score: number;
deduction: string;
deduction?: string;
num_questions: number;
name: string;
start_time: Date;
time_limit_minutes: number;
}
export interface MockMeta extends Metadata {
test_id: string;
}
export interface SubjectMeta extends Metadata {
subject_id: string;
subject_name: string;
}
export interface TopicMeta extends Metadata {
topic_id: string;
topic_name: string;
start_time: string; // keep ISO string for consistency
time_limit_minutes?: number;
}
export type Question = {
question_id: string;
question: string;
options: string[];
type: string;
type: "Single" | "Multiple";
};
export interface Test {
@ -34,28 +22,27 @@ export interface Test {
questions: Question[];
}
type Answers = number | null;
export type Answer = number | null;
export type AnswersMap = Record<string, Answer>;
export interface TestAttempt {
user_id: string;
user_id: string | undefined;
test_id: string;
subject_id: string;
topic_id: string;
test_type: "Subject" | "Topic" | "Mock" | "Past";
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>;
start_time: string;
end_time: string;
user_questions: Question[];
user_answers: (number | null)[];
correct_answers: number[];
correct_answers_count: number;
wrong_answers_count: number;
skipped_questions_count: number;
}
export interface ExamContextType {
export interface TestContextType {
currentExam: Test | null;
currentAttempt: TestAttempt | null;
isHydrated: boolean;
@ -64,13 +51,13 @@ export interface ExamContextType {
// Actions
setCurrentExam: (exam: Test) => void;
startExam: (exam?: Test) => void;
setAnswer: (questionId: string, answer: Answers) => void;
submitExam: () => TestAttempt | null;
setAnswer: (questionId: string, answer: Answer) => void;
submitExam: () => TestAttempt | null; // or Promise<TestAttempt | null> if API
clearExam: () => void;
setApiResponse: (response: any) => void;
// Getters
getAnswer: (questionId: string) => Answers;
getAnswer: (questionId: string) => Answer;
getProgress: () => number;
isExamStarted: () => boolean;
isExamCompleted: () => boolean;