33 lines
927 B
Ruby
33 lines
927 B
Ruby
module Mobile
|
|
module Entities
|
|
class Project < Grape::Entity
|
|
expose :name
|
|
expose :id
|
|
expose :user_id
|
|
expose :invite_code
|
|
expose :qrcode
|
|
expose :can_setting, if: lambda { |instance, options| options[:user] } do |instance, options|
|
|
current_user = options[:user]
|
|
|
|
my_member = instance.member_principals.where("users.id=#{current_user.id}").first
|
|
can_setting = false
|
|
if my_member && my_member.roles[0] && my_member.roles[0].id == 3
|
|
can_setting = true
|
|
end
|
|
can_setting
|
|
end
|
|
|
|
expose :is_creator, if: lambda { |instance, options| options[:user] } do |instance, options|
|
|
current_user = options[:user]
|
|
|
|
current_user.id == instance.user_id
|
|
end
|
|
|
|
|
|
expose :member_count, if: lambda { |instance, options| options[:user] } do |instance, options|
|
|
instance.members.count
|
|
end
|
|
end
|
|
end
|
|
end
|