refactor: Move inline Zod schemas from routes to validator files
Create ai-kurzy.validators.js and service.validators.js with schemas extracted from their respective route files. Routes now import schemas instead of defining them inline. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
72
src/validators/ai-kurzy.validators.js
Normal file
72
src/validators/ai-kurzy.validators.js
Normal file
@@ -0,0 +1,72 @@
|
||||
import { z } from 'zod';
|
||||
|
||||
export const kurzIdSchema = z.object({
|
||||
kurzId: z.string().regex(/^\d+$/),
|
||||
});
|
||||
|
||||
export const ucastnikIdSchema = z.object({
|
||||
ucastnikId: z.string().regex(/^\d+$/),
|
||||
});
|
||||
|
||||
export const registraciaIdSchema = z.object({
|
||||
registraciaId: z.string().regex(/^\d+$/),
|
||||
});
|
||||
|
||||
export const createKurzSchema = z.object({
|
||||
nazov: z.string().min(1).max(255),
|
||||
typKurzu: z.string().min(1).max(100),
|
||||
popis: z.string().optional().nullable(),
|
||||
cena: z.string().or(z.number()),
|
||||
maxKapacita: z.number().int().positive().optional().nullable(),
|
||||
aktivny: z.boolean().optional(),
|
||||
farba: z.string().max(20).optional().nullable(),
|
||||
});
|
||||
|
||||
export const updateKurzSchema = createKurzSchema.partial();
|
||||
|
||||
export const createUcastnikSchema = z.object({
|
||||
titul: z.string().max(50).optional().nullable(),
|
||||
meno: z.string().min(1).max(100),
|
||||
priezvisko: z.string().min(1).max(100),
|
||||
email: z.string().email().max(255),
|
||||
telefon: z.string().max(50).optional().nullable(),
|
||||
firma: z.string().max(255).optional().nullable(),
|
||||
firmaIco: z.string().max(20).optional().nullable(),
|
||||
firmaDic: z.string().max(20).optional().nullable(),
|
||||
firmaIcDph: z.string().max(25).optional().nullable(),
|
||||
firmaSidlo: z.string().optional().nullable(),
|
||||
mesto: z.string().max(100).optional().nullable(),
|
||||
ulica: z.string().max(255).optional().nullable(),
|
||||
psc: z.string().max(10).optional().nullable(),
|
||||
});
|
||||
|
||||
export const updateUcastnikSchema = createUcastnikSchema.partial();
|
||||
|
||||
export const createRegistraciaSchema = z.object({
|
||||
kurzId: z.number().int().positive(),
|
||||
ucastnikId: z.number().int().positive(),
|
||||
datumOd: z.string().optional().nullable(),
|
||||
datumDo: z.string().optional().nullable(),
|
||||
formaKurzu: z.enum(['prezencne', 'online', 'hybridne']).optional(),
|
||||
pocetUcastnikov: z.number().int().positive().optional(),
|
||||
fakturaCislo: z.string().max(100).optional().nullable(),
|
||||
fakturaVystavena: z.boolean().optional(),
|
||||
zaplatene: z.boolean().optional(),
|
||||
stav: z.enum(['potencialny', 'registrovany', 'potvrdeny', 'absolvoval', 'zruseny']).optional(),
|
||||
poznamka: z.string().optional().nullable(),
|
||||
});
|
||||
|
||||
export const updateRegistraciaSchema = createRegistraciaSchema.partial();
|
||||
|
||||
export const registracieQuerySchema = z.object({
|
||||
kurzId: z.string().regex(/^\d+$/).optional(),
|
||||
});
|
||||
|
||||
export const updateFieldSchema = z.object({
|
||||
field: z.string(),
|
||||
value: z.any(),
|
||||
});
|
||||
|
||||
export const prilohaIdSchema = z.object({
|
||||
prilohaId: z.string().regex(/^\d+$/),
|
||||
});
|
||||
22
src/validators/service.validators.js
Normal file
22
src/validators/service.validators.js
Normal file
@@ -0,0 +1,22 @@
|
||||
import { z } from 'zod';
|
||||
|
||||
export const serviceIdSchema = z.object({
|
||||
serviceId: z.string().uuid(),
|
||||
});
|
||||
|
||||
export const folderIdSchema = z.object({
|
||||
folderId: z.string().uuid(),
|
||||
});
|
||||
|
||||
export const folderDocumentIdSchema = z.object({
|
||||
folderId: z.string().uuid(),
|
||||
documentId: z.string().uuid(),
|
||||
});
|
||||
|
||||
export const createFolderSchema = z.object({
|
||||
name: z.string().min(1).max(255),
|
||||
});
|
||||
|
||||
export const updateFolderSchema = z.object({
|
||||
name: z.string().min(1).max(255),
|
||||
});
|
||||
Reference in New Issue
Block a user