2019-11-12 10:06:26 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Mutations
|
|
|
|
module Todos
|
|
|
|
class MarkDone < ::Mutations::Todos::Base
|
|
|
|
graphql_name 'TodoMarkDone'
|
|
|
|
|
|
|
|
authorize :update_todo
|
|
|
|
|
|
|
|
argument :id,
|
2020-10-16 08:09:33 -04:00
|
|
|
::Types::GlobalIDType[::Todo],
|
2019-11-12 10:06:26 -05:00
|
|
|
required: true,
|
2021-08-17 20:11:18 -04:00
|
|
|
description: 'Global ID of the to-do item to mark as done.'
|
2019-11-12 10:06:26 -05:00
|
|
|
|
|
|
|
field :todo, Types::TodoType,
|
|
|
|
null: false,
|
2021-08-17 20:11:18 -04:00
|
|
|
description: 'Requested to-do item.'
|
2019-11-12 10:06:26 -05:00
|
|
|
|
|
|
|
def resolve(id:)
|
|
|
|
todo = authorized_find!(id: id)
|
2019-12-03 13:06:49 -05:00
|
|
|
|
|
|
|
mark_done(todo)
|
2019-11-12 10:06:26 -05:00
|
|
|
|
|
|
|
{
|
|
|
|
todo: todo.reset,
|
|
|
|
errors: errors_on_object(todo)
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def mark_done(todo)
|
2020-05-28 14:08:37 -04:00
|
|
|
TodoService.new.resolve_todo(todo, current_user, resolved_by_action: :api_done)
|
2019-11-12 10:06:26 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|