feat: add Zod validation schemas for all domain routes
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
24
src/schemas/users.schema.ts
Normal file
24
src/schemas/users.schema.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
import { z } from 'zod';
|
||||
|
||||
export const CreateUserSchema = z.object({
|
||||
username: z.string().min(1, 'Uživatelské jméno je povinné'),
|
||||
email: z.string().email('Neplatný formát e-mailu'),
|
||||
password: z.string().min(8, 'Heslo musí mít alespoň 8 znaků'),
|
||||
first_name: z.string().min(1, 'Jméno je povinné'),
|
||||
last_name: z.string().min(1, 'Příjmení je povinné'),
|
||||
role_id: z.union([z.number(), z.string()]).transform(v => Number(v)),
|
||||
is_active: z.any().optional().default(true),
|
||||
});
|
||||
|
||||
export const UpdateUserSchema = z.object({
|
||||
username: z.string().optional(),
|
||||
email: z.string().email('Neplatný formát e-mailu').optional(),
|
||||
password: z.string().min(8, 'Heslo musí mít alespoň 8 znaků').optional(),
|
||||
first_name: z.string().optional(),
|
||||
last_name: z.string().optional(),
|
||||
role_id: z.union([z.number(), z.string(), z.null()]).optional(),
|
||||
is_active: z.any().optional(),
|
||||
});
|
||||
|
||||
export type CreateUserInput = z.infer<typeof CreateUserSchema>;
|
||||
export type UpdateUserInput = z.infer<typeof UpdateUserSchema>;
|
||||
Reference in New Issue
Block a user