summaryrefslogtreecommitdiff
path: root/app/graphql/mutations/boards/destroy.rb
blob: 4a0068edee2fe27e70c8e31089a8c1d7a5239b8f (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 Boards
    class Destroy < ::Mutations::BaseMutation
      graphql_name 'DestroyBoard'

      field :board,
            Types::BoardType,
            null: true,
            description: 'The board after mutation.'
      argument :id,
                ::Types::GlobalIDType[::Board],
                required: true,
                description: 'The global ID of the board to destroy.'

      authorize :admin_issue_board

      def resolve(id:)
        board = authorized_find!(id: id)

        response = ::Boards::DestroyService.new(board.resource_parent, current_user).execute(board)

        {
          board: response.success? ? nil : board,
          errors: response.errors
        }
      end

      private

      def find_object(id:)
        GitlabSchema.object_from_id(id, expected_type: ::Board)
      end
    end
  end
end