Skip to content

Commit

Permalink
refactor(groupe instructeur): use logic validation system for routing
Browse files Browse the repository at this point in the history
rule"
  • Loading branch information
E-L-T committed Nov 6, 2023
1 parent 3e2e5a0 commit 6c959d9
Showing 1 changed file with 2 additions and 17 deletions.
19 changes: 2 additions & 17 deletions app/models/groupe_instructeur.rb
Original file line number Diff line number Diff line change
Expand Up @@ -116,23 +116,8 @@ def other_groupe_instructeurs
private

def routing_rule_matches_tdc?(rule)
routing_tdc = procedure.active_revision.types_de_champ.find_by(stable_id: rule.left.stable_id)

options = case routing_tdc.type_champ
when TypeDeChamp.type_champs.fetch(:communes), TypeDeChamp.type_champs.fetch(:departements), TypeDeChamp.type_champs.fetch(:epci)
APIGeoService.departements.map { _1[:code] }
when TypeDeChamp.type_champs.fetch(:regions)
APIGeoService.regions.map { _1[:code] }
when TypeDeChamp.type_champs.fetch(:drop_down_list), TypeDeChamp.type_champs.fetch(:multiple_drop_down_list)
routing_tdc.drop_down_list_enabled_non_empty_options(other: true).map { _1.is_a?(Array) ? _1.last : _1 }
when TypeDeChamp.type_champs.fetch(:checkbox), TypeDeChamp.type_champs.fetch(:yes_no)
[true, false]
when TypeDeChamp.type_champs.fetch(:integer_number)
return rule.right.value.is_a? Integer
when TypeDeChamp.type_champs.fetch(:decimal_number)
return rule.right.value.is_a? Float
end
rule.right.value.in?(options)
tdcs = procedure.active_revision.types_de_champ_public
rule.errors(tdcs).blank?
end

serialize :routing_rule, LogicSerializer
Expand Down

0 comments on commit 6c959d9

Please sign in to comment.