Parcourir la source

Add function to Merchant for updating ingredient quantities rather than just setting.
New transactions now update ingredient quantities.

Lee Morgan il y a 5 ans
Parent
commit
4628da821e
2 fichiers modifiés avec 10 ajouts et 2 suppressions
  1. 5 1
      views/dashboardPage/bundle.js
  2. 5 1
      views/dashboardPage/js/Merchant.js

+ 5 - 1
views/dashboardPage/bundle.js

@@ -176,6 +176,10 @@ class MerchantIngredient{
         this._quantity = quantity;
     }
 
+    updateQuantity(quantity){
+        this._quantity -= this.convertToBase(quantity);
+    }
+
     convertToBase(quantity){
         switch(this._ingredient.unit){
             case "g": return quantity;
@@ -446,7 +450,7 @@ class Merchant{
         for(let i = 0; i < keys.length; i++){
             for(let j = 0; j < this._ingredients.length; j++){
                 if(keys[i] === this._ingredients[j].ingredient.id){
-                    this._ingredients.quantity -= ingredients[keys[i]];
+                    this._ingredients[j].updateQuantity(ingredients[keys[i]]);
                 }
             }
         }

+ 5 - 1
views/dashboardPage/js/Merchant.js

@@ -49,6 +49,10 @@ class MerchantIngredient{
         this._quantity = quantity;
     }
 
+    updateQuantity(quantity){
+        this._quantity -= this.convertToBase(quantity);
+    }
+
     convertToBase(quantity){
         switch(this._ingredient.unit){
             case "g": return quantity;
@@ -319,7 +323,7 @@ class Merchant{
         for(let i = 0; i < keys.length; i++){
             for(let j = 0; j < this._ingredients.length; j++){
                 if(keys[i] === this._ingredients[j].ingredient.id){
-                    this._ingredients.quantity -= ingredients[keys[i]];
+                    this._ingredients[j].updateQuantity(ingredients[keys[i]]);
                 }
             }
         }