INNER CODE UNIT · JavaScript
deleteHandler
basir/next-tailwind-amazona · pages/api/admin/products/[id]/index.js:47
const deleteHandler = async (req, res) => {
await db.connect();
const product = await Product.findById(req.query.id);
if (product) {
await product.remove();
await db.disconnect();
res.send({ message: 'Product deleted successfully' });
} else {
await db.disconnect();
res.status(404).send({ message: 'Product not found' });
}
};
export default handler;