summaryrefslogtreecommitdiff
path: root/app/graphql/mutations/boards/lists/base_update.rb
blob: c6e6b1c9bfee7b2d75e3d8ffa99ac2fb6e312486 (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
38
39
40
# frozen_string_literal: true

module Mutations
  module Boards
    module Lists
      class BaseUpdate < BaseMutation
        argument :position, GraphQL::Types::Int,
                  required: false,
                  description: 'Position of list within the board.'

        argument :collapsed, GraphQL::Types::Boolean,
                  required: false,
                  description: 'Indicates if the list is collapsed for the user.'

        def resolve(list: nil, **args)
          if list.nil? || !can_read_list?(list)
            raise_resource_not_available_error!
          end

          update_result = update_list(list, args)

          {
            list: update_result.payload[:list],
            errors: update_result.errors
          }
        end

        private

        def update_list(list, args)
          raise NotImplementedError
        end

        def can_read_list?(list)
          raise NotImplementedError
        end
      end
    end
  end
end