* wip
This commit is contained in:
parent
bb9beb9cab
commit
1e250b63a9
|
|
@ -310,3 +310,4 @@ web_playable_jamtracks.sql
|
|||
affiliate_partner_rate.sql
|
||||
track_downloads.sql
|
||||
jam_track_lang_idx.sql
|
||||
giftcard.sql
|
||||
|
|
|
|||
|
|
@ -0,0 +1,13 @@
|
|||
CREATE TABLE gift_card (
|
||||
id VARCHAR(64) PRIMARY KEY DEFAULT uuid_generate_v4(),
|
||||
code VARCHAR(64) UNIQUE NOT NULL,
|
||||
user_id VARCHAR (64) REFERENCES users(id) ON DELETE CASCADE,
|
||||
card_type VARCHAR(64) NOT NULL,
|
||||
used BOOLEAN NOT NULL DEFAULT FALSE,
|
||||
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
|
||||
);
|
||||
|
||||
ALTER TABLE users ADD COLUMN free_jamtracks INTEGER DEFAULT 0;
|
||||
UPDATE users set free_jamtracks = 1 WHERE has_redeemable_jamtrack = TRUE;
|
||||
ALTER TABLE users DROP COLUMN has_redeemable_jamtrack;
|
||||
|
|
@ -0,0 +1,36 @@
|
|||
module JamRuby
|
||||
class GiftCard < ActiveRecord::Base
|
||||
|
||||
@@log = Logging.logger[GiftCard]
|
||||
|
||||
FIVE_JAM_TRACKS = 'five_jam_tracks'
|
||||
TEN_JAM_TRACKS = 'ten_jam_tracks'
|
||||
CARD_TYPES =
|
||||
[
|
||||
FIVE_JAM_TRACKS,
|
||||
TEN_JAM_TRACKS
|
||||
]
|
||||
|
||||
|
||||
belongs_to :user, class_name: "JamRuby::User"
|
||||
|
||||
validates :card_type, presence: true, inclusion: {in: CARD_TYPES}
|
||||
validates :redeemed, inclusion: {in: [true, false]}
|
||||
validates :code, presence: true, uniqueness: true
|
||||
|
||||
def redeem(user)
|
||||
|
||||
transaction do
|
||||
update({redeemed: true, user: user})
|
||||
|
||||
if card_type == FIVE_JAM_TRACK
|
||||
user.red
|
||||
elsif card_type == TEN_JAM_TRACK
|
||||
else
|
||||
raise 'unknown type'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
|
@ -194,6 +194,7 @@ module JamRuby
|
|||
validates :terms_of_service, :acceptance => {:accept => true, :on => :create, :allow_nil => false }
|
||||
validates :reuse_card, :inclusion => {:in => [true, false]}
|
||||
validates :has_redeemable_jamtrack, :inclusion => {:in => [true, false]}
|
||||
validates :free_jamtracks, presence: true, minimum: 0, maximum: 100
|
||||
validates :subscribe_email, :inclusion => {:in => [nil, true, false]}
|
||||
validates :musician, :inclusion => {:in => [true, false]}
|
||||
validates :show_whats_next, :inclusion => {:in => [nil, true, false]}
|
||||
|
|
|
|||
Loading…
Reference in New Issue