add variables_schema response
This commit is contained in:
@@ -4,9 +4,9 @@ module Templates
|
|||||||
module SerializeForApi
|
module SerializeForApi
|
||||||
SERIALIZE_PARAMS = {
|
SERIALIZE_PARAMS = {
|
||||||
only: %w[
|
only: %w[
|
||||||
id archived_at fields name preferences schema
|
id name slug schema submitters fields variables_schema
|
||||||
slug source submitters created_at updated_at
|
preferences source created_at updated_at archived_at author_id
|
||||||
author_id external_id folder_id shared_link
|
external_id folder_id shared_link
|
||||||
],
|
],
|
||||||
methods: %i[application_key folder_name],
|
methods: %i[application_key folder_name],
|
||||||
include: { author: { only: %i[id email first_name last_name] } }
|
include: { author: { only: %i[id email first_name last_name] } }
|
||||||
@@ -22,7 +22,16 @@ module Templates
|
|||||||
|
|
||||||
preview_image_attachments ||= preload_preview_image_attachments(schema_documents, dynamic_documents)
|
preview_image_attachments ||= preload_preview_image_attachments(schema_documents, dynamic_documents)
|
||||||
|
|
||||||
json['documents'] = template.schema.filter_map do |item|
|
json['variables_schema'] ||= {}
|
||||||
|
|
||||||
|
json['documents'] = build_documents_array(template, schema_documents, dynamic_documents,
|
||||||
|
preview_image_attachments, expires_at)
|
||||||
|
|
||||||
|
json
|
||||||
|
end
|
||||||
|
|
||||||
|
def build_documents_array(template, schema_documents, dynamic_documents, preview_image_attachments, expires_at)
|
||||||
|
template.schema.filter_map do |item|
|
||||||
if item['dynamic']
|
if item['dynamic']
|
||||||
dynamic_document = dynamic_documents.find { |e| e.uuid == item['attachment_uuid'] }
|
dynamic_document = dynamic_documents.find { |e| e.uuid == item['attachment_uuid'] }
|
||||||
|
|
||||||
@@ -44,8 +53,6 @@ module Templates
|
|||||||
'filename' => attachment.filename
|
'filename' => attachment.filename
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
json
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def preload_dynamic_documents(template)
|
def preload_dynamic_documents(template)
|
||||||
|
|||||||
@@ -230,6 +230,7 @@ describe 'Templates API' do
|
|||||||
name: 'sample-document'
|
name: 'sample-document'
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
|
variables_schema: template.variables_schema || {},
|
||||||
shared_link: template.shared_link,
|
shared_link: template.shared_link,
|
||||||
author_id: author.id,
|
author_id: author.id,
|
||||||
archived_at: nil,
|
archived_at: nil,
|
||||||
|
|||||||
Reference in New Issue
Block a user