mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-09-13 08:34:49 +08:00
Add basic serializer for form response to api [SCI-11533]
This commit is contained in:
parent
cec91eb85f
commit
f77ad7d56d
5 changed files with 21 additions and 1 deletions
|
@ -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
|
||||
|
|
16
app/serializers/api/v1/form_response_serializer.rb
Normal file
16
app/serializers/api/v1/form_response_serializer.rb
Normal 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
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Reference in a new issue