Se agrego la api que hace la peticion a la base de datos de funcionario
This commit is contained in:
@@ -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
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user