commit 63cc22d39fd3c01db0c2c78923d54bc02ca3b18f
parent 0bb1aaf5e57a4739412fad3f3cccfffbddb1320c
Author: n0tr1v <n0tr1v@protonmail.com>
Date: Fri, 15 Dec 2023 22:37:37 -0500
cleanup
Diffstat:
2 files changed, 14 insertions(+), 7 deletions(-)
diff --git a/pkg/database/tablePokerTables.go b/pkg/database/tablePokerTables.go
@@ -92,3 +92,15 @@ func (d *DkfDB) PokerTableAccountRefundBet(userID UserID, pokerTableID int64) (e
userID, pokerTableID).Error
return
}
+
+func (d *DkfDB) PokerTableAccountResetAmountBet(userID UserID, pokerTableID int64) (err error) {
+ err = d.db.Exec(`UPDATE poker_table_accounts SET amount_bet = 0 WHERE user_id = ? AND poker_table_id = ?`,
+ userID, pokerTableID).Error
+ return
+}
+
+func (d *DkfDB) PokerTableAccountGain(userID UserID, pokerTableID int64, gain PokerChip) (err error) {
+ err = d.db.Exec(`UPDATE poker_table_accounts SET amount = amount + ?, amount_bet = 0 WHERE user_id = ? AND poker_table_id = ?`,
+ gain, userID, pokerTableID).Error
+ return
+}
diff --git a/pkg/web/handlers/poker/poker.go b/pkg/web/handlers/poker/poker.go
@@ -921,17 +921,12 @@ END:
for _, el := range playersGain {
newLogEvent(g, roomLogsTopic, fmt.Sprintf("Winner #%d: %s %s -> %d", el.Group, el.Player.Username, el.HandStr, el.Gain))
- account, _ := tx.GetPokerTableAccount(el.Player.UserID, g.PokerTableID)
- account.Amount += el.Gain
- account.AmountBet = 0
- account.DoSave(tx)
+ _ = tx.PokerTableAccountGain(el.Player.UserID, g.PokerTableID, el.Gain)
winnersStr += el.Player.Username.String() + " "
el.Player.Cash += el.Gain
}
for _, op := range g.Ongoing.Players {
- account, _ := tx.GetPokerTableAccount(op.UserID, g.PokerTableID)
- account.AmountBet = 0
- account.DoSave(tx)
+ _ = tx.PokerTableAccountResetAmountBet(op.UserID, g.PokerTableID)
}
tx.Commit()