grouped transactions

This commit is contained in:
Fran Jurmanović
2021-06-30 21:55:47 +02:00
parent 81e55896b1
commit 81505baf7a
4 changed files with 35 additions and 11 deletions

View File

@@ -38,7 +38,10 @@ func (as *TransactionService) GetAll(am *models.Auth, walletId string, filtered
wm := new([]models.Transaction)
sm := new([]models.Subscription)
query2 := as.Db.Model(sm).Relation("Wallet").Where("wallet.? = ?", pg.Ident("user_id"), am.Id)
tx, _ := as.Db.Begin()
defer tx.Rollback()
query2 := tx.Model(sm).Relation("Wallet").Where("wallet.? = ?", pg.Ident("user_id"), am.Id)
if walletId != "" {
query2 = query2.Where("? = ?", pg.Ident("wallet_id"), walletId)
}
@@ -48,9 +51,11 @@ func (as *TransactionService) GetAll(am *models.Auth, walletId string, filtered
as.Ss.SubToTrans(&sub)
}
query := as.Db.Model(wm).Relation("Wallet").Where("wallet.? = ?", pg.Ident("user_id"), am.Id)
query := tx.Model(wm).Relation("Wallet").Where("wallet.? = ?", pg.Ident("user_id"), am.Id)
if walletId != "" {
query = query.Where("? = ?", pg.Ident("wallet_id"), walletId)
}
FilteredResponse(query, wm, filtered)
tx.Commit()
}