Update Data Product

Dibawah fungsi insert product, isi dengan script dibawah:

// folder-project/routes/product.js

router.put('/product/:id', upload.single('image'), (req, res) => {
  const updateProduct = {
    name: req.body.name,
    price: req.body.price,
    image: req.file === undefined ? "" : req.file.filename
  }
  Product.update(updateProduct, { 
    where: { id: req.params.id }
  })
  .then(data => {
    return product.findOne({
      where: { id: req.params.id }
    })      
  })
  .then(product => {
    res.json({
      "status": "success",
      "message": "Product updated!",
      "data": product
    })
  })
});

results matching ""

    No results matching ""