Skip to content

Commit

Permalink
Frontend & Backend: Add logs and Update routes
Browse files Browse the repository at this point in the history
Add console.logs to frontend for debugging
Update the ProductEdit and ProductEditList routes to match the schema design.

This update is to fix the issue where the user basket does not get updated when the Company Product details changes.
  • Loading branch information
JancoEngelbrecht committed Sep 17, 2024
1 parent 45fb52e commit 7668332
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
6 changes: 3 additions & 3 deletions backend/routes/userBasket.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,13 @@ router.get('/users/basketProducts/:productId', async (req, res) => {
try {
const { productId } = req.params;
const users = await schemas.User.find(
{ 'basket.identity': productId }, // Look into the 'basket' field now
'auth0Id basket'
{ 'products.identity': productId }, // Look into the 'basket' field now
'auth0Id products'
).lean();

// Filter the basket items to only include those with the specific productId
const result = users.map(user => {
const filteredBasket = user.basket.filter(product => product.identity === productId);
const filteredBasket = user.products.filter(product => product.identity === productId);
return {
auth0Id: user.auth0Id,
basket: filteredBasket
Expand Down
2 changes: 2 additions & 0 deletions frontend/src/components/common/private/product/ProductEdit.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,12 @@ const ProductEdit = ({ product, onUpdate, onDelete }) => {
const handleSubmit = (e) => {
e.preventDefault();
onUpdate(localProduct); // Pass updated product data to parent
console.log("Print Local Product in ProductEdit.js ",localProduct)
};

const handleDelete = () => {
onDelete(localProduct._id); // Pass product ID to parent for deletion
console.log("Print Local Product Id in ProductEdit.js ",localProduct._id)
};

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const ProductEditList = ({ products, loading, error, onDelete }) => {
// Fetch all users who have the product in their baskets
const response = await axios.get(`${process.env.REACT_APP_API_URL}/users/basketProducts/${updatedProduct._id}`);
const users = response.data;
console.log(users)

// Update the product in all user baskets
for (const user of users) {
Expand Down Expand Up @@ -43,6 +44,7 @@ const ProductEditList = ({ products, loading, error, onDelete }) => {
// Fetch all users who have the product in their baskets
const response = await axios.get(`${process.env.REACT_APP_API_URL}/users/basketProducts/${productId}`);
const users = response.data;


// Remove the product from all user baskets
for (const user of users) {
Expand Down

0 comments on commit 7668332

Please sign in to comment.