Procházet zdrojové kódy

Everything working now for orders

Lee Morgan před 5 roky
rodič
revize
589d5cdf26

+ 23 - 3
views/dashboardPage/bundle.js

@@ -2791,18 +2791,34 @@ let newOrder = {
                 if(typeof(response) === "string"){
                     banner.createError(response);
                 }else{
+                    let ingredients = [];
+                    for(let i = 0; i < response.ingredients.length; i++){
+                        for(let j = 0; j < merchant.ingredients.length; j++){
+                            if(merchant.ingredients[j].ingredient.id === response.ingredients[i].ingredient){
+                                ingredients.push({
+                                    ingredient: merchant.ingredients[j].ingredient,
+                                    quantity: response.ingredients[i].quantity,
+                                    pricePerUnit: response.ingredients[j].pricePerUnit
+                                });
+
+                                break;
+                            }
+                        }
+                    }
+
                     let order = new Order(
                         response._id,
                         response.name,
                         response.date,
                         response.taxes,
                         response.fees,
-                        response.ingredients,
+                        ingredients,
                         merchant
                     );
 
                     merchant.addOrder(order, true);
                     
+                    controller.openStrand("orders");
                     banner.createNotification("NEW ORDER CREATED");
                 }
             })
@@ -3110,8 +3126,9 @@ let orderDetails = {
                 if(typeof(response) === "string"){
                     banner.createError(response);
                 }else{
-
                     merchant.removeOrder(order);
+
+                    controller.openStrand("orders");
                     banner.createNotification("ORDER REMOVED");
                 }
             })
@@ -3187,7 +3204,10 @@ let orders = {
                 });
         }
 
-        
+        if(!this.isPopulated){
+            this.populate();
+            this.isPopulated = true;
+        }
     },
 
     populate: function(){

+ 17 - 1
views/dashboardPage/js/newOrder.js

@@ -108,18 +108,34 @@ let newOrder = {
                 if(typeof(response) === "string"){
                     banner.createError(response);
                 }else{
+                    let ingredients = [];
+                    for(let i = 0; i < response.ingredients.length; i++){
+                        for(let j = 0; j < merchant.ingredients.length; j++){
+                            if(merchant.ingredients[j].ingredient.id === response.ingredients[i].ingredient){
+                                ingredients.push({
+                                    ingredient: merchant.ingredients[j].ingredient,
+                                    quantity: response.ingredients[i].quantity,
+                                    pricePerUnit: response.ingredients[j].pricePerUnit
+                                });
+
+                                break;
+                            }
+                        }
+                    }
+
                     let order = new Order(
                         response._id,
                         response.name,
                         response.date,
                         response.taxes,
                         response.fees,
-                        response.ingredients,
+                        ingredients,
                         merchant
                     );
 
                     merchant.addOrder(order, true);
                     
+                    controller.openStrand("orders");
                     banner.createNotification("NEW ORDER CREATED");
                 }
             })

+ 2 - 1
views/dashboardPage/js/orderDetails.js

@@ -49,8 +49,9 @@ let orderDetails = {
                 if(typeof(response) === "string"){
                     banner.createError(response);
                 }else{
-
                     merchant.removeOrder(order);
+
+                    controller.openStrand("orders");
                     banner.createNotification("ORDER REMOVED");
                 }
             })

+ 4 - 1
views/dashboardPage/js/orders.js

@@ -59,7 +59,10 @@ let orders = {
                 });
         }
 
-        
+        if(!this.isPopulated){
+            this.populate();
+            this.isPopulated = true;
+        }
     },
 
     populate: function(){