summaryrefslogtreecommitdiff
path: root/app/graphql/mutations/notes/update.rb
blob: ebf57b800c0736504df7be86bc9030959b104ba7 (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
# frozen_string_literal: true

module Mutations
  module Notes
    class Update < Base
      graphql_name 'UpdateNote'

      authorize :admin_note

      argument :id,
                GraphQL::ID_TYPE,
                required: true,
                description: 'The global id of the note to update'

      argument :body,
                GraphQL::STRING_TYPE,
                required: true,
                description: copy_field_description(Types::Notes::NoteType, :body)

      def resolve(args)
        note = authorized_find!(id: args[:id])

        check_object_is_note!(note)

        note = ::Notes::UpdateService.new(
          note.project,
          current_user,
          { note: args[:body] }
        ).execute(note)

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