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

create.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: 96dc047c3dbf29154b147cb7eec1c6d2fb006c14 (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
60
61
62
63
64
65
66
67
# frozen_string_literal: true

module Mutations
  module CustomerRelations
    module Contacts
      class Create < BaseMutation
        graphql_name 'CustomerRelationsContactCreate'

        include ResolvesIds
        include Gitlab::Graphql::Authorize::AuthorizeResource

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

        argument :group_id, ::Types::GlobalIDType[::Group],
                 required: true,
                 description: 'Group for the contact.'

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

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

        argument :last_name, GraphQL::Types::String,
                 required: true,
                 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.'

        authorize :admin_crm_contact

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

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

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

        def set_organization!(args)
          return unless args[:organization_id]

          args[:organization_id] = resolve_ids(args[:organization_id], ::Types::GlobalIDType[::CustomerRelations::Organization])[0]
        end
      end
    end
  end
end