Actualizar frontend/src/lib/api.js

This commit is contained in:
2026-10-09 13:50:08 -05:00
parent f2f78fe49d
commit 58a201d308

View File

@@ -156,6 +156,22 @@ export const api = {
method: "POST", headers: { "Content-Type": "application/json" }, method: "POST", headers: { "Content-Type": "application/json" },
body: JSON.stringify({ codigos, asesores, estados }), body: JSON.stringify({ codigos, asesores, estados }),
}).then((r) => { if (!r.ok) throw new Error("Error al obtener base"); return r.json(); }), }).then((r) => { if (!r.ok) throw new Error("Error al obtener base"); return r.json(); }),
// EXPORTAR BASE
exportarBaseAsesores: () => _fetch("/api/exportar-base/asesores", {}),
exportarBaseDescargar: async (asesor, etiquetas = []) => {
const qEtq = (etiquetas || []).map((e) => `&etiquetas=${encodeURIComponent(e)}`).join("");
const r = await fetch(`${BASE_URL}/api/exportar-base?asesor=${encodeURIComponent(asesor)}${qEtq}`);
if (!r.ok) throw new Error("Error al exportar base");
const blob = await r.blob();
const cd = r.headers.get("Content-Disposition") || "";
const m = cd.match(/filename=([^;]+)/);
const nombre = m ? m[1].trim() : "base.xlsx";
const url = URL.createObjectURL(blob);
const a = document.createElement("a");
a.href = url; a.download = nombre;
document.body.appendChild(a); a.click();
document.body.removeChild(a); URL.revokeObjectURL(url);
},
// SUBIR BASE // SUBIR BASE
subirBaseEtiquetas: () => _fetch("/api/subir-base/etiquetas", {}), subirBaseEtiquetas: () => _fetch("/api/subir-base/etiquetas", {}),
subirBaseAsesores: () => _fetch("/api/subir-base/asesores", {}), subirBaseAsesores: () => _fetch("/api/subir-base/asesores", {}),