2018-08-07 21:19:24 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-08-07 20:19:49 +08:00
|
|
|
module Api
|
|
|
|
module V1
|
|
|
|
class InventoryCellSerializer < ActiveModel::Serializer
|
2018-08-08 23:15:08 +08:00
|
|
|
type :inventory_cells
|
2018-08-23 20:52:00 +08:00
|
|
|
attributes :id, :value_type, :value
|
2018-08-07 20:19:49 +08:00
|
|
|
attribute :repository_column_id, key: :column_id
|
|
|
|
|
2018-08-23 20:52:00 +08:00
|
|
|
def value_type
|
2018-08-07 20:19:49 +08:00
|
|
|
type_id = RepositoryColumn
|
|
|
|
.data_types[object.repository_column.data_type]
|
|
|
|
I18n.t("api.v1.inventory_data_types.t#{type_id}")
|
|
|
|
end
|
|
|
|
|
2018-08-23 20:52:00 +08:00
|
|
|
def value
|
2018-08-07 20:19:49 +08:00
|
|
|
value =
|
|
|
|
case object.value_type
|
|
|
|
when 'RepositoryTextValue'
|
|
|
|
object.repository_text_value
|
|
|
|
when 'RepositoryDateValue'
|
|
|
|
object.repository_date_value
|
|
|
|
when 'RepositoryListValue'
|
|
|
|
object.repository_list_value
|
|
|
|
when 'RepositoryAssetValue'
|
2018-08-23 20:52:00 +08:00
|
|
|
object.repository_asset_value
|
2018-08-07 20:19:49 +08:00
|
|
|
end
|
|
|
|
ActiveModelSerializers::SerializableResource.new(
|
|
|
|
value,
|
|
|
|
namespace: Api::V1,
|
|
|
|
adapter: :attribute
|
|
|
|
).as_json
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|