Add basic serializer for form response to api [SCI-11533]

This commit is contained in:
Andrej 2025-03-20 06:45:18 +01:00
parent cec91eb85f
commit f77ad7d56d
5 changed files with 21 additions and 1 deletions

View file

@ -92,7 +92,7 @@ module Api
end
def permitted_includes
%w(tables assets checklists checklists.checklist_items comments user)
%w(tables assets checklists checklists.checklist_items comments user form_responses)
end
def check_manage_permissions

View file

@ -0,0 +1,16 @@
# frozen_string_literal: true
module Api
module V1
class FormResponseSerializer < ActiveModel::Serializer
type :form_responses
attributes :id, :form_id, :position
include TimestampableModel
def position
object&.step_orderable_element&.position
end
end
end
end

View file

@ -13,6 +13,8 @@ module Api
TableSerializer.new(object.orderable.table).as_json
when 'StepText'
StepTextSerializer.new(object.orderable).as_json
when 'FromResponse'
FormResponseSerializer.new(object.orderable).as_json
end
end
end

View file

@ -17,6 +17,7 @@ module Api
has_many :tables, serializer: TableSerializer
has_many :step_texts, serializer: StepTextSerializer
has_many :step_comments, key: :comments, serializer: CommentSerializer
has_many :form_responses, serializer: FormResponseSerializer
has_many :step_orderable_elements, key: :step_elements, serializer: StepOrderableElementSerializer
include TimestampableModel

View file

@ -17,6 +17,7 @@ module Api
has_many :tables, serializer: Api::V1::TableSerializer
has_many :step_texts, serializer: Api::V1::StepTextSerializer
has_many :step_comments, key: :comments, serializer: Api::V1::CommentSerializer
has_many :form_responses, serializer: Api::V1::FormResponseSerializer
has_many :step_orderable_elements, key: :step_elements, serializer: Api::V1::StepOrderableElementSerializer
include TimestampableModel