Allocation Usage
1. Tổng quan
| Thuộc tính | Giá trị |
|---|---|
| ID | FEAT-SALE-ALLOC |
| Trạng thái | Stable |
| Owner | sale-team |
| Phụ thuộc | AllocationUnit, AllocationZone, AllocationLayout (schema allocation), SaleOrder, Reservation |
Sức chứa allocation sử dụng một dòng đa hình AllocationUsage(usageType, usageId) liên kết một AllocationUnit (bàn/ghế/tủ) với hoặc một SaleOrder hoặc một Reservation. Mỗi đơn vị được phân bổ có một dòng usage; cùng vòng đời cho cả hai parent. Xem ADR-0004.
2. Mô hình thực thể
Chi tiết trường — xem Mô hình miền §3.5.
3. Vòng đời
| Từ | Sự kiện | Đến |
|---|---|---|
ACTIVE | SaleOrder thanh toán thành công | SUCCESS |
ACTIVE | hủy order/reservation | CANCELLED |
ACTIVE | reservedTo của reservation đã qua mà chưa check-in | EXPIRED |
4. Vận hành
AllocationUsageService (allocation-usage.service.ts — 841 dòng).
| Phương thức | Chữ ký | Mục đích |
|---|---|---|
startForOrder | { saleOrderId, merchantId, allocationUnitId, type, assigneeId? } | Tạo usage ACTIVE gắn với SaleOrder |
complete | { usageId } | ACTIVE → SUCCESS (gọi từ payment-success handler) |
moveUsagesToOrder | { fromOrderId, toOrderId } | Dùng khi merge order để chuyển hướng usage hiện có |
resolvePrincipalIdsByAllocation | { unitId, zoneId, ... } | Phân giải order/reservation TỪ unit/zone để định tuyến |
| Batch cancel / complete | endpoint theo spec | Chuyển trạng thái hàng loạt |
5. REST Endpoints
| Verb | Path | Auth | Permission | Handler |
|---|---|---|---|---|
| 6× CRUD | /allocation-usages | JWT/BASIC | AllocationUsage.<crud> | merchant-scoped |
GET | /allocation-usages?zoneId=...&unitId=... | JWT/BASIC | AllocationUsage.find | lọc theo zone/unit |
| Batch ops | /allocation-usages/batch/... | JWT/BASIC | (theo op) | AllocationUsageService.* |
OpenAPI live:
/v1/api/sale/doc/openapi.json.
6. Sự kiện
Outbound (WebSocket):
| Topic | Khi nào | Action enum | Rooms |
|---|---|---|---|
observation/allocation/allocation-usage | startForOrder | USAGE_CREATED | getAllocationUsageRooms (merchant + unit + cây phân cấp zone) |
| same | complete | USAGE_COMPLETED | same |
| same | cancel | USAGE_CANCELLED | same |
Outbound (Kafka): không trực tiếp — phát Kafka payment-success thuộc về SaleOrderPaymentWebhookService.
7. Trang liên quan
- Reservation — đồng tác giả các dòng usage
- Sale Order
- Mô hình miền
- ADR-0004 Polymorphic AllocationUsage