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:
2026-05-21 09:01:59 +01:00
parent e6ebc0909c
commit e62dc9d6e6
44 changed files with 5341 additions and 273 deletions

51
app/api/animals/route.ts Normal file
View File

@@ -0,0 +1,51 @@
import { NextResponse } from 'next/server';
import { prisma } from '@/lib/db/prisma';
import { animalFilterSchema } from '@/lib/validations/animal';
export async function GET(request: Request) {
const { searchParams } = new URL(request.url);
const parsed = animalFilterSchema.safeParse(
Object.fromEntries(searchParams.entries())
);
if (!parsed.success) {
return NextResponse.json(
{ error: 'Parâmetros inválidos.', details: parsed.error.flatten() },
{ status: 400 }
);
}
const { district, species, sex, sterilized, urgent, status, page, limit } =
parsed.data;
const where = {
...(species && { species }),
...(sex && { sex }),
...(sterilized !== undefined && { sterilized }),
...(urgent !== undefined && { urgent }),
status: status ?? 'AVAILABLE',
...(district && {
shelter: { district: { contains: district, mode: 'insensitive' as const } },
}),
};
const [animals, total] = await Promise.all([
prisma.animal.findMany({
where,
include: {
photos: { where: { isPrimary: true }, take: 1 },
shelter: { select: { id: true, name: true, district: true } },
},
orderBy: [{ urgent: 'desc' }, { createdAt: 'desc' }],
skip: (page - 1) * limit,
take: limit,
}),
prisma.animal.count({ where }),
]);
return NextResponse.json({
animals,
pagination: { page, limit, total, pages: Math.ceil(total / limit) },
});
}