Some checks failed
Automated Container Build / build-and-push (push) Failing after 7s
48 lines
1.3 KiB
TypeScript
48 lines
1.3 KiB
TypeScript
import { z } from "zod";
|
|
|
|
const optionSchema = z.object({
|
|
text: z.string().min(1),
|
|
correct: z.boolean(),
|
|
});
|
|
|
|
const questionSchema = z
|
|
.object({
|
|
type: z.enum(["multiple_choice", "sata"]),
|
|
prompt: z.string().min(1),
|
|
rationale: z.string().min(1),
|
|
category: z.string().min(1),
|
|
options: z.array(optionSchema).min(2),
|
|
})
|
|
.refine((q) => q.options.filter((o) => o.correct).length >= 1, {
|
|
message: "Each question needs at least one correct option",
|
|
})
|
|
.refine(
|
|
(q) =>
|
|
q.type !== "multiple_choice" ||
|
|
q.options.filter((o) => o.correct).length === 1,
|
|
{ message: "multiple_choice questions must have exactly one correct option" }
|
|
);
|
|
|
|
export const quizImportSchema = z.object({
|
|
type: z.literal("quiz"),
|
|
quizName: z.string().min(1),
|
|
description: z.string().optional(),
|
|
questions: z.array(questionSchema).min(1),
|
|
});
|
|
|
|
export const flashcardImportSchema = z.object({
|
|
type: z.literal("flashcards"),
|
|
deckName: z.string().min(1),
|
|
description: z.string().optional(),
|
|
cards: z
|
|
.array(
|
|
z.object({
|
|
front: z.string().min(1),
|
|
back: z.string().min(1),
|
|
})
|
|
)
|
|
.min(1),
|
|
});
|
|
|
|
export type QuizImportData = z.infer<typeof quizImportSchema>;
|
|
export type FlashcardImportData = z.infer<typeof flashcardImportSchema>;
|