Created
April 21, 2014 22:31
-
-
Save laser/11158798 to your computer and use it in GitHub Desktop.
TodoManager raising an error
This file contains hidden or 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
// 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