Lee Morgan il y a 6 ans
Parent
commit
a0bb16d286

+ 4 - 4
models/ingredient.js

@@ -3,16 +3,16 @@ const mongoose = require("mongoose");
 const IngredientSchema = new mongoose.Schema({
     name: {
         type: String,
-        minlength: [2, "Name of ingredient is too short.  Please have at least two characters"],
-        required: [true, "Must provide a name for the ingredient"]
+        minlength: 2,
+        required: true
     },
     category: {
         type: String,
-        minlength: [3, "Category name must contain at least three characters"]
+        minlength: 3
     },
     unit: {
         type: String,
-        required: [true, "You must provide the measurement unit for this item"]
+        required: true
     }
 });
 

+ 6 - 2
models/merchant.js

@@ -8,7 +8,7 @@ const MerchantSchema = new mongoose.Schema({
     email: String,
     password: {
         type: String,
-        minlength: [15, "Password must contain at least 15 characters"]
+        minlength: 15
     },
     pos: {
         type: String,
@@ -37,7 +37,11 @@ const MerchantSchema = new mongoose.Schema({
         quantity: {
             type: Number,
             required: true,
-            min: [0, "Quantity cannot be less than 0"]
+            min: 0
+        },
+        displayUnit: {
+            type: String,
+            required: true
         }
     }],
     recipes: [{

+ 90 - 0
views/dashboardPage/Merchant.js

@@ -485,4 +485,94 @@ class Merchant{
 
         return recipes;
     }
+}
+
+let convertMass = (quantity, from, to)=>{
+    //change to g
+    let converted = 0;
+    switch(from){
+        case "g":
+            converted = quantity;
+            break;
+        case "kg":
+            converted = quantity * 1000;
+            break;
+        case "oz":
+            converted = quantity * 28.3495;
+            break;
+        case "lb":
+            converted = quantity * 453.5924;
+            break;
+    }
+
+    //change to end
+    switch(to){
+        case "g":
+            break;
+        case "kg":
+            converted = converted / 1000;
+            break;
+        case "oz":
+            converted = converted / 28.3495;
+            break;
+        case "lb":
+            converted = converted / 453.5924;
+            break;
+    }
+
+    return converted;
+}
+
+let convertVolume = (quantity, from, to)=>{
+    //change to l
+    let converted = 0;
+    switch(from){
+        case "ml": converted = quantity / 1000; break;
+        case "l": converted = quantity; break;
+        case "tsp": converted = quantity / 202.8842; break;
+        case "tbsp": converted = quantity / 67.6278; break;
+        case "ozfl": converted = quantity / 33.8141; break;
+        case "cup": converted = quantity / 4.1667; break;
+        case "pt": converted = quantity / 2.1134; break;
+        case "qt": converted = quantity / 1.0567; break;
+        case "gal": converted = quantity * 3.7854; break;
+    }
+
+    //change to end
+    switch(to){
+        case "ml": converted *= 1000; break;
+        case "l": break;
+        case "tsp": converted *= 202.8842; break;
+        case "tbsp": converted *= 67.6278; break;
+        case "ozfl": converted *= 33.8141; break;
+        case "cup": converted *= 4.1667; break;
+        case "pt": converted *= 2.1134; break;
+        case "qt": converted *= 1.0567; break;
+        case "gal": converted /= 3.7854; break;
+    }
+
+    return converted;
+}
+
+let convertLength = (quantity, from, to)=>{
+    //change to m
+    let converted = 0;
+    switch(from){
+        case "mm": converted = quantity / 1000; break;
+        case "cm": converted = quantity / 100; break;
+        case "m": converted = quantity; break;
+        case "in": converted = quantity / 39.3701; break;
+        case "ft": converted = quantity / 3.2808; break;
+    }
+
+    //change to end
+    switch(to){
+        case "mm": converted *= 1000; break;
+        case "cm": converted *= 100; break;
+        case "m": break;
+        case "in": converted *= 39.3701; break;
+        case "ft": converted *= 3.2808; break;
+    }
+
+    return converted;
 }

+ 32 - 1
views/dashboardPage/sidebars/newIngredient.ejs

@@ -23,7 +23,38 @@
     </label>
 
     <label>UNIT:
-        <input id="newIngUnit" type="text">
+        <select id="unitSelector">
+            <optgroup label="MASS/WEIGHT">
+                <option value="g">g</option>
+                <option value="kg">kg</option>
+                <option value="oz">oz</option>
+                <option value="lb">lb</option>
+            </optgroup>
+
+            <optgroup label="VOLUME">
+                <option value="ml">ml</option>
+                <option value="l">l</option>
+                <option value="tsp">tsp</option>
+                <option value="tbsp">tbsp</option>
+                <option value="ozfl">oz. fl</option>
+                <option value="cup">cup</option>
+                <option value="pt">pt</option>
+                <option value="qt">qt</option>
+                <option value="gal">gal</option>
+            </optgroup>
+
+            <optgroup label="LENGTH">
+                <option value="m">m</option>
+                <option value="cm">cm</option>
+                <option value="mm">mm</option>
+                <option value="in">in</option>
+                <option value="ft">ft</option>
+            </optgroup>
+
+            <optgroup label="OTHER">
+                <option value="count">count</option>
+            </optgroup>
+        </select>
     </label>
 
     <button class="button" onclick="newIngredientComp.submit()">CREATE</button>

+ 3 - 4
views/dashboardPage/sidebars/sidebars.js

@@ -318,15 +318,14 @@ let newIngredientComp = {
         document.querySelector("#newIngName").value = "";
         document.querySelector("#newIngCategory").value = "";
         document.querySelector("#newIngQuantity").value = 0;
-        document.querySelector("#newIngUnit").value = ""
     },
 
     submit: function(){
         let newIngredient = {
             ingredient: {
-                name: document.querySelector("#newIngName").value,
-                category: document.querySelector("#newIngCategory").value,
-                unit: document.querySelector("#newIngUnit").value
+                name: document.getElementById("newIngName").value,
+                category: document.getElementById("newIngCategory").value,
+                unit: document.getElementById("unitSelector").value
             },
             quantity: document.querySelector("#newIngQuantity").value
         }