2018-09-07 21:19:20 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Api
|
|
|
|
module V1
|
|
|
|
class ProtocolSerializer < ActiveModel::Serializer
|
|
|
|
type :protocols
|
2018-10-07 17:29:56 +08:00
|
|
|
attributes :id, :name, :authors, :description, :protocol_type
|
|
|
|
has_many :protocol_keywords,
|
2018-10-07 19:28:29 +08:00
|
|
|
key: :keywords,
|
|
|
|
serializer: ProtocolKeywordSerializer,
|
|
|
|
class_name: 'ProtocolKeyword',
|
|
|
|
unless: -> { object.protocol_keywords.empty? }
|
2019-09-17 19:02:38 +08:00
|
|
|
has_many :steps, serializer: StepSerializer, if: -> { object.steps.any? }
|
|
|
|
belongs_to :parent, serializer: ProtocolSerializer, if: -> { object.parent.present? }
|
2018-09-07 21:19:20 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|