feat: sessão #3 — lib (db/auth/email/validations), API routes, NextAuth v5, middleware, páginas account/shelters/shelter-dashboard, Prisma v7 fix
This commit is contained in:
32
lib/validations/animal.ts
Normal file
32
lib/validations/animal.ts
Normal file
@@ -0,0 +1,32 @@
|
||||
import { z } from 'zod';
|
||||
|
||||
export const animalFilterSchema = z.object({
|
||||
district: z.string().optional(),
|
||||
species: z.enum(['DOG', 'CAT', 'OTHER']).optional(),
|
||||
sex: z.enum(['MALE', 'FEMALE']).optional(),
|
||||
sterilized: z.coerce.boolean().optional(),
|
||||
urgent: z.coerce.boolean().optional(),
|
||||
status: z.enum(['AVAILABLE', 'RESERVED', 'ADOPTED']).optional(),
|
||||
page: z.coerce.number().int().positive().default(1),
|
||||
limit: z.coerce.number().int().min(1).max(50).default(12),
|
||||
});
|
||||
|
||||
export const createAnimalSchema = z.object({
|
||||
name: z.string().min(1, 'Nome obrigatório.').max(80),
|
||||
species: z.enum(['DOG', 'CAT', 'OTHER']),
|
||||
breed: z.string().max(80).optional(),
|
||||
ageMonths: z.number().int().min(0).max(300),
|
||||
sex: z.enum(['MALE', 'FEMALE']),
|
||||
sterilized: z.boolean(),
|
||||
urgent: z.boolean().default(false),
|
||||
description: z.string().max(2000).optional(),
|
||||
shelterId: z.string().cuid(),
|
||||
});
|
||||
|
||||
export const updateAnimalSchema = createAnimalSchema
|
||||
.partial()
|
||||
.extend({ status: z.enum(['AVAILABLE', 'RESERVED', 'ADOPTED']).optional() });
|
||||
|
||||
export type AnimalFilter = z.infer<typeof animalFilterSchema>;
|
||||
export type CreateAnimalInput = z.infer<typeof createAnimalSchema>;
|
||||
export type UpdateAnimalInput = z.infer<typeof updateAnimalSchema>;
|
||||
Reference in New Issue
Block a user