Parcourir la source

Update orders strand to not loop through the ingredients of each order.
Looping through was redundant, as the Order constructor already does this.

Lee Morgan il y a 5 ans
Parent
commit
a3d2b241a4
2 fichiers modifiés avec 4 ajouts et 30 suppressions
  1. 2 15
      views/dashboardPage/bundle.js
  2. 2 15
      views/dashboardPage/js/orders.js

+ 2 - 15
views/dashboardPage/bundle.js

@@ -3338,28 +3338,15 @@ let orders = {
                 banner.createError(response);
             }else{
                 let orders = [];
-                for(let i = 0; i < response.length; i++){
-                    let ingredients = [];
-                    for(let j = 0; j < response[i].ingredients.length; j++){
-                        for(let k = 0; k < merchant.ingredients.length; k++){
-                            if(merchant.ingredients[k].ingredient.id === response[i].ingredients[j].ingredient){
-                                ingredients.push({
-                                    ingredient: merchant.ingredients[k].ingredient,
-                                    quantity: response[i].ingredients[j].quantity,
-                                    pricePerUnit: response[i].ingredients[j].pricePerUnit
-                                });
-                                break;
-                            }
-                        }
-                    }
 
+                for(let i = 0; i < response.length; i++){
                     orders.push(new Order(
                         response[i]._id,
                         response[i].name,
                         response[i].date,
                         response[i].taxes,
                         response[i].fees,
-                        ingredients,
+                        response[i].ingredients,
                         merchant
                     ));
                 }

+ 2 - 15
views/dashboardPage/js/orders.js

@@ -50,28 +50,15 @@ let orders = {
                 banner.createError(response);
             }else{
                 let orders = [];
-                for(let i = 0; i < response.length; i++){
-                    let ingredients = [];
-                    for(let j = 0; j < response[i].ingredients.length; j++){
-                        for(let k = 0; k < merchant.ingredients.length; k++){
-                            if(merchant.ingredients[k].ingredient.id === response[i].ingredients[j].ingredient){
-                                ingredients.push({
-                                    ingredient: merchant.ingredients[k].ingredient,
-                                    quantity: response[i].ingredients[j].quantity,
-                                    pricePerUnit: response[i].ingredients[j].pricePerUnit
-                                });
-                                break;
-                            }
-                        }
-                    }
 
+                for(let i = 0; i < response.length; i++){
                     orders.push(new Order(
                         response[i]._id,
                         response[i].name,
                         response[i].date,
                         response[i].taxes,
                         response[i].fees,
-                        ingredients,
+                        response[i].ingredients,
                         merchant
                     ));
                 }