fix
This commit is contained in:
@@ -112,20 +112,32 @@ export const learningAllSchema = z.object({
|
||||
infographic: infographicBodySchema,
|
||||
});
|
||||
|
||||
const quizDifficultyEnum = z.enum(['easy', 'medium', 'hard']);
|
||||
const quizDifficultyEnum = z.enum(['easy', 'medium', 'hard']).catch('medium');
|
||||
|
||||
const quizQuestionSchema = z.object({
|
||||
id: z.string().min(1),
|
||||
id: z.string().min(1).catch(`gen-${Math.random().toString(36).slice(2, 8)}`),
|
||||
question: z.string().min(1),
|
||||
topicLabel: z.string().min(1),
|
||||
topicLabel: z.string().min(1).catch('General'),
|
||||
options: z.array(z.string().min(1)).length(4),
|
||||
correctIndex: z.number().int().min(0).max(3),
|
||||
explanation: z.string().min(1),
|
||||
correctIndex: z.preprocess(
|
||||
(v) => (typeof v === 'number' ? Math.round(v) : v),
|
||||
z.number().int().min(0).max(3),
|
||||
),
|
||||
explanation: z.string().min(1).catch('See the correct answer above.'),
|
||||
difficulty: quizDifficultyEnum,
|
||||
});
|
||||
|
||||
export const quizQuestionsSchema = z.object({
|
||||
questions: z.array(quizQuestionSchema).min(1),
|
||||
questions: z.preprocess(
|
||||
(v) => {
|
||||
// If the model returned an array directly, wrap it
|
||||
if (Array.isArray(v)) return v;
|
||||
// If it returned a single object, wrap in array
|
||||
if (v && typeof v === 'object' && !Array.isArray(v)) return [v];
|
||||
return v;
|
||||
},
|
||||
z.array(quizQuestionSchema).min(1),
|
||||
),
|
||||
});
|
||||
|
||||
export const customTopicSchema = z.object({
|
||||
|
||||
Reference in New Issue
Block a user