2021-06-22 11:13:44 +02:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
# Provides methods for Prices
|
|
|
|
class PriceService
|
2022-11-23 17:35:39 +01:00
|
|
|
extend ApplicationHelper
|
|
|
|
|
2021-06-22 11:13:44 +02:00
|
|
|
def self.list(filters)
|
|
|
|
prices = Price.where(nil)
|
|
|
|
|
|
|
|
prices = prices.where(priceable_type: filters[:priceable_type]) if filters[:priceable_type].present?
|
2022-11-23 17:35:39 +01:00
|
|
|
prices = prices.where(priceable_id: may_array(filters[:priceable_id])) if filters[:priceable_id].present?
|
|
|
|
prices = prices.where(group_id: may_array(filters[:group_id])) if filters[:group_id].present?
|
2021-06-22 11:13:44 +02:00
|
|
|
if filters[:plan_id].present?
|
|
|
|
plan_id = /no|nil|null|undefined/i.match?(filters[:plan_id]) ? nil : filters[:plan_id]
|
|
|
|
prices = prices.where(plan_id: plan_id)
|
|
|
|
end
|
|
|
|
|
|
|
|
prices
|
|
|
|
end
|
|
|
|
end
|