Fix Llamadas de Ambitos Para Resultados

This commit is contained in:
2025-10-22 10:29:02 -03:00
parent bea752f7d0
commit 5ef3eb1af2
9 changed files with 70 additions and 51 deletions

View File

@@ -246,11 +246,24 @@ export const getEstablecimientosPorMunicipio = async (municipioId: string): Prom
return response.data;
};
export const getPanelElectoral = async (eleccionId: number, ambitoId: string | null, categoriaId: number): Promise<PanelElectoralDto> => {
// Construimos la URL base
let url = ambitoId
? `/elecciones/${eleccionId}/panel/${ambitoId}`
: `/elecciones/${eleccionId}/panel`;
export const getPanelElectoral = async (
eleccionId: number,
ambitoId: string | null,
categoriaId: number,
nivel: 'pais' | 'provincia' | 'municipio'
): Promise<PanelElectoralDto> => {
let url: string;
// Construimos la URL con el prefijo correcto.
if (nivel === 'pais' || !ambitoId) {
url = `/elecciones/${eleccionId}/panel`;
} else if (nivel === 'provincia') {
url = `/elecciones/${eleccionId}/panel/distrito:${ambitoId}`;
} else { // nivel === 'municipio'
url = `/elecciones/${eleccionId}/panel/municipio:${ambitoId}`;
}
url += `?categoriaId=${categoriaId}`;
try {
@@ -259,8 +272,6 @@ export const getPanelElectoral = async (eleccionId: number, ambitoId: string | n
} catch (error) {
if (axios.isAxiosError(error) && error.response?.status === 404) {
console.warn(`API devolvió 404 para ${url}. Devolviendo un estado vacío.`);
// Devolvemos el objeto vacío PERO con la nueva bandera activada
return {
ambitoNombre: 'Sin Datos',
mapaData: [],