Skip to content

Commit

Permalink
add findOneAndUpdate
Browse files Browse the repository at this point in the history
  • Loading branch information
AdithyakrishnaV committed Jul 2, 2021
1 parent d1652ef commit 03102a9
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 11 deletions.
21 changes: 13 additions & 8 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -249,15 +249,20 @@ Access Public
Parameter isbn
Method PUT
*/
booky.put("/book/update/title/:isbn", (req, res) => {
database.books.forEach((book) => {
if(book.ISBN === req.params.isbn) {
book.title = req.body.newBookTitle;
return;
}
});
booky.put("/book/update/title/:isbn", async (req, res) => {

const updatedBook = await BookModel.findOneAndUpdate({
ISBN: req.params.isbn,
},
{
title: req.body.bookTitle,
},
{
new: true,
}
);

return res.json({ book: database.books});
return res.json({ book: updatedBook});
});

/*
Expand Down
10 changes: 7 additions & 3 deletions requirements.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,10 @@
//Add / update new author✅

//DELETE
//Delete a book
//Delete an author
//Delete a book✅
//Delete an author from a book✅



// Authors

Expand All @@ -50,6 +52,8 @@
// Delete an author




// Publications

//GET
Expand All @@ -59,7 +63,7 @@
// to get list of publication based on book [task] ✅

// POST
// Add new publications [Task] 🚀
// Add new publications [Task]

// PUT
// UPdate the publication name using it's id [Task] 🚀
Expand Down

0 comments on commit 03102a9

Please sign in to comment.