@@ -2,13 +2,26 @@ import { z } from 'zod';
22import db from '@/lib/db' ; // Import db
33
44// Schema for the data structure stored in the quiz table's content column
5- // This should align with PartialQuizData or QuizData from domain schemas
5+ // This should align with the actual structure generated by AI and expected by QuizDataSchema
66export const QuizContentSchema = z . object ( {
7- passage : z . string ( ) ,
7+ paragraph : z . string ( ) , // Changed from passage
8+ topic : z . string ( ) . optional ( ) . nullable ( ) , // Added optional topic
89 question : z . string ( ) ,
9- options : z . object ( { A : z . string ( ) , B : z . string ( ) , C : z . string ( ) , D : z . string ( ) } ) ,
10- answer : z . string ( ) , // The correct option key (e.g., 'A')
11- explanation : z . string ( ) ,
10+ options : z . object ( {
11+ A : z . string ( ) ,
12+ B : z . string ( ) ,
13+ C : z . string ( ) ,
14+ D : z . string ( ) ,
15+ } ) ,
16+ correctAnswer : z . string ( ) , // Changed from answer
17+ allExplanations : z . object ( {
18+ // Changed from explanation: string
19+ A : z . string ( ) ,
20+ B : z . string ( ) ,
21+ C : z . string ( ) ,
22+ D : z . string ( ) ,
23+ } ) ,
24+ relevantText : z . string ( ) . optional ( ) . nullable ( ) , // Added optional relevantText
1225} ) ;
1326
1427// Schema for the raw row returned by the database
@@ -33,9 +46,12 @@ export type Quiz = z.infer<typeof QuizSchema>;
3346
3447// Finds a quiz by its ID
3548export const findQuizById = ( id : number ) : Quiz | null => {
49+ // console.log(`[QuizRepository:findQuizById] Attempting to find quiz with ID: ${id}`);
3650 try {
3751 const row = db . prepare ( 'SELECT * FROM quiz WHERE id = ?' ) . get ( id ) as QuizRow | undefined ;
52+ // console.log('[QuizRepository:findQuizById] Raw row from DB:', row);
3853 if ( ! row ) {
54+ // console.log(`[QuizRepository:findQuizById] No row found for ID: ${id}`);
3955 return null ;
4056 }
4157 // Validate the base row structure
0 commit comments