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
|
|
|
|
|
2021-08-18 16:00:01 +08:00
|
|
|
include TimestampableModel
|
|
|
|
|
2018-08-23 20:52:00 +08:00
|
|
|
def value
|
2018-08-07 20:19:49 +08:00
|
|
|
ActiveModelSerializers::SerializableResource.new(
|
2018-10-16 21:35:02 +08:00
|
|
|
object.value,
|
2020-02-17 07:26:20 +08:00
|
|
|
class_name: object.repository_column.data_type,
|
2018-08-07 20:19:49 +08:00
|
|
|
namespace: Api::V1,
|
|
|
|
adapter: :attribute
|
|
|
|
).as_json
|
|
|
|
end
|
2018-10-16 21:35:02 +08:00
|
|
|
|
|
|
|
def value_type
|
2020-02-17 07:26:20 +08:00
|
|
|
Extends::API_REPOSITORY_DATA_TYPE_MAPPINGS[object.repository_column.data_type]
|
2018-10-16 21:35:02 +08:00
|
|
|
end
|
2018-08-07 20:19:49 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|