debian-mirror-gitlab/app/graphql/resolvers/crm/contacts_resolver.rb

54 lines
1.5 KiB
Ruby
Raw Normal View History

2022-07-23 23:45:48 +05:30
# frozen_string_literal: true
module Resolvers
module Crm
class ContactsResolver < BaseResolver
include Gitlab::Graphql::Authorize::AuthorizeResource
include ResolvesIds
authorize :read_crm_contact
type Types::CustomerRelations::ContactType, null: true
2022-08-27 11:52:29 +05:30
argument :sort, Types::CustomerRelations::ContactSortEnum,
description: 'Criteria to sort contacts by.',
required: false,
default_value: { field: 'last_name', direction: :asc }
2022-07-23 23:45:48 +05:30
argument :search, GraphQL::Types::String,
required: false,
description: 'Search term to find contacts with.'
argument :state, Types::CustomerRelations::ContactStateEnum,
required: false,
description: 'State of the contacts to search for.'
argument :ids, [::Types::GlobalIDType[CustomerRelations::Contact]],
required: false,
description: 'Filter contacts by IDs.'
def resolve(**args)
args[:ids] = resolve_ids(args.delete(:ids))
2022-08-27 11:52:29 +05:30
args.delete(:state) if args[:state] == :all
contacts = ::Crm::ContactsFinder.new(current_user, { group: group }.merge(args)).execute
if needs_offset?(args)
offset_pagination(contacts)
else
contacts
end
2022-07-23 23:45:48 +05:30
end
def group
object.respond_to?(:sync) ? object.sync : object
end
2022-08-27 11:52:29 +05:30
private
def needs_offset?(args)
args.key?(:sort) && args[:sort][:field] == 'organization'
end
2022-07-23 23:45:48 +05:30
end
end
end