Closed khushi2706 closed 12 months ago
Hello @khushi2706 can u asign this issue to me I can fix this.
The existing code contains an error in the delete blog API, causing issues with the blog deletion functionality. I have implemented the following changes to rectify this issue.
const deleteBlog = async (req, res, next) => { const id = req.params.id;
try {
const blog = await Blog.findByIdAndDelete(id).populate('user');
if (!blog) {
return res.status(404).json({ message: "Blog not found" });
}
// Remove the blog from the user's blogs array
const user = blog.user;
user.blogs.pull(blog);
await user.save();
return res.status(200).json({ message: "Successfully deleted" });
} catch (e) {
console.error(e);
return res.status(500).json({ message: "Unable to delete" });
}
}
Issue found :
Explanation
blog
: { "_id": "63bb9871feda215df5b1c287", "title": "xyz", "desc": "issue.", "img": "image_url", "user": "63bb782b7db0d507fa04bd69", "__v": 0 }blog.user.id
Resolve