2020-01-01 13:55:28 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Mutations
|
|
|
|
module Todos
|
|
|
|
class Restore < ::Mutations::Todos::Base
|
|
|
|
graphql_name 'TodoRestore'
|
|
|
|
|
|
|
|
authorize :update_todo
|
|
|
|
|
|
|
|
argument :id,
|
|
|
|
GraphQL::ID_TYPE,
|
|
|
|
required: true,
|
|
|
|
description: 'The global id of the todo to restore'
|
|
|
|
|
|
|
|
field :todo, Types::TodoType,
|
|
|
|
null: false,
|
|
|
|
description: 'The requested todo'
|
|
|
|
|
|
|
|
def resolve(id:)
|
|
|
|
todo = authorized_find!(id: id)
|
2020-06-23 00:09:42 +05:30
|
|
|
restore(todo)
|
2020-01-01 13:55:28 +05:30
|
|
|
|
|
|
|
{
|
|
|
|
todo: todo.reset,
|
|
|
|
errors: errors_on_object(todo)
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2020-06-23 00:09:42 +05:30
|
|
|
def restore(todo)
|
|
|
|
TodoService.new.restore_todo(todo, current_user)
|
2020-01-01 13:55:28 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|