Переглянути джерело

Update models for new unit conversion.

Lee Morgan 5 роки тому
батько
коміт
a6090db3c4

+ 0 - 1
controllers/admin.js

@@ -188,7 +188,6 @@ module.exports = {
                 return res.redirect("/dashboard");
             })
             .catch((err)=>{
-                console.log(err);
                 return res.json("ERROR: A whoopsie has been made");
             });
     }

+ 3 - 0
models/ingredient.js

@@ -30,6 +30,9 @@ const IngredientSchema = new mongoose.Schema({
         min: [0, "SIZE CANNOT BE A NEGATIVE NUMBER"],
         required: false
     },
+    toMass: Number,
+    toVolume: Number,
+    toLength: Number,
     ingredients: [{
         ingredient: {
             type: mongoose.Schema.Types.ObjectId,

+ 1 - 2
models/recipe.js

@@ -46,8 +46,7 @@ const RecipeSchema = new mongoose.Schema({
             min: [0, "QUANTITY OF INGREDIENTS CANNOT BE A NEGATIVE NUMBER"],
             required: [true, "MUST PROVED A QUANTITY FOR ALL INGREDIENTS"]
         },
-        unit: String,
-        baseUnitMultiplier: Number
+        unit: String
     }]
 });
 

+ 6 - 0
views/dashboardPage/js/sidebars/newIngredient.js

@@ -40,6 +40,12 @@ let newIngredient = {
             defaultUnit: unit
         }
 
+        switch(newIngredient.ingredient.unitType){
+            case "mass": newIngredient.ingredient.toMass = 1; break;
+            case "volume": newIngredient.ingredient.toVolume = 1; break;
+            case "length": newIngredient.ingredient.toLength = 1; break;
+        }
+
         //Change the ingredient if it is a special unit type (ie "bottle")
         if(unit === "bottle"){
             newIngredient.ingredient.unitType = document.getElementById("bottleUnits").value;

+ 7 - 5
views/dashboardPage/js/sidebars/newRecipe.js

@@ -80,11 +80,13 @@ let newRecipe = {
                 unit: ingredients[i].children[1].children[1].value
             }
     
-            if(ingredient.getPotentialUnits().includes(newIngredient.unit) === false){
-                mismatchUnits.push({ingredient: ingredient, newIngredient: newIngredient});
-            }else{
-                newIngredient.baseUnitMultiplier = 1 / controller.baseUnit(1, newIngredient.unit);
-            }
+            // if(ingredient.getPotentialUnits().includes(newIngredient.unit) === false){
+            //     mismatchUnits.push({ingredient: ingredient, newIngredient: newIngredient});
+            // }else{
+            //     newIngredient.baseUnitMultiplier = 1 / controller.baseUnit(1, newIngredient.unit);
+            // }
+
+            
     
             data.ingredients.push(newIngredient);
         }