# frozen_string_literal: true module Account class DiscountsController < Account::BaseController before_action :group_by_params def index # @discounts = current_account.discounts # @ticket = TranslationCms::Api::Ticket # .all(_satellite_id: Settings.satellite_id) # .reject{|t| t.picture_url.blank? }.first case @group when DiscountsPageType.onetime @coupons = TranslationCms::Api::Customers::Discounts::Coupon.all @personal_coupons = TranslationCms::Api::Customers::Discounts::PersonalCoupon.all when DiscountsPageType.lifetime @lifetimes = TranslationCms::Api::Discounts::Lifetime.all!.sort { |x, y| x.value <=> y.value } customer_lifetimes = TranslationCms::Api::Customers::Discounts::Lifetime.all @active_lifetime = customer_lifetimes.map(&:value).max || 0 @customer_lifetime = customer_lifetimes.detect { |l| l.value == @active_lifetime } end end protected def group_by_params @group = DiscountsPageType.find_by(slug: params[:page_type]) end end end