Selaa lähdekoodia

상품 삭제

허용운 5 vuotta sitten
vanhempi
commit
2709e247ac
1 muutettua tiedostoa jossa 18 lisäystä ja 0 poistoa
  1. 18 0
      routes/products.js

+ 18 - 0
routes/products.js

@@ -84,4 +84,22 @@ router.put('/products/:id', upload.single('photo'), async (req, res) => {
   }
 })
 
+router.delete('/products/:id', async (req, res) => {
+  try {
+    let deleteProduct = await Product.findOneAndDelete( { _id: req.params.id })
+    
+    if (deleteProduct) {
+      res.json({
+        success: true,
+        message: 'Successfully deleted'
+      })
+    }
+  } catch (err) {
+    res.status(500).json({
+      success: false,
+      message: err.message
+    })
+  }
+})
+
 module.exports = router