From 03102a91495b3e3640f6defbd8c6df3cbf69f991 Mon Sep 17 00:00:00 2001 From: AdithyakrishnaV Date: Fri, 2 Jul 2021 06:33:43 +0530 Subject: [PATCH] add findOneAndUpdate --- index.js | 21 +++++++++++++-------- requirements.js | 10 +++++++--- 2 files changed, 20 insertions(+), 11 deletions(-) diff --git a/index.js b/index.js index 09b8d42..9997dc7 100644 --- a/index.js +++ b/index.js @@ -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}); }); /* diff --git a/requirements.js b/requirements.js index e8297bb..a6d3372 100644 --- a/requirements.js +++ b/requirements.js @@ -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 @@ -50,6 +52,8 @@ // Delete an author + + // Publications //GET @@ -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] 🚀