feat(validation): schémas zod et erreurs applicatives

This commit is contained in:
devcodetools committed 2026-09-21 17:58:59 +02:00
1 parent c997010c8c
commit a3d9be86d8
2 files changed
+31

No files matched your search

+10
View File
@@ -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()
+21
View File
@@ -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)
}
}