2019-12-26 22:10:19 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Mutations
|
|
|
|
module Todos
|
|
|
|
class MarkDone < ::Mutations::Todos::Base
|
|
|
|
graphql_name 'TodoMarkDone'
|
|
|
|
|
|
|
|
authorize :update_todo
|
|
|
|
|
|
|
|
argument :id,
|
2021-01-03 14:25:43 +05:30
|
|
|
::Types::GlobalIDType[::Todo],
|
2019-12-26 22:10:19 +05:30
|
|
|
required: true,
|
|
|
|
description: 'The global id of the todo to mark as done'
|
|
|
|
|
|
|
|
field :todo, Types::TodoType,
|
|
|
|
null: false,
|
|
|
|
description: 'The requested todo'
|
|
|
|
|
|
|
|
def resolve(id:)
|
|
|
|
todo = authorized_find!(id: id)
|
2020-01-01 13:55:28 +05:30
|
|
|
|
|
|
|
mark_done(todo)
|
2019-12-26 22:10:19 +05:30
|
|
|
|
|
|
|
{
|
|
|
|
todo: todo.reset,
|
|
|
|
errors: errors_on_object(todo)
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def mark_done(todo)
|
2020-06-23 00:09:42 +05:30
|
|
|
TodoService.new.resolve_todo(todo, current_user, resolved_by_action: :api_done)
|
2019-12-26 22:10:19 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|