| 
									
										
										
										
											2025-08-22 21:55:03 -03:00
										 |  |  | // src/apiService.ts
 | 
					
						
							|  |  |  | import axios from 'axios'; | 
					
						
							| 
									
										
										
										
											2025-09-03 13:49:35 -03:00
										 |  |  | import type { ProyeccionBancas, MunicipioSimple, TelegramaData, CatalogoItem, CategoriaResumen, ResultadoTicker, ApiResponseResultadosPorSeccion } from './types/types'; | 
					
						
							| 
									
										
										
										
											2025-09-01 14:04:40 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 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-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); | 
					
						
							|  |  |  |   // La API ahora devuelve { seccionId, nombre }, lo mapeamos a { id, nombre }
 | 
					
						
							|  |  |  |   return response.data.map((m: any) => ({ id: m.seccionId, nombre: m.nombre })); | 
					
						
							| 
									
										
										
										
											2025-08-22 21:55:03 -03:00
										 |  |  | }; |