From 860ea35d8aa3512fb7fb59bc0b3f13888ca2b848 Mon Sep 17 00:00:00 2001 From: Igor Gonchar Date: Mon, 30 Sep 2024 23:01:35 +0300 Subject: [PATCH] ref-1556, improve filtering destinations by rate plan, country --- app/models/routing/destination.rb | 8 ++++++-- .../api/rest/admin/routing/destination_resource.rb | 8 ++++++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/app/models/routing/destination.rb b/app/models/routing/destination.rb index 5135cd56b..503190c91 100644 --- a/app/models/routing/destination.rb +++ b/app/models/routing/destination.rb @@ -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 }) } @@ -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 diff --git a/app/resources/api/rest/admin/routing/destination_resource.rb b/app/resources/api/rest/admin/routing/destination_resource.rb index ff1e2ce63..62781daa8 100644 --- a/app/resources/api/rest/admin/routing/destination_resource.rb +++ b/app/resources/api/rest/admin/routing/destination_resource.rb @@ -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[