adjust create submission resp
This commit is contained in:
@@ -93,7 +93,13 @@ module Api
|
||||
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
|
||||
Rollbar.warning(e) if defined?(Rollbar)
|
||||
|
||||
|
||||
@@ -71,7 +71,9 @@ module Api
|
||||
Submitters.send_signature_requests([@submitter])
|
||||
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
|
||||
|
||||
def submitter_params
|
||||
|
||||
@@ -2,38 +2,44 @@
|
||||
|
||||
module Submitters
|
||||
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
|
||||
|
||||
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(
|
||||
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
|
||||
|
||||
values = SerializeForWebhook.build_values_array(submitter)
|
||||
documents = SerializeForWebhook.build_documents_array(submitter)
|
||||
additional_attrs = {}
|
||||
|
||||
submitter_name = (submitter.submission.template_submitters ||
|
||||
submitter.submission.template.submitters).find { |e| e['uuid'] == submitter.uuid }['name']
|
||||
additional_attrs['values'] = SerializeForWebhook.build_values_array(submitter)
|
||||
additional_attrs['documents'] = SerializeForWebhook.build_documents_array(submitter) if with_documents
|
||||
additional_attrs['preferences'] = submitter.preferences.except('default_values')
|
||||
|
||||
serialize_params = {
|
||||
include: {},
|
||||
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]
|
||||
}
|
||||
additional_attrs['role'] =
|
||||
(submitter.submission.template_submitters ||
|
||||
submitter.submission.template.submitters).find { |e| e['uuid'] == submitter.uuid }['name']
|
||||
|
||||
serialize_params[:include][:template] = { only: %i[id name created_at updated_at] } if with_template
|
||||
|
||||
if with_events
|
||||
serialize_params[:include][:submission_events] =
|
||||
{ as: :events, only: %i[id submitter_id event_type event_timestamp] }
|
||||
if with_urls
|
||||
additional_attrs['embed_src'] =
|
||||
Rails.application.routes.url_helpers.submit_form_url(slug: submitter.slug, **Docuseal.default_url_options)
|
||||
end
|
||||
|
||||
submitter.as_json(serialize_params)
|
||||
.merge('values' => values,
|
||||
'documents' => documents,
|
||||
'role' => submitter_name)
|
||||
include_params = {}
|
||||
include_params[:template] = { only: %i[id name created_at updated_at] } if with_template
|
||||
include_params[:submission_events] = { only: %i[id submitter_id event_type event_timestamp] } if with_events
|
||||
|
||||
submitter.as_json(SERIALIZE_PARAMS.merge(include: include_params)).merge(additional_attrs)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -2,6 +2,12 @@
|
||||
|
||||
module Submitters
|
||||
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
|
||||
|
||||
def call(submitter)
|
||||
@@ -16,10 +22,7 @@ module Submitters
|
||||
submitter_name = (submitter.submission.template_submitters ||
|
||||
submitter.submission.template.submitters).find { |e| e['uuid'] == submitter.uuid }['name']
|
||||
|
||||
submitter.as_json(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])
|
||||
.except('uuid', 'values', 'slug')
|
||||
submitter.as_json(SERIALIZE_PARAMS)
|
||||
.merge('role' => submitter_name,
|
||||
'preferences' => submitter.preferences.except('default_values'),
|
||||
'values' => values,
|
||||
|
||||
@@ -2,13 +2,15 @@
|
||||
|
||||
module Templates
|
||||
module SerializeForApi
|
||||
SERIALIZE_PARAMS = {
|
||||
methods: %i[application_key folder_name],
|
||||
include: { author: { only: %i[id email first_name last_name] } }
|
||||
}.freeze
|
||||
|
||||
module_function
|
||||
|
||||
def call(template, schema_documents = template.schema_documents, preview_image_attachments = [])
|
||||
json = template.as_json(
|
||||
methods: %i[application_key folder_name],
|
||||
include: { author: { only: %i[id email first_name last_name] } }
|
||||
)
|
||||
json = template.as_json(SERIALIZE_PARAMS)
|
||||
|
||||
json[:documents] = template.schema.map do |item|
|
||||
attachment = schema_documents.find { |e| e.uuid == item['attachment_uuid'] }
|
||||
|
||||
Reference in New Issue
Block a user