Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/Danielings/Pasantia-Proyecto/llms.txt

Use this file to discover all available pages before exploring further.

The export module allows authorized users to download a point-in-time snapshot of the inventory in either a print-ready PDF or a machine-readable Excel spreadsheet. Both formats apply the same role-based data scoping as the rest of the API — Superadministrador users export the full inventory while all other roles receive only the assets assigned to their office. Filters can be combined freely to narrow the export to exactly the records needed.

Authentication

Both export endpoints require a valid session cookie. Pass acceso_token in the request cookie header. Unauthenticated requests receive 401 Unauthorized.

Endpoints

GET /api/export/tipos

Returns the list of all distinct asset types currently present in the inventory (from both equipos and perifericos collections). Use this to populate filter dropdowns in a UI before calling the download endpoint.
curl -b 'acceso_token=<token>' \
  http://localhost:3001/api/export/tipos
["Corneta", "Impresora", "Laptop", "Monitor", "Mouse", "PC", "Switch", "Teclado"]
Types are deduplicated, normalized to their canonical casing (from CANONICAL_TIPOS), and sorted alphabetically using the es locale.

GET /api/export/descargar

Downloads the inventory file. The response Content-Type and filename are set automatically based on the formato parameter.

Query Parameters

ParameterRequiredValuesDescription
formatopdf | excelOutput file format
tipoAny type string, or completa / completoFilter to a single asset type; omit or use completa for all types
estadosComma-separated status valuese.g., Funcional,En Reparación
modelosComma-separated model stringse.g., ThinkPad E15,OptiPlex 7090
sedesComma-separated office namese.g., Torre Norte,Torre Sur
tiposComma-separated type valuesMulti-type filter; combined with tipo
searchFree textSearches against marca and serial (normalized)
tipo and tipos can be used together, but they are applied as independent AND filters — both must match for a record to be included. tipo is a single-value filter (e.g., ?tipo=PC) that skips items whose type does not match. tipos is a multi-value filter (e.g., ?tipos=PC,Laptop) that requires the item’s type to appear in the list. If you supply both, only items satisfying both conditions are exported. For a single-type export use tipo alone; for a multi-type export use tipos alone.

Role-Based Data Scoping

The fetchInventario(user) function enforces data boundaries before any filter is applied:
function userCanSeeItem(data, rol, sedeUsuarioNormalizada) {
  if (rol === "Superadministrador") return true;

  const sedeComponente = data.asignacion?.sede?.trim().toLowerCase() || null;
  const torreComponente = data.sede?.trim().toLowerCase() || null;

  return (
    sedeComponente === sedeUsuarioNormalizada ||
    torreComponente === sedeUsuarioNormalizada
  );
}
  • Superadministrador: Receives every record from equipos and perifericos.
  • All other roles: Receive only records where the asset’s asignacion.sede (or legacy sede) matches their own office. Users with no sede receive an empty file.

PDF Output

PDF files are generated server-side using PDFKit. The output is A4 landscape orientation with 40-point margins. Layout features:
  • Title centered at the top with the type label and total record count.
  • Generated timestamp (formatted for es-VE locale) below the title.
  • Table header row with blue background (#1e40af) and white text.
  • Alternating row colors: even rows use #f8fafc, odd rows use #ffffff.
  • Auto-pagination: when a row would exceed the bottom margin, a new landscape page is added and rendering continues at y = 40.
  • Long cell values are truncated with an ellipsis (ellipsis: true) to prevent overflow.
Column widths (points):
ColumnWidth
Tipo70
Serial90
Marca70
Modelo70
Ubicación80
Estado60
Observaciones100

Excel Output

Excel files are generated with SheetJS (xlsx). The workbook contains a single sheet named “Inventario” with the following column structure:
ColumnFieldPreset width (chars)
A — Tipotipo14
B — Serialserial18
C — Marcamarca14
D — Modelomodelo14
E — Ubicaciónsede18
F — Estadoestado12
G — Observacionesnotas30
The first row is the header row with the column names. All subsequent rows contain data. Missing values are written as empty strings.

curl Examples

Download a PDF of all PCs

curl -b 'acceso_token=<token>' \
  "http://localhost:3001/api/export/descargar?formato=pdf&tipo=PC" \
  --output inventario-pc.pdf
The downloaded file will be named inventario-PC-<YYYY-MM-DD>.pdf and will contain only records with tipo: "PC" visible to the authenticated user’s role.

Download an Excel file of the full inventory

curl -b 'acceso_token=<token>' \
  "http://localhost:3001/api/export/descargar?formato=excel&tipo=completa" \
  --output inventario-completo.xlsx

Download a PDF filtered by status and office

curl -b 'acceso_token=<token>' \
  "http://localhost:3001/api/export/descargar?formato=pdf&estados=En+Reparación&sedes=Torre+Norte,Torre+Sur" \
  --output reparaciones.pdf

Download an Excel file for multiple asset types

curl -b 'acceso_token=<token>' \
  "http://localhost:3001/api/export/descargar?formato=excel&tipos=Monitor,Teclado,Mouse" \
  --output perifericos.xlsx

File Naming Convention

The downloaded filename is generated automatically by buildFileName(formato, tipo):
inventario-<tipo-label>-<YYYY-MM-DD>.<ext>
ScenarioExample filename
Single typeinventario-pc-2024-11-03.pdf
Full inventoryinventario-informacion-completa-2024-11-03.xlsx
Multi-word typeinventario-en-reparacion-2024-11-03.pdf
Spaces in the type label are replaced with hyphens, and the value is normalized to lowercase.
If the authenticated user has no sede and is not a Superadministrador, the export endpoint returns a valid but empty file (zero data rows) rather than an error. This is by design — it prevents information leakage while still returning a well-formed document.

Build docs developers (and LLMs) love