mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2025-03-14 07:00:01 -04:00
Add exhausted property to prepaid model
It is true when redeemers.length >= maxRedeemers
This commit is contained in:
parent
e98d60fa7d
commit
c3735ba0eb
3 changed files with 7 additions and 0 deletions
|
@ -10,6 +10,7 @@ PrepaidSchema = c.object({title: 'Prepaid', required: ['creator', 'type']}, {
|
|||
code: c.shortString(title: "Unique code to redeem")
|
||||
type: { type: 'string' }
|
||||
properties: {type: 'object'}
|
||||
exhausted: { type: 'boolean' }
|
||||
})
|
||||
|
||||
c.extendBasicProperties(PrepaidSchema, 'prepaid')
|
||||
|
|
|
@ -12,5 +12,10 @@ PrepaidSchema.statics.generateNewCode = (done) ->
|
|||
return done(code) unless prepaid
|
||||
tryCode()
|
||||
tryCode()
|
||||
|
||||
PrepaidSchema.pre('save', (next) ->
|
||||
@set('exhausted', @get('maxRedeemers') <= _.size(@get('redeemers')))
|
||||
next()
|
||||
)
|
||||
|
||||
module.exports = Prepaid = mongoose.model('prepaid', PrepaidSchema)
|
||||
|
|
|
@ -306,6 +306,7 @@ describe '/db/prepaid', ->
|
|||
joeCode = prepaid.code
|
||||
expect(prepaid.creator).toBeDefined()
|
||||
expect(prepaid.maxRedeemers).toEqual(3)
|
||||
expect(prepaid.exhausted).toBe(false)
|
||||
expect(prepaid.properties).toBeDefined()
|
||||
expect(prepaid.properties.months).toEqual(3)
|
||||
done()
|
||||
|
|
Loading…
Reference in a new issue