feat(alertas): add alerts CRUD with stats and management UI
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
33
apps/web/lib/api/alertas.ts
Normal file
33
apps/web/lib/api/alertas.ts
Normal file
@@ -0,0 +1,33 @@
|
||||
import { apiClient } from './client';
|
||||
import type { AlertaFull, AlertaCreate, AlertaUpdate, AlertasStats } from '@horux/shared';
|
||||
|
||||
export async function getAlertas(filters?: { leida?: boolean; resuelta?: boolean }): Promise<AlertaFull[]> {
|
||||
const params = new URLSearchParams();
|
||||
if (filters?.leida !== undefined) params.set('leida', String(filters.leida));
|
||||
if (filters?.resuelta !== undefined) params.set('resuelta', String(filters.resuelta));
|
||||
const response = await apiClient.get<AlertaFull[]>(`/alertas?${params}`);
|
||||
return response.data;
|
||||
}
|
||||
|
||||
export async function getStats(): Promise<AlertasStats> {
|
||||
const response = await apiClient.get<AlertasStats>('/alertas/stats');
|
||||
return response.data;
|
||||
}
|
||||
|
||||
export async function createAlerta(data: AlertaCreate): Promise<AlertaFull> {
|
||||
const response = await apiClient.post<AlertaFull>('/alertas', data);
|
||||
return response.data;
|
||||
}
|
||||
|
||||
export async function updateAlerta(id: number, data: AlertaUpdate): Promise<AlertaFull> {
|
||||
const response = await apiClient.patch<AlertaFull>(`/alertas/${id}`, data);
|
||||
return response.data;
|
||||
}
|
||||
|
||||
export async function deleteAlerta(id: number): Promise<void> {
|
||||
await apiClient.delete(`/alertas/${id}`);
|
||||
}
|
||||
|
||||
export async function markAllAsRead(): Promise<void> {
|
||||
await apiClient.post('/alertas/mark-all-read');
|
||||
}
|
||||
28
apps/web/lib/api/calendario.ts
Normal file
28
apps/web/lib/api/calendario.ts
Normal file
@@ -0,0 +1,28 @@
|
||||
import { apiClient } from './client';
|
||||
import type { EventoFiscal, EventoCreate, EventoUpdate } from '@horux/shared';
|
||||
|
||||
export async function getEventos(año: number, mes?: number): Promise<EventoFiscal[]> {
|
||||
const params = new URLSearchParams({ año: año.toString() });
|
||||
if (mes) params.set('mes', mes.toString());
|
||||
const response = await apiClient.get<EventoFiscal[]>(`/calendario?${params}`);
|
||||
return response.data;
|
||||
}
|
||||
|
||||
export async function getProximos(dias = 30): Promise<EventoFiscal[]> {
|
||||
const response = await apiClient.get<EventoFiscal[]>(`/calendario/proximos?dias=${dias}`);
|
||||
return response.data;
|
||||
}
|
||||
|
||||
export async function createEvento(data: EventoCreate): Promise<EventoFiscal> {
|
||||
const response = await apiClient.post<EventoFiscal>('/calendario', data);
|
||||
return response.data;
|
||||
}
|
||||
|
||||
export async function updateEvento(id: number, data: EventoUpdate): Promise<EventoFiscal> {
|
||||
const response = await apiClient.patch<EventoFiscal>(`/calendario/${id}`, data);
|
||||
return response.data;
|
||||
}
|
||||
|
||||
export async function deleteEvento(id: number): Promise<void> {
|
||||
await apiClient.delete(`/calendario/${id}`);
|
||||
}
|
||||
36
apps/web/lib/api/reportes.ts
Normal file
36
apps/web/lib/api/reportes.ts
Normal file
@@ -0,0 +1,36 @@
|
||||
import { apiClient } from './client';
|
||||
import type { EstadoResultados, FlujoEfectivo, ComparativoPeriodos, ConcentradoRfc } from '@horux/shared';
|
||||
|
||||
export async function getEstadoResultados(fechaInicio?: string, fechaFin?: string): Promise<EstadoResultados> {
|
||||
const params = new URLSearchParams();
|
||||
if (fechaInicio) params.set('fechaInicio', fechaInicio);
|
||||
if (fechaFin) params.set('fechaFin', fechaFin);
|
||||
const response = await apiClient.get<EstadoResultados>(`/reportes/estado-resultados?${params}`);
|
||||
return response.data;
|
||||
}
|
||||
|
||||
export async function getFlujoEfectivo(fechaInicio?: string, fechaFin?: string): Promise<FlujoEfectivo> {
|
||||
const params = new URLSearchParams();
|
||||
if (fechaInicio) params.set('fechaInicio', fechaInicio);
|
||||
if (fechaFin) params.set('fechaFin', fechaFin);
|
||||
const response = await apiClient.get<FlujoEfectivo>(`/reportes/flujo-efectivo?${params}`);
|
||||
return response.data;
|
||||
}
|
||||
|
||||
export async function getComparativo(año?: number): Promise<ComparativoPeriodos> {
|
||||
const params = año ? `?año=${año}` : '';
|
||||
const response = await apiClient.get<ComparativoPeriodos>(`/reportes/comparativo${params}`);
|
||||
return response.data;
|
||||
}
|
||||
|
||||
export async function getConcentradoRfc(
|
||||
tipo: 'cliente' | 'proveedor',
|
||||
fechaInicio?: string,
|
||||
fechaFin?: string
|
||||
): Promise<ConcentradoRfc[]> {
|
||||
const params = new URLSearchParams({ tipo });
|
||||
if (fechaInicio) params.set('fechaInicio', fechaInicio);
|
||||
if (fechaFin) params.set('fechaFin', fechaFin);
|
||||
const response = await apiClient.get<ConcentradoRfc[]>(`/reportes/concentrado-rfc?${params}`);
|
||||
return response.data;
|
||||
}
|
||||
21
apps/web/lib/api/usuarios.ts
Normal file
21
apps/web/lib/api/usuarios.ts
Normal file
@@ -0,0 +1,21 @@
|
||||
import { apiClient } from './client';
|
||||
import type { UserListItem, UserInvite, UserUpdate } from '@horux/shared';
|
||||
|
||||
export async function getUsuarios(): Promise<UserListItem[]> {
|
||||
const response = await apiClient.get<UserListItem[]>('/usuarios');
|
||||
return response.data;
|
||||
}
|
||||
|
||||
export async function inviteUsuario(data: UserInvite): Promise<UserListItem> {
|
||||
const response = await apiClient.post<UserListItem>('/usuarios/invite', data);
|
||||
return response.data;
|
||||
}
|
||||
|
||||
export async function updateUsuario(id: string, data: UserUpdate): Promise<UserListItem> {
|
||||
const response = await apiClient.patch<UserListItem>(`/usuarios/${id}`, data);
|
||||
return response.data;
|
||||
}
|
||||
|
||||
export async function deleteUsuario(id: string): Promise<void> {
|
||||
await apiClient.delete(`/usuarios/${id}`);
|
||||
}
|
||||
Reference in New Issue
Block a user