Skip to content

Commit

Permalink
refactor: move condition on top
Browse files Browse the repository at this point in the history
  • Loading branch information
sylv-p committed Feb 22, 2022
1 parent cd2184f commit 30eab63
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions app/models/evaluation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,19 @@ class Evaluation < ApplicationRecord
validates :reference_to, presence: true
attr_accessor :evaluation_infos

after_create :email_for_evaluation!
after_create :email_for_evaluation! if ENV['ENABLE_AUTHENTICATION'].present?

def email_for_evaluation!
if ENV['ENABLE_AUTHENTICATION'].present?
infos = self.evaluation_infos
evaluation_mode = infos["evaluation_mode"]
questions = infos["questions"]
author = self.pia.user_pias.find_by({role: "author"}).user
evaluator = self.pia.user_pias.find_by({role: "evaluator"}).user
infos = self.evaluation_infos
evaluation_mode = infos["evaluation_mode"]
questions = infos["questions"]
author = self.pia.user_pias.find_by({role: "author"}).user
evaluator = self.pia.user_pias.find_by({role: "evaluator"}).user

if evaluation_mode === 'item' ||
(evaluation_mode === 'question' && questions[0]["id"] == self.reference_to.split(".").last.to_i)
UserMailer.with(evaluator: evaluator, pia: self.pia).section_ready_for_evaluation.deliver_now
end
byebug
if evaluation_mode === 'item' ||
(evaluation_mode === 'question' && questions[0]["id"] == self.reference_to.split(".").last.to_i)
UserMailer.with(evaluator: evaluator, pia: self.pia).section_ready_for_evaluation.deliver_now
end
byebug
end
end

0 comments on commit 30eab63

Please sign in to comment.