Ver Fonte

Merge branch 'development' into bugFixes

Lee Morgan há 5 anos atrás
pai
commit
ef148031e0

+ 6 - 3
controllers/recipeData.js

@@ -12,6 +12,7 @@ module.exports = {
     req.body = {
         name: name of recipe,
         price: price of the recipe,
+        category: String
         ingredients: [{
             id: id of ingredient,
             quantity: quantity of ingredient in recipe
@@ -24,6 +25,7 @@ module.exports = {
             merchant: res.locals.merchant._id,
             name: req.body.name,
             price: req.body.price,
+            category: req.body.category,
             ingredients: req.body.ingredients
         });
 
@@ -51,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
@@ -64,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();
@@ -78,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);
                 }

+ 5 - 1
models/recipe.js

@@ -25,7 +25,11 @@ const RecipeSchema = new mongoose.Schema({
     },
     category: {
         type: String,
-        required: false
+        default: "",
+        validate: {
+            validator: isSanitary,
+            message: "RECIPE CATEGORY CONTAINS ILLEGAL CHARACTERS"
+        }
     },
     hidden: {
         type: Boolean,

+ 4 - 0
views/dashboardPage/css/sidebars/recipeDetails.css

@@ -4,6 +4,10 @@
     width: 100%;
 }
 
+    #recipeName{
+        padding: 0;
+    }
+
     #recipeIngredientList{
         width: 100%;
     }

+ 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>
 

+ 2 - 1
views/dashboardPage/ejs/sidebars/newRecipe.ejs

@@ -17,12 +17,13 @@
 
             <div id="recipeChoices"></div>
         </div>
-        
 
         <div id="newRecipeData">
             <div id="newRecipeDataInputs">
                 <input id="newRecipeName" type="text" placeholder="NAME">
 
+                <input id="newRecipeCategory" type="text" placeholder="CATEGORY">
+
                 <input id="newRecipePrice" type="number" step="0.01" min="0" placeholder="PRICE">
             </div>
 

+ 2 - 0
views/dashboardPage/ejs/sidebars/recipeDetails.ejs

@@ -42,6 +42,8 @@
     </div>
 
     <h1 id="recipeName"></h1>
+
+    <h4 id="recipeCategory"></h4>
     
     <div id="recipeIngredientList"></div>
 

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

@@ -8,6 +8,8 @@ let editRecipe = {
             nameInput.parentNode.style.display = "none";
         }
 
+        document.getElementById("editRecipeCategory").value = recipe.category;
+
         //Populate ingredients
         let ingredientList = document.getElementById("editRecipeIngList");
 
@@ -65,6 +67,7 @@ let editRecipe = {
             id: recipe.id,
             name: recipe.name,
             price: document.getElementById("editRecipePrice").value * 100,
+            category: document.getElementById("editRecipeCategory").value,
             ingredients: []
         }
 

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

@@ -56,6 +56,7 @@ let newRecipe = {
     submit: function(){
         let data = {
             name: document.getElementById("newRecipeName").value,
+            category: document.getElementById("newRecipeCategory").value,
             price: parseInt(document.getElementById("newRecipePrice").value * 100),
             ingredients: []
         };

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

@@ -15,6 +15,7 @@ let recipeDetails = {
         }
         document.getElementById("hideRecipeBtn").onclick = ()=>{this.hide(recipe)};
         document.getElementById("recipeName").innerText = recipe.name;
+        document.getElementById("recipeCategory").innerText = recipe.category;
 
         let button = document.getElementById("removeRecipeBtn");
         switch(merchant.pos){