У меня есть функция deleteBook
, которая отправляет данные через axios на сервер для удаления.Данные регистрируются в функции deteBook
, но не удаляются в базе данных.
Компонент
deleteBook = () => {
const existingBook = {
id: this.props.data[0]._id,
title: this.props.data[0].title,
author: this.props.data[0].author,
isbn: this.props.data[0].isbn,
// noOfCopies: this.state.noOfCopies,
};
console.log(existingBook);
axios.delete('/api/book/delete', existingBook)
.then(res => console.log(res))
.then(this.toggleAlertSuccess)
.catch(this.toggleAlertFail);
}
Сервер
router.delete('/delete', (req, res) => {
Book.findOneAndDelete({isbn: req.body.isbn})
.then(book => res.json(book))
.catch(err => console.log(err.message))
})