Skip to content
Snippets Groups Projects
Unverified Commit 38ab16d4 authored by Réthelyi Bálint's avatar Réthelyi Bálint :no_mouth:
Browse files

fix credits

parent e156ba59
No related branches found
No related tags found
1 merge request!28fix credits
Pipeline #45074 failed
...@@ -331,8 +331,6 @@ func (u *User) Load() error { ...@@ -331,8 +331,6 @@ func (u *User) Load() error {
return e return e
} }
const credit = 5000
func SaveMultipleSpend(sp []*Spend) error { func SaveMultipleSpend(sp []*Spend) error {
e := db.RunInTransaction(context.Background(), func(tx *pg.Tx) error { e := db.RunInTransaction(context.Background(), func(tx *pg.Tx) error {
for _, s := range sp { for _, s := range sp {
...@@ -349,6 +347,12 @@ func SaveMultipleSpend(sp []*Spend) error { ...@@ -349,6 +347,12 @@ func SaveMultipleSpend(sp []*Spend) error {
} }
e = tx.Model(u).WherePK().First() e = tx.Model(u).WherePK().First()
var credit int64
if u.Credits > 5000 {
credit = u.Credits
} else {
credit = 5000
}
price := p.Price * s.Amount price := p.Price * s.Amount
if price > u.Money+credit { if price > u.Money+credit {
return fmt.Errorf("Not enough funds") return fmt.Errorf("Not enough funds")
......
...@@ -95,7 +95,7 @@ func NewHandler(w http.ResponseWriter, r *http.Request) { ...@@ -95,7 +95,7 @@ func NewHandler(w http.ResponseWriter, r *http.Request) {
} }
var credit int64 var credit int64
if session.User.Credits > 0 { if session.User.Credits > 5000 {
credit = session.User.Credits credit = session.User.Credits
} else { } else {
credit = 5000 credit = 5000
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment