<aside> <img src="/icons/checklist_green.svg" alt="/icons/checklist_green.svg" width="40px" />

</aside>

Persistence Model

Table orders [note: 'Đơn hàng chính sau khi checkout từ giỏ'] 
{
  id                         uuid                [pk, note: 'Khóa chính đơn hàng']  
  user_id                    uuid                [ref: > users.id, note: 'Người tạo đơn']  
  cart_id                    uuid                [ref: > carts.id] 
  total_amount_before        int                 [not null, note: 'Tổng trước giảm giá']
  total_amount_after         int                 [not null, note: 'Tổng sau giảm giá']
  discount_total             int                 [not null, note: 'Tổng giảm giá']        
  currency                   varchar             [not null, default: 'VND', note: 'Đơn vị tiền tệ']  
  status                     order_status        [default: 'pending', note: 'pending/paid/cancelled/refunded']  
  notes                      text                [null]
  created_at                 timestamp           [default: `now()`]  
  updated_at                 timestamp           [default: `now()`] 
}
Table order_items [note: 'Chi tiết từng mục trong đơn hàng'] 
{
  id                  uuid                          [pk, note: 'Mục riêng trong đơn hàng']  
  order_id            uuid                          [ref: > orders.id, note: 'Thuộc đơn nào']  
  product_id          uuid                          [not null, ref: > products.id]
  regularPrice        int
  discountedPrice     int
  quantity            int                           [default: 1, note: 'Số lượng mua']  
  discount_amount     int                           [default: 0, note: 'Số tiền giảm trên mục này']  
  created_at          timestamp                     [default: `now()`]  
}
Table order_promotions {
  order_id            uuid [ref: > orders.id]
  promotion_id        uuid [ref: > promotions.id]
  discount_amount     int
  indexes { (order_id, promotion_id) [unique] }
}

Domain Use Cases

Create Order From Cart Command

Cancel Order Command

Get Current Order By Cart Query

Apply Promotion Command

Remove Applied Promotion Command


(TODO) Order Confirmation Notification Command

(TODO) Validate Order Command

(TODO) Auto‐Cancel Pending Order Command (Job)

(TODO) Get All Orders Query (Admin)

(TODO) List Orders By User Query (Admin)