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

update.rb « contacts « customer_relations « mutations « graphql « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: a3abf37f21f65ed8f2072a569de86312d4e339a2 (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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# frozen_string_literal: true

module Mutations
  module CustomerRelations
    module Contacts
      class Update < Mutations::BaseMutation
        graphql_name 'CustomerRelationsContactUpdate'

        include ResolvesIds

        authorize :admin_crm_contact

        field :contact,
              Types::CustomerRelations::ContactType,
              null: true,
              description: 'Contact after the mutation.'

        argument :id, ::Types::GlobalIDType[::CustomerRelations::Contact],
                 required: true,
                 description: 'Global ID of the contact.'

        argument :organization_id, ::Types::GlobalIDType[::CustomerRelations::Organization],
                 required: false,
                 description: 'Organization of the contact.'

        argument :first_name, GraphQL::Types::String,
                  required: false,
                  description: 'First name of the contact.'

        argument :last_name, GraphQL::Types::String,
                  required: false,
                  description: 'Last name of the contact.'

        argument :phone, GraphQL::Types::String,
                  required: false,
                  description: 'Phone number of the contact.'

        argument :email, GraphQL::Types::String,
                  required: false,
                  description: 'Email address of the contact.'

        argument :description, GraphQL::Types::String,
                  required: false,
                  description: 'Description of or notes for the contact.'

        def resolve(args)
          contact = ::Gitlab::Graphql::Lazy.force(GitlabSchema.object_from_id(args.delete(:id), expected_type: ::CustomerRelations::Contact))
          raise_resource_not_available_error! unless contact

          group = contact.group
          authorize!(group)

          result = ::CustomerRelations::Contacts::UpdateService.new(group: group, current_user: current_user, params: args).execute(contact)
          { contact: result.payload, errors: result.errors }
        end
      end
    end
  end
end