From 9783ba587e102f811fba32629bc70f2079ed6bf0 Mon Sep 17 00:00:00 2001 From: Jules Date: Wed, 3 Jul 2024 14:59:38 +0200 Subject: [PATCH] =?UTF-8?q?fix:=20calcul=20de=20quantit=C3=A9=20par=20plat?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- routes/api/order.js | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/routes/api/order.js b/routes/api/order.js index 105d8be..b27ef80 100644 --- a/routes/api/order.js +++ b/routes/api/order.js @@ -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 }); }