I am having fun with Promises
and have one problem.
Here is my code
req.checkBody(BookManager.SCHEME);
req.getValidationResult()
.then(function (result) {
if (!result.isEmpty()) {
handler.onError('Invalid payload');
return;
}
return new BookModel({
author: data.author,
name: data.name,
year: data.year
});
})
.then((book) => {
book.save();
})
.then((saved) => {
handler.onSuccess(saved);
})
.catch((error) => {
handler.onError(error.message);
});
But for some reason this then statement
.then((book) => {
book.save();
})
Has the book argument set to undefined.
What I am doing wrong, and how can I pass the result from the then
statement to the next one.
Thanks.
via e109848
No comments:
Post a Comment