summaryrefslogtreecommitdiff
path: root/app/graphql/mutations/jira_import/import_users.rb
blob: af2bb18161fbd16521dff350dee5866b9b09e282 (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
# frozen_string_literal: true

module Mutations
  module JiraImport
    class ImportUsers < BaseMutation
      include FindsProject

      graphql_name 'JiraImportUsers'

      authorize :admin_project

      field :jira_users,
            [Types::JiraUserType],
            null: true,
            description: 'Users returned from Jira, matched by email and name if possible.'

      argument :project_path, GraphQL::ID_TYPE,
               required: true,
               description: 'The project to import the Jira users into.'
      argument :start_at, GraphQL::INT_TYPE,
               required: false,
               description: 'The index of the record the import should started at, default 0 (50 records returned).'

      def resolve(project_path:, start_at: 0)
        project = authorized_find!(project_path)

        service_response = ::JiraImport::UsersImporter.new(context[:current_user], project, start_at.to_i).execute

        {
          jira_users: service_response.payload,
          errors: service_response.errors
        }
      end
    end
  end
end