Skip to content

Commit

Permalink
Send required info for users.
Browse files Browse the repository at this point in the history
  • Loading branch information
xhagrg committed Apr 19, 2017
1 parent 97385ab commit 6c867b2
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion app/serializers/user_serializer.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,32 @@
class UserSerializer < ActiveModel::Serializer
attributes :name, :nick_name, :email
attributes :id, :name, :nick_name, :email, :is_friend,
:invitation_present
has_many :friends

def id
object._id.to_s
end

def friends
if @instance_options[:current_user_id] == id
object.friends
else
[]
end
end

def is_friend
current_user.friend_ids.map(&:to_s).include?(id)
end

def invitation_present
Invitation.or([
{ sender_id: id, receiver_id: current_user.id },
{ sender_id: current_user.id, receiver_id: id }
]).present?
end

def sent_invitation
current_user.sent_invitations.map { |i| i.receiver_id.to_s }.include?(id)
end
end

0 comments on commit 6c867b2

Please sign in to comment.