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-09-17 00:45:57 +03:00
|
|
|
load_and_authorize_resource :template
|
|
|
|
|
|
2023-05-21 17:59:36 +03:00
|
|
|
def create
|
2023-07-12 23:56:42 +03:00
|
|
|
return head :unprocessable_entity if params[:blobs].blank? && params[:files].blank?
|
|
|
|
|
|
2023-09-01 01:27:13 +03:00
|
|
|
documents = Templates::CreateAttachments.call(@template, params)
|
2023-05-21 17:59:36 +03:00
|
|
|
|
|
|
|
|
schema = documents.map do |doc|
|
|
|
|
|
{ attachment_uuid: doc.uuid, name: doc.filename.base }
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
render json: {
|
|
|
|
|
schema:,
|
|
|
|
|
documents: documents.as_json(
|
2024-02-17 22:14:28 +02:00
|
|
|
methods: %i[metadata signed_uuid],
|
2023-05-21 17:59:36 +03:00
|
|
|
include: {
|
|
|
|
|
preview_images: { methods: %i[url metadata filename] }
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
}
|
2024-01-14 23:22:41 +02:00
|
|
|
rescue Templates::CreateAttachments::PdfEncrypted
|
|
|
|
|
render json: { error: 'PDF encrypted' }, status: :unprocessable_entity
|
2023-05-21 17:59:36 +03:00
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|