mirror of
https://github.com/HackPlan/RootPanel.git
synced 2026-04-24 03:35:59 +08:00
31 lines
660 B
CoffeeScript
31 lines
660 B
CoffeeScript
class CouponProvider
|
|
defaults:
|
|
name: null
|
|
validate: (account, coupon) ->
|
|
apply: (account, coupon) ->
|
|
populateCoupon: (coupon, {req}) -> coupon
|
|
|
|
constructor: (options) ->
|
|
_.extend @, @defaults, options
|
|
|
|
module.exports = class CouponProviderManager
|
|
constructor: ->
|
|
@providers = {}
|
|
|
|
register: (options) ->
|
|
{name} = options
|
|
|
|
unless name
|
|
throw new Error 'coupon provider should have a name'
|
|
|
|
if @providers[name]
|
|
throw new Error "coupon provider `#{name}` already exists"
|
|
|
|
@providers[name] = new CouponType options
|
|
|
|
all: ->
|
|
return _.values @providers
|
|
|
|
byName: (name) ->
|
|
return @providers[name]
|