scinote-web/app/services/client_api/teams/create_service.rb

27 lines
543 B
Ruby
Raw Normal View History

module ClientApi
module Teams
class CreateService < BaseService
attr_accessor :team
def execute
@team = Team.new(@params)
2017-09-21 14:06:11 +08:00
@team.created_by = @current_user
if @team.save
# Okay, team is created, now
# add the current user as admin
UserTeam.create(
2017-09-21 14:06:11 +08:00
user: @current_user,
team: @team,
role: 2
)
success
else
error(@team.errors.full_messages.uniq.join('. '))
end
end
end
end
end