mirror of https://github.com/docusealco/docuseal
parent
872fbbc875
commit
1f41807412
@ -0,0 +1,13 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module Api
|
||||
class SubmittersController < ApiBaseController
|
||||
load_and_authorize_resource :submitter
|
||||
|
||||
def show
|
||||
Submissions::EnsureResultGenerated.call(@submitter) if @submitter.completed_at?
|
||||
|
||||
render json: Submitters::SerializeForApi.call(@submitter, with_template: true, with_events: true)
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -0,0 +1,38 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module Submitters
|
||||
module SerializeForApi
|
||||
module_function
|
||||
|
||||
def call(submitter, with_template: false, with_events: false)
|
||||
ActiveRecord::Associations::Preloader.new(
|
||||
records: [submitter],
|
||||
associations: [documents_attachments: :blob, attachments_attachments: :blob]
|
||||
).call
|
||||
|
||||
values = SerializeForWebhook.build_values_array(submitter)
|
||||
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 = {
|
||||
include: {},
|
||||
only: %i[id slug uuid name email phone completed_at
|
||||
opened_at sent_at created_at updated_at]
|
||||
}
|
||||
|
||||
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] }
|
||||
end
|
||||
|
||||
submitter.as_json(serialize_params)
|
||||
.merge('values' => values,
|
||||
'documents' => documents,
|
||||
'role' => submitter_name)
|
||||
end
|
||||
end
|
||||
end
|
||||
Loading…
Reference in new issue