Skip to content

Commit

Permalink
show has_required_contacts status
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Fenner committed Apr 15, 2021
1 parent 977d9d3 commit e6f65e7
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 0 deletions.
6 changes: 6 additions & 0 deletions app/controllers/providers_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,12 @@ def index
response.response.aggregations.non_profit_statuses.buckets,
)
end
has_required_contacts =
if total > 0
facet_by_key(
response.response.aggregations.has_required_contacts.buckets,
)
end

@providers = response.results
respond_to do |format|
Expand Down
6 changes: 6 additions & 0 deletions app/controllers/v3/providers_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,12 @@ def index
response.response.aggregations.non_profit_statuses.buckets,
)
end
has_required_contacts =
if total > 0
facet_by_key(
response.response.aggregations.has_required_contacts.buckets,
)
end

@providers = response.results
respond_to do |format|
Expand Down
5 changes: 5 additions & 0 deletions app/graphql/types/member_connection_with_total_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class MemberConnectionWithTotalType < BaseConnection
field :organization_types, [FacetType], null: true, cache: true
field :focus_areas, [FacetType], null: true, cache: true
field :non_profit_statuses, [FacetType], null: true, cache: true
field :has_required_contacts, [FacetType], null: true, cache: true

def total_count
object.total_count
Expand Down Expand Up @@ -39,4 +40,8 @@ def focus_areas
def non_profit_statuses
facet_by_key(object.aggregations.non_profit_statuses.buckets)
end

def has_required_contacts
facet_by_key(object.aggregations.has_required_contacts.buckets)
end
end
13 changes: 13 additions & 0 deletions app/models/provider.rb
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,7 @@ class Provider < ApplicationRecord
family_name: { type: :text },
name: { type: :text },
}
indexes :has_required_contacts, type: :boolean
indexes :created, type: :date
indexes :updated, type: :date
indexes :deleted_at, type: :date
Expand Down Expand Up @@ -414,6 +415,7 @@ def as_indexed_json(options = {})
"service_contact" => service_contact,
"secondary_service_contact" => secondary_service_contact,
"voting_contact" => voting_contact,
"has_required_contacts" => has_required_contacts,
"created" => created.try(:iso8601),
"updated" => updated.try(:iso8601),
"deleted_at" => deleted_at.try(:iso8601),
Expand Down Expand Up @@ -465,6 +467,9 @@ def self.query_aggregations
non_profit_statuses: {
terms: { field: "non_profit_status", size: 10, min_doc_count: 1 },
},
has_required_contacts: {
terms: { field: "has_required_contacts", size: 2, min_doc_count: 1 },
},
}
end

Expand Down Expand Up @@ -625,6 +630,14 @@ def voting_contact_family_name
voting_contact.fetch("family_name", nil) if voting_contact.present?
end

def has_required_contacts
if member_type == "consortium_organization"
service_contact_email.present?
else
voting_contact_email.present? && service_contact_email.present? && billing_contact_email.present?
end
end

def billing_department
billing_information.fetch("department", nil) if billing_information.present?
end
Expand Down
14 changes: 14 additions & 0 deletions app/serializers/provider_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,20 @@ class ProviderSerializer
end
end

attribute :has_required_contacts,
if:
Proc.new { |object, params|
params[:current_ability] &&
params[:current_ability].can?(
:read_contact_information,
object,
) ==
true
} do |object|
object.has_required_contacts
end
end

attribute :salesforce_id,
if:
Proc.new { |object, params|
Expand Down

0 comments on commit e6f65e7

Please sign in to comment.