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