From 6a298a068c6af5d818b212bc10946a6aefa705cd Mon Sep 17 00:00:00 2001 From: Pete Matsyburka Date: Tue, 29 Oct 2024 12:11:21 +0200 Subject: [PATCH] fix updated templates --- lib/templates/serialize_for_api.rb | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/templates/serialize_for_api.rb b/lib/templates/serialize_for_api.rb index 3087035b..f5f03ebe 100644 --- a/lib/templates/serialize_for_api.rb +++ b/lib/templates/serialize_for_api.rb @@ -25,9 +25,15 @@ module Templates name: :preview_images) .preload(:blob) - json[:documents] = template.schema.map do |item| + json[:documents] = template.schema.filter_map do |item| attachment = schema_documents.find { |e| e.uuid == item['attachment_uuid'] } + unless attachment + Rollbar.error("Documents missing: #{template.id}") if defined?(Rollbar) + + next + end + first_page_blob = preview_image_attachments.find { |e| e.record_id == attachment.id }&.blob first_page_blob ||= attachment.preview_images.joins(:blob).find_by(blob: { filename: ['0.jpg', '0.png'] })&.blob