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.

Order management is the core operational flow of Ordervista. The system supports three order types — Delivery, Retiro, and Consumo Local — and tracks each order through its status lifecycle from creation to completion. Customers can place and track their own orders, while Operators and Admins have full visibility over all orders and can drive status transitions. Every order creation automatically decrements product stock and generates a linked kitchen command (comanda) in the same database transaction.

Order Types

Orders are classified using the TIPOS_PEDIDO table, referenced by id_tipo_pedido on every order:
id_tipo_pedidoTypeNotes
1DeliveryRequires a saved delivery address (id_direccion)
2RetiroCustomer collects in person at the restaurant; no address required
3Consumo LocalCreated by an Operator or Admin at the counter; id_tipo_pedido is always fixed to 3

Order Statuses

Each order has an id_estado that maps to a stage in the ESTADOS_PEDIDO table. The updateOrderStatus controller accepts values [1, 2, 3, 4, 5].
id_estadoStatusDescription
1PendienteOrder just created, awaiting kitchen acknowledgement
2En preparaciónKitchen is actively preparing the order
3ListoOrder is ready for pickup or delivery
4EntregadoOrder has been handed to the customer
5CancelledAccepted by the status validation logic but not seeded as a named status; excluded from sales reports

Creating a Customer Order

Authenticated customers use this endpoint to place Delivery or Retiro orders. Endpoint: POST /api/orders
Auth: Required (any authenticated user)
The server validates each item against live stock, calculates the total server-side (the caller-supplied total field is ignored), inserts the order and its line items, decrements stock, and creates the COMANDA record — all within a single database transaction.
{
  "id_tipo_pedido": 1,
  "id_direccion": 5,
  "observacion": "Sin cebolla por favor",
  "items": [
    {
      "id_producto": 3,
      "cantidad": 2
    }
  ]
}
Success response: 201 Created
{
  "mensaje": "Pedido creado correctamente",
  "id_pedido": 47
}

Creating an In-Person Order

Operators and Admins use this endpoint to register walk-in orders at the counter. id_tipo_pedido is automatically set to 3 (Consumo Local) by the server; the caller does not supply it. Endpoint: POST /api/orders/in-person
Auth: Required — Operator or Admin role only
{
  "observacion": "Mesa 4",
  "items": [
    {
      "id_producto": 7,
      "cantidad": 1
    }
  ]
}
Success response: 201 Created
{
  "mensaje": "Pedido presencial creado correctamente",
  "id_pedido": 48
}

Updating Order Status

Operators and Admins advance an order through the lifecycle using a PATCH request. Only valid status IDs [1, 2, 3, 4, 5] are accepted. Endpoint: PATCH /api/orders/manage/:id/status
Auth: Required — Operator or Admin role only
{
  "id_estado": 2
}
Success response: 200 OK
{
  "mensaje": "Estado del pedido actualizado correctamente"
}

Order Data Schema

PEDIDOS table

ColumnTypeDescription
id_pedidoINTPrimary key
id_usuarioINTFK → USUARIOS
id_tipo_pedidoINTFK → TIPOS_PEDIDO
id_direccionINT (nullable)FK → DIRECCIONES
id_estadoINTFK → ESTADOS_PEDIDO
fecha_pedidoDATETIMETimestamp of creation
totalDECIMAL(10,2)Server-calculated order total
observacionVARCHAR(255)Optional notes

DETALLE_PEDIDO table

ColumnTypeDescription
id_detalleINTPrimary key
id_pedidoINTFK → PEDIDOS
id_productoINTFK → PRODUCTOS
cantidadINTUnits ordered
precio_unitarioDECIMAL(10,2)Price at time of order (taken from PRODUCTOS at insert time)
subtotalDECIMAL(10,2)cantidad × precio_unitario

Typical Operator Workflow

1

Log in as Operator

Navigate to /login and authenticate with Operator credentials. The JWT is stored in LocalStorage.
2

View all active orders

Open the Operator panel at /operator. The screen calls GET /api/orders/manage and lists every order across all customers.
3

Create an in-person order (if needed)

Navigate to /operator/new-order and use the new-order form, which calls POST /api/orders/in-person. A comanda is generated automatically.
4

Advance order status

From the order list, select an order and update its status via PATCH /api/orders/manage/:id/status — e.g., move it from Pendiente (1) → En preparación (2) → Listo (3) → Entregado (4).
5

Generate a receipt

Once the order is delivered, navigate to /receipts to generate and print the operational voucher for the completed order.

Build docs developers (and LLMs) love