Browse Source

Remove some temp files.
Last minute bug fixes to admin uploading.

Lee Morgan 5 years ago
parent
commit
8ef0dbf6a0

+ 15 - 4
controllers/admin.js

@@ -33,18 +33,29 @@ module.exports = {
                     let ingredientData = fs.readFileSync(req.files.ingredients.tempFilePath).toString();
                     fs.unlink(req.files.ingredients.tempFilePath, ()=>{});
                     ingredientData = ingredientData.split("\n");
-
+                    let convertMass = {toMass: 1};
+                    let convertVolume = {toVolume: 1};
+                    let convertLength = {toLength: 1};
+                    
                     merchant.inventory = [];
                     for(let i = 0; i < ingredientData.length; i++){
                         if(ingredientData[i] === "") continue;
                         let data = ingredientData[i].split(",");
+                        let unitType = helper.getUnitType(data[3]);
                         let ingredient = new Ingredient({
                             name: data[0],
                             category: data[1],
-                            unitType: helper.getUnitType(data[3]),
-                            ingredients: []
+                            unitType: unitType,
+                            ingredients: [],
                         });
 
+                        switch(unitType){
+                            case "mass": ingredient.convert = convertMass; break;
+                            case "volume": ingredient.convert = convertVolume; break;
+                            case "length": ingredient.convert = convertLength; break;
+                            default: ingredient.convert = convertMass; break;
+                        }
+
                         let merchIngredient = {
                             ingredient: ingredient._id,
                             quantity: helper.convertQuantityToBaseUnit(data[2], data[3]),
@@ -157,6 +168,7 @@ module.exports = {
                 //Transactions
                 let newTransactions = [];
                 if(req.files.transactions !== undefined){
+                    Transaction.deleteMany({merchant: req.body.id}).catch((err)=>{});
                     let transactionData = fs.readFileSync(req.files.transactions.tempFilePath).toString()
                     fs.unlink(req.files.transactions.tempFilePath, ()=>{});
                     transactionData = transactionData.split("\n");
@@ -196,7 +208,6 @@ module.exports = {
                 return res.redirect("/dashboard");
             })
             .catch((err)=>{
-                console.log(err);
                 return res.json("ERROR: A whoopsie has been made");
             });
     }

+ 0 - 3
tmp/tmp-1-1626255598484

@@ -1,3 +0,0 @@
-thingon1
-thingtwo
-thing3,dirtybitchtits

+ 0 - 3
tmp/tmp-1-1626255671953

@@ -1,3 +0,0 @@
-thingon1
-thingtwo
-thing3,dirtybitchtits

+ 0 - 8
tmp/tmp-1-1626611059164

@@ -1,8 +0,0 @@
-Ingredient one
-things
-g
-
-ingredient two
-things
-kg
-ingredient one

+ 0 - 8
tmp/tmp-1-1626611169668

@@ -1,8 +0,0 @@
-Ingredient one
-things
-g
-
-ingredient two
-things
-kg
-ingredient one

+ 0 - 8
tmp/tmp-1-1626611188789

@@ -1,8 +0,0 @@
-Ingredient one
-things
-g
-
-ingredient two
-things
-kg
-ingredient one

+ 0 - 1
tmp/tmp-3-1626615775947

@@ -1 +0,0 @@
-Recipe One,1.11,Stuffs,ingredient one,2,ml,5

+ 0 - 3
tmp/tmp-4-1626614628182

@@ -1,3 +0,0 @@
-Ingredient one,Things,12,g,,
-Ingredient Two,Things,3,bottle,750,ml
-Ingredient Three,Other thangs,2,gal,,