debian-mirror-gitlab/app/graphql/mutations/todos/mark_all_done.rb

44 lines
994 B
Ruby
Raw Normal View History

2020-01-01 13:55:28 +05:30
# frozen_string_literal: true
module Mutations
module Todos
class MarkAllDone < ::Mutations::Todos::Base
graphql_name 'TodosMarkAllDone'
authorize :update_user
field :updated_ids,
2021-01-29 00:20:46 +05:30
[::Types::GlobalIDType[::Todo]],
2020-01-01 13:55:28 +05:30
null: false,
2020-07-28 23:09:34 +05:30
deprecated: { reason: 'Use todos', milestone: '13.2' },
2021-03-08 18:12:59 +05:30
description: 'Ids of the updated todos.'
2020-01-01 13:55:28 +05:30
2020-07-28 23:09:34 +05:30
field :todos, [::Types::TodoType],
null: false,
2021-03-08 18:12:59 +05:30
description: 'Updated todos.'
2020-07-28 23:09:34 +05:30
2020-01-01 13:55:28 +05:30
def resolve
authorize!(current_user)
updated_ids = mark_all_todos_done
{
2021-01-29 00:20:46 +05:30
updated_ids: updated_ids,
2020-07-28 23:09:34 +05:30
todos: Todo.id_in(updated_ids),
2020-01-01 13:55:28 +05:30
errors: []
}
end
private
def mark_all_todos_done
return [] unless current_user
2020-06-23 00:09:42 +05:30
todos = TodosFinder.new(current_user).execute
TodoService.new.resolve_todos(todos, current_user, resolved_by_action: :api_all_done)
2020-01-01 13:55:28 +05:30
end
end
end
end