Sha256: 9b8f5e326fd393a6987d0c72d525a51118275d99a88af44496952a0e51012aff

Contents?: true

Size: 1.09 KB

Versions: 6

Compression:

Stored size: 1.09 KB

Contents

module Spree
  module Api
    module V2
      module Platform
        class UserSerializer < BaseSerializer
          set_type :user

          attributes :email, :first_name, :last_name, :created_at, :updated_at, :public_metadata, :private_metadata

          attribute :average_order_value do |user, params|
            price_stats(user.report_values_for(:average_order_value, params[:store]))
          end

          attribute :lifetime_value do |user, params|
            price_stats(user.report_values_for(:lifetime_value, params[:store]))
          end

          attribute :store_credits do |user, params|
            price_stats(user.available_store_credits(params[:store]))
          end

          has_one :bill_address,
                  record_type: :address,
                  serializer: :address

          has_one :ship_address,
                  record_type: :address,
                  serializer: :address

          def self.price_stats(stats)
            stats.map { |value| { currency: value.currency.to_s, amount: value.money.to_s } }
          end
        end
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
spree_api-4.5.5 app/serializers/spree/api/v2/platform/user_serializer.rb
spree_api-4.5.4 app/serializers/spree/api/v2/platform/user_serializer.rb
spree_api-4.5.3 app/serializers/spree/api/v2/platform/user_serializer.rb
spree_api-4.5.2 app/serializers/spree/api/v2/platform/user_serializer.rb
spree_api-4.5.1 app/serializers/spree/api/v2/platform/user_serializer.rb
spree_api-4.5.0 app/serializers/spree/api/v2/platform/user_serializer.rb