mirror of
https://github.com/sudoxnym/habitica.git
synced 2026-08-05 12:02:13 +00:00
don't delete on invalid cron, but undefined cron. still thinking on this
This commit is contained in:
parent
c625458ce3
commit
0e8d4b4f1f
1 changed files with 7 additions and 7 deletions
|
|
@ -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
|
|
||||||
Loading…
Reference in a new issue