2018-09-13 16:37:21 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Api
|
|
|
|
module V1
|
|
|
|
class ResultSerializer < ActiveModel::Serializer
|
|
|
|
type :results
|
2023-08-16 16:37:44 +08:00
|
|
|
attributes :name, :archived, :result_text, :result_table, :result_asset
|
2018-10-07 18:36:58 +08:00
|
|
|
belongs_to :user, serializer: UserSerializer
|
2021-08-18 16:00:01 +08:00
|
|
|
has_many :result_comments, key: :comments, serializer: CommentSerializer
|
2023-08-16 16:37:44 +08:00
|
|
|
has_many :result_orderable_elements, key: :result_elements, serializer: ResultOrderableElementSerializer
|
|
|
|
has_many :assets, serializer: AssetSerializer
|
2021-08-18 16:00:01 +08:00
|
|
|
|
|
|
|
include TimestampableModel
|
2023-08-16 16:37:44 +08:00
|
|
|
|
|
|
|
def result_text
|
|
|
|
Api::V1::ResultTextSerializer.new(object.result_texts.first).as_json if object.result_texts.any?
|
|
|
|
end
|
|
|
|
|
|
|
|
def result_table
|
|
|
|
Api::V1::ResultTableSerializer.new(object.result_tables.first).as_json if object.result_tables.any?
|
|
|
|
end
|
|
|
|
|
|
|
|
def result_asset
|
|
|
|
Api::V1::ResultAssetSerializer.new(object.result_assets.first).as_json if object.result_assets.any?
|
|
|
|
end
|
2018-09-13 16:37:21 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|