Delete task for the API

This commit is contained in:
Rob Scanlon 2013-03-09 02:08:20 -05:00
parent 1ef32c771b
commit 2b8f2f48c1

View file

@ -60,7 +60,7 @@ validateTask = (req, res, next) ->
newTask = { type, text, notes, value, up, down, completed } = req.body
# If we're updating, get the task from the user
if req.method is 'PUT'
if req.method is 'PUT' or req.method is 'DELETE'
task = req.userObj?.tasks[req.params.id]
return res.json 400, err: "No task found." if !task || _.isEmpty(task)
# Strip for now
@ -90,6 +90,14 @@ router.put '/user/task/:id', auth, validateTask, (req, res) ->
res.json 200, req.task
router.delete '/user/task/:id', auth, validateTask, (req, res) ->
taskIds = req.user.get("#{req.task.type}Ids")
taskIds.splice(taskIds.indexOf(req.task.id),1)
req.user.set "#{req.task.type}Ids", taskIds
req.user.del "tasks.#{req.task.id}"
res.send 204
router.post '/user/task', auth, validateTask, (req, res) ->
task = req.task
type = task.type