diff --git a/src/domain/card-schemas.ts b/src/domain/card-schemas.ts new file mode 100644 index 0000000..a52c7ed --- /dev/null +++ b/src/domain/card-schemas.ts @@ -0,0 +1,10 @@ +import { z } from 'zod' + +export const createCardSchema = z.object({ + question: z.string().trim().min(1, 'La question est requise').max(1000, 'Question trop longue'), + response: z.string().trim().min(1, 'La réponse est requise').max(2000, 'Réponse trop longue'), + theme: z.string().trim().min(1, 'Le thème est requis').max(50, 'Thème trop long'), + tags: z.array(z.string().trim().min(1, 'Tag vide')).max(50, 'Trop de tags').optional(), +}) + +export const updateCardSchema = createCardSchema.partial() \ No newline at end of file diff --git a/src/domain/errors.ts b/src/domain/errors.ts new file mode 100644 index 0000000..05e7cbc --- /dev/null +++ b/src/domain/errors.ts @@ -0,0 +1,21 @@ +export class AppError extends Error { + constructor( + public readonly status: number, + message: string, + ) { + super(message) + this.name = new.target.name + } +} + +export class NotFoundError extends AppError { + constructor(message: string) { + super(404, message) + } +} + +export class ValidationError extends AppError { + constructor(message: string) { + super(400, message) + } +} \ No newline at end of file