socialforge/app/api/mobile/entities/project.rb

33 lines
927 B
Ruby
Raw Normal View History

2016-07-25 15:20:01 +08:00
module Mobile
module Entities
class Project < Grape::Entity
expose :name
expose :id
2016-07-27 14:30:19 +08:00
expose :user_id
2016-08-03 10:56:55 +08:00
expose :invite_code
2016-08-04 09:08:18 +08:00
expose :qrcode
2016-07-25 15:20:01 +08:00
expose :can_setting, if: lambda { |instance, options| options[:user] } do |instance, options|
current_user = options[:user]
2016-07-27 14:30:19 +08:00
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
2016-07-25 15:20:01 +08:00
can_setting
end
2016-07-27 14:30:19 +08:00
expose :is_creator, if: lambda { |instance, options| options[:user] } do |instance, options|
current_user = options[:user]
current_user.id == instance.user_id
end
2016-07-25 15:20:01 +08:00
expose :member_count, if: lambda { |instance, options| options[:user] } do |instance, options|
instance.members.count
end
end
end
end