Se agrego la api que hace la peticion a la base de datos de funcionario

This commit is contained in:
santiago
2025-08-07 12:47:24 -06:00
parent 799f511cc0
commit 7ee49a81f4
2 changed files with 33 additions and 17 deletions
@@ -0,0 +1,27 @@
import { NextResponse } from 'next/server';
import axios from 'axios';
export async function POST(request) {
const { Nombre = '', Apellidos = '', IdUnidadResponsable } = await request.json();
if (!IdUnidadResponsable) {
return NextResponse.json({ error: 'IdUnidadResponsable es requerido' }, { status: 400 });
}
const apiUrl = process.env.API_URL_CON_PARAMS; // Ejemplo: https://.../consultaDirectorioPorArea?ve=...&uf=...
try {
const response = await axios.post(apiUrl, {
Nombre,
Apellidos,
IdUnidadResponsable: Number(IdUnidadResponsable),
}, {
headers: { 'Content-Type': 'application/json' }
});
return NextResponse.json(response.data);
} catch (error) {
console.error('Error en API proxy:', error.response?.data || error.message || error);
return NextResponse.json({ error: 'Error al consultar la API externa' }, { status: 500 });
}
}
+6 -17
View File
@@ -21,23 +21,12 @@ export default function Home() {
}
try {
const response = await axios.post(
apiUrl,
{
Nombre: '',
Apellidos: '',
IdUnidadResponsable: parseInt(area),
},
{
headers: {
'Content-Type': 'application/json',
'uf': 'x0PUzGIf@5M7aD9Bicp71eQYmNP2|kY4',
'Authorization': 'Bearer eunsatoXto2TSzyMlwqhJSdy6l1dYdRqrhNBg0UnTVzrNUq1jNsqLQ==',
},
}
);
console.log(response.data); // 👈 Para revisar qué llega
const response = await axios.post('/api/directorioPorArea', {
Nombre: nombre,
Apellidos: '',
IdUnidadResponsable: parseInt(area),
});
console.log(response.data);
setResultados(response.data || []);
} catch (error) {
console.error('Error al consultar:', error);