adjust signature prefill

This commit is contained in:
Pete Matsyburka
2024-07-24 09:13:13 +03:00
parent 11c48a495f
commit 04295f4540
4 changed files with 31 additions and 40 deletions
+20
View File
@@ -2,6 +2,7 @@
module Submitters
TRUE_VALUES = ['1', 'true', true].freeze
PRELOAD_ALL_PAGES_AMOUNT = 200
module_function
@@ -29,6 +30,25 @@ module Submitters
end
end
def preload_with_pages(submitter)
ActiveRecord::Associations::Preloader.new(
records: [submitter],
associations: [submission: [:template, { template_schema_documents: :blob }]]
).call
total_pages =
submitter.submission.template_schema_documents.sum { |e| e.metadata.dig('pdf', 'number_of_pages').to_i }
if total_pages < PRELOAD_ALL_PAGES_AMOUNT
ActiveRecord::Associations::Preloader.new(
records: submitter.submission.template_schema_documents,
associations: [:blob, { preview_images_attachments: :blob }]
).call
end
submitter
end
def create_attachment!(submitter, params)
blob =
if (file = params[:file])