Class: EVSS::DependentsApplicationJob

Inherits:
Object
  • Object
show all
Includes:
Sidekiq::Job
Defined in:
app/sidekiq/evss/dependents_application_job.rb

Instance Method Summary collapse

Instance Method Details

#dependents_applicationObject



37
38
39
# File 'app/sidekiq/evss/dependents_application_job.rb', line 37

def dependents_application
  @dependents_application ||= DependentsApplication.find(@app_id)
end

#perform(app_id, encrypted_form, user_uuid) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'app/sidekiq/evss/dependents_application_job.rb', line 12

def perform(app_id, encrypted_form, user_uuid)
  @app_id = app_id
  form = JSON.parse(KmsEncrypted::Box.new.decrypt(encrypted_form))
  user = User.find(user_uuid)
  service = Dependents::Service.new(user)
  cached_info = Dependents::RetrievedInfo.for_user(user)

  merged_form = DependentsApplication.transform_form(form, cached_info.body)
  merged_form = service.clean_form(merged_form)

  service.validate(merged_form).tap do |res|
    return dependents_application.update!(state: 'failed', response: res.to_json) if res['errors'].present?
  end

  form_id = service.save(merged_form)['formId']
  res = service.submit(merged_form, form_id)

  cached_info.delete

  dependents_application.update!(state: 'success', response: res.to_json)
rescue
  dependents_application.update!(state: 'failed')
  raise
end