codecombat/server/achievements/EarnedAchievement.coffee

18 lines
580 B
CoffeeScript
Raw Normal View History

mongoose = require 'mongoose'
jsonschema = require '../../app/schemas/models/earned_achievement'
EarnedAchievementSchema = new mongoose.Schema({
notified:
type: Boolean
default: false
}, {strict:false})
EarnedAchievementSchema.pre 'save', (next) ->
@set('changed', Date.now())
next()
EarnedAchievementSchema.index({user: 1, achievement: 1}, {unique: true, name: 'earned achievement index'})
EarnedAchievementSchema.index({user: 1, changed: -1}, {name: 'latest '})
module.exports = EarnedAchievement = mongoose.model('EarnedAchievement', EarnedAchievementSchema)