Files
openfoodnetwork/app/serializers/api/admin/customer_serializer.rb
Matt-Yorkley 1d5077061e Remove andand
This old gem implemented some functionality for handling nils which is no longer needed, as it's provided natively by Ruby with the &. operator.
2021-09-08 14:28:31 +01:00

43 lines
1.0 KiB
Ruby

# frozen_string_literal: true
module Api
module Admin
class CustomerSerializer < ActiveModel::Serializer
attributes :id, :email, :enterprise_id, :user_id, :code, :tags, :tag_list, :name,
:allow_charges, :default_card_present?
has_one :ship_address, serializer: Api::AddressSerializer
has_one :bill_address, serializer: Api::AddressSerializer
def name
object.name.presence || object.bill_address&.full_name
end
def tag_list
customer_tag_list.join(",")
end
def tags
customer_tag_list.map do |tag|
tag_rule_map = options.dig(:tag_rule_mapping, tag)
tag_rule_map || { text: tag, rules: nil }
end
end
def default_card_present?
return unless object.user
object.user.default_card.present?
end
private
def customer_tag_list
return object.tag_list unless options[:customer_tags]
options.dig(:customer_tags, object.id) || []
end
end
end
end