Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'app/graphql/mutations/todos/mark_all_done.rb')
-rw-r--r--app/graphql/mutations/todos/mark_all_done.rb29
1 files changed, 25 insertions, 4 deletions
diff --git a/app/graphql/mutations/todos/mark_all_done.rb b/app/graphql/mutations/todos/mark_all_done.rb
index 7dd06cc8293..67a822c1067 100644
--- a/app/graphql/mutations/todos/mark_all_done.rb
+++ b/app/graphql/mutations/todos/mark_all_done.rb
@@ -7,14 +7,22 @@ module Mutations
authorize :update_user
+ TodoableID = Types::GlobalIDType[Todoable]
+
+ argument :target_id,
+ TodoableID,
+ required: false,
+ description: "Global ID of the to-do item's parent. Issues, merge requests, designs, and epics are supported. " \
+ "If argument is omitted, all pending to-do items of the current user are marked as done."
+
field :todos, [::Types::TodoType],
null: false,
description: 'Updated to-do items.'
- def resolve
+ def resolve(**args)
authorize!(current_user)
- updated_ids = mark_all_todos_done
+ updated_ids = mark_all_todos_done(**args)
{
todos: Todo.id_in(updated_ids),
@@ -24,10 +32,23 @@ module Mutations
private
- def mark_all_todos_done
+ def mark_all_todos_done(**args)
return [] unless current_user
- todos = TodosFinder.new(current_user).execute
+ finder_params = { state: :pending }
+
+ if args[:target_id].present?
+ target = Gitlab::Graphql::Lazy.force(
+ GitlabSchema.find_by_gid(TodoableID.coerce_isolated_input(args[:target_id]))
+ )
+
+ raise Gitlab::Graphql::Errors::ResourceNotAvailable, "Resource not available: #{args[:target_id]}" if target.nil?
+
+ finder_params[:type] = target.class.name
+ finder_params[:target_id] = target.id
+ end
+
+ todos = TodosFinder.new(current_user, finder_params).execute
TodoService.new.resolve_todos(todos, current_user, resolved_by_action: :api_all_done)
end