import { NextRequest, NextResponse } from "next/server"; import { prisma } from "@/lib/prisma"; import { verificarSesion } from "@/lib/auth-admin"; export async function GET(req: NextRequest) { const sesion = await verificarSesion("admin_session", "admin"); if (!sesion) return NextResponse.json({ error: "No autorizado" }, { status: 401 }); const { searchParams } = new URL(req.url); const fecha = searchParams.get("fecha"); // YYYY-MM-DD const clienteId = searchParams.get("clienteId"); const where: Record = {}; if (fecha) { where.fechaInicio = { gte: new Date(`${fecha}T00:00:00`), lte: new Date(`${fecha}T23:59:59`), }; } if (clienteId) where.clienteId = clienteId; const turnos = await prisma.turno.findMany({ where, include: { cliente: { select: { nombre: true, apellido: true, telefono: true } }, auto: true, tipoServicio: true, }, orderBy: { fechaInicio: "asc" }, }); return NextResponse.json(turnos); }