Skip to content

Commit

Permalink
Fix delete functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
ebenezerdon committed Nov 14, 2018
1 parent 401be4f commit 2c0e32c
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions UI/assets/js/products.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,19 @@ const getProducts = () => {
<a href='product-item.html'>
<p>${product.productname}</p>
<p>${product.price}</p>
<p>${product.id}</p>
</a>
<button>Add to cart</button>
<div class='edit-product-div'>
<button class='edit-product'>Edit</button>
<button class='delete-product' onclick='deleteProduct()'>Delete</button>
<button class='delete-product' onclick='deleteProduct(${product.id})'>Delete</button>
</div>
<div>
</div>
`;
document.getElementById('products-list').innerHTML += output;

const productId = product.id;
deleteProduct = () => {
deleteProduct = (productId) => {
const options = {
method: 'DELETE',
headers: new Headers({
Expand All @@ -60,7 +60,7 @@ const getProducts = () => {
.then(res => res.json())
.then((data) => {
if (data.success === true) {
console.log('Product deleted!');
console.log(`Product with id ${productId} deleted!`);
} else { console.log('Not successful!'); }
})
.catch(err => console.log(err));
Expand Down

0 comments on commit 2c0e32c

Please sign in to comment.