diff --git a/script/algos.coffee b/script/algos.coffee index f5442b3141..e89a690cbc 100644 --- a/script/algos.coffee +++ b/script/algos.coffee @@ -355,6 +355,7 @@ obj.cron = (user, options={}) -> [paths, now] = [options.paths || {}, +options.now || +new Date] # New user (!lastCron, lastCron==new) or it got busted somehow, maybe they went to a different timezone + # FIXME move this to pre-save in mongoose if !user.lastCron? or user.lastCron is 'new' or moment(user.lastCron).isAfter(now) user.lastCron = now; paths['lastCron'] = true return @@ -371,6 +372,7 @@ obj.cron = (user, options={}) -> # Tally each task todoTally = 0 user.todos.concat(user.dailys).forEach (task) -> + return unless task {id, type, completed, repeat} = task # Deduct experience for missed Daily tasks, but not for Todos (just increase todo's value) unless completed diff --git a/script/helpers.coffee b/script/helpers.coffee index 58bf9e6a7b..efaa22593f 100644 --- a/script/helpers.coffee +++ b/script/helpers.coffee @@ -63,7 +63,7 @@ module.exports = items: { weapon: 0, armor: 0, head: 0, shield: 0 } preferences: { gender: 'm', skin: 'white', hair: 'blond', armorSet: 'v1', dayStart:0, showHelm: true } apiToken: uuid() # set in newUserObject below - lastCron: 'new' #this will be replaced with `+new Date` on first run + lastCron: +new Date #this will be replaced with `+new Date` on first run balance: 0 flags: partyEnabled: false @@ -373,21 +373,4 @@ module.exports = keys = _.keys(spec).concat(_.keys(spec.__proto__)) keys.forEach (k) => hydrated[k] = @hydrate(spec[k]) hydrated - else spec - ### - Derby stores the user schema a bit different than other apps prefer. The biggest difference is it stores - tasks as "refLists" - user[taskType + "Ids"] & user.tasks - where 3rd party apps prefer user[taskType + "s"] (array) - This function transforms the derby-stored data into 3rd-party consumable data - {userScope} the user racer-model scope, NOT an object - {withoutTasks} true if you don't want to return the user.tasks obj & id-lists. We keep them around when doing - local ops, because the var-by-reference lets us edit the original tasks - ### - derbyUserToAPI: (user, options={}) -> - _.defaults options, {keepTasks:true, asScope:true} - uObj = if options.asScope then user.get() else user - _.each ['habit','daily','todo','reward'], (type) -> - # we use _.transform instead of a simple _.where in order to maintain sort-order - uObj["#{type}s"] = _.transform uObj["#{type}Ids"], (result, tid) -> result.push(uObj.tasks[tid]) - delete uObj["#{type}Ids"] unless options.keepTasks - delete uObj.tasks unless options.keepTasks - uObj \ No newline at end of file + else spec \ No newline at end of file