scinote-web/app/services/client_api/teams/create_service.rb
2017-09-21 08:06:11 +02:00

26 lines
543 B
Ruby

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