|
|
|
@ -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 ||
|
|
|
|
|
|
|
|
submitter.submission.template.submitters).find { |e| e['uuid'] == submitter.uuid }['name']
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
serialize_params = {
|
|
|
|
additional_attrs['values'] = SerializeForWebhook.build_values_array(submitter)
|
|
|
|
include: {},
|
|
|
|
additional_attrs['documents'] = SerializeForWebhook.build_documents_array(submitter) if with_documents
|
|
|
|
only: %i[id slug uuid name email phone completed_at external_id
|
|
|
|
additional_attrs['preferences'] = submitter.preferences.except('default_values')
|
|
|
|
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
|
|
|
|
additional_attrs['role'] =
|
|
|
|
|
|
|
|
(submitter.submission.template_submitters ||
|
|
|
|
|
|
|
|
submitter.submission.template.submitters).find { |e| e['uuid'] == submitter.uuid }['name']
|
|
|
|
|
|
|
|
|
|
|
|
if with_events
|
|
|
|
if with_urls
|
|
|
|
serialize_params[:include][:submission_events] =
|
|
|
|
additional_attrs['embed_src'] =
|
|
|
|
{ as: :events, only: %i[id submitter_id event_type event_timestamp] }
|
|
|
|
Rails.application.routes.url_helpers.submit_form_url(slug: submitter.slug, **Docuseal.default_url_options)
|
|
|
|
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
|
|
|
|
|