Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/ytabeloved/ordervista/llms.txt

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

The Reports API provides a single, data-rich endpoint designed to power the Ordervista admin dashboard. A single GET request fires seven parallel database queries and returns the results as a structured JSON object containing sales summaries, day-by-day revenue trends, top-selling products, order status breakdowns, category-level sales, and a snapshot of the most recent orders. Most sections respect the optional startDate / endDate date window; the metrics and recentOrders keys always return system-wide aggregates regardless of the filter. Cancelled orders (id_estado = 5) are excluded from all date-filtered queries. This endpoint is restricted to Administrator users (role 1) only.

GET /api/reports/dashboard

Returns a composite analytics payload for the admin dashboard. Auth required: Yes — role 1 (Admin)

Query parameters

startDate
string
Start of the date range, in YYYY-MM-DD format (e.g. 2025-01-01). When omitted, the query covers all historical data.
endDate
string
End of the date range, in YYYY-MM-DD format (e.g. 2025-01-31). When omitted, the query covers up to the current date.

Response

summary
object
Aggregated sales figures for the requested date range, excluding cancelled orders.
summary.total_pedidos
integer
Count of all non-cancelled orders within the date window.
summary.ventas_estimadas
number
Sum of all order totals within the date window.
summary.ticket_promedio
number
Average order value (ventas_estimadas / total_pedidos) within the date window.
summary.clientes_atendidos
integer
Count of distinct customers who placed at least one non-cancelled order within the date window.
metrics
object
System-wide operational metrics calculated over all data, independent of the date filter.
metrics.orders_today
integer
Count of non-cancelled orders placed today.
metrics.total_customers
integer
Total number of registered customer accounts (role 3).
metrics.active_products
integer
Count of products currently marked as active.
metrics.active_orders
integer
Count of orders currently in an active state (Pendiente, En preparación, or Listo).
salesByDay
array
Array of daily revenue data points for the requested period. Used to render the bar chart in the dashboard.
salesByDay[].fecha
string
Date string in YYYY-MM-DD format.
salesByDay[].total_pedidos
integer
Count of non-cancelled orders placed on that day.
salesByDay[].ventas
number
Total revenue for that day.
topProducts
array
Ranked list of best-selling products within the date window, limited to 8 results.
topProducts[].id_producto
integer
Product identifier.
topProducts[].nombre
string
Product name.
topProducts[].categoria
string | null
Category name from CATEGORIAS.nombre.
topProducts[].cantidad_vendida
integer
Total units sold within the date window.
topProducts[].total_vendido
number
Total revenue generated by this product within the date window.
ordersByStatus
array
Breakdown of order counts by status code, excluding cancelled orders. Used for the status distribution chart.
ordersByStatus[].id_estado
integer
Status code.
ordersByStatus[].estado
string
Human-readable status name (e.g. "Pendiente", "En preparación", "Listo", "Entregado").
ordersByStatus[].total
integer
Number of orders in this status within the date window.
salesByCategory
array
Revenue grouped by product category. Used for the pie chart.
salesByCategory[].id_categoria
integer
Category identifier.
salesByCategory[].categoria
string | null
Category name from CATEGORIAS.nombre.
salesByCategory[].total_vendido
number
Total revenue attributable to this category within the date window.
salesByCategory[].cantidad_vendida
integer
Total units sold in this category within the date window.
recentOrders
array
Fixed snapshot of the 8 most recently placed orders, regardless of the date filter. Intended for the “Recent Activity” feed on the dashboard.
recentOrders[].id_pedido
integer
Order identifier.
recentOrders[].fecha_pedido
string
ISO 8601 datetime the order was placed.
recentOrders[].total
number
Order total.
recentOrders[].id_estado
integer
Current status code (14).
recentOrders[].id_tipo_pedido
integer
Order type (1 = Delivery, 2 = Retiro, 3 = Consumo Local).
recentOrders[].cliente_nombre
string
Full name of the customer who placed the order.
recentOrders[].cliente_email
string
Email address of the customer who placed the order.
recentOrders[].estado
string
Human-readable status name from ESTADOS_PEDIDO.nombre.
recentOrders[].total_items
integer
Count of distinct line items in the order.
curl "https://ordervista-backend.onrender.com/api/reports/dashboard?startDate=2025-01-01&endDate=2025-01-31" \
  -H "Authorization: Bearer <token>"

Sample partial response

{
  "summary": {
    "total_pedidos": 42,
    "ventas_estimadas": 485000.00,
    "ticket_promedio": 11547.62,
    "clientes_atendidos": 31
  },
  "metrics": {
    "orders_today": 7,
    "total_customers": 120,
    "active_products": 38,
    "active_orders": 5
  },
  "salesByDay": [
    { "fecha": "2025-01-01", "total_pedidos": 3, "ventas": 14500.00 },
    { "fecha": "2025-01-02", "total_pedidos": 5, "ventas": 22000.00 }
  ],
  "topProducts": [
    {
      "id_producto": 3,
      "nombre": "Hamburguesa Clásica",
      "categoria": "Hamburguesas",
      "cantidad_vendida": 34,
      "total_vendido": 289000.00
    }
  ],
  "ordersByStatus": [
    { "id_estado": 4, "estado": "Entregado", "total": 35 },
    { "id_estado": 1, "estado": "Pendiente", "total": 3 }
  ],
  "salesByCategory": [
    {
      "id_categoria": 1,
      "categoria": "Hamburguesas",
      "total_vendido": 289000.00,
      "cantidad_vendida": 34
    }
  ],
  "recentOrders": [
    {
      "id_pedido": 98,
      "fecha_pedido": "2025-01-31T18:45:00.000Z",
      "total": 17000.00,
      "id_estado": 2,
      "id_tipo_pedido": 1,
      "cliente_nombre": "María González",
      "cliente_email": "maria@example.com",
      "estado": "En preparación",
      "total_items": 2
    }
  ]
}

Error responses

Statusmensaje
401Unauthorized — missing or invalid token
403Forbidden — insufficient role
500"Error al obtener reportes"

Build docs developers (and LLMs) love