From 33c0784bc6de14a06df6951e52ab053abb6336d6 Mon Sep 17 00:00:00 2001 From: Pete Matsyburka Date: Thu, 11 Apr 2024 16:36:53 +0300 Subject: [PATCH] add folder name to submission resp --- app/controllers/api/submissions_controller.rb | 6 ++++-- app/models/template.rb | 2 ++ lib/templates/serialize_for_api.rb | 4 +--- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/app/controllers/api/submissions_controller.rb b/app/controllers/api/submissions_controller.rb index daf9eceb..1e032fda 100644 --- a/app/controllers/api/submissions_controller.rb +++ b/app/controllers/api/submissions_controller.rb @@ -17,7 +17,8 @@ module Api submissions = submissions.joins(template: :folder).where(folder: { name: params[:template_folder] }) end - submissions = paginate(submissions.preload(:created_by_user, :template, :submitters, + submissions = paginate(submissions.preload(:created_by_user, :submitters, + template: :folder, audit_trail_attachment: :blob)) render json: { @@ -155,7 +156,8 @@ module Api completed_at opened_at sent_at created_at updated_at external_id metadata], methods: %i[status application_key] }, - template: { only: %i[id name created_at updated_at] }, + template: { only: %i[id name external_id created_at updated_at], + methods: %i[folder_name] }, created_by_user: { only: %i[id email first_name last_name] } } } diff --git a/app/models/template.rb b/app/models/template.rb index 2e5be5a1..2e499030 100644 --- a/app/models/template.rb +++ b/app/models/template.rb @@ -62,6 +62,8 @@ class Template < ApplicationRecord scope :active, -> { where(archived_at: nil) } scope :archived, -> { where.not(archived_at: nil) } + delegate :name, to: :folder, prefix: true + def application_key external_id end diff --git a/lib/templates/serialize_for_api.rb b/lib/templates/serialize_for_api.rb index 47c3c3dc..5c0a1094 100644 --- a/lib/templates/serialize_for_api.rb +++ b/lib/templates/serialize_for_api.rb @@ -6,12 +6,10 @@ module Templates def call(template, schema_documents = template.schema_documents, preview_image_attachments = []) json = template.as_json( - methods: %i[application_key], + methods: %i[application_key folder_name], include: { author: { only: %i[id email first_name last_name] } } ) - json[:folder_name] = template.folder.name - json[:documents] = template.schema.map do |item| attachment = schema_documents.find { |e| e.uuid == item['attachment_uuid'] }