mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-26 20:56:48 +00:00
22 lines
439 B
Ruby
22 lines
439 B
Ruby
# frozen_string_literal: true
|
|
|
|
# Fetches complete orders of the specified user including their balance as a computed column
|
|
class CompleteOrdersWithBalanceQuery
|
|
def initialize(user)
|
|
@user = user
|
|
end
|
|
|
|
def call
|
|
OutstandingBalanceQuery.new(sorted_finalized_orders).call
|
|
end
|
|
|
|
private
|
|
|
|
def sorted_finalized_orders
|
|
@user.orders
|
|
.finalized
|
|
.select('spree_orders.*')
|
|
.order(completed_at: :desc)
|
|
end
|
|
end
|