2018-08-08 22:55:51 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Api
|
|
|
|
module V1
|
|
|
|
class InventoryColumnSerializer < ActiveModel::Serializer
|
|
|
|
type :inventory_columns
|
2020-04-01 19:29:21 +08:00
|
|
|
attributes :name, :data_type, :metadata
|
2018-10-07 19:28:29 +08:00
|
|
|
has_many :repository_list_items,
|
|
|
|
key: :inventory_list_items,
|
|
|
|
serializer: InventoryListItemSerializer,
|
|
|
|
class_name: 'RepositoryListItem',
|
2018-10-16 21:35:02 +08:00
|
|
|
if: (lambda do
|
|
|
|
object.data_type == 'RepositoryListValue' &&
|
|
|
|
!instance_options[:hide_list_items]
|
|
|
|
end)
|
2020-02-17 07:26:20 +08:00
|
|
|
has_many :repository_checklist_items,
|
|
|
|
key: :inventory_checklist_items,
|
|
|
|
serializer: InventoryChecklistItemSerializer,
|
|
|
|
class_name: 'RepositoryChecklistItem',
|
|
|
|
if: (lambda do
|
|
|
|
object.data_type == 'RepositoryChecklistValue' &&
|
|
|
|
!instance_options[:hide_list_items]
|
|
|
|
end)
|
2019-10-21 17:53:18 +08:00
|
|
|
has_many :repository_status_items,
|
2022-04-20 17:07:15 +08:00
|
|
|
key: :inventory_status_items,
|
2019-10-21 17:53:18 +08:00
|
|
|
serializer: InventoryStatusItemSerializer,
|
|
|
|
class_name: 'RepositoryStatusItem',
|
|
|
|
if: (lambda do
|
|
|
|
object.data_type == 'RepositoryStatusValue' &&
|
|
|
|
!instance_options[:hide_list_items]
|
|
|
|
end)
|
2022-04-08 20:09:00 +08:00
|
|
|
has_many :repository_stock_unit_items,
|
2022-04-20 17:07:15 +08:00
|
|
|
key: :inventory_stock_unit_items,
|
2022-04-08 20:09:00 +08:00
|
|
|
serializer: InventoryStockUnitItemSerializer,
|
|
|
|
class_name: 'RepositoryStockUnitItem',
|
|
|
|
if: (lambda do
|
|
|
|
object.data_type == 'RepositoryStockValue' &&
|
|
|
|
!instance_options[:hide_list_items]
|
|
|
|
end)
|
2018-10-16 21:35:02 +08:00
|
|
|
|
2021-08-18 16:00:01 +08:00
|
|
|
include TimestampableModel
|
|
|
|
|
2018-10-16 21:35:02 +08:00
|
|
|
def data_type
|
|
|
|
Extends::API_REPOSITORY_DATA_TYPE_MAPPINGS[object.data_type]
|
|
|
|
end
|
2018-08-08 22:55:51 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|