Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/Edwin950821/BodegaX/llms.txt

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

BodegaX does not expose a dedicated /orders endpoint. Instead, order tracking is implemented through the existing sales data model: every dispatched client request becomes a venta (sale) record with associated producto_ventas line items. Understanding this mapping is key to reading the History page correctly, filtering order data by client, and generating end-of-day reports with the TerminarJornada PDF export.
Pending or in-progress crate requests (Solicitar Caja) are tracked exclusively in frontend state — they are not persisted to the backend until an admin confirms the dispatch via Despachar Caja. The backend stores only completed, confirmed orders.

What Is an “Order” in BodegaX?

In BodegaX terminology, a crate request (solicitud de caja) becomes a sale (venta) the moment an admin dispatches it. There is no intermediate “pending order” state in the database. The lifecycle moves from a frontend-only draft directly to a persisted sale record upon admin confirmation. From a data perspective, a fully recorded order consists of:
  • One venta record — the sale header, capturing the client, admin, total value, and date
  • One or more producto_venta records — one per product brand included in the order, capturing quantity and subtotal
  • Updated producto records — each product’s stock count is decremented as part of the same dispatch operation

Full Order Lifecycle

The diagram below shows how a client crate request flows through BodegaX from initiation to history and reporting: Step 1 — Client Requests Crates (Solicitar Caja) A user with role === 'user' opens the Solicitar Caja dialog on the Home page. They specify which beer brands and quantities they need. This step exists only in the Angular frontend — no API call is made yet. The selection is passed as data to the Despachar Caja dialog. Step 2 — Admin Dispatches (Despachar Caja) An admin confirms the client’s request. The frontend then executes the following API calls in sequence:
  1. POST /ventas/create — creates the sale header and returns the new uuid
  2. POST /producto-ventas/create — called once for each product with cantidad > 0, using the uuid from step 1
  3. PUT /productos/edit — called for each product to decrement its stock by the dispatched quantity
The dialog closes only after the final stock update completes successfully. Step 3 — Order Appears in History The completed sale is now retrievable via GET /ventas/all. The History page fetches all sales, filters by the logged-in user’s UUID if they are a role === 'user', joins client names from GET /admin/all, and joins product names from GET /productos/all via the line items from GET /producto-ventas/all. Step 4 — End-of-Day PDF Report (TerminarJornada) An admin opens the TerminarJornada dialog, selects a client, and generates a PDF. The dialog loads the same four endpoints (/admin/all, /ventas/all, /productos/all, /producto-ventas/all) and aggregates quantities and subtotals per product across all sales for the selected client. The PDF is saved locally as Jornada.pdf.

Entity Relationships

The table below shows how the four data entities relate to each other:
EntityAPI SourceKey FieldsRelates To
usuario (User/Client)GET /admin/alluuid, nombre, roleReferenced by venta.uuid_cliente and venta.uuid_admin
producto (Product)GET /productos/alluuid, nombre, precio, stockReferenced by producto_venta.uuid_producto
venta (Sale/Order)GET /ventas/alluuid, uuid_cliente, uuid_admin, total_venta, fechaParent of producto_venta records
producto_venta (Line Item)GET /producto-ventas/alluuid, uuid_producto, uuid_venta, cantidad, total_parcialChild of venta; references producto
Relationship summary:
  • A venta belongs to one admin (uuid_admin) and one client (uuid_cliente), both resolvable via GET /admin/all
  • A venta has one or many producto_ventas (joined by uuid_venta === venta.uuid)
  • Each producto_venta references one producto (joined by uuid_producto === producto.uuid)
  • A producto can appear in many producto_ventas across different sales

Filtering Orders by Client

The backend returns all records from GET /ventas/all without built-in filtering. To retrieve a specific client’s order history, filter the response array client-side by the client’s UUID:
curl http://localhost:8080/ventas/all
Then, in your application code or API client:
// All sales where uuid_cliente matches the target client
ventas.filter(v => v.uuid_cliente === "b2c3d4e5-f6a7-8901-bcde-f12345678901")
To get a complete order history for a specific client — including per-product quantities — fetch all four endpoints, filter ventas by uuid_cliente, then filter producto_ventas by the matching uuid_venta values. This gives you every crate brand, quantity, and subtotal for that client across all their orders.

Complete Dispatch Request Sequence

The following curl sequence demonstrates the full set of API calls that occur during a single Despachar Caja operation in which a client orders 5 crates of Club Colombia and 3 crates of Águila: 1. Create the sale header:
curl -X POST http://localhost:8080/ventas/create \
  -H "Content-Type: application/json" \
  -d '{
    "uuid_admin": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
    "uuid_cliente": "b2c3d4e5-f6a7-8901-bcde-f12345678901",
    "total_venta": 641000,
    "fecha": "2024-11-15T14:32:00.000Z"
  }'
Response includes "uuid": "f6a7b8c9-d0e1-2345-fabc-456789012345" — used in all subsequent calls. 2. Add the Club Colombia line item:
curl -X POST http://localhost:8080/producto-ventas/create \
  -H "Content-Type: application/json" \
  -d '{
    "uuid_producto": "c3d4e5f6-a7b8-9012-cdef-123456789012",
    "uuid_venta": "f6a7b8c9-d0e1-2345-fabc-456789012345",
    "cantidad": 5,
    "total_parcial": 425000
  }'
3. Decrement Club Colombia stock (was 120, now 115):
curl -X PUT http://localhost:8080/productos/edit \
  -H "Content-Type: application/json" \
  -d '{
    "uuid": "c3d4e5f6-a7b8-9012-cdef-123456789012",
    "nombre": "Club Colombia",
    "precio": 85000,
    "stock": 115
  }'
4. Add the Águila line item:
curl -X POST http://localhost:8080/producto-ventas/create \
  -H "Content-Type: application/json" \
  -d '{
    "uuid_producto": "d4e5f6a7-b8c9-0123-defa-234567890123",
    "uuid_venta": "f6a7b8c9-d0e1-2345-fabc-456789012345",
    "cantidad": 3,
    "total_parcial": 216000
  }'
5. Decrement Águila stock (was 85, now 82):
curl -X PUT http://localhost:8080/productos/edit \
  -H "Content-Type: application/json" \
  -d '{
    "uuid": "d4e5f6a7-b8c9-0123-defa-234567890123",
    "nombre": "Águila",
    "precio": 72000,
    "stock": 82
  }'
After step 5 completes, the Despachar Caja dialog closes and the sale is fully recorded. It will appear in GET /ventas/all and GET /producto-ventas/all immediately.

Build docs developers (and LLMs) love