2019-12-13 09:08:01 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Mutations
|
|
|
|
module Snippets
|
|
|
|
class Destroy < Base
|
|
|
|
graphql_name 'DestroySnippet'
|
|
|
|
|
|
|
|
ERROR_MSG = 'Error deleting the snippet'
|
|
|
|
|
2020-11-09 21:08:48 +00:00
|
|
|
argument :id, ::Types::GlobalIDType[::Snippet],
|
2019-12-13 09:08:01 +00:00
|
|
|
required: true,
|
2021-08-18 00:11:18 +00:00
|
|
|
description: 'Global ID of the snippet to destroy.'
|
2019-12-13 09:08:01 +00:00
|
|
|
|
|
|
|
def resolve(id:)
|
|
|
|
snippet = authorized_find!(id: id)
|
|
|
|
|
2020-01-17 00:09:00 +00:00
|
|
|
response = ::Snippets::DestroyService.new(current_user, snippet).execute
|
|
|
|
errors = response.success? ? [] : [ERROR_MSG]
|
2019-12-13 09:08:01 +00:00
|
|
|
|
|
|
|
{
|
|
|
|
errors: errors
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def ability_name
|
|
|
|
"admin"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|