don't delete on invalid cron, but undefined cron. still thinking on this

This commit is contained in:
Tyler Renelle 2013-01-28 16:45:14 -05:00
parent c625458ce3
commit 0e8d4b4f1f

View file

@ -22,20 +22,20 @@ module.exports.deleteStaleAccounts = ->
today = +new Date today = +new Date
isValidDate = (d) -> # isValidDate = (d) ->
return false if Object::toString.call(d) isnt "[object Date]" # return false if Object::toString.call(d) isnt "[object Date]"
not isNaN(d.getTime()) # not isNaN(d.getTime())
removeAccount = (collection, id) -> collection.remove {_id: id}, (err, res) -> throw err if err removeAccount = (collection, id) -> collection.remove {_id: id}, (err, res) -> throw err if err
collection.findEach un_registered, (err, user) -> collection.findEach un_registered, (err, user) ->
throw err if err throw err if err
return unless user? #why does this happen sometimes? return unless user? #why does this happen sometimes?
lastCron = new Date(user.lastCron) unless user.lastCron
if !isValidDate(lastCron)
removeAccount(collection, user._id) removeAccount(collection, user._id)
return return
lastCron = new Date(user.lastCron)
diff = Math.abs(moment(today).sod().diff(moment(lastCron).sod(), "days")) diff = Math.abs(moment(today).sod().diff(moment(lastCron).sod(), "days"))
if diff > 15 if diff > 15
removeAccount(collection, user._id) removeAccount(collection, user._id)
return