Initial working commit
Some checks failed
Automated Container Build / build-and-push (push) Failing after 7s
Some checks failed
Automated Container Build / build-and-push (push) Failing after 7s
This commit is contained in:
parent
666ceb7325
commit
b7ce314f01
105 changed files with 35510 additions and 11 deletions
48
src/lib/validation/importSchemas.ts
Normal file
48
src/lib/validation/importSchemas.ts
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
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>;
|
||||
Loading…
Add table
Add a link
Reference in a new issue