mirror of
https://github.com/FJurmanovic/wallet-go-api.git
synced 2026-02-06 14:18:12 +00:00
fixed transaction pending
This commit is contained in:
@@ -67,28 +67,24 @@ Gets all rows from subscription type table.
|
||||
*[]models.SubscriptionType: List of subscription type objects.
|
||||
*/
|
||||
// Gets filtered rows from transaction table.
|
||||
func (as *TransactionService) GetAll(ctx context.Context, am *models.Auth, walletId string, filtered *models.FilteredResponse, transactionStatusId string) {
|
||||
func (as *TransactionService) GetAll(ctx context.Context, am *models.Auth, walletId string, filtered *models.FilteredResponse, noPending bool) {
|
||||
db := as.Db.WithContext(ctx)
|
||||
|
||||
wm := new([]models.Transaction)
|
||||
sm := new([]models.Subscription)
|
||||
transactionStatus := new(models.TransactionStatus)
|
||||
|
||||
tx, _ := 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)
|
||||
}
|
||||
if transactionStatusId != "" {
|
||||
query2 = query2.Where("? = ?", pg.Ident("transaction_status_id"), transactionStatusId)
|
||||
}
|
||||
query2.Select()
|
||||
tx.Model(transactionStatus).Where("? = ?", pg.Ident("status"), "completed").Select()
|
||||
|
||||
query := tx.Model(wm).Relation("Wallet").Where("wallet.? = ?", pg.Ident("user_id"), am.Id)
|
||||
if walletId != "" {
|
||||
query = query.Where("? = ?", pg.Ident("wallet_id"), walletId)
|
||||
}
|
||||
if noPending {
|
||||
query = query.Where("? = ?", pg.Ident("transaction_status_id"), transactionStatus.Id)
|
||||
}
|
||||
|
||||
FilteredResponse(query, wm, filtered)
|
||||
|
||||
@@ -109,15 +105,15 @@ Checks subscriptions and create transacitons.
|
||||
func (as *TransactionService) Check(ctx context.Context, am *models.Auth, walletId string, filtered *models.FilteredResponse) {
|
||||
db := as.Db.WithContext(ctx)
|
||||
|
||||
transactionStatus := new(models.TransactionStatus)
|
||||
wm := new([]models.Transaction)
|
||||
sm := new([]models.Subscription)
|
||||
transactionStatus := new(models.TransactionStatus)
|
||||
|
||||
tx, _ := db.Begin()
|
||||
defer tx.Rollback()
|
||||
tx.Model(transactionStatus).Where("? = ?", pg.Ident("status"), "pending").Select()
|
||||
|
||||
query2 := tx.Model(sm).Relation("Wallet").Where("wallet.? = ?", pg.Ident("user_id"), am.Id).Where("? = ?", pg.Ident("transaction_status_id"), transactionStatus.Id)
|
||||
tx.Model(transactionStatus).Where("? = ?", pg.Ident("status"), "pending").Select()
|
||||
query2 := tx.Model(sm).Relation("Wallet").Where("wallet.? = ?", pg.Ident("user_id"), am.Id)
|
||||
if walletId != "" {
|
||||
query2 = query2.Where("? = ?", pg.Ident("wallet_id"), walletId)
|
||||
}
|
||||
@@ -133,6 +129,7 @@ func (as *TransactionService) Check(ctx context.Context, am *models.Auth, wallet
|
||||
if walletId != "" {
|
||||
query = query.Where("? = ?", pg.Ident("wallet_id"), walletId)
|
||||
}
|
||||
query = query.Where("? = ?", pg.Ident("transaction_status_id"), transactionStatus.Id)
|
||||
|
||||
FilteredResponse(query, wm, filtered)
|
||||
|
||||
|
||||
@@ -128,10 +128,12 @@ func (as *WalletService) GetHeader(ctx context.Context, am *models.Auth, walletI
|
||||
wallets := new([]models.WalletTransactions)
|
||||
transactions := new([]models.Transaction)
|
||||
subscriptions := new([]models.Subscription)
|
||||
transactionStatus := new(models.TransactionStatus)
|
||||
|
||||
tx, _ := db.Begin()
|
||||
defer tx.Rollback()
|
||||
|
||||
tx.Model(transactionStatus).Where("? = ?", pg.Ident("status"), "completed").Select()
|
||||
query2 := tx.Model(subscriptions).Relation("Wallet").Where("wallet.? = ?", pg.Ident("user_id"), am.Id).Relation("TransactionType").Relation("SubscriptionType")
|
||||
if walletId != "" {
|
||||
query2.Where("? = ?", pg.Ident("wallet_id"), walletId)
|
||||
@@ -151,6 +153,7 @@ func (as *WalletService) GetHeader(ctx context.Context, am *models.Auth, walletI
|
||||
if walletId != "" {
|
||||
query.Where("? = ?", pg.Ident("wallet_id"), walletId)
|
||||
}
|
||||
query = query.Where("? = ?", pg.Ident("transaction_status_id"), transactionStatus.Id)
|
||||
query.Select()
|
||||
tx.Commit()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user