Last active
January 11, 2016 13:39
-
-
Save andrewjmead/d9eae9339325a0a688ae to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// POST /todos | |
app.post('/todos', middleware.requireAuthentication, function(req, res) { | |
var body = _.pick(req.body, 'description', 'completed'); | |
db.sequelize.transaction(function(t) { | |
var t; | |
return db.todo.create(body).then(function(todo) { | |
t = todo; | |
return req.user.addTodo(todo) | |
}).then(function() { | |
return t.reload(); | |
}) | |
}).then(function(todo) { | |
res.json(todo.toJSON()); | |
}, function(error) { | |
// Handle specific errors here | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment