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

mark_done.rb « todos « mutations « graphql « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 2ae50846108954eca3468d8d05d5d8edf091063b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# frozen_string_literal: true

module Mutations
  module Todos
    class MarkDone < ::Mutations::Todos::Base
      graphql_name 'TodoMarkDone'

      authorize :update_todo

      argument :id,
               ::Types::GlobalIDType[::Todo],
               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)

        mark_done(todo)

        {
          todo: todo.reset,
          errors: errors_on_object(todo)
        }
      end

      private

      def mark_done(todo)
        TodoService.new.resolve_todo(todo, current_user, resolved_by_action: :api_done)
      end
    end
  end
end