Skip to content

Commit

Permalink
Merge pull request #220 from SCCapstone/jack-best-selling-new-release
Browse files Browse the repository at this point in the history
Best Selling and New Arrivals work
  • Loading branch information
jackcoberman authored Apr 11, 2023
2 parents d7a74af + ad0811b commit b165599
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 5 deletions.
4 changes: 2 additions & 2 deletions client/src/components/sort.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ const sort = (books, selection) => {
break;
case "Best Selling":
books_changed = books.sort(function (a, b) {
return b.quantitySold - a.quantitySold;
return Number(b.quantitySold) - Number(a.quantitySold);
});
break;
case "New Arrivals":
books_changed = books.sort(function (a, b) {
return new Date(b.date) - new Date(a.date);
return (b.dateAdded > a.dateAdded) ? 1 : -1;
});
break;
case "Price: low to high":
Expand Down
28 changes: 25 additions & 3 deletions client/src/views/Cart.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -150,16 +150,38 @@ class MainCart extends Component {
console.log(error.response.data.message);
swal.fire({
icon: "error",
title: "Error updating user balanace",
title: "Error updating user balance",
text: error.response.data.message,
});
}
return;
}

// TO-DO: Step 3: Update Each Book's Quantity Sold
// Step 3: Update Each Book's Quantity Sold
for (let bookId in order.order) {
try {
const url = "api/books/" + bookId;
const newBook = {
quantitySold: order.order[bookId]
};
// TO-DO: Update stock as well
axios.put(url, newBook).catch((e) => {
swal.fire({
icon: "error",
title: "Error updating book data",
text: "Quantity of that book sold improperly updated"
});
})
} catch {
swal.fire({
icon: "error",
title: "Error updating book data",
text: "Quantity of that book sold improperly updated"
});
}
}

//window.location.reload();
window.location.reload();
}

// getting user balance
Expand Down

0 comments on commit b165599

Please sign in to comment.