docbrown/app/serializers/search/user_serializer.rb
2022-02-18 09:02:17 +07:00

24 lines
608 B
Ruby

module Search
class UserSerializer < ApplicationSerializer
HASH_TRANSFORM = ->(key, value) { { name: key, value: value } }
attributes :id,
:comments_count,
:badge_achievements_count,
:last_comment_at,
:name,
:path,
:public_reactions_count,
:profile_image_90,
:reactions_count,
:username
attribute :roles do |user|
user.roles.map(&:name)
end
attribute :profile_fields do |user|
user.profile&.data&.map(&HASH_TRANSFORM)
end
end
end