mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2025-03-14 07:00:01 -04:00
Managed to track the difference between init and save, achievements work now
This commit is contained in:
parent
51e326efaa
commit
fb9ada6f97
3 changed files with 4 additions and 13 deletions
|
@ -10,8 +10,6 @@ class EarnedAchievementHandler extends Handler
|
|||
req.method is 'GET'
|
||||
|
||||
getByRelationship: (req, res, related, id) ->
|
||||
console.log related
|
||||
console.log id
|
||||
switch related
|
||||
when 'user'
|
||||
query = @modelClass.find({user: new mongoose.Types.ObjectId(id)})
|
||||
|
|
|
@ -28,14 +28,13 @@ module.exports = AchievablePlugin = (schema, options) ->
|
|||
before = {}
|
||||
|
||||
schema.post 'init', (doc) ->
|
||||
before[doc.id] = doc
|
||||
before[doc.id] = doc.toObject()
|
||||
|
||||
schema.post 'save', (doc) ->
|
||||
isNew = not doc.isInit('_id')
|
||||
console.log doc
|
||||
console.log 'is new: ' + isNew
|
||||
previousDocObj = before[doc.id] unless isNew
|
||||
|
||||
category = doc.constructor.modelName
|
||||
console.log 'category: ' + category
|
||||
|
||||
if category of achievements
|
||||
docObj = doc.toObject()
|
||||
|
@ -43,12 +42,7 @@ module.exports = AchievablePlugin = (schema, options) ->
|
|||
query = achievement.get('query')
|
||||
isRepeatable = achievement.get('proportionalTo')?
|
||||
console.log 'isRepeatable: ' + isRepeatable
|
||||
alreadyAchieved = false
|
||||
unless isNew
|
||||
previousDocObj = before[doc.id].toObject()
|
||||
alreadyAchieved = LocalMongo.matchesQuery previousDocObj, query
|
||||
console.log 'Already achieved: ' + alreadyAchieved
|
||||
console.log 'Matches: ' + LocalMongo.matchesQuery(docObj, query)
|
||||
alreadyAchieved = if isNew then false else LocalMongo.matchesQuery previousDocObj, query
|
||||
if LocalMongo.matchesQuery(docObj, query) and (isRepeatable or not alreadyAchieved)
|
||||
userID = doc.get(achievement.get('userField'))
|
||||
console.log 'Creating a new earned achievement for \'' + (achievement.get 'name') + '\' for ' + userID
|
||||
|
|
|
@ -31,7 +31,6 @@ module.exports.setup = (app) ->
|
|||
moduleName = module.replace '.', '_'
|
||||
name = handlers[moduleName]
|
||||
handler = require('../' + name)
|
||||
console.log parts
|
||||
return handler.getLatestVersion(req, res, parts[1], parts[3]) if parts[2] is 'version'
|
||||
return handler.versions(req, res, parts[1]) if parts[2] is 'versions'
|
||||
return handler.files(req, res, parts[1]) if parts[2] is 'files'
|
||||
|
|
Loading…
Reference in a new issue