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:
27
app/api/shelters/[id]/route.ts
Normal file
27
app/api/shelters/[id]/route.ts
Normal file
@@ -0,0 +1,27 @@
|
||||
import { NextResponse } from 'next/server';
|
||||
import { prisma } from '@/lib/db/prisma';
|
||||
|
||||
export async function GET(
|
||||
_request: Request,
|
||||
{ params }: { params: Promise<{ id: string }> }
|
||||
) {
|
||||
const { id } = await params;
|
||||
|
||||
const shelter = await prisma.shelter.findUnique({
|
||||
where: { id, verified: true },
|
||||
include: {
|
||||
animals: {
|
||||
where: { status: 'AVAILABLE' },
|
||||
include: { photos: { where: { isPrimary: true }, take: 1 } },
|
||||
orderBy: [{ urgent: 'desc' }, { createdAt: 'desc' }],
|
||||
},
|
||||
needs: { where: { active: true }, orderBy: { urgent: 'desc' } },
|
||||
},
|
||||
});
|
||||
|
||||
if (!shelter) {
|
||||
return NextResponse.json({ error: 'Canil não encontrado.' }, { status: 404 });
|
||||
}
|
||||
|
||||
return NextResponse.json(shelter);
|
||||
}
|
||||
31
app/api/shelters/route.ts
Normal file
31
app/api/shelters/route.ts
Normal file
@@ -0,0 +1,31 @@
|
||||
import { NextResponse } from 'next/server';
|
||||
import { prisma } from '@/lib/db/prisma';
|
||||
|
||||
export async function GET(request: Request) {
|
||||
const { searchParams } = new URL(request.url);
|
||||
const district = searchParams.get('district');
|
||||
|
||||
const shelters = await prisma.shelter.findMany({
|
||||
where: {
|
||||
verified: true,
|
||||
...(district && {
|
||||
district: { contains: district, mode: 'insensitive' },
|
||||
}),
|
||||
},
|
||||
select: {
|
||||
id: true,
|
||||
name: true,
|
||||
district: true,
|
||||
address: true,
|
||||
phone: true,
|
||||
email: true,
|
||||
description: true,
|
||||
website: true,
|
||||
openHours: true,
|
||||
_count: { select: { animals: { where: { status: 'AVAILABLE' } } } },
|
||||
},
|
||||
orderBy: { name: 'asc' },
|
||||
});
|
||||
|
||||
return NextResponse.json(shelters);
|
||||
}
|
||||
Reference in New Issue
Block a user