Skip to content

Commit

Permalink
add DELETE routes
Browse files Browse the repository at this point in the history
  • Loading branch information
AdithyakrishnaV committed Jun 29, 2021
1 parent 878deb6 commit 8261cb8
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,40 @@ booky.delete("/book/delete/author/:isbn/:authorId", (req, res) => {
})
});

/*
Route /publication/delete/book
Discription delete a book from publication
Access Public
Parameter isbn, publication id
Method DELETE
*/
booky.delete("/publication/delete/book/:isbn/:pubId", (req, res) => {
//update publication database
database.publications.forEach((publication) => {
if(publication.id === parseInt(req.params.pubId)) {
const newBooksList = publication.books.filter(
(book) => book !== req.params.isbn
);

publication.books = newBooksList;
return;
}
});

//update book database
database.books.forEach((book) => {
if(book.ISBN !== req.params.isbn){
book.publication = 0;
return;
}
});

return res.json({
books: database.books,
publications: database.publications,
});
});

booky.listen(3000, () => console.log("Hey server booting..."));

//HTTP client -> helper who helps you to make http request

0 comments on commit 8261cb8

Please sign in to comment.