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

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

58 lines
1.6 KiB
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
2022-06-21 17:19:12 +05:30
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."
2020-07-28 23:09:34 +05:30
field :todos, [::Types::TodoType],
null: false,
2021-03-11 19:13:27 +05:30
description: 'Updated to-do items.'
2020-07-28 23:09:34 +05:30
2022-06-21 17:19:12 +05:30
def resolve(**args)
2020-01-01 13:55:28 +05:30
authorize!(current_user)
2022-06-21 17:19:12 +05:30
updated_ids = mark_all_todos_done(**args)
2020-01-01 13:55:28 +05:30
{
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
2022-06-21 17:19:12 +05:30
def mark_all_todos_done(**args)
2020-01-01 13:55:28 +05:30
return [] unless current_user
2022-06-21 17:19:12 +05:30
finder_params = { state: :pending }
if args[:target_id].present?
target = Gitlab::Graphql::Lazy.force(
2022-07-16 23:28:13 +05:30
GitlabSchema.find_by_gid(args[:target_id])
2022-06-21 17:19:12 +05:30
)
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
2020-06-23 00:09:42 +05:30
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