Skip to content

Instantly share code, notes, and snippets.

@andrewjmead
Last active January 11, 2016 13:39
Show Gist options
  • Save andrewjmead/d9eae9339325a0a688ae to your computer and use it in GitHub Desktop.
Save andrewjmead/d9eae9339325a0a688ae to your computer and use it in GitHub Desktop.
// 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