| 
									
										
										
										
											2025-08-22 21:55:03 -03:00
										 |  |  | // src/apiService.ts
 | 
					
						
							|  |  |  | import axios from 'axios'; | 
					
						
							| 
									
										
										
										
											2025-09-04 15:54:00 -03:00
										 |  |  | import type { ApiResponseRankingMunicipio, ApiResponseRankingSeccion, ApiResponseTablaDetallada, ProyeccionBancas, MunicipioSimple, TelegramaData, CatalogoItem, CategoriaResumen, ResultadoTicker, ApiResponseResultadosPorSeccion } from './types/types'; | 
					
						
							| 
									
										
										
										
											2025-09-01 14:04:40 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-09-03 18:49:55 -03:00
										 |  |  | /** | 
					
						
							|  |  |  |  * URL base para las llamadas a la API. | 
					
						
							|  |  |  |  * - En desarrollo, apunta directamente al backend de .NET. | 
					
						
							|  |  |  |  * - En producción, apunta al endpoint público de la API. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | export const API_BASE_URL = import.meta.env.DEV | 
					
						
							|  |  |  |   ? 'http://localhost:5217/api' | 
					
						
							|  |  |  |   : 'https://elecciones2025.eldia.com/api'; | 
					
						
							| 
									
										
										
										
											2025-09-01 14:04:40 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-09-03 18:49:55 -03:00
										 |  |  | /** | 
					
						
							|  |  |  |  * URL base para los activos estáticos (imágenes, etc.) de la carpeta `public`. | 
					
						
							|  |  |  |  * - En desarrollo, es una ruta relativa a la raíz (servida por Vite). | 
					
						
							|  |  |  |  * - En producción, es la URL absoluta del dominio donde se alojan los widgets. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | export const assetBaseUrl = import.meta.env.DEV | 
					
						
							|  |  |  |   ? '' | 
					
						
							| 
									
										
										
										
											2025-09-03 18:36:54 -03:00
										 |  |  |   : 'https://elecciones2025.eldia.com'; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-09-01 14:04:40 -03:00
										 |  |  | const apiClient = axios.create({ | 
					
						
							|  |  |  |   baseURL: API_BASE_URL, | 
					
						
							|  |  |  |   headers: { 'Content-Type': 'application/json' }, | 
					
						
							|  |  |  | }); | 
					
						
							| 
									
										
										
										
											2025-08-22 21:55:03 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-08-29 09:54:22 -03:00
										 |  |  | interface PartidoData { | 
					
						
							|  |  |  |   id: string; | 
					
						
							|  |  |  |   nombre: string; | 
					
						
							|  |  |  |   nombreCorto: string | null; | 
					
						
							|  |  |  |   bancasTotales: number; | 
					
						
							|  |  |  |   color: string | null; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | interface CamaraData { | 
					
						
							|  |  |  |   camaraNombre: string; | 
					
						
							|  |  |  |   totalBancas: number; | 
					
						
							|  |  |  |   bancasEnJuego: number; | 
					
						
							|  |  |  |   partidos: PartidoData[]; | 
					
						
							|  |  |  |   presidenteBancada: { color: string | null } | null; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | export interface ComposicionData { | 
					
						
							|  |  |  |   diputados: CamaraData; | 
					
						
							|  |  |  |   senadores: CamaraData; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | export interface OcupanteBanca { | 
					
						
							|  |  |  |   id: number; | 
					
						
							|  |  |  |   nombreOcupante: string; | 
					
						
							| 
									
										
										
										
											2025-08-29 15:49:13 -03:00
										 |  |  |   fotoUrl: string | null; | 
					
						
							|  |  |  |   periodo: string | null; | 
					
						
							| 
									
										
										
										
											2025-08-29 09:54:22 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | interface PartidoData { | 
					
						
							|  |  |  |   id: string; | 
					
						
							|  |  |  |   nombre: string; | 
					
						
							|  |  |  |   nombreCorto: string | null; | 
					
						
							|  |  |  |   bancasTotales: number; | 
					
						
							|  |  |  |   color: string | null; | 
					
						
							|  |  |  |   ocupantes: OcupanteBanca[]; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | export interface BancadaDetalle { | 
					
						
							|  |  |  |   id: number; // Este es el ID de la Bancada
 | 
					
						
							|  |  |  |   camara: number; // 0 o 1
 | 
					
						
							| 
									
										
										
										
											2025-08-30 11:31:45 -03:00
										 |  |  |   numeroBanca: number; | 
					
						
							| 
									
										
										
										
											2025-08-29 09:54:22 -03:00
										 |  |  |   agrupacionPoliticaId: string | null; | 
					
						
							|  |  |  |   ocupante: OcupanteBanca | null; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-09-01 14:04:40 -03:00
										 |  |  | export interface ConfiguracionPublica { | 
					
						
							|  |  |  |   TickerResultadosCantidad?: string; | 
					
						
							|  |  |  |   ConcejalesResultadosCantidad?: string; | 
					
						
							|  |  |  |   // ... otras claves públicas que pueda añadir en el futuro
 | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2025-08-22 21:55:03 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-09-02 09:48:46 -03:00
										 |  |  | export interface ResultadoDetalleSeccion { | 
					
						
							|  |  |  |   id: string; // ID de la agrupación para la key
 | 
					
						
							|  |  |  |   nombre: string; | 
					
						
							|  |  |  |   votos: number; | 
					
						
							|  |  |  |   porcentaje: number; | 
					
						
							| 
									
										
										
										
											2025-09-02 15:39:01 -03:00
										 |  |  |   color: string | null; | 
					
						
							| 
									
										
										
										
											2025-09-02 09:48:46 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-09-01 14:04:40 -03:00
										 |  |  | export const getResumenProvincial = async (): Promise<CategoriaResumen[]> => { | 
					
						
							| 
									
										
										
										
											2025-08-25 10:25:54 -03:00
										 |  |  |   const response = await apiClient.get('/resultados/provincia/02'); | 
					
						
							|  |  |  |   return response.data; | 
					
						
							| 
									
										
										
										
											2025-08-22 21:55:03 -03:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-09-04 11:27:12 -03:00
										 |  |  | export const getBancasPorSeccion = async (seccionId: string, camara: 'diputados' | 'senadores'): Promise<ProyeccionBancas> => { | 
					
						
							|  |  |  |     const { data } = await apiClient.get(`/resultados/bancas-por-seccion/${seccionId}/${camara}`); | 
					
						
							|  |  |  |     return data; | 
					
						
							| 
									
										
										
										
											2025-08-22 21:55:03 -03:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							| 
									
										
										
										
											2025-08-25 10:25:54 -03:00
										 |  |  |  * Obtiene la lista de Secciones Electorales desde la API. | 
					
						
							| 
									
										
										
										
											2025-08-22 21:55:03 -03:00
										 |  |  |  */ | 
					
						
							| 
									
										
										
										
											2025-09-03 13:49:35 -03:00
										 |  |  | export const getSeccionesElectorales = async (categoriaId?: number): Promise<MunicipioSimple[]> => { | 
					
						
							|  |  |  |   let url = '/catalogos/secciones-electorales'; | 
					
						
							|  |  |  |   // Si se proporciona una categoría, la añadimos a la URL
 | 
					
						
							|  |  |  |   if (categoriaId) { | 
					
						
							|  |  |  |     url += `?categoriaId=${categoriaId}`; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   const response = await apiClient.get(url); | 
					
						
							| 
									
										
										
										
											2025-08-22 21:55:03 -03:00
										 |  |  |   return response.data; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							| 
									
										
										
										
											2025-08-25 10:25:54 -03:00
										 |  |  |  * Obtiene los datos completos de un telegrama por su ID de mesa. | 
					
						
							| 
									
										
										
										
											2025-08-22 21:55:03 -03:00
										 |  |  |  */ | 
					
						
							| 
									
										
										
										
											2025-08-25 10:25:54 -03:00
										 |  |  | export const getTelegramaPorId = async (mesaId: string): Promise<TelegramaData> => { | 
					
						
							|  |  |  |   const response = await apiClient.get(`/telegramas/${mesaId}`); | 
					
						
							| 
									
										
										
										
											2025-08-22 21:55:03 -03:00
										 |  |  |   return response.data; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-08-25 10:25:54 -03:00
										 |  |  | export const getSecciones = async (): Promise<CatalogoItem[]> => { | 
					
						
							| 
									
										
										
										
											2025-08-29 09:54:22 -03:00
										 |  |  |   const response = await apiClient.get('/catalogos/secciones'); | 
					
						
							|  |  |  |   return response.data; | 
					
						
							| 
									
										
										
										
											2025-08-25 10:25:54 -03:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | export const getMunicipiosPorSeccion = async (seccionId: string): Promise<CatalogoItem[]> => { | 
					
						
							| 
									
										
										
										
											2025-08-29 09:54:22 -03:00
										 |  |  |   const response = await apiClient.get(`/catalogos/municipios/${seccionId}`); | 
					
						
							|  |  |  |   return response.data; | 
					
						
							| 
									
										
										
										
											2025-08-25 10:25:54 -03:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | export const getCircuitosPorMunicipio = async (municipioId: string): Promise<CatalogoItem[]> => { | 
					
						
							| 
									
										
										
										
											2025-08-29 09:54:22 -03:00
										 |  |  |   const response = await apiClient.get(`/catalogos/circuitos/${municipioId}`); | 
					
						
							|  |  |  |   return response.data; | 
					
						
							| 
									
										
										
										
											2025-08-25 10:25:54 -03:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | export const getEstablecimientosPorCircuito = async (circuitoId: string): Promise<CatalogoItem[]> => { | 
					
						
							| 
									
										
										
										
											2025-08-29 09:54:22 -03:00
										 |  |  |   const response = await apiClient.get(`/catalogos/establecimientos/${circuitoId}`); | 
					
						
							|  |  |  |   return response.data; | 
					
						
							| 
									
										
										
										
											2025-08-25 10:25:54 -03:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | export const getMesasPorEstablecimiento = async (establecimientoId: string): Promise<CatalogoItem[]> => { | 
					
						
							| 
									
										
										
										
											2025-08-29 09:54:22 -03:00
										 |  |  |   const response = await apiClient.get(`/catalogos/mesas/${establecimientoId}`); | 
					
						
							|  |  |  |   return response.data; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | export const getComposicionCongreso = async (): Promise<ComposicionData> => { | 
					
						
							|  |  |  |   const response = await apiClient.get('/resultados/composicion-congreso'); | 
					
						
							|  |  |  |   return response.data; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | export const getBancadasDetalle = async (): Promise<BancadaDetalle[]> => { | 
					
						
							|  |  |  |   const response = await apiClient.get('/resultados/bancadas-detalle'); | 
					
						
							|  |  |  |   return response.data; | 
					
						
							| 
									
										
										
										
											2025-09-01 14:04:40 -03:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | export const getConfiguracionPublica = async (): Promise<ConfiguracionPublica> => { | 
					
						
							|  |  |  |   const response = await apiClient.get('/resultados/configuracion-publica'); | 
					
						
							|  |  |  |   return response.data; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-09-03 13:49:35 -03:00
										 |  |  | export const getResultadosPorSeccion = async (seccionId: string, categoriaId: number): Promise<ApiResponseResultadosPorSeccion> => { | 
					
						
							|  |  |  |   const response = await apiClient.get(`/resultados/seccion-resultados/${seccionId}?categoriaId=${categoriaId}`); | 
					
						
							| 
									
										
										
										
											2025-09-01 14:04:40 -03:00
										 |  |  |   return response.data; | 
					
						
							| 
									
										
										
										
											2025-09-02 09:48:46 -03:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | export const getDetalleSeccion = async (seccionId: string, categoriaId: number): Promise<ResultadoDetalleSeccion[]> => { | 
					
						
							| 
									
										
										
										
											2025-09-02 19:38:04 -03:00
										 |  |  |   const response = await apiClient.get(`/resultados/seccion/${seccionId}?categoriaId=${categoriaId}`); | 
					
						
							|  |  |  |   return response.data; | 
					
						
							| 
									
										
										
										
											2025-09-02 15:39:01 -03:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-09-02 17:08:56 -03:00
										 |  |  | export const getResultadosPorMunicipioYCategoria = async (municipioId: string, categoriaId: number): Promise<ResultadoTicker[]> => { | 
					
						
							|  |  |  |   const response = await apiClient.get(`/resultados/partido/${municipioId}?categoriaId=${categoriaId}`); | 
					
						
							| 
									
										
										
										
											2025-09-02 15:39:01 -03:00
										 |  |  |   return response.data.resultados; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-09-02 19:38:04 -03:00
										 |  |  | export const getResultadosPorMunicipio = async (municipioId: string, categoriaId: number): Promise<ResultadoTicker[]> => { | 
					
						
							|  |  |  |   const response = await apiClient.get(`/resultados/partido/${municipioId}?categoriaId=${categoriaId}`); | 
					
						
							|  |  |  |   // La respuesta es un objeto, nosotros extraemos el array de resultados
 | 
					
						
							|  |  |  |   return response.data.resultados; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | export const getMunicipios = async (categoriaId?: number): Promise<MunicipioSimple[]> => { | 
					
						
							|  |  |  |   let url = '/catalogos/municipios'; | 
					
						
							|  |  |  |   if (categoriaId) { | 
					
						
							|  |  |  |     url += `?categoriaId=${categoriaId}`; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   const response = await apiClient.get(url); | 
					
						
							| 
									
										
										
										
											2025-09-07 20:12:03 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  |   // --- CORRECCIÓN ---
 | 
					
						
							|  |  |  |   // La API devuelve un array de objetos con las propiedades { id, nombre }.
 | 
					
						
							|  |  |  |   // Ya no es necesario mapear. Simplemente devolvemos los datos como vienen.
 | 
					
						
							| 
									
										
										
										
											2025-09-07 19:53:59 -03:00
										 |  |  |   return response.data; | 
					
						
							| 
									
										
										
										
											2025-09-04 11:27:12 -03:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | export const getSeccionesElectoralesConCargos = async (): Promise<MunicipioSimple[]> => { | 
					
						
							|  |  |  |   // Hacemos la petición al nuevo endpoint del backend
 | 
					
						
							|  |  |  |   const { data } = await apiClient.get<MunicipioSimple[]>('/resultados/secciones-electorales-con-cargos'); | 
					
						
							|  |  |  |   return data; | 
					
						
							| 
									
										
										
										
											2025-09-04 14:35:12 -03:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | export const getResultadosTablaDetallada = async (seccionId: string): Promise<ApiResponseTablaDetallada> => { | 
					
						
							|  |  |  |   const { data } = await apiClient.get(`/resultados/tabla-ranking-seccion/${seccionId}`); | 
					
						
							|  |  |  |   return data; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | export const getRankingResultadosPorSeccion = async (seccionId: string): Promise<ApiResponseRankingSeccion> => { | 
					
						
							|  |  |  |   const { data } = await apiClient.get(`/resultados/ranking-por-seccion/${seccionId}`); | 
					
						
							|  |  |  |   return data; | 
					
						
							| 
									
										
										
										
											2025-09-04 15:54:00 -03:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | export const getRankingMunicipiosPorSeccion = async (seccionId: string): Promise<ApiResponseRankingMunicipio> => { | 
					
						
							|  |  |  |   const { data } = await apiClient.get(`/resultados/ranking-municipios-por-seccion/${seccionId}`); | 
					
						
							|  |  |  |   return data; | 
					
						
							| 
									
										
										
										
											2025-08-22 21:55:03 -03:00
										 |  |  | }; |