Avis: move assign_gestionnaire logic to avis model
This commit is contained in:
parent
fe1b97b738
commit
7016bdc49a
4 changed files with 52 additions and 26 deletions
|
@ -3,6 +3,7 @@ class Avis < ApplicationRecord
|
|||
belongs_to :gestionnaire
|
||||
belongs_to :claimant, class_name: 'Gestionnaire'
|
||||
|
||||
before_create :try_to_assign_gestionnaire
|
||||
after_create :notify_gestionnaire
|
||||
|
||||
scope :with_answer, -> { where.not(answer: nil) }
|
||||
|
@ -28,4 +29,12 @@ class Avis < ApplicationRecord
|
|||
def notify_gestionnaire
|
||||
AvisMailer.avis_invitation(self).deliver_now
|
||||
end
|
||||
|
||||
def try_to_assign_gestionnaire
|
||||
gestionnaire = Gestionnaire.find_by(email: email)
|
||||
if gestionnaire
|
||||
self.gestionnaire = gestionnaire
|
||||
self.email = nil
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue