Skip to content

Commit

Permalink
apply matches filters for institutions
Browse files Browse the repository at this point in the history
  • Loading branch information
LucienMLD authored and clairezed committed May 28, 2024
1 parent 83814e5 commit 9848db1
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 16 deletions.
1 change: 0 additions & 1 deletion app/models/expert.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ class Expert < ApplicationRecord
has_many :antenne_communes, through: :antenne, source: :communes, inverse_of: :antenne_experts
has_many :antenne_territories, -> { distinct }, through: :antenne, source: :territories, inverse_of: :antenne_experts
has_many :antenne_regions, -> { distinct.regions }, through: :antenne, source: :regions, inverse_of: :antenne_experts
has_many :match_filters, through: :antenne, source: :match_filters, inverse_of: :experts

# :received_matches
has_many :received_needs, through: :received_matches, source: :need, inverse_of: :experts
Expand Down
7 changes: 6 additions & 1 deletion app/models/expert_subject.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ class ExpertSubject < ApplicationRecord
#
has_one :subject, through: :institution_subject, inverse_of: :experts_subjects
has_one :theme, through: :subject, inverse_of: :experts_subjects
has_many :match_filters, through: :expert, inverse_of: :experts_subjects

belongs_to :not_deleted_expert, -> { not_deleted }, class_name: 'Expert', foreign_key: 'expert_id', optional: true, inverse_of: :experts_subjects

Expand Down Expand Up @@ -99,6 +98,12 @@ class ExpertSubject < ApplicationRecord

scope :support, -> { where(institution_subject: InstitutionSubject.support_subjects) }

##
#
def match_filters
MatchFilter.where(id: expert.antenne.match_filters.ids + expert.institution.match_filters.ids)
end

## used for serialization in advisors csv
#
def csv_description
Expand Down
12 changes: 10 additions & 2 deletions app/models/match_filter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,16 @@ class MatchFilter < ApplicationRecord

validate :antenne_or_institution

has_many :experts, through: :antenne, source: :experts, inverse_of: :match_filters
has_many :experts_subjects, through: :experts, inverse_of: :match_filters
has_many :antenne_experts, through: :antenne, source: :experts
has_many :institution_experts, through: :institution, source: :experts

def experts
antenne.present? ? antenne_experts : institution_experts
end

def experts_subjects
ExpertSubject.where(expert_id: experts.ids)
end

def antenne_or_institution
if antenne.nil? && institution.nil?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
let!(:es_01) { create :expert_subject }

context 'min_years_of_existence' do
let(:match_filter_01) { create :match_filter, min_years_of_existence: 3 }
let(:match_filter_01) { create :match_filter, :for_antenne, min_years_of_existence: 3 }

before { es_01.expert.antenne.match_filters << match_filter_01 }

Expand All @@ -31,7 +31,7 @@
end

context 'max_years_of_existence' do
let(:match_filter_01) { create :match_filter, max_years_of_existence: 5 }
let(:match_filter_01) { create :match_filter, :for_antenne, max_years_of_existence: 5 }

before { es_01.expert.antenne.match_filters << match_filter_01 }

Expand All @@ -54,7 +54,7 @@
let(:need) { create :need, diagnosis: diagnosis, subject: need_subject }

let!(:tresorerie_subject) { create :subject }
let(:match_filter_01) { create :match_filter, effectif_max: 20, subjects: [tresorerie_subject] }
let(:match_filter_01) { create :match_filter, :for_antenne, effectif_max: 20, subjects: [tresorerie_subject] }
let!(:es_01) { create :expert_subject }

before { es_01.expert.antenne.match_filters << match_filter_01 }
Expand Down Expand Up @@ -93,8 +93,8 @@
let(:need) { create :need, diagnosis: diagnosis, subject: need_subject }

let!(:difficulte_subject) { create :subject }
let(:match_filter_01) { create :match_filter, accepted_naf_codes: ['1101Z', '1102A', '1102B'], subjects: [difficulte_subject] }
let(:match_filter_excluding_naf) { create :match_filter, excluded_naf_codes: ['9001Z'], subjects: [difficulte_subject] }
let(:match_filter_01) { create :match_filter, :for_antenne, accepted_naf_codes: ['1101Z', '1102A', '1102B'], subjects: [difficulte_subject] }
let(:match_filter_excluding_naf) { create :match_filter, :for_antenne, excluded_naf_codes: ['9001Z'], subjects: [difficulte_subject] }

let!(:es_including_naf) { create :expert_subject }
let!(:es_excluding_naf) { create :expert_subject }
Expand Down Expand Up @@ -155,8 +155,8 @@
let(:need) { create :need, diagnosis: diagnosis, subject: need_subject }

let!(:difficulte_subject) { create :subject }
let(:match_filter_01) { create :match_filter, accepted_legal_forms: %w[4160 6533 6534], subjects: [difficulte_subject] }
let(:match_filter_excluding_legal_forms) { create :match_filter, excluded_legal_forms: %w[5499], subjects: [difficulte_subject] }
let(:match_filter_01) { create :match_filter, :for_antenne, accepted_legal_forms: %w[4160 6533 6534], subjects: [difficulte_subject] }
let(:match_filter_excluding_legal_forms) { create :match_filter, :for_antenne, excluded_legal_forms: %w[5499], subjects: [difficulte_subject] }

let!(:es_including) { create :expert_subject }
let!(:es_excluding) { create :expert_subject }
Expand Down Expand Up @@ -213,8 +213,8 @@
let(:diagnosis) { create :diagnosis, facility: facility }
let(:need) { create :need, diagnosis: diagnosis }

let(:match_filter_01) { create :match_filter, effectif_min: 10 }
let(:match_filter_02) { create :match_filter, min_years_of_existence: 3 }
let(:match_filter_01) { create :match_filter, :for_antenne, effectif_min: 10 }
let(:match_filter_02) { create :match_filter, :for_antenne, min_years_of_existence: 3 }
let!(:es_01) { create :expert_subject }

before do
Expand Down Expand Up @@ -262,7 +262,7 @@

let!(:difficulte_subject) { create :subject }
let!(:rh_subject) { create :subject }
let(:match_filter_01) { create :match_filter, min_years_of_existence: 3, subjects: [difficulte_subject, rh_subject] }
let(:match_filter_01) { create :match_filter, :for_antenne, min_years_of_existence: 3, subjects: [difficulte_subject, rh_subject] }

let!(:es_01) { create :expert_subject }

Expand Down Expand Up @@ -308,8 +308,8 @@
let!(:rh_subject) { create :subject }
let!(:eau_subject) { create :subject }
let!(:energie_subject) { create :subject }
let(:match_filter_01) { create :match_filter, min_years_of_existence: 3, subjects: [rh_subject] }
let(:match_filter_02) { create :match_filter, min_years_of_existence: 3, effectif_max: 50, subjects: [eau_subject, energie_subject] }
let(:match_filter_01) { create :match_filter, :for_antenne, min_years_of_existence: 3, subjects: [rh_subject] }
let(:match_filter_02) { create :match_filter, :for_antenne, min_years_of_existence: 3, effectif_max: 50, subjects: [eau_subject, energie_subject] }

let!(:es_01) { create :expert_subject }

Expand Down

0 comments on commit 9848db1

Please sign in to comment.