Class: V0::Preneeds::BurialFormsController

Inherits:
PreneedsController show all
Includes:
SentryLogging
Defined in:
app/controllers/v0/preneeds/burial_forms_controller.rb

Constant Summary collapse

FORM =
'40-10007'

Constants inherited from ApplicationController

ApplicationController::VERSION_STATUS

Constants included from SignIn::Authentication

SignIn::Authentication::BEARER_PATTERN

Constants included from ExceptionHandling

ExceptionHandling::SKIP_SENTRY_EXCEPTION_TYPES

Instance Attribute Summary

Attributes inherited from ApplicationController

#current_user

Instance Method Summary collapse

Methods included from SentryLogging

#log_exception_to_sentry, #log_message_to_sentry, #non_nil_hash?, #normalize_level, #rails_logger, #set_sentry_metadata

Methods inherited from PreneedsController

#client

Methods inherited from ApplicationController

#clear_saved_form, #cors_preflight, #pagination_params, #render_job_id, #routing_error, #set_csrf_header

Methods included from Traceable

#set_trace_tags

Methods included from SentryControllerLogging

#set_tags_and_extra_context, #tags_context, #user_context

Methods included from Instrumentation

#append_info_to_payload

Methods included from SignIn::Authentication

#access_token, #access_token_authenticate, #authenticate, #authenticate_access_token, #bearer_token, #cookie_access_token, #handle_authenticate_error, #load_user, #load_user_object, #scrub_bearer_token, #validate_request_ip

Methods included from Headers

#set_app_info_headers

Methods included from ExceptionHandling

#render_errors, #report_mapped_exception, #report_original_exception, #skip_sentry_exception?, #skip_sentry_exception_types

Methods included from AuthenticationAndSSOConcerns

#authenticate, #clear_session, #extend_session!, #load_user, #log_sso_info, #render_unauthorized, #reset_session, #set_api_cookie!, #set_current_user, #set_session_expiration_header, #set_session_object, #sign_in_service_exp_time, #sign_in_service_session, #sso_cookie_content, #sso_logging_info, #validate_inbound_login_params, #validate_session

Methods included from SignIn::AudienceValidator

#authenticate, #validate_audience!

Instance Method Details

#burial_form_paramsObject (private)



54
55
56
57
58
59
60
61
62
63
# File 'app/controllers/v0/preneeds/burial_forms_controller.rb', line 54

def burial_form_params
  params.require(:application).permit(
    :application_status, :has_currently_buried, :sending_code,
    preneed_attachments: ::Preneeds::PreneedAttachmentHash.permitted_params,
    applicant: ::Preneeds::Applicant.permitted_params,
    claimant: ::Preneeds::Claimant.permitted_params,
    currently_buried_persons: ::Preneeds::CurrentlyBuriedPerson.permitted_params,
    veteran: ::Preneeds::Veteran.permitted_params
  )
end

#createObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'app/controllers/v0/preneeds/burial_forms_controller.rb', line 10

def create
  @form = ::Preneeds::BurialForm.new(burial_form_params)
  validate!(Common::HashHelpers.deep_transform_parameters!(burial_form_params) { |k| k.camelize(:lower) })

  @resource = client.receive_pre_need_application(@form)
  ::Preneeds::PreneedSubmission.create!(
    tracking_number: @resource.tracking_number,
    application_uuid: @resource.application_uuid,
    return_description: @resource.return_description,
    return_code: @resource.return_code
  )

  send_confirmation_email

  clear_saved_form(FORM)
  render json: ReceiveApplicationSerializer.new(@resource)
end

#send_confirmation_emailObject



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'app/controllers/v0/preneeds/burial_forms_controller.rb', line 28

def send_confirmation_email
  email = @form.claimant.email
  claimant = @form.applicant.name.first
  first_name = @form.applicant.name.first
  last_initial = @form.applicant.name.last.first

  if @form.applicant.applicant_relationship_to_claimant != 'Self'
    first_name = @form.claimant.name.first
    last_initial = @form.claimant.name.last.first
  end

  VANotify::EmailJob.perform_async(
    email,
    Settings.vanotify.services.va_gov.template_id.preneeds_burial_form_email,
    {
      'form_name' => 'Burial Pre-Need (Form 40-10007)',
      'first_name' => claimant&.upcase.presence,
      'applicant_1_first_name_last_initial' => "#{first_name} #{last_initial}",
      'confirmation_number' => @resource.application_uuid,
      'date_submitted' => Time.zone.today.strftime('%B %d, %Y')
    }
  )
end

#validate!(form) ⇒ Object (private)



65
66
67
68
69
70
71
72
73
74
75
# File 'app/controllers/v0/preneeds/burial_forms_controller.rb', line 65

def validate!(form)
  # Leave in for manual testing of new schemas before made available on Vets JSON Schema
  # schema = JSON.parse(File.read(Settings.preneeds.burial_form_schema))
  schema = VetsJsonSchema::SCHEMAS[FORM]
  validation_errors = ::Preneeds::BurialForm.validate(schema, form)

  if validation_errors.present?
    Sentry.set_tags(validation: 'preneeds')
    raise Common::Exceptions::SchemaValidationErrors, validation_errors
  end
end