Merge pull request #198 from jbutz/todo_archive_flag_cron

feat(archive_todo): add cron to archive todos
This commit is contained in:
Tyler Renelle 2014-05-03 21:44:11 -06:00
commit 00147a8671

View file

@ -485,7 +485,9 @@ api.wrap = (user, main=true) ->
# ------
clearCompleted: (req, cb) ->
_.remove user.todos, (t)-> t.completed and !t.challenge?.id
user.todos = _.map user.todos, (t)->
t.archived = true if t.completed and !t.challenge?.id
t
user.markModified? 'todos'
cb? null, user.todos
@ -1234,6 +1236,10 @@ api.wrap = (user, main=true) ->
else
task.value = task.value / 2
user.todos.forEach (task) -> # Archive todos
if !task.archived && task.completed && moment(now).subtract('days',3).isAfter(moment(task.dateCompleted))
task.archived = true
# Finished tallying
((user.history ?= {}).todos ?= []).push { date: now, value: todoTally }