The sales endpoints cover the two core operations of the register: recording a completed sale with one or more line items, and fetching a previously recorded sale by its internal ID. Both endpoints delegate to stored procedures; the backend executes no raw SQL.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/15aozzz/Lab-Nova-Salud/llms.txt
Use this file to discover all available pages before exploring further.
All routes except
POST /api/auth/login require a valid JWT in the Authorization: Bearer <token> header.POST /api/ventas/registrar
Registers a complete sale — header and line items — in a single database transaction. Internally callssp_registrar_venta, which generates the document number, decrements stock via triggers, and rolls back automatically if any item is out of stock.
Request body
Document type ID (e.g.,
1 for Boleta, 2 for Factura). Obtain valid IDs from GET /api/comprobantes/tipos.ID of the cashier registering the sale.
Grand total of the sale. Must be greater than
0.Line items array. Must contain at least one item.
Customer DNI or RUC. Optional for anonymous sales.
Customer full name or business name. Optional for anonymous sales.
Response
200 OK — successtrue when the sale was committed successfully.Internal ID of the new sale record.
Document series assigned to this sale (e.g.,
"B001").Zero-padded correlative number (e.g.,
"00000001").Total amount echoed back from the request body.
Always
false.Human-readable reason for the failure (e.g., insufficient stock detected by the trigger).
Errors
| Status | Condition | Body |
|---|---|---|
400 | id_tipo_comprobante missing or not a number | { "error": "id_tipo_comprobante es requerido y debe ser un número" } |
400 | id_usuario missing or not a number | { "error": "id_usuario es requerido y debe ser un número" } |
400 | total missing or <= 0 | { "error": "total es requerido y debe ser mayor a 0" } |
400 | detalle empty or not an array | { "error": "detalle debe ser un array con al menos 1 elemento" } |
400 | Stock trigger rejects the transaction | { "exito": false, "mensaje": "<trigger message>" } |
500 | Unexpected server or database error | { "error": "<message>" } |
Example
Response
GET /api/ventas/:id
Returns the full detail of a sale: the document header and all associated line items. Callssp_get_venta_detalle, which returns two result sets; the backend maps them to cabecera and detalle.
Path parameters
Internal sale ID returned by
POST /api/ventas/registrar.Response
200 OKSale header record from the first SP result set.
Line items from the second SP result set.
Errors
| Status | Condition | Body |
|---|---|---|
404 | No sale exists for the given ID | { "error": "Venta no encontrada" } |
500 | Database or server error | { "error": "<message>" } |
Example
Response