From 9e1341f0e6e01f4fa020f39f84914e7e49f17077 Mon Sep 17 00:00:00 2001 From: Tyler Renelle Date: Mon, 12 Aug 2013 20:40:59 -0400 Subject: [PATCH] derbyUserToAPI - allow pass in user as object, not scope --- script/helpers.coffee | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/script/helpers.coffee b/script/helpers.coffee index 08975fa9ac..82d145e8c0 100644 --- a/script/helpers.coffee +++ b/script/helpers.coffee @@ -363,11 +363,12 @@ module.exports = {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: (userScope, keepTasks=true) -> - uObj = userScope.get() + 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 keepTasks - delete uObj.tasks unless keepTasks + delete uObj["#{type}Ids"] unless options.keepTasks + delete uObj.tasks unless options.keepTasks uObj \ No newline at end of file