Sha256: 6a006f9775fc6c8f6a2ca68e9904e02995a4d88ad42fbf222c689b63fa2d90f8

Contents?: true

Size: 1.1 KB

Versions: 16

Compression:

Stored size: 1.1 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, :selected_locale

          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

16 entries across 16 versions & 1 rubygems

Version Path
spree_api-4.10.1 app/serializers/spree/api/v2/platform/user_serializer.rb
spree_api-4.10.0 app/serializers/spree/api/v2/platform/user_serializer.rb
spree_api-4.9.0 app/serializers/spree/api/v2/platform/user_serializer.rb
spree_api-4.8.3 app/serializers/spree/api/v2/platform/user_serializer.rb
spree_api-4.8.2 app/serializers/spree/api/v2/platform/user_serializer.rb
spree_api-4.7.3 app/serializers/spree/api/v2/platform/user_serializer.rb
spree_api-4.6.6 app/serializers/spree/api/v2/platform/user_serializer.rb
spree_api-4.6.5 app/serializers/spree/api/v2/platform/user_serializer.rb
spree_api-4.7.2 app/serializers/spree/api/v2/platform/user_serializer.rb
spree_api-4.7.1 app/serializers/spree/api/v2/platform/user_serializer.rb
spree_api-4.6.4 app/serializers/spree/api/v2/platform/user_serializer.rb
spree_api-4.7.0 app/serializers/spree/api/v2/platform/user_serializer.rb
spree_api-4.6.3 app/serializers/spree/api/v2/platform/user_serializer.rb
spree_api-4.6.2 app/serializers/spree/api/v2/platform/user_serializer.rb
spree_api-4.6.1 app/serializers/spree/api/v2/platform/user_serializer.rb
spree_api-4.6.0 app/serializers/spree/api/v2/platform/user_serializer.rb