This repository is currently being migrated. It's locked while the migration is in progress.
-
Notifications
You must be signed in to change notification settings - Fork 94
Expand file tree
/
Copy pathpipe_test_controller.rb
More file actions
69 lines (58 loc) · 2.03 KB
/
pipe_test_controller.rb
File metadata and controls
69 lines (58 loc) · 2.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# frozen_string_literal: true
module V0
class PipeTestController < ApplicationController
include AuthenticationConcern
before_action :authenticate
before_action :require_loa3, only: [:create]
def create
submission = PipeTestSubmission.new(pipe_test_params)
if submission.valid?
submission.save!
job_id = Lighthouse::SubmitPipeTestJob.perform_async(submission.id)
submission.update!(job_id: job_id, status: 'pending')
StatsD.increment('api.pipe_test.submission.success')
render json: PipeTestSerializer.new(submission), status: :created
else
StatsD.increment('api.pipe_test.submission.validation_error')
render json: { errors: submission.errors }, status: :unprocessable_entity
end
rescue => e
StatsD.increment('api.pipe_test.submission.error')
Rails.logger.error "PIPE-TEST submission error: #{e.message}"
render json: { errors: [{ title: 'Internal server error' }] }, status: :internal_server_error
end
def show
submission = PipeTestSubmission.find_by!(guid: params[:id])
render json: PipeTestSerializer.new(submission)
rescue ActiveRecord::RecordNotFound
render json: { errors: [{ title: 'Submission not found' }] }, status: :not_found
end
private
def pipe_test_params
params.require(:pipe_test).permit(
:form,
:veteran_ssn,
:veteran_first_name,
:veteran_last_name,
:veteran_date_of_birth,
:veteran_phone,
:veteran_email,
:mailing_address_line_1,
:mailing_address_line_2,
:mailing_address_city,
:mailing_address_state,
:mailing_address_postal_code,
:application_type,
:application_details,
:signature_date,
:privacy_agreement_accepted
).merge(
user_uuid: current_user.uuid,
user_account: current_user.user_account
)
end
def require_loa3
raise Common::Exceptions::Forbidden unless current_user.loa3?
end
end
end