configurable values normalize exception
This commit is contained in:
@@ -148,7 +148,8 @@ module Api
|
|||||||
values, new_attachments =
|
values, new_attachments =
|
||||||
Submitters::NormalizeValues.call(template,
|
Submitters::NormalizeValues.call(template,
|
||||||
default_values,
|
default_values,
|
||||||
submitter[:role] || template.submitters[index]['name'])
|
submitter[:role] || template.submitters[index]['name'],
|
||||||
|
throw_errors: true)
|
||||||
|
|
||||||
attachments.push(*new_attachments)
|
attachments.push(*new_attachments)
|
||||||
|
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ module Submitters
|
|||||||
|
|
||||||
module_function
|
module_function
|
||||||
|
|
||||||
def call(template, values, submitter_name)
|
def call(template, values, submitter_name, throw_errors: false)
|
||||||
submitter =
|
submitter =
|
||||||
template.submitters.find { |e| e['name'] == submitter_name } ||
|
template.submitters.find { |e| e['name'] == submitter_name } ||
|
||||||
raise(UnknownSubmitterName, "Unknown submitter: #{submitter_name}")
|
raise(UnknownSubmitterName, "Unknown submitter: #{submitter_name}")
|
||||||
@@ -21,11 +21,15 @@ module Submitters
|
|||||||
|
|
||||||
attachments = []
|
attachments = []
|
||||||
|
|
||||||
normalized_values = values.to_h.to_h do |key, value|
|
normalized_values = values.to_h.filter_map do |key, value|
|
||||||
if fields_uuid_index[key].blank?
|
if fields_uuid_index[key].blank?
|
||||||
key = fields_name_index[key]&.dig('uuid') || raise(UnknownFieldName, "Unknown field: #{key}")
|
key = fields_name_index[key]&.dig('uuid')
|
||||||
|
|
||||||
|
raise(UnknownFieldName, "Unknown field: #{key}") if key.blank? && throw_errors
|
||||||
end
|
end
|
||||||
|
|
||||||
|
next if key.blank?
|
||||||
|
|
||||||
if fields_uuid_index[key]['type'].in?(%w[initials signature image file])
|
if fields_uuid_index[key]['type'].in?(%w[initials signature image file])
|
||||||
new_value, new_attachments = normalize_attachment_value(value, template.account)
|
new_value, new_attachments = normalize_attachment_value(value, template.account)
|
||||||
|
|
||||||
@@ -35,7 +39,7 @@ module Submitters
|
|||||||
end
|
end
|
||||||
|
|
||||||
[key, value]
|
[key, value]
|
||||||
end
|
end.to_h
|
||||||
|
|
||||||
[normalized_values, attachments]
|
[normalized_values, attachments]
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user