fix(orders): keep the customer a new order is created for
CreateOrderContractToModel never copied customer_id, so every order from POST /orders was saved without a customer. Paying it then earned no EnakPoint or EnakCoin (skipped as NO_CUSTOMER, which is not logged). The customer must now belong to the order's organization, as SetOrderCustomer already requires: it is who earns once the order is paid, and orders.customer_id has no foreign key. A nil UUID means no customer. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
c9654a387a
commit
892575202b
@@ -27,6 +27,7 @@ func CreateOrderContractToModel(req *contract.CreateOrderRequest) *models.Create
|
||||
return &models.CreateOrderRequest{
|
||||
OutletID: req.OutletID,
|
||||
UserID: req.UserID,
|
||||
CustomerID: req.CustomerID,
|
||||
TableID: req.TableID,
|
||||
TableNumber: req.TableNumber,
|
||||
OrderType: constants.OrderType(req.OrderType),
|
||||
|
||||
@@ -32,6 +32,20 @@ func TestCreateOrderContractToModelCarriesWeight(t *testing.T) {
|
||||
require.Equal(t, weight, *result.OrderItems[0].Weight)
|
||||
}
|
||||
|
||||
func TestCreateOrderContractToModelCarriesCustomer(t *testing.T) {
|
||||
customerID := uuid.New()
|
||||
|
||||
result := CreateOrderContractToModel(&contract.CreateOrderRequest{
|
||||
OutletID: uuid.New(),
|
||||
UserID: uuid.New(),
|
||||
CustomerID: &customerID,
|
||||
OrderItems: []contract.CreateOrderItemRequest{{ProductID: uuid.New(), Quantity: 1}},
|
||||
})
|
||||
|
||||
require.NotNil(t, result.CustomerID, "the order's customer is who earns EnakPoint and EnakCoin")
|
||||
require.Equal(t, customerID, *result.CustomerID)
|
||||
}
|
||||
|
||||
func TestAddToOrderContractToModelCarriesWeight(t *testing.T) {
|
||||
weight := 0.8
|
||||
|
||||
|
||||
Reference in New Issue
Block a user