feat(shared): add domain types and zod schemas

This commit is contained in:
2026-05-20 20:33:53 +02:00
parent 4d0a5aee66
commit 59261b3bab
3 changed files with 120 additions and 1 deletions

View File

@@ -0,0 +1,45 @@
import { z } from 'zod';
export const lessonCreateSchema = z.object({
parentId: z.number().int().nullable().optional(),
name: z.string().min(1).max(200),
description: z.string().max(2000).optional().nullable(),
bidirectional: z.boolean().optional(),
});
export const lessonUpdateSchema = lessonCreateSchema.partial();
export const lessonMoveSchema = z.object({
parentId: z.number().int().nullable(),
position: z.number().int().min(0),
});
export const cardCreateSchema = z.object({
question: z.string().min(1).max(2000),
answer: z.string().min(1).max(2000),
hint: z.string().max(2000).optional().nullable(),
});
export const cardUpdateSchema = cardCreateSchema.partial();
export const sessionStartSchema = z.object({
lessonId: z.number().int().positive(),
maxCards: z.number().int().min(1).max(500).nullable().optional(),
shuffle: z.boolean().optional(),
direction: z.enum(['forward', 'backward', 'both']).optional(),
});
export const attemptCreateSchema = z.object({
cardId: z.number().int().positive(),
direction: z.enum(['forward', 'backward']),
result: z.enum(['correct', 'incorrect']),
timeToAnswerMs: z.number().int().min(0).nullable().optional(),
});
export type LessonCreateInput = z.infer<typeof lessonCreateSchema>;
export type LessonUpdateInput = z.infer<typeof lessonUpdateSchema>;
export type LessonMoveInput = z.infer<typeof lessonMoveSchema>;
export type CardCreateInput = z.infer<typeof cardCreateSchema>;
export type CardUpdateInput = z.infer<typeof cardUpdateSchema>;
export type SessionStartInput = z.infer<typeof sessionStartSchema>;
export type AttemptCreateInput = z.infer<typeof attemptCreateSchema>;