WIP addTask in api.coffee
This commit is contained in:
+8
-11
@@ -170,10 +170,7 @@ updateTasks = (tasks, user, model) ->
|
||||
else
|
||||
user.set "tasks.#{task.id}", task
|
||||
else
|
||||
type = task.type || 'habit'
|
||||
model.ref '_user', user
|
||||
model.refList "_#{type}List", "_user.tasks", "_user.#{type}Ids"
|
||||
model.at("_#{type}List").push task
|
||||
task = addTask(model,task)
|
||||
tasks[idx] = task
|
||||
return tasks
|
||||
|
||||
@@ -181,19 +178,19 @@ router.post '/user/tasks', auth, (req, res) ->
|
||||
tasks = updateTasks req.body, req.user, req.getModel()
|
||||
res.json 201, tasks
|
||||
|
||||
addTask = module.exports.addTask = (model, task) ->
|
||||
type = task.type || 'habit'{
|
||||
model.ref '_user', req.user
|
||||
model.refList "_#{type}List", "_user.tasks", "_user.#{type}Ids"
|
||||
model.at("_#{type}List").push task
|
||||
task
|
||||
|
||||
###
|
||||
POST /user/task/
|
||||
###
|
||||
router.post '/user/task', auth, validateTask, (req, res) ->
|
||||
task = req.task
|
||||
type = task.type
|
||||
|
||||
model = req.getModel()
|
||||
model.ref '_user', req.user
|
||||
model.refList "_#{type}List", "_user.tasks", "_user.#{type}Ids"
|
||||
model.at("_#{type}List").push task
|
||||
|
||||
task = addTask(model, req.task)
|
||||
res.json 201, task
|
||||
|
||||
###
|
||||
|
||||
Reference in New Issue
Block a user