Skip to content

Instantly share code, notes, and snippets.

@laser
Created April 21, 2014 22:31
Show Gist options
  • Save laser/11158798 to your computer and use it in GitHub Desktop.
Save laser/11158798 to your computer and use it in GitHub Desktop.
TodoManager raising an error
// Changing TodoManager Implementation
server.addHandler('TodoManager', {
'readTodos': function(callback) {
callback(null, store.getAll());
},
'createTodo': function(props, callback) {
callback(null, store.save(props));
},
'updateTodo': function(id, props, callback) {
callback(null, store.update(id, props));
},
'deleteTodo': function(id, callback) {
var todos = store.getAll();
if (todos.length === 1 && todos[0]['id'] === id) {
callback({
'code': 1004,
'message': 'User cannot delete their last todo'
}, null);
}
else {
callback(null, !!store.delete(id));
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment