2019-05-03 06:17:27 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2015-03-17 03:14:33 +08:00
|
|
|
class DirectoryItemSerializer < ApplicationSerializer
|
2018-12-06 19:18:52 +08:00
|
|
|
class UserSerializer < UserNameSerializer
|
|
|
|
include UserPrimaryGroupMixin
|
2021-06-08 01:34:01 +08:00
|
|
|
|
|
|
|
attributes :user_fields
|
|
|
|
|
|
|
|
def user_fields
|
2021-06-23 23:45:18 +08:00
|
|
|
fields = {}
|
|
|
|
|
|
|
|
object.user_custom_fields.each do |cuf|
|
|
|
|
user_field_id = @options[:user_custom_field_map][cuf.name]
|
|
|
|
fields[user_field_id] = cuf.value if user_field_id
|
|
|
|
end
|
|
|
|
|
|
|
|
fields
|
2021-06-08 01:34:01 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def include_user_fields?
|
2021-06-23 23:45:18 +08:00
|
|
|
@options[:user_custom_field_map].present?
|
2021-06-08 01:34:01 +08:00
|
|
|
end
|
2018-12-06 19:18:52 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
has_one :user, embed: :objects, serializer: UserSerializer
|
2021-06-24 03:55:17 +08:00
|
|
|
|
|
|
|
attributes :id
|
2015-03-17 03:14:33 +08:00
|
|
|
|
|
|
|
def id
|
|
|
|
object.user_id
|
|
|
|
end
|
|
|
|
|
2021-06-24 03:55:17 +08:00
|
|
|
private
|
|
|
|
|
|
|
|
def attributes
|
|
|
|
hash = super
|
|
|
|
|
|
|
|
@options[:attributes].each { |attr| hash.merge!("#{attr}": object[attr]) }
|
|
|
|
|
|
|
|
if object.period_type == DirectoryItem.period_types[:all]
|
|
|
|
hash.merge!(time_read: object.user_stat.time_read)
|
|
|
|
end
|
2015-03-17 03:14:33 +08:00
|
|
|
|
2021-06-24 03:55:17 +08:00
|
|
|
hash
|
2015-03-17 03:14:33 +08:00
|
|
|
end
|
|
|
|
end
|