Skip to content

Commit

Permalink
fix(back): points on low balance
Browse files Browse the repository at this point in the history
  • Loading branch information
yyewolf committed Nov 24, 2023
1 parent e5f6e9c commit b9d017e
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions backend/api/passerCommande.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,8 +252,16 @@ func (s *Server) PostTransactions(c echo.Context) error {

transaction.TotalCost = transactionCost

// update account balance
if int64(transactionCost) > account.Points {
account.Balance -= int64(transactionCost) - account.Points
account.Points = 0
} else {
account.Points -= int64(transactionCost)
}

if account.Role != autogen.AccountGhost {
if account.Balance < int64(transactionCost) {
if account.Balance < 0 {
logrus.Warnf("Account %s does not have enough money", accountID)
return nil, Error400(c)
}
Expand All @@ -265,14 +273,6 @@ func (s *Server) PostTransactions(c echo.Context) error {
return nil, errors.New("failed to create transaction")
}

// update account balance
if int64(transactionCost) > account.Points {
account.Balance -= int64(transactionCost) - account.Points
account.Points = 0
} else {
account.Points -= int64(transactionCost)
}

err = s.DBackend.UpdateAccount(ctx, account)
if err != nil {
logrus.Error(err)
Expand Down

0 comments on commit b9d017e

Please sign in to comment.