mirror of
https://github.com/discourse/discourse.git
synced 2024-12-01 02:53:40 +08:00
27 lines
591 B
Ruby
27 lines
591 B
Ruby
class UserBadgeSerializer < ApplicationSerializer
|
|
attributes :id, :granted_at, :count, :post_id, :post_number
|
|
|
|
has_one :badge
|
|
has_one :user, serializer: BasicUserSerializer, root: :users
|
|
has_one :granted_by, serializer: BasicUserSerializer, root: :users
|
|
has_one :topic, serializer: BasicTopicSerializer
|
|
|
|
def include_count?
|
|
object.respond_to? :count
|
|
end
|
|
|
|
def include_post_id?
|
|
object.post_id && object.post
|
|
end
|
|
|
|
alias :include_topic? :include_post_id?
|
|
|
|
def post_number
|
|
object.post && object.post.post_number
|
|
end
|
|
|
|
def topic
|
|
object.post.topic
|
|
end
|
|
end
|