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