Use a SubscriptionsCount query object to provide counts to IndexOrderCycleSerializer

This commit is contained in:
Rob Harrington
2018-06-13 17:00:46 +10:00
parent d5b1041481
commit 7af11da901
5 changed files with 56 additions and 33 deletions

View File

@@ -19,7 +19,7 @@ module Admin
respond_to do |format|
format.html
format.json do
render_as_json @collection, ams_prefix: params[:ams_prefix], current_user: spree_current_user, subscriptions_counts: subscriptions_counts
render_as_json @collection, ams_prefix: params[:ams_prefix], current_user: spree_current_user, subscriptions_count: SubscriptionsCount.new(@collection)
end
end
end
@@ -81,7 +81,7 @@ module Admin
def bulk_update
if order_cycle_set.andand.save
respond_to do |format|
format.json { render_as_json @order_cycles, ams_prefix: 'index', current_user: spree_current_user, subscriptions_counts: subscriptions_counts }
format.json { render_as_json @order_cycles, ams_prefix: 'index', current_user: spree_current_user, subscriptions_count: SubscriptionsCount.new(@collection) }
end
else
respond_to do |format|
@@ -230,11 +230,6 @@ module Admin
render json: { errors: t('admin.order_cycles.bulk_update.no_data') }, status: :unprocessable_entity
end
def subscriptions_counts
return [] if @collection.blank?
ProxyOrder.not_canceled.group(:order_cycle_id).where(order_cycle_id: @collection).count
end
def ams_prefix_whitelist
[:basic, :index]
end