Skip to content

Commit

Permalink
Merge pull request #1566 from gigorok/YETIWEB-1556-improve-filtering-…
Browse files Browse the repository at this point in the history
…destinations-by-rate-plan

ref-1556, improve filtering destinations by rate plan, country
  • Loading branch information
dmitry-sinina authored Oct 1, 2024
2 parents 23cda05 + 860ea35 commit c8e61a0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
8 changes: 6 additions & 2 deletions app/models/routing/destination.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,12 @@ class Routing::Destination < ApplicationRecord
scope :time_valid, -> { where('valid_till >= :time AND valid_from < :time', time: Time.now) }
scope :rateplan_id_filter, lambda { |value|
rate_group_ids = Routing::RatePlanGroup.where(rateplan_id: value).pluck(:rate_group_id)
where('rate_group_id IN (?)', rate_group_ids)
where(rate_group_id: rate_group_ids)
}
scope :country_id_filter, lambda { |value|
network_prefix_ids = System::NetworkPrefix.where(country_id: value).pluck(:id)
where(network_prefix_id: network_prefix_ids)
}

scope :where_customer, lambda { |id|
joins(:rate_group).joins(:rateplans).joins(:customers_auths).where(CustomersAuth.table_name => { customer_id: id })
}
Expand Down Expand Up @@ -176,6 +179,7 @@ def self.ransackable_scopes(_auth_object = nil)
tagged
routing_tag_ids_count_equals
rateplan_id_filter
country_id_filter
]
end
end
8 changes: 6 additions & 2 deletions app/resources/api/rest/admin/routing/destination_resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,12 @@ module CONST
ransack_filter :reverse_billing, type: :boolean
ransack_filter :profit_control_mode_id, type: :number
ransack_filter :rate_policy_id, type: :number
ransack_filter :rateplan_id, type: :foreign_key, column: :rate_group_rateplans_id
ransack_filter :country_id, type: :foreign_key, column: :network_prefix_country_id
filter :rateplan_id_eq, apply: lambda { |records, values, _options|
records.ransack(rateplan_id_filter: values).result
}
filter :country_id_eq, apply: lambda { |records, values, _options|
records.ransack(country_id_filter: values).result
}

def self.updatable_fields(_context)
%i[
Expand Down

0 comments on commit c8e61a0

Please sign in to comment.