I need help when clicking on my icon the corresponding message deletes it
I can’t get my route to work on the front side
mon code front
const handleTrash = (id) => {
fetch(`http://localhost:3000/deleteTweet/${id}`, {
method: "DELETE",
// headers: { "Content-Type": "application/json" },
// body: JSON.stringify({ id: tweet._id }),
}).then((response => response.json()) => {
console.log(response.status);
});
// .then((response) => response.json())
// .then((data) => {
// console.log("data is", data);
// })
// .then((response) => response.json())
// .then((data) => {
// setTrash(!trash);
// console.log("Delete :", reponse);
// });
};
ma route back
router.delete("/deleteTweet/:id", (req, res) => {
// if (!checkUser(req.params.token)) {
// res.json({ results: false, error: "Missing or empty fields" });
// return;
// }
Tweet.deleteOne({ _id: req.params.id }).then(() =>
res.json({ result: true })
);
});
New contributor
Ines Latrache is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.