๐ฆ Orders API โ
โ Create Order โ
POST /api/orders
Authorization: Bearer <token> (optional โ guest checkout supported)Request (authenticated customer):
json
{
"locationId": "location-id",
"orderType": "DELIVERY",
"addressId": "address-id",
"items": [
{
"menuItemId": "item-id",
"quantity": 2,
"comment": "No onions",
"options": [
{ "menuOptionValueId": "option-value-id" }
]
}
],
"tip": 5.00,
"couponCode": "WELCOME10",
"scheduledAt": "2025-06-15T18:00:00Z",
"paymentMethod": "STRIPE"
}Request (guest checkout):
json
{
"locationId": "location-id",
"orderType": "PICKUP",
"guestName": "John Doe",
"guestEmail": "john@example.com",
"guestPhone": "+1234567890",
"items": [
{
"menuItemId": "item-id",
"quantity": 1
}
],
"paymentMethod": "CASH"
}Response: 201 Created
json
{
"success": true,
"data": {
"id": "cuid",
"orderNumber": "KA-20250615-001",
"status": "PENDING",
"orderType": "DELIVERY",
"subtotal": 25.98,
"deliveryFee": 3.99,
"tax": 2.08,
"discount": 2.60,
"tip": 5.00,
"total": 34.45,
"items": [...]
}
}๐ List Orders (Staff) โ
GET /api/orders?page=1&limit=20
Authorization: Bearer <staff-token>Returns all orders with pagination. Staff only.
๐๏ธ List Customer Orders โ
GET /api/orders/my-orders
Authorization: Bearer <customer-token>Returns orders for the authenticated customer.
๐ Get Order โ
GET /api/orders/:id
Authorization: Bearer <token>Returns full order details with items, options, and payment info.
๐ Update Order Status โ
PATCH /api/orders/:id/status
Authorization: Bearer <staff-token>Request:
json
{
"status": "CONFIRMED"
}Valid transitions:
| From | To |
|---|---|
PENDING | โ
CONFIRMED, โ CANCELLED |
CONFIRMED | ๐ณ PREPARING, โ CANCELLED |
PREPARING | โ
READY, โ CANCELLED |
READY | ๐ OUT_FOR_DELIVERY, โ
DELIVERED, ๐ PICKED_UP, โ CANCELLED |
OUT_FOR_DELIVERY | โ
DELIVERED, โ CANCELLED |
โ ๏ธ Error Cases โ
| Scenario | Status | Error |
|---|---|---|
| ๐ฝ๏ธ Invalid menu item | 400 | Menu item not found |
| ๐ช Location inactive | 400 | Location is not active |
| ๐ฐ Below minimum order | 400 | Order below minimum |
| ๐๏ธ Invalid coupon | 400 | Coupon validation error |
| ๐ Invalid status transition | 400 | Invalid status transition |
| ๐ Order not found | 404 | Order not found |