Files
FRASA-CAS/apps/mi-dia/src/services/reporte-mi-tablero.ts
Consult AS Technology 98889bbf6a fix(api-url): todas las apps usan || en vez de ?? para VITE_API_URL
- 11 archivos corregidos: agente-ia, alta-clientes, cobranza, cotizador,
  dashboards, mi-dia, landing (auth.ts, api.ts, mi-dia.ts, reportes.ts,
  push.ts, notas.ts, recordatorios.ts, reporte-mi-tablero.ts)
- ?? solo cubre null/undefined, || cubre string vacío
- 7 apps reconstruidas
2026-09-10 21:26:54 +00:00

48 lines
1.1 KiB
TypeScript

import { conAuth, manejar401 } from './auth'
const API_URL = import.meta.env.VITE_API_URL || '/api'
async function fetchJson<T>(path: string, init: RequestInit = {}): Promise<T> {
const res = await fetch(`${API_URL}${path}`, conAuth(init))
manejar401(res)
if (!res.ok) {
const body = (await res.json().catch(() => null)) as { error?: string } | null
throw new Error(body?.error ?? `Error ${res.status}`)
}
return (await res.json()) as T
}
// ---------- Interfaces ----------
export interface MiTablero {
generadoEn: string
leadsPorDia: { fecha: string; cantidad: number }[]
conversion: {
leads: number
oportunidades: number
apartados: number
vendidos: number
}
ventasMes: {
monto: number
unidades: number
}
porOrigen: {
origen: string
total: number
convertidos: number
}[]
porDesarrollo: {
desarrollo: string
ventas: number
}[]
actividadesHoy: number
actividadesPendientes: number
}
// ---------- Fetch ----------
export function fetchMiTablero(): Promise<MiTablero> {
return fetchJson<MiTablero>('/reportes/mi-tablero')
}