Prechádzať zdrojové kódy

Add ability to update recipe including category.

Lee Morgan 5 rokov pred
rodič
commit
28fe9835ef

+ 4 - 3
controllers/recipeData.js

@@ -53,6 +53,7 @@ module.exports = {
         id: id of recipe,
         name: name of recipe,
         price: price of recipe,
+        category: String
         ingredients: [{
             ingredient: id of ingredient,
             quantity: quantity of ingredient in recipe
@@ -66,12 +67,14 @@ module.exports = {
                     merchant: res.locals.merchant._id,
                     name: recipe.name,
                     price: recipe.price,
+                    category: recipe.category,
                     date: new Date(),
                     ingredients: recipe.ingredients
                 }).save().catch(()=>{});
 
                 recipe.name = req.body.name;
                 recipe.price = req.body.price;
+                recipe.category = req.body.category;
                 recipe.ingredients = req.body.ingredients;
 
                 return recipe.save();
@@ -80,9 +83,7 @@ module.exports = {
                 res.json(recipe);
             })
             .catch((err)=>{
-                if(typeof(err) === "string"){
-                    return res.json(err);
-                }
+                if(typeof(err) === "string") return res.json(err);
                 if(err.name === "ValidationError"){
                     return res.json(err.errors[Object.keys(err.errors)[0]].properties.message);
                 }

+ 4 - 0
views/dashboardPage/ejs/sidebars/editRecipe.ejs

@@ -12,6 +12,10 @@
     <label>NAME:
         <input id="editRecipeName" type="text">
     </label>
+
+    <label>CATEGORY:
+        <input id="editRecipeCategory" type="text">
+    </label>
     
     <h1 id="editRecipeNoName"></h1>
 

+ 1 - 0
views/dashboardPage/js/sidebars/editRecipe.js

@@ -65,6 +65,7 @@ let editRecipe = {
             id: recipe.id,
             name: recipe.name,
             price: document.getElementById("editRecipePrice").value * 100,
+            category: document.getElementById("editRecipeCategory").value,
             ingredients: []
         }