Files
HoruxDespachos/apps/web/lib/api/dashboard.ts
2026-04-27 22:09:36 -06:00

42 lines
2.0 KiB
TypeScript

import { apiClient } from './client';
import type { KpiData, IngresosEgresosData, Alerta } from '@horux/shared';
export async function getKpis(fechaInicio: string, fechaFin: string, conciliacion?: boolean, contribuyenteId?: string | null): Promise<KpiData> {
const params = new URLSearchParams();
params.set('fechaInicio', fechaInicio);
params.set('fechaFin', fechaFin);
if (conciliacion) params.set('conciliacion', 'true');
if (contribuyenteId) params.set('contribuyenteId', contribuyenteId);
const response = await apiClient.get<KpiData>(`/dashboard/kpis?${params}`);
return response.data;
}
export async function getIngresosEgresos(año?: number, conciliacion?: boolean, contribuyenteId?: string | null): Promise<IngresosEgresosData[]> {
const params = new URLSearchParams();
if (año) params.set('año', año.toString());
if (conciliacion) params.set('conciliacion', 'true');
if (contribuyenteId) params.set('contribuyenteId', contribuyenteId);
const response = await apiClient.get<IngresosEgresosData[]>(`/dashboard/ingresos-egresos?${params}`);
return response.data;
}
export async function getRegimenesDelPeriodo(fechaInicio: string, fechaFin: string, conciliacion?: boolean, contribuyenteId?: string | null): Promise<{ clave: string; descripcion: string }[]> {
const params = new URLSearchParams();
params.set('fechaInicio', fechaInicio);
params.set('fechaFin', fechaFin);
if (conciliacion) params.set('conciliacion', 'true');
if (contribuyenteId) params.set('contribuyenteId', contribuyenteId);
const response = await apiClient.get<{ clave: string; descripcion: string }[]>(`/dashboard/regimenes-periodo?${params}`);
return response.data;
}
export async function getAlertas(limit = 5, contribuyenteId?: string | null): Promise<Alerta[]> {
const params = new URLSearchParams({ limit: String(limit) });
if (contribuyenteId) params.set('contribuyenteId', contribuyenteId);
const response = await apiClient.get<Alerta[]>(`/dashboard/alertas?${params}`);
return response.data;
}