diff options
Diffstat (limited to 'app/graphql/types/customer_relations/organization_state_counts_type.rb')
-rw-r--r-- | app/graphql/types/customer_relations/organization_state_counts_type.rb | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/app/graphql/types/customer_relations/organization_state_counts_type.rb b/app/graphql/types/customer_relations/organization_state_counts_type.rb new file mode 100644 index 00000000000..7d813209a8e --- /dev/null +++ b/app/graphql/types/customer_relations/organization_state_counts_type.rb @@ -0,0 +1,24 @@ +# frozen_string_literal: true + +module Types + module CustomerRelations + # `object` is a hash. Authorization is performed by OrganizationStateCountsResolver + class OrganizationStateCountsType < Types::BaseObject # rubocop:disable Graphql/AuthorizeTypes + graphql_name 'OrganizationStateCounts' + description 'Represents the total number of organizations for the represented states.' + + AVAILABLE_STATES = ::CustomerRelations::Organization.states.keys.push('all').freeze + + AVAILABLE_STATES.each do |state| + field state, + GraphQL::Types::Int, + null: true, + description: "Number of organizations with state `#{state.upcase}`" + end + + def all + object.values.sum + end + end + end +end |