Class: FormSubmission

Inherits:
ApplicationRecord show all
Defined in:
app/models/form_submission.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ApplicationRecord

descendants_using_encryption, lockbox_options, #timestamp_attributes_for_update_in_model, #valid?

Class Method Details

.with_form_types(form_types) ⇒ Object



25
26
27
28
29
30
31
# File 'app/models/form_submission.rb', line 25

def with_form_types(form_types)
  if form_types.present?
    where(form_type: form_types)
  else
    where.not(form_type: nil)
  end
end

.with_latest_benefits_intake_uuid(user_account) ⇒ Object



14
15
16
17
18
19
20
21
22
23
# File 'app/models/form_submission.rb', line 14

def with_latest_benefits_intake_uuid()
  select('form_submissions.id, form_submissions.form_type, la.benefits_intake_uuid, form_submissions.created_at')
    .from('form_submissions')
    .joins(
      "LEFT JOIN (#{FormSubmissionAttempt.latest_attempts.to_sql}) AS la " \
      'ON form_submissions.id = la.form_submission_id'
    )
    .order('form_submissions.id')
    .where(user_account:)
end

Instance Method Details

#latest_attemptObject



34
35
36
# File 'app/models/form_submission.rb', line 34

def latest_attempt
  form_submission_attempts.order(created_at: :asc).last
end

#latest_pending_attemptObject



38
39
40
# File 'app/models/form_submission.rb', line 38

def latest_pending_attempt
  form_submission_attempts.where(aasm_state: 'pending').order(created_at: :asc).last
end

#non_failure_attemptObject



42
43
44
# File 'app/models/form_submission.rb', line 42

def non_failure_attempt
  form_submission_attempts.where(aasm_state: %w[pending success]).first
end