Deal with Api::OrdersController and SearchOrders service

This commit is contained in:
Matt-Yorkley
2021-06-18 17:24:02 +01:00
parent 3213c30a37
commit eba60a6130
2 changed files with 4 additions and 14 deletions

View File

@@ -15,9 +15,11 @@ module Api
orders = SearchOrders.new(params, current_api_user).orders
pagy, paged_orders = pagy(orders, items: params[:per_page] || default_per_page)
render json: {
orders: serialized_orders(orders),
pagination: pagination_data(orders)
orders: serialized_orders(paged_orders),
pagination: pagination_data(pagy)
}
end

View File

@@ -19,8 +19,6 @@ class SearchOrders
includes(:payments, :subscription, :shipments, :bill_address, :distributor, :order_cycle).
ransack(params[:q])
return paginated_results if using_pagination?
@search.result(distinct: true)
end
@@ -35,14 +33,4 @@ class SearchOrders
shipping_method_id: params[:shipping_method_id]
})
end
def paginated_results
@search.result(distinct: true)
.page(params[:page])
.per(params[:per_page])
end
def using_pagination?
params[:page]
end
end