Skip to Content
MySagra 1.4.0 is released 🎉

Orders

Manage the full order lifecycle — from creation to confirmation, completion, and pickup. Orders contain items grouped by category, support discounts/surcharges, and broadcast real-time events.

Order Lifecycle

PENDING → CONFIRMED → COMPLETED → PICKED_UP

You can transition from any state to any other state directly.

Order Object (List)

Returned by GET /v1/orders (lightweight, without item details):

{ "id": "clx1a2b3c4d5e6f7g8h9i0j1", "displayCode": "A01", "table": "5", "customer": "Mario Rossi", "subTotal": "25.50", "status": "pending", "createdAt": "2025-11-04T10:30:00Z", "updatedAt": "2025-11-04T10:30:00Z" }
FieldTypeDescription
idstringUnique identifier (CUID)
displayCodestring3-character alphanumeric order code
tablestringTable number or identifier
customerstringCustomer name
subTotalstringSubtotal before discount
statusstringpending, confirmed, completed, or picked_up
createdAtstringISO 8601 creation timestamp
updatedAtstringISO 8601 last update timestamp

Order Object (Detail)

Returned by GET /v1/orders/{id} (items grouped by category with ingredients):

{ "id": 42, "displayCode": "A01", "table": "5", "customer": "Mario Rossi", "subTotal": "25.50", "createdAt": "2025-11-12T10:30:00.000Z", "categorizedItems": [ { "category": { "id": 1, "name": "Pizza" }, "items": [ { "id": "clm1234567890", "quantity": 2, "notes": "No onions, extra cheese", "unitPrice": 8.50, "unitSurcharge": 0.75, "total": 18.50, "food": { "id": "clx1a2b3c4d5e6f7g8h9i0j1", "name": "Pizza Margherita", "description": "Classic pizza with tomato and mozzarella", "price": "8.50", "available": true, "ingredients": [ { "id": "clm111", "name": "Mozzarella" }, { "id": "clm222", "name": "Tomato Sauce" } ] } } ] } ] }

Order Item Input

Used when creating or confirming orders:

FieldTypeRequiredDescription
foodIdstringYesFood item ID (CUID)
quantityintegerYesQuantity (min: 1)
notesstringNoNotes for this item
surchargenumberNoExtra surcharge (default: 0)

GET /v1/orders

Retrieve orders with advanced filtering and pagination.

Authentication: Bearer token (admin or operator)

Query Parameters

ParameterTypeDefaultDescription
searchstring—Search by customer, table, or order code
displayCodestring—Filter by display code
pageinteger1Page number (1-based)
limitinteger20Items per page (max 100)
sortBystringcreatedAtSort field
statusstring[]—Filter by status (repeatable)
dateFromdatetime—Start date filter (inclusive)
dateTodatetime—End date filter (inclusive)

Example

GET /v1/orders?status=CONFIRMED&status=COMPLETED&page=1&limit=10&dateFrom=2025-11-01T00:00:00Z

Response 200 OK

{ "orders": [ ... ], "pagination": { "currentPage": 1, "totalOrdersPages": 5, "totalOrdersItems": 100, "itemsPerPage": 20, "hasNextPage": true, "hasPrevPage": false, "nextPage": 2, "prevPage": null } }

Errors

StatusDescription
400Invalid query parameters
401Unauthorized — authentication required
403Forbidden — insufficient permissions

GET /v1/orders/{id}

Retrieve complete order details with items grouped by category.

Authentication: Bearer token (admin or operator)

Path Parameters

ParameterTypeDescription
idintegerNumeric order ID

Response 200 OK

Returns an Order Detail Object.

Errors

StatusDescription
400Invalid order ID format
401Unauthorized — authentication required
403Forbidden — insufficient permissions
404Order not found

POST /v1/orders

Create a new order, optionally confirming it immediately.

Authentication: Bearer token (admin or operator)

Request Body

{ "table": "5", "customer": "Mario Rossi", "orderItems": [ { "foodId": "clx1a2b3c4d5e6f7g8h9i0j1", "quantity": 2, "notes": "No onions, extra cheese", "surcharge": 1.50 } ], "confirm": { "paymentMethod": "CASH", "discount": 2.50, "userId": "clx1a2b3c4d5e6f7g8h9i0j1", "cashRegisterId": "clx9z8y7x6w5v4u3t2s1r0q9" } }
FieldTypeRequiredDescription
tablestringYesTable number (min 1 char)
customerstringYesCustomer name (min 1 char)
orderItemsarrayYesAt least one Order Item Input
confirmobjectNoIf provided, order is created as CONFIRMED

Confirm Object

FieldTypeRequiredDescription
paymentMethodstringYesCASH or CARD
discountnumberNoDiscount amount (default: 0)
userIdstringNoUser who confirmed
cashRegisterIdstringNoCash register used
orderItemsarrayNoReplace existing items

Price Calculation

  • Item total = surcharge + (unitPrice × quantity)
  • Subtotal = sum of all item totals
  • Total = subtotal - discount

Response 201 Created

{ "id": "clx1a2b3c4d5e6f7g8h9i0j1", "displayCode": "A01", "table": "5", "customer": "Mario Rossi", "subTotal": "25.50", "status": "CONFIRMED", "ticketNumber": 42, "createdAt": "2025-11-12T10:30:00Z", "updatedAt": "2025-11-12T10:30:00Z", "orderItems": true }

The orderItems field is true to indicate items were created. Use GET /v1/orders/{id} for full details.

Errors

StatusDescription
400Invalid request or food items not found
401Unauthorized — authentication required
403Forbidden — insufficient permissions

POST /v1/orders/{id}/confirm

Confirm a PENDING order.

Authentication: Bearer token (admin or operator)

Path Parameters

ParameterTypeDescription
idintegerOrder ID (must be PENDING)

Request Body

{ "paymentMethod": "CASH", "discount": 5, "userId": "clx1a2b3c4d5e6f7g8h9i0j1", "cashRegisterId": "clx9z8y7x6w5v4u3t2s1r0q9", "orderItems": [ { "foodId": "clm1234567890", "quantity": 2, "notes": "Extra spicy", "surcharge": 1.50 } ] }
FieldTypeRequiredDescription
paymentMethodstringYesCASH or CARD
discountnumberNoDiscount amount (default: 0)
userIdstringNoUser who confirmed
cashRegisterIdstringNoCash register used
orderItemsarrayNoIf provided, replaces all existing items

Ticket numbers are daily progressive and reset at 12:00 PM.

Response 200 OK

Returns the confirmed order with ticket number and payment details.

Errors

StatusDescription
400Invalid items, or order is already confirmed
401Unauthorized — authentication required
403Forbidden — insufficient permissions
404Order not found
500Internal server error

POST /v1/orders/{id}/reprint

Trigger a reprint of selected order items by broadcasting a reprint-order event to the printer SSE channel. Does not modify the order.

Authentication: Bearer token (admin or operator)

Path Parameters

ParameterTypeDescription
idintegerNumeric order ID

Request Body

{ "orderItems": [ { "id": "clx0abc0001mx01example" } ], "reprintReceipt": false }
FieldTypeRequiredDescription
orderItemsarrayYesList of { id: string } — order item CUIDs to reprint (min 1)
reprintReceiptbooleanYesWhether to also reprint the fiscal receipt

Response 200 OK

Returns the order with:

  • reprintOrderItems — filtered items selected for reprint
  • reprintReceipt — whether the receipt should be reprinted
  • orderItems — complete unfiltered list of all order items

Errors

StatusDescription
400Invalid request body or item IDs not found in this order
401Unauthorized — authentication required
403Forbidden — insufficient permissions
404Order not found

PATCH /v1/orders/{id}

Update order status.

Authentication: Bearer token (admin or operator)

Path Parameters

ParameterTypeDescription
idintegerNumeric order ID

Request Body

{ "status": "COMPLETED" }
FieldTypeRequiredValues
statusstringYesPENDING, CONFIRMED, COMPLETED, PICKED_UP

Response 200 OK

Returns the updated order.

Errors

StatusDescription
400Invalid status value
401Unauthorized — authentication required
403Forbidden — insufficient permissions
404Order not found

DELETE /v1/orders/{id}

Permanently delete an order and all its items.

Authentication: Bearer token (admin or operator)

Path Parameters

ParameterTypeDescription
idintegerNumeric order ID

Response 204 No Content

Errors

StatusDescription
400Invalid order ID
401Unauthorized — authentication required
403Forbidden — insufficient permissions
404Order not found
Last updated on