From 6c959d9d4e53003fae63b091f62bac0e4455e912 Mon Sep 17 00:00:00 2001 From: Eric Leroy-Terquem Date: Mon, 6 Nov 2023 17:44:21 +0100 Subject: [PATCH] refactor(groupe instructeur): use logic validation system for routing rule" --- app/models/groupe_instructeur.rb | 19 ++----------------- 1 file changed, 2 insertions(+), 17 deletions(-) diff --git a/app/models/groupe_instructeur.rb b/app/models/groupe_instructeur.rb index 7c937f088..e9b67ac6c 100644 --- a/app/models/groupe_instructeur.rb +++ b/app/models/groupe_instructeur.rb @@ -116,23 +116,8 @@ class GroupeInstructeur < ApplicationRecord 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