| 
									
										
										
										
											2025-08-22 21:55:03 -03:00
										 |  |  | // src/apiService.ts
 | 
					
						
							|  |  |  | import axios from 'axios'; | 
					
						
							| 
									
										
										
										
											2025-09-01 14:04:40 -03:00
										 |  |  | import type { ProyeccionBancas, MunicipioSimple, TelegramaData, CatalogoItem, CategoriaResumen, ResultadoTicker } from './types/types'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | const API_BASE_URL = 'http://localhost:5217/api'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 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-08-25 10:25:54 -03:00
										 |  |  | export const getBancasPorSeccion = async (seccionId: string): Promise<ProyeccionBancas> => { | 
					
						
							|  |  |  |   const response = await apiClient.get(`/resultados/bancas/${seccionId}`); | 
					
						
							| 
									
										
										
										
											2025-08-22 21:55:03 -03:00
										 |  |  |   return response.data; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							| 
									
										
										
										
											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-08-25 10:25:54 -03:00
										 |  |  | export const getSeccionesElectorales = async (): Promise<MunicipioSimple[]> => { | 
					
						
							|  |  |  |   const response = await apiClient.get('/catalogos/secciones-electorales'); | 
					
						
							| 
									
										
										
										
											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; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | export const getResultadosConcejales = async (seccionId: string): Promise<ResultadoTicker[]> => { | 
					
						
							|  |  |  |   const response = await apiClient.get(`/resultados/concejales/${seccionId}`); | 
					
						
							|  |  |  |   return response.data; | 
					
						
							| 
									
										
										
										
											2025-09-02 09:48:46 -03:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | export const getDetalleSeccion = async (seccionId: string, categoriaId: number): Promise<ResultadoDetalleSeccion[]> => { | 
					
						
							|  |  |  |     const response = await apiClient.get(`/resultados/seccion/${seccionId}?categoriaId=${categoriaId}`); | 
					
						
							|  |  |  |     return response.data; | 
					
						
							| 
									
										
										
										
											2025-09-02 15:39:01 -03:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | export const getResultadosConcejalesPorMunicipio = async (municipioId: string): Promise<ResultadoTicker[]> => { | 
					
						
							|  |  |  |   // Usamos el endpoint 'partido' que, según la aclaración de la API, busca por municipio
 | 
					
						
							|  |  |  |   const response = await apiClient.get(`/resultados/partido/${municipioId}`); | 
					
						
							|  |  |  |   // La API devuelve un objeto, nosotros extraemos el array de resultados
 | 
					
						
							|  |  |  |   return response.data.resultados; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | export const getMunicipios = async (): Promise<MunicipioSimple[]> => { | 
					
						
							|  |  |  |   const response = await apiClient.get('/catalogos/municipios'); | 
					
						
							|  |  |  |   return response.data; | 
					
						
							| 
									
										
										
										
											2025-08-22 21:55:03 -03:00
										 |  |  | }; |