Skip to content

Commit

Permalink
fix(payments): fix sort query param (#1280)
Browse files Browse the repository at this point in the history
  • Loading branch information
paul-nicolas authored Feb 26, 2024
1 parent 79bfad6 commit 693044a
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 13 deletions.
5 changes: 3 additions & 2 deletions components/payments/cmd/api/internal/storage/accounts.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,12 @@ func (s *Storage) ListAccounts(ctx context.Context, q ListAccountsQuery) (*api.C
(*bunpaginate.OffsetPaginatedQuery[PaginatedQueryOptions[AccountQuery]])(&q),
func(query *bun.SelectQuery) *bun.SelectQuery {
query = query.
Relation("PoolAccounts").
Order("created_at DESC")
Relation("PoolAccounts")

if q.Options.Sorter != nil {
query = q.Options.Sorter.Apply(query)
} else {
query = query.Order("created_at DESC")
}

return query
Expand Down
5 changes: 2 additions & 3 deletions components/payments/cmd/api/internal/storage/balances.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,12 @@ func (s *Storage) ListBalances(ctx context.Context, q ListBalancesQuery) (*api.C
return PaginateWithOffset[PaginatedQueryOptions[BalanceQuery], models.Balance](s, ctx,
(*bunpaginate.OffsetPaginatedQuery[PaginatedQueryOptions[BalanceQuery]])(&q),
func(query *bun.SelectQuery) *bun.SelectQuery {
query = query.
Order("created_at DESC")

query = applyBalanceQuery(query, q.Options.Options)

if q.Options.Sorter != nil {
query = q.Options.Sorter.Apply(query)
} else {
query = query.Order("created_at DESC")
}

return query
Expand Down
5 changes: 3 additions & 2 deletions components/payments/cmd/api/internal/storage/bank_accounts.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,12 @@ func (s *Storage) ListBankAccounts(ctx context.Context, q ListBankAccountQuery)
(*bunpaginate.OffsetPaginatedQuery[PaginatedQueryOptions[BankAccountQuery]])(&q),
func(query *bun.SelectQuery) *bun.SelectQuery {
query = query.
Relation("RelatedAccounts").
Order("created_at DESC")
Relation("RelatedAccounts")

if q.Options.Sorter != nil {
query = q.Options.Sorter.Apply(query)
} else {
query = query.Order("created_at DESC")
}

return query
Expand Down
5 changes: 3 additions & 2 deletions components/payments/cmd/api/internal/storage/payments.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,12 @@ func (s *Storage) ListPayments(ctx context.Context, q ListPaymentsQuery) (*api.C
query = query.
Relation("Connector").
Relation("Metadata").
Relation("Adjustments").
Order("created_at DESC")
Relation("Adjustments")

if q.Options.Sorter != nil {
query = q.Options.Sorter.Apply(query)
} else {
query = query.Order("created_at DESC")
}

return query
Expand Down
5 changes: 3 additions & 2 deletions components/payments/cmd/api/internal/storage/pools.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,12 @@ func (s *Storage) ListPools(ctx context.Context, q ListPoolsQuery) (*api.Cursor[
(*bunpaginate.OffsetPaginatedQuery[PaginatedQueryOptions[PoolQuery]])(&q),
func(query *bun.SelectQuery) *bun.SelectQuery {
query = query.
Relation("PoolAccounts").
Order("created_at DESC")
Relation("PoolAccounts")

if q.Options.Sorter != nil {
query = q.Options.Sorter.Apply(query)
} else {
query = query.Order("created_at DESC")
}

return query
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,7 @@ func (s *Storage) ListTransferInitiations(ctx context.Context, q ListTransferIni
func(query *bun.SelectQuery) *bun.SelectQuery {
query = query.
Column("id", "connector_id", "created_at", "scheduled_at", "description", "type", "source_account_id", "destination_account_id", "provider", "initial_amount", "amount", "asset", "metadata").
Relation("RelatedAdjustments").
Order("created_at DESC")
Relation("RelatedAdjustments")

if q.Options.QueryBuilder != nil {
where, args, err := s.transferInitiationQueryContext(q.Options.QueryBuilder)
Expand All @@ -84,6 +83,8 @@ func (s *Storage) ListTransferInitiations(ctx context.Context, q ListTransferIni

if q.Options.Sorter != nil {
query = q.Options.Sorter.Apply(query)
} else {
query = query.Order("created_at DESC")
}

return query
Expand Down

0 comments on commit 693044a

Please sign in to comment.