diff --git a/app/presenters/worldwide_organisation_presenter.rb b/app/presenters/worldwide_organisation_presenter.rb index 959529d331..51697b627f 100644 --- a/app/presenters/worldwide_organisation_presenter.rb +++ b/app/presenters/worldwide_organisation_presenter.rb @@ -78,7 +78,9 @@ def people_in_non_primary_roles def main_office return unless (office_item = content_item.dig("links", "main_office")&.first) - return unless (office_contact_item = office_item.dig("links", "contact")&.first) + + office_contact_item = contact_for_office(office_item["content_id"]) + return unless office_contact_item WorldwideOffice.new( contact: WorldwideOrganisation::LinkedContactPresenter.new(office_contact_item), @@ -93,7 +95,7 @@ def home_page_offices return [] unless content_item.dig("links", "home_page_offices") content_item.dig("links", "home_page_offices").map { |office| - next unless (contact = office.dig("links", "contact")&.first) + next unless (contact = contact_for_office(office["content_id"])) WorldwideOrganisation::LinkedContactPresenter.new(contact) }.compact @@ -128,6 +130,18 @@ def sponsoring_organisations private + def contact_for_office(office_content_id) + contact_mapping = content_item.dig("details", "office_contact_associations").select { |office_contact_association| + office_contact_association["office_content_id"] == office_content_id + }.first + + return unless contact_mapping + + content_item.dig("links", "contacts").select { |contact| + contact["content_id"] == contact_mapping["contact_content_id"] + }.first + end + def presented_title_for_roles(roles) roles .map { |role| role["title"] }