Class: Api::FollowersSerializer

Inherits:
ActiveModel::Serializer
  • Object
show all
Includes:
RelationsSerializerHelper
Defined in:
app/serializers/api/followers_serializer.rb

Instance Method Summary collapse

Methods included from RelationsSerializerHelper

#has_clapped, #has_followed, #has_saved

Instance Method Details

#followersObject



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'app/serializers/api/followers_serializer.rb', line 9

def followers
  object.followers.map do |follower|
    follower = Users::DeletedUser.new if follower.nil? || follower.deleted?
    data = {
      id: follower.id,
      first_name: follower.first_name,
      last_name: follower.last_name,
      nickname: follower.nickname,
      mutual_count: mutual_count(follower),
      logo_url: follower.logo_url,
      logo_url_sm: follower.logo_url_sm,
      has_followed: has_followed(follower),
      has_clapped: has_clapped(follower),
      can_contact: follower.can_contact,
      short_bio: follower.short_bio
    }
    if object.instance_of?(User)
      data = data.merge({
                          projects_count: follower.projects_count,
                          spaces_count: follower.spaces_count
                        })
    end
    data
  end
end

#mutual_count(follower) ⇒ Object



35
36
37
38
39
40
41
# File 'app/serializers/api/followers_serializer.rb', line 35

def mutual_count(follower)
  if current_user.nil?
    0
  else
    follower.follow_mutual_count(current_user)
  end
end