Files
docuseal/app/controllers/api/templates_documents_controller.rb
T

32 lines
755 B
Ruby
Raw Normal View History

2023-05-21 17:59:36 +03:00
# frozen_string_literal: true
module Api
2023-05-31 23:19:20 +03:00
class TemplatesDocumentsController < ApiBaseController
2023-05-21 17:59:36 +03:00
def create
2023-05-31 23:19:20 +03:00
@template = current_account.templates.find(params[:template_id])
2023-05-21 17:59:36 +03:00
documents =
params[:blobs].map do |blob|
blob = ActiveStorage::Blob.find_signed(blob[:signed_id])
2023-05-31 23:19:20 +03:00
document = @template.documents.create!(blob:)
2023-05-21 17:59:36 +03:00
2023-05-31 23:19:20 +03:00
Templates::ProcessDocument.call(document)
2023-05-21 17:59:36 +03:00
end
schema = documents.map do |doc|
{ attachment_uuid: doc.uuid, name: doc.filename.base }
end
render json: {
schema:,
documents: documents.as_json(
include: {
preview_images: { methods: %i[url metadata filename] }
}
)
}
end
end
end