瀏覽代碼

Order spreadsheet submission can now no longer accept more than one order.

Lee Morgan 5 年之前
父節點
當前提交
31067a29a8

+ 13 - 19
controllers/orderData.js

@@ -220,40 +220,34 @@ module.exports = {
             .then((response)=>{
                 merchant = response;
 
-                let orders = [];
-                let currentOrder = {};
+                let order = new Order({
+                    merchant: req.session.user,
+                    name: array[1][locations.name],
+                    date: spreadsheetDate,
+                    taxes: parseInt(array[1][locations.taxes] * 100),
+                    fees: parseInt(array[1][locations.fees] * 100),
+                    ingredients: []
+                });
+
                 for(let i = 1; i < array.length; i++){
                     if(array[i].length === 0 || array[i][locations.ingredients] === undefined || array[i][locations.quantity === 0]){
                         continue;
                     }
 
-                    if(array[i][locations.name] !== undefined){
-                        currentOrder = {
-                            merchant: req.session.user,
-                            name: array[i][locations.name],
-                            date: spreadsheetDate,
-                            taxes: parseInt(array[i][locations.taxes] * 100),
-                            fees: parseInt(array[i][locations.fees] * 100),
-                            ingredients: []
-                        }
-
-                        orders.push(currentOrder);
-                    }
-
                     let exists = false;
                     for(let j = 0; j < merchant.inventory.length; j++){
                         if(merchant.inventory[j].ingredient.name.toLowerCase() === array[i][locations.ingredients].toLowerCase()){
                             let baseQuantity = 0;
                             if(merchant.inventory[j].ingredient.specialUnit === "bottle"){
-                                baseQuantity = array[i][locations.quantity] * merchant.inventory[j].ingredient.unitSize;
-                                currentOrder.ingredients.push({
+                                baseQuantity = array[i][locations.quantity];
+                                order.ingredients.push({
                                     ingredient: merchant.inventory[j].ingredient._id,
                                     quantity: baseQuantity,
                                     pricePerUnit: (array[i][locations.price] * 100) / merchant.inventory[j].ingredient.unitSize
                                 });
                             }else{
                                 baseQuantity = helper.convertQuantityToBaseUnit(array[i][locations.quantity], merchant.inventory[j].defaultUnit);
-                                currentOrder.ingredients.push({
+                                order.ingredients.push({
                                     ingredient: merchant.inventory[j].ingredient._id,
                                     quantity: baseQuantity,
                                     pricePerUnit: helper.convertPrice(array[i][locations.price] * 100, merchant.inventory[j].defaultUnit)
@@ -272,7 +266,7 @@ module.exports = {
                     }
                 }
 
-                return Promise.all([Order.create(orders), merchant.save()]);
+                return Promise.all([order.save(), merchant.save()]);
             })
             .then((response)=>{
                 return res.json(response[0]);

+ 6 - 9
views/dashboardPage/bundle.js

@@ -129,10 +129,6 @@ class Ingredient{
 
 module.exports = Ingredient;
 },{}],2:[function(require,module,exports){
-const Order = require("./Order.js");
-const Recipe = require("./Recipe.js");
-const Transaction = require("./Transaction.js");
-
 class MerchantIngredient{
     constructor(ingredient, quantity){
         this._quantity = quantity;
@@ -360,7 +356,7 @@ class Merchant{
     }
 
     addRecipe(id, name, price, ingredients){
-        let recipe = new Recipe(id, name, price, ingredients, this);
+        let recipe = new this._modules.Recipe(id, name, price, ingredients, this);
 
         this._recipes.push(recipe);
 
@@ -434,7 +430,7 @@ class Merchant{
     }
 
     addTransaction(transaction){
-        transaction = new Transaction(
+        transaction = new this._modules.Transaction(
             transaction._id,
             transaction.date,
             transaction.recipes,
@@ -517,7 +513,7 @@ class Merchant{
     }
 
     addOrder(data, isNew = false){
-        let order = new Order(
+        let order = new this._modules.Order(
             data._id,
             data.name,
             data.date,
@@ -825,7 +821,7 @@ class Merchant{
 }
 
 module.exports = Merchant;
-},{"./Order.js":3,"./Recipe.js":4,"./Transaction.js":5}],3:[function(require,module,exports){
+},{}],3:[function(require,module,exports){
 class OrderIngredient{
     constructor(ingredient, quantity, pricePerUnit){
         if(quantity < 0){
@@ -1340,7 +1336,8 @@ merchant = new Merchant(data.merchant, data.transactions, {
     orders: orders,
     Ingredient: Ingredient,
     Recipe: Recipe,
-    Transaction: Transaction
+    Transaction: Transaction,
+    Order: Order
 });
 
 controller = {

+ 3 - 7
views/dashboardPage/js/classes/Merchant.js

@@ -1,7 +1,3 @@
-const Order = require("./Order.js");
-const Recipe = require("./Recipe.js");
-const Transaction = require("./Transaction.js");
-
 class MerchantIngredient{
     constructor(ingredient, quantity){
         this._quantity = quantity;
@@ -229,7 +225,7 @@ class Merchant{
     }
 
     addRecipe(id, name, price, ingredients){
-        let recipe = new Recipe(id, name, price, ingredients, this);
+        let recipe = new this._modules.Recipe(id, name, price, ingredients, this);
 
         this._recipes.push(recipe);
 
@@ -303,7 +299,7 @@ class Merchant{
     }
 
     addTransaction(transaction){
-        transaction = new Transaction(
+        transaction = new this._modules.Transaction(
             transaction._id,
             transaction.date,
             transaction.recipes,
@@ -386,7 +382,7 @@ class Merchant{
     }
 
     addOrder(data, isNew = false){
-        let order = new Order(
+        let order = new this._modules.Order(
             data._id,
             data.name,
             data.date,

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

@@ -34,7 +34,8 @@ merchant = new Merchant(data.merchant, data.transactions, {
     orders: orders,
     Ingredient: Ingredient,
     Recipe: Recipe,
-    Transaction: Transaction
+    Transaction: Transaction,
+    Order: Order
 });
 
 controller = {