diff --git a/components/payments/cmd/api/internal/storage/accounts.go b/components/payments/cmd/api/internal/storage/accounts.go index d09661de5e..919ae0ab40 100644 --- a/components/payments/cmd/api/internal/storage/accounts.go +++ b/components/payments/cmd/api/internal/storage/accounts.go @@ -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 diff --git a/components/payments/cmd/api/internal/storage/balances.go b/components/payments/cmd/api/internal/storage/balances.go index a98a752616..7303264347 100644 --- a/components/payments/cmd/api/internal/storage/balances.go +++ b/components/payments/cmd/api/internal/storage/balances.go @@ -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 diff --git a/components/payments/cmd/api/internal/storage/bank_accounts.go b/components/payments/cmd/api/internal/storage/bank_accounts.go index b17eae5b95..b2326731fa 100644 --- a/components/payments/cmd/api/internal/storage/bank_accounts.go +++ b/components/payments/cmd/api/internal/storage/bank_accounts.go @@ -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 diff --git a/components/payments/cmd/api/internal/storage/payments.go b/components/payments/cmd/api/internal/storage/payments.go index 1749489a9e..35d2a14988 100644 --- a/components/payments/cmd/api/internal/storage/payments.go +++ b/components/payments/cmd/api/internal/storage/payments.go @@ -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 diff --git a/components/payments/cmd/api/internal/storage/pools.go b/components/payments/cmd/api/internal/storage/pools.go index 624e612772..9395817864 100644 --- a/components/payments/cmd/api/internal/storage/pools.go +++ b/components/payments/cmd/api/internal/storage/pools.go @@ -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 diff --git a/components/payments/cmd/api/internal/storage/transfer_initiation.go b/components/payments/cmd/api/internal/storage/transfer_initiation.go index d5212bf7fd..4cd68afc09 100644 --- a/components/payments/cmd/api/internal/storage/transfer_initiation.go +++ b/components/payments/cmd/api/internal/storage/transfer_initiation.go @@ -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) @@ -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