Răsfoiți Sursa

Add create of data from merchant creation

Lee Morgan 6 ani în urmă
părinte
comite
c65050e3de

+ 4 - 1
models/merchant.js

@@ -18,7 +18,10 @@ const MerchantSchema = new mongoose.Schema({
             type: mongoose.Schema.Types.ObjectId,
             ref: "Ingredient"
         },
-        quantity: String
+        quantity: {
+            type: Number,
+            min: [0, "Quantity cannot be less than 0"]
+        }
     }]
 });
 

+ 1 - 1
views/merchantSetupPage/merchantSetup.ejs

@@ -68,7 +68,7 @@
 
             <button onclick="addRecipeIngredientField()">+</button>
             <button id="next"></button>
-            <button onclick="changeRecipe(-1)">Previous Recipe</button>
+            <button id="previous" onclick="changeRecipe(-1)">Previous Recipe</button>
         </div>
 
         <script>

+ 25 - 2
views/merchantSetupPage/merchantSetup.js

@@ -177,7 +177,7 @@ let showRecipe = ()=>{
         let ingQuant = document.createElement("input");
         ingQuant.type = "number";
         ingQuant.step = "0.01";
-        ingQuant.value = ing.name;
+        ingQuant.value = ing.quantity;
         quantTd.appendChild(ingQuant);
     }
 
@@ -189,6 +189,13 @@ let showRecipe = ()=>{
         nextButton.innerText = "Next Recipe";
         nextButton.onclick = ()=>{changeRecipe(1)};
     }
+
+    let previousButton = document.querySelector("#previous");
+    if(recipeDataIndex === 0){
+        previousButton.style.display = "none";
+    }else{
+        previousButton.style.display = "inline-block";
+    }
 }
 
 let addRecipeIngredientField = ()=>{
@@ -233,6 +240,7 @@ let changeRecipe = (num)=>{
             id: row.childNodes[0].childNodes[0].value,
             quantity: row.childNodes[1].childNodes[0].value
         });
+        recipeData[recipeDataIndex].ingredients = recipeIngredients;
 
         body.removeChild(row);
     }
@@ -241,7 +249,22 @@ let changeRecipe = (num)=>{
 }
 
 let submitAll = ()=>{
-    console.log("something");
+    data.recipes = [];
+
+    for(let recipe of recipeData){
+        let newRecipe = {
+            id: recipe.id,
+            ingredients: []
+        };
+        for(let ingredient of recipe.ingredients){
+            newRecipe.ingredients.push({
+                id: ingredient.id,
+                quantity: ingredient.quantity
+            });
+        }
+        data.recipes.push(newRecipe);
+    }
+    console.log(data);
 }
 
 populateIngredients();