Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/123048152-JJDS/CafeteriaPM_S203/llms.txt

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

The /compras/ endpoints record ingredient supply purchases — the act of buying raw materials from a supplier to restock the kitchen. Every purchase is an atomic operation: a compras_suministros record is created and the associated ingredient’s stock_actual is incremented by the purchased cantidad in the same database transaction. This keeps inventory levels synchronized with procurement history without a separate stock adjustment step. Both the ingredient details and the purchasing user are embedded in every response for full traceability.
Purchases vs. manual stock adjustments: Use /compras/ to record actual supply procurement. Every purchase creates a timestamped audit record that appears in inventory reports and purchase history. For ad-hoc corrections (e.g. adjusting for waste, breakage, or a counting error), use PATCH /productos/ingredientes/{id}/ajustar-stock instead — that endpoint modifies stock_actual directly without creating a purchase record and does not appear in procurement reports.

Endpoints

List all supply purchases

Authorization
string
required
Bearer <token> — Roles: admin, cocina.

GET /compras/
Returns all supply purchase records, ordered by created_at descending (most recent first). Each record includes full ingredient details and the user who registered the purchase. Example response
[
  {
    "id": 22,
    "id_ingrediente": 5,
    "ingrediente": {
      "id": 5,
      "nombre": "Harina de trigo",
      "unidad": "kg",
      "stock_actual": 48.5,
      "stock_minimo": 10.0,
      "costo_unitario": 0.85
    },
    "usuario": {
      "id": 4,
      "nombre": "Pedro Martínez",
      "email": "[email protected]",
      "activo": true,
      "created_at": "2023-09-01T07:00:00",
      "role": { "id": 3, "nombre": "cocina", "descripcion": null }
    },
    "cantidad": 25.0,
    "costo_total": 150.00,
    "fecha": "2024-01-15",
    "created_at": "2024-01-15T08:45:12"
  }
]

Register a supply purchase

Authorization
string
required
Bearer <token> — Roles: admin, cocina.

POST /compras/
Records a new supply purchase and immediately increments the ingredient’s stock_actual by cantidad. The id_usuario is taken from the JWT token automatically. The stock update and purchase record creation happen in a single database transaction — if either fails, both are rolled back. Request body
id_ingrediente
integer
required
ID of the ingredient being restocked. Must match an existing ingredient.
cantidad
float
required
Quantity purchased, expressed in the ingredient’s configured unit (e.g. kg, litres, units). Must be greater than 0. This value is added directly to Ingredient.stock_actual upon successful creation.
costo_total
float
required
Total cost of the purchase in currency units. Must be >= 0. This is the full invoice amount, not the per-unit cost. The per-unit cost (costo_unitario) on the ingredient record itself is not updated by this endpoint.
fecha
string
required
Purchase date in YYYY-MM-DD format. Can be a past date to allow retroactive entry of receipts.
Example request
{
  "id_ingrediente": 5,
  "cantidad": 25.0,
  "costo_total": 150.00,
  "fecha": "2024-01-15"
}
Response201 Created The response reflects the ingredient’s updated stock level (post-purchase).
{
  "id": 22,
  "id_ingrediente": 5,
  "ingrediente": {
    "id": 5,
    "nombre": "Harina de trigo",
    "unidad": "kg",
    "stock_actual": 48.5,
    "stock_minimo": 10.0,
    "costo_unitario": 0.85
  },
  "usuario": {
    "id": 4,
    "nombre": "Pedro Martínez",
    "email": "[email protected]",
    "activo": true,
    "created_at": "2023-09-01T07:00:00",
    "role": { "id": 3, "nombre": "cocina", "descripcion": null }
  },
  "cantidad": 25.0,
  "costo_total": 150.00,
  "fecha": "2024-01-15",
  "created_at": "2024-01-15T08:45:12.004Z"
}
Error responses
StatusDetail
400"Ingrediente no encontrado"id_ingrediente does not match any ingredient.

The CompraOut object

id
integer
Internal purchase record ID.
id_ingrediente
integer
ID of the ingredient that was restocked.
ingrediente
object
Full ingredient snapshot at the time of the response: {id, nombre, unidad, stock_actual, stock_minimo, costo_unitario}. The stock_actual shown here reflects the post-purchase level.
usuario
object
Full user object for the person who registered the purchase: {id, nombre, email, activo, created_at, role}. Populated from the JWT token automatically.
cantidad
float
Quantity purchased, in the ingredient’s configured unit.
costo_total
float
Total purchase cost as recorded at time of entry.
fecha
date
Date the purchase occurred (YYYY-MM-DD), as supplied by the caller.
created_at
datetime
System timestamp when the purchase record was created.

Inventory impact

After a successful POST /compras/, the ingredient’s stock_actual is updated atomically:
new stock_actual = old stock_actual + cantidad
You can verify the result in the response’s ingrediente.stock_actual field or by calling GET /productos/ingredientes/{id}. The GET /stats/inventario-estado endpoint also reflects the update immediately and will remove the ingredient from the criticos list if restocking brought it above stock_minimo.

Build docs developers (and LLMs) love