Sha256: da5365e937efcf74aa3b9fa8019a03077401700945139285880ca1043f66514e

Contents?: true

Size: 890 Bytes

Versions: 26

Compression:

Stored size: 890 Bytes

Contents

module Workarea
  module Pricing
    class Discount
      # Represents an instance of redemption for a {Discount}.
      # Used for calculating single use discounts.
      #
      class Redemption
        include ApplicationDocument

        # @!attribute email
        #   @return [String] the email that received the discount
        #
        field :email, type: String

        # @!attribute discount
        #   @return [Discount] the discount
        #
        belongs_to :discount,
          class_name: 'Workarea::Pricing::Discount'

        scope :recent, -> { desc(:created_at) }
        index({ discount_id: 1, email: 1 })
        index({ discount_id: 1, created_at: -1 }, { background: true })

        before_validation :downcase_email

        private

        def downcase_email
          self.email = email.downcase if email.present?
        end
      end
    end
  end
end

Version data entries

26 entries across 26 versions & 1 rubygems

Version Path
workarea-core-3.5.6 app/models/workarea/pricing/discount/redemption.rb
workarea-core-3.5.5 app/models/workarea/pricing/discount/redemption.rb
workarea-core-3.5.4 app/models/workarea/pricing/discount/redemption.rb
workarea-core-3.5.3 app/models/workarea/pricing/discount/redemption.rb
workarea-core-3.5.2 app/models/workarea/pricing/discount/redemption.rb
workarea-core-3.5.1 app/models/workarea/pricing/discount/redemption.rb