Arreglo de error en detalle y data con espacio en cursos.
This commit is contained in:
commit
3d0f898a8a
30 files changed
+8081
No files matched your search
@@ -0,0 +1,40 @@
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
|
||||
const API_BASE = "https://api.devops.norteamericano.cl/api/Informes/cursos-empresa";
|
||||
|
||||
export async function GET(req: NextRequest) {
|
||||
try {
|
||||
const { searchParams } = new URL(req.url);
|
||||
const tipo = searchParams.get("tipo");
|
||||
const varA = searchParams.get("varA");
|
||||
const varB = searchParams.get("varB");
|
||||
const varC = searchParams.get("varC");
|
||||
const cursoId = searchParams.get("cursoId");
|
||||
|
||||
if (!tipo || !varA || !varB || !varC || !cursoId) {
|
||||
return NextResponse.json(
|
||||
{ error: "Faltan parámetros: tipo, varA, varB, varC, cursoId" },
|
||||
{ status: 400 }
|
||||
);
|
||||
}
|
||||
|
||||
const url = `${API_BASE}?tipo=${encodeURIComponent(tipo)}&varA=${encodeURIComponent(varA)}&varB=${encodeURIComponent(varB)}&varC=${encodeURIComponent(varC)}&cursoId=${encodeURIComponent(cursoId)}`;
|
||||
|
||||
const res = await fetch(url);
|
||||
const data = await res.json();
|
||||
|
||||
if (!data || (Array.isArray(data) && data.length === 0)) {
|
||||
return NextResponse.json(
|
||||
{ error: "No se encontraron cursos" },
|
||||
{ status: 404 }
|
||||
);
|
||||
}
|
||||
|
||||
return NextResponse.json(data, { status: res.status });
|
||||
} catch {
|
||||
return NextResponse.json(
|
||||
{ error: "Error al obtener datos del dashboard" },
|
||||
{ status: 500 }
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user