Class: GIBillFeedback
Constant Summary
collapse
- FORM_ID =
'FEEDBACK-TOOL'
- FEEDBACK_MAPPINGS =
{
'post9::11 ch 33' => 'Post-9/11 Ch 33',
'chapter33' => 'Post-9/11 Ch 33',
'mGIBAd ch 30' => 'MGIB-AD Ch 30',
'chapter30' => 'MGIB-AD Ch 30',
'mGIBSr ch 1606' => 'MGIB-SR Ch 1606',
'chapter1606' => 'MGIB-SR Ch 1606',
'tatu' => 'TATU',
'reap' => 'REAP',
'dea ch 35' => 'DEA Ch 35',
'chapter35' => 'DEA Ch 35',
'vre ch 31' => 'VRE Ch 31',
'chapter31' => 'VRE Ch 31',
'ta' => 'TA',
'taAgr' => 'TA-AGR',
'myCaa' => 'MyCAA',
'ffa' => 'FFA'
}.freeze
Common::RedisStore::REQ_CLASS_INSTANCE_VARS
Instance Method Summary
collapse
Methods included from RedisForm
#form_matches_schema, #parsed_form, #parsed_response, #save
create, delete, #destroy, #destroyed?, exists?, #expire, find, find_or_build, #initialize, #initialize_dup, keys, #persisted?, pop, redis_key, redis_store, redis_ttl, #save, #save!, #ttl, #update, #update!
Instance Method Details
#anonymous? ⇒ Boolean
121
122
123
|
# File 'app/models/gi_bill_feedback.rb', line 121
def anonymous?
parsed_form['onBehalfOf'] == 'Anonymous'
end
|
#create_submission_job ⇒ Object
131
132
133
134
|
# File 'app/models/gi_bill_feedback.rb', line 131
def create_submission_job
user_uuid = anonymous? ? nil : user&.uuid
GIBillFeedbackSubmissionJob.perform_async(id, form, user_uuid)
end
|
#fix_options(options_hash, key) ⇒ Object
77
78
79
80
81
82
83
84
85
86
87
88
89
90
|
# File 'app/models/gi_bill_feedback.rb', line 77
def fix_options(options_hash, key)
keys_size = options_hash.keys.size
max_size = VetsJsonSchema::SCHEMAS[FORM_ID]['properties'][
'educationDetails'
]['properties'][key]['properties'].size
return remove_malformed_options(options_hash) if keys_size > max_size
transform_malformed_options(options_hash)
end
|
#get_user_details ⇒ Object
27
28
29
30
31
32
33
34
35
36
37
38
|
# File 'app/models/gi_bill_feedback.rb', line 27
def get_user_details
profile_data = {}
if user.present?
profile_data = {
'active_ICN' => user.icn,
'sec_ID' => user.sec_id
}
end
{ 'profile_data' => profile_data }
end
|
92
93
94
95
96
|
# File 'app/models/gi_bill_feedback.rb', line 92
def remove_malformed_options(options_hash)
options_hash.reject do |k, _v|
FEEDBACK_MAPPINGS.keys.include?(k)
end
end
|
rubocop:disable Metrics/MethodLength
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
70
71
72
|
# File 'app/models/gi_bill_feedback.rb', line 41
def transform_form
transformed = parsed_form.deep_transform_keys(&:underscore)
transformed.delete('privacy_agreement_accepted')
transformed['affiliation'] = transformed.delete('service_affiliation')
transformed.delete('service_date_range').tap do |service_date_range|
next if service_date_range.blank?
transformed['entered_duty'] = service_date_range['from']
transformed['release_from_duty'] = service_date_range['to']
end
transformed.merge!(get_user_details)
transformed['education_details'].tap do |education_details|
school = education_details['school']
transformed['facility_code'] = school.delete('facility_code')
transform_school_address(school['address'])
%w[programs assistance].each do |key|
options_hash = fix_options(parsed_form['educationDetails'][key], key)
education_details[key] = transform_keys_into_array(options_hash)
end
end
transformed['issue'] = transform_keys_into_array(transformed['issue'])
transformed['email'] = transformed.delete('anonymous_email') || transformed.delete('applicant_email')
transformed = Common::HashHelpers.deep_compact(transformed)
transformed.delete('profile_data') if transformed['profile_data'].blank?
transformed
end
|
125
126
127
128
129
|
# File 'app/models/gi_bill_feedback.rb', line 125
def transform_keys_into_array(hash)
return [] if hash.blank?
hash.compact_blank!.keys
end
|
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
|
# File 'app/models/gi_bill_feedback.rb', line 98
def transform_malformed_options(options_hash)
return_val = {}
options_hash.each do |k, v|
FEEDBACK_MAPPINGS[k].tap do |new_key|
if new_key.blank?
return_val[k] = v
else
return_val[new_key] = v
end
end
end
return_val
end
|
114
115
116
117
118
119
|
# File 'app/models/gi_bill_feedback.rb', line 114
def transform_school_address(address)
return if address['street3'].blank?
address['street'] = [address['street'], address['street2']].compact.join(', ')
address['street2'] = address.delete('street3')
end
|