From a3d9be86d8591fc4043dad18d07bfc4871ae99a0 Mon Sep 17 00:00:00 2001 From: gilles Date: Mon, 21 Sep 2026 17:58:59 +0200 Subject: [PATCH] =?UTF-8?q?feat(validation):=20sch=C3=A9mas=20zod=20et=20e?= =?UTF-8?q?rreurs=20applicatives?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/domain/card-schemas.ts | 10 ++++++++++ src/domain/errors.ts | 21 +++++++++++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 src/domain/card-schemas.ts create mode 100644 src/domain/errors.ts 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