adjust create submission resp
This commit is contained in:
@@ -93,7 +93,13 @@ module Api
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
render json: submissions.flat_map(&:submitters)
|
json = submissions.flat_map do |submission|
|
||||||
|
submission.submitters.map do |s|
|
||||||
|
Submitters::SerializeForApi.call(s, with_documents: false, with_urls: true)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
render json:
|
||||||
rescue Submitters::NormalizeValues::BaseError => e
|
rescue Submitters::NormalizeValues::BaseError => e
|
||||||
Rollbar.warning(e) if defined?(Rollbar)
|
Rollbar.warning(e) if defined?(Rollbar)
|
||||||
|
|
||||||
|
|||||||
@@ -71,7 +71,9 @@ module Api
|
|||||||
Submitters.send_signature_requests([@submitter])
|
Submitters.send_signature_requests([@submitter])
|
||||||
end
|
end
|
||||||
|
|
||||||
render json: Submitters::SerializeForApi.call(@submitter, with_template: false, with_events: false)
|
render json: Submitters::SerializeForApi.call(@submitter, with_template: false,
|
||||||
|
with_urls: true,
|
||||||
|
with_events: false)
|
||||||
end
|
end
|
||||||
|
|
||||||
def submitter_params
|
def submitter_params
|
||||||
|
|||||||
@@ -2,38 +2,44 @@
|
|||||||
|
|
||||||
module Submitters
|
module Submitters
|
||||||
module SerializeForApi
|
module SerializeForApi
|
||||||
|
SERIALIZE_PARAMS = {
|
||||||
|
only: %i[id slug uuid name email phone completed_at external_id
|
||||||
|
submission_id metadata opened_at sent_at created_at updated_at],
|
||||||
|
methods: %i[status application_key]
|
||||||
|
}.freeze
|
||||||
|
|
||||||
module_function
|
module_function
|
||||||
|
|
||||||
def call(submitter, with_template: false, with_events: false)
|
def call(submitter, with_template: false, with_events: false, with_documents: true, with_urls: false)
|
||||||
ActiveRecord::Associations::Preloader.new(
|
ActiveRecord::Associations::Preloader.new(
|
||||||
records: [submitter],
|
records: [submitter],
|
||||||
associations: [documents_attachments: :blob, attachments_attachments: :blob]
|
associations: if with_documents
|
||||||
|
[documents_attachments: :blob, attachments_attachments: :blob]
|
||||||
|
else
|
||||||
|
[attachments_attachments: :blob]
|
||||||
|
end
|
||||||
).call
|
).call
|
||||||
|
|
||||||
values = SerializeForWebhook.build_values_array(submitter)
|
additional_attrs = {}
|
||||||
documents = SerializeForWebhook.build_documents_array(submitter)
|
|
||||||
|
|
||||||
submitter_name = (submitter.submission.template_submitters ||
|
additional_attrs['values'] = SerializeForWebhook.build_values_array(submitter)
|
||||||
submitter.submission.template.submitters).find { |e| e['uuid'] == submitter.uuid }['name']
|
additional_attrs['documents'] = SerializeForWebhook.build_documents_array(submitter) if with_documents
|
||||||
|
additional_attrs['preferences'] = submitter.preferences.except('default_values')
|
||||||
|
|
||||||
serialize_params = {
|
additional_attrs['role'] =
|
||||||
include: {},
|
(submitter.submission.template_submitters ||
|
||||||
only: %i[id slug uuid name email phone completed_at external_id
|
submitter.submission.template.submitters).find { |e| e['uuid'] == submitter.uuid }['name']
|
||||||
submission_id metadata opened_at sent_at created_at updated_at],
|
|
||||||
methods: %i[status application_key]
|
|
||||||
}
|
|
||||||
|
|
||||||
serialize_params[:include][:template] = { only: %i[id name created_at updated_at] } if with_template
|
if with_urls
|
||||||
|
additional_attrs['embed_src'] =
|
||||||
if with_events
|
Rails.application.routes.url_helpers.submit_form_url(slug: submitter.slug, **Docuseal.default_url_options)
|
||||||
serialize_params[:include][:submission_events] =
|
|
||||||
{ as: :events, only: %i[id submitter_id event_type event_timestamp] }
|
|
||||||
end
|
end
|
||||||
|
|
||||||
submitter.as_json(serialize_params)
|
include_params = {}
|
||||||
.merge('values' => values,
|
include_params[:template] = { only: %i[id name created_at updated_at] } if with_template
|
||||||
'documents' => documents,
|
include_params[:submission_events] = { only: %i[id submitter_id event_type event_timestamp] } if with_events
|
||||||
'role' => submitter_name)
|
|
||||||
|
submitter.as_json(SERIALIZE_PARAMS.merge(include: include_params)).merge(additional_attrs)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -2,6 +2,12 @@
|
|||||||
|
|
||||||
module Submitters
|
module Submitters
|
||||||
module SerializeForWebhook
|
module SerializeForWebhook
|
||||||
|
SERIALIZE_PARAMS = {
|
||||||
|
methods: %i[status application_key],
|
||||||
|
only: %i[id submission_id email phone name ua ip sent_at opened_at
|
||||||
|
completed_at created_at updated_at external_id metadata]
|
||||||
|
}.freeze
|
||||||
|
|
||||||
module_function
|
module_function
|
||||||
|
|
||||||
def call(submitter)
|
def call(submitter)
|
||||||
@@ -16,10 +22,7 @@ module Submitters
|
|||||||
submitter_name = (submitter.submission.template_submitters ||
|
submitter_name = (submitter.submission.template_submitters ||
|
||||||
submitter.submission.template.submitters).find { |e| e['uuid'] == submitter.uuid }['name']
|
submitter.submission.template.submitters).find { |e| e['uuid'] == submitter.uuid }['name']
|
||||||
|
|
||||||
submitter.as_json(methods: %i[status application_key],
|
submitter.as_json(SERIALIZE_PARAMS)
|
||||||
only: %i[id submission_id email phone name ua ip sent_at opened_at
|
|
||||||
completed_at created_at updated_at external_id metadata])
|
|
||||||
.except('uuid', 'values', 'slug')
|
|
||||||
.merge('role' => submitter_name,
|
.merge('role' => submitter_name,
|
||||||
'preferences' => submitter.preferences.except('default_values'),
|
'preferences' => submitter.preferences.except('default_values'),
|
||||||
'values' => values,
|
'values' => values,
|
||||||
|
|||||||
@@ -2,13 +2,15 @@
|
|||||||
|
|
||||||
module Templates
|
module Templates
|
||||||
module SerializeForApi
|
module SerializeForApi
|
||||||
|
SERIALIZE_PARAMS = {
|
||||||
|
methods: %i[application_key folder_name],
|
||||||
|
include: { author: { only: %i[id email first_name last_name] } }
|
||||||
|
}.freeze
|
||||||
|
|
||||||
module_function
|
module_function
|
||||||
|
|
||||||
def call(template, schema_documents = template.schema_documents, preview_image_attachments = [])
|
def call(template, schema_documents = template.schema_documents, preview_image_attachments = [])
|
||||||
json = template.as_json(
|
json = template.as_json(SERIALIZE_PARAMS)
|
||||||
methods: %i[application_key folder_name],
|
|
||||||
include: { author: { only: %i[id email first_name last_name] } }
|
|
||||||
)
|
|
||||||
|
|
||||||
json[:documents] = template.schema.map do |item|
|
json[:documents] = template.schema.map do |item|
|
||||||
attachment = schema_documents.find { |e| e.uuid == item['attachment_uuid'] }
|
attachment = schema_documents.find { |e| e.uuid == item['attachment_uuid'] }
|
||||||
|
|||||||
Reference in New Issue
Block a user