Skip to content

Commit

Permalink
fix: calcul de quantité par plat
Browse files Browse the repository at this point in the history
  • Loading branch information
JulesGresset committed Jul 3, 2024
1 parent 7e60c84 commit 9783ba5
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions routes/api/order.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,16 +58,24 @@ router.get('/:id', (req, res) => {
is_ready: foodOrdered.is_ready
};

const existingFoodDetails = foodDetailsList.find(item =>
JSON.stringify(item) === JSON.stringify({ ...foodDetails, quantity: item.quantity })
);
function omit(obj, keys) {
const newObj = { ...obj };
keys.forEach(key => delete newObj[key]);
return newObj;
}

const existingFoodDetails = foodDetailsList.find(item => {
const modifiedItem = omit(item, ['id']);
const modifiedFoodDetails = omit(foodDetails, ['id']);
return JSON.stringify(modifiedItem) === JSON.stringify({ ...modifiedFoodDetails, quantity: modifiedItem.quantity });
});

if (existingFoodDetails) {
existingFoodDetails.quantity += 1;
} else {
foodDetailsList.push({
"id": foodOrdered.id,
...foodDetails,
"id": foodOrdered.id,
quantity: 1
});
}
Expand Down

0 comments on commit 9783ba5

Please sign in to comment.