debian-mirror-gitlab/app/services/achievements/create_service.rb

26 lines
662 B
Ruby
Raw Permalink Normal View History

2023-03-17 16:20:25 +05:30
# frozen_string_literal: true
module Achievements
class CreateService < BaseService
def execute
return error_no_permissions unless allowed?
achievement = Achievements::Achievement.create(params.merge(namespace_id: @namespace.id))
return error_creating(achievement) unless achievement.persisted?
ServiceResponse.success(payload: achievement)
end
private
def error_no_permissions
error('You have insufficient permissions to create achievements for this namespace')
end
def error_creating(achievement)
error(achievement&.errors&.full_messages || 'Failed to create achievement')
end
end
end