Skip to content

armgit / spree

Public Imported from GitHub
0

Open Source Platform for DTC, B2B Commerce, Marketplaces & Omnichannel. REST APIs, TypeScript SDKs, and production-ready Next.js storefront. Self-host it. Own your data. No vendor lock-in. Zero platform fees.

Stop promising a null the company schema cannot produce

Łukasz Adamczyk93626616a09d
diff --git a/spree/api/app/serializers/spree/api/v3/admin/company_contact_serializer.rb b/spree/api/app/serializers/spree/api/v3/admin/company_contact_serializer.rb
index b4037b52b7..d93c4a1223 100644
--- a/spree/api/app/serializers/spree/api/v3/admin/company_contact_serializer.rb
+++ b/spree/api/app/serializers/spree/api/v3/admin/company_contact_serializer.rb
@@ -8,18 +8,21 @@ module Spree
attributes :role, created_at: :iso8601, updated_at: :iso8601
+ # Both associations are required, so these are never null and the
+ # types above say so. Safe navigation here would have promised a null
+ # the schema cannot produce.
attribute :company_location_id do |contact|
- contact.company_location&.prefixed_id
+ contact.company_location.prefixed_id
end
attribute :customer_id do |contact|
- contact.customer&.prefixed_id
+ contact.customer.prefixed_id
end
# The dashboard lists contacts by who they are, and would otherwise
# need a customer request per row.
attribute :email do |contact|
- contact.customer&.email
+ contact.customer.email
end
end
end
diff --git a/spree/api/app/serializers/spree/api/v3/admin/company_location_serializer.rb b/spree/api/app/serializers/spree/api/v3/admin/company_location_serializer.rb
index 37f396f717..8961593826 100644
--- a/spree/api/app/serializers/spree/api/v3/admin/company_location_serializer.rb
+++ b/spree/api/app/serializers/spree/api/v3/admin/company_location_serializer.rb
@@ -15,8 +15,9 @@ module Spree
attributes :name, :external_id, :metadata,
created_at: :iso8601, updated_at: :iso8601
+ # A branch always belongs to a company, so this is never null.
attribute :company_id do |location|
- location.company&.prefixed_id
+ location.company.prefixed_id
end
attribute :contacts_count do |location|