Method: Quby::Answers::Services::UpdatesAnswers#update

Defined in:
lib/quby/answers/services/updates_answers.rb

#update(new_attributes = {}) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/quby/answers/services/updates_answers.rb', line 16

def update(new_attributes = {})
  save_raw_params_on_error(new_attributes) do
    attribute_filter = FiltersAnswerValue.new(answer.questionnaire)
    attribute_filter.filter(new_attributes).each { |name, value| answer.send("#{name}=", value) }

    answer.extend AnswerValidations
    answer.cleanup_input
    answer.validate_answers

    if answer.errors.empty?
      if new_attributes["rendered_at"].present?
        started_at = Time.at(new_attributes["rendered_at"].to_i)
      else
        started_at = nil
      end
      answer.mark_completed(started_at)
      answer.outcome = OutcomeCalculation.new(answer).calculate
      Quby.answers.update!(answer)
      succeed!
    else
      if defined?(::Roqua::Support)
        # We know that Quby v1 does not run client-side validations when the "Toch opslaan"
        # button is clicked. So if the answer is aborted, this is likely due to the user
        # ignoring/overlooking error messages other than the requires-answer validations that the
        # "Toch opslaan" button is designed to bypass.
        #
        # Since we know this is a current shortcoming of Quby v1 that's not likely to be fixed,
        # for now there's no point in sending these client-server validation mismatches
        # to AppSignal.
        unless answer.aborted
          ::Roqua::Support::Errors.report(Quby::ValidationError.new(answer.errors.full_messages))
        end
      end
      fail!
    end
  end
end