浏览代码

Re-add on new computer

Lee Morgan 6 年之前
父节点
当前提交
4590f0cdf0

+ 6 - 1
.gitignore

@@ -251,7 +251,12 @@ module.exports = {
             name: data.name,
             email: data.email,
             password: hash,
-            pos: "none"
+            pos: "none",
+            accountStatus: {
+                status: "valid",
+                //working here
+            }
+
         });
 
         for(let item of data.inventory){

+ 1 - 0
controllers/otherData.js

@@ -22,6 +22,7 @@ module.exports = function(app){
     app.post("/merchant/recipes/ingredients/create", merchantData.addRecipeIngredient);
     app.post("/merchant/recipes/ingredients/update", merchantData.updateRecipeIngredient);
     app.post("/merchant/recipes/ingredients/remove", merchantData.removeRecipeIngredient);
+    app.post("/merchant/update", merchantData.updateMerchant);
 
     //Ingredients
     app.get("/ingredients", ingredientData.getIngredients);

+ 46 - 0
views/informationPage/controller.js

@@ -2,5 +2,51 @@ window.accountObj = {
     display: function(){
         clearScreen();
         document.querySelector("#accountStrand").style.display = "flex";
+    },
+
+    editAccount: function(){
+        event.preventDefault();
+
+        document.querySelector("#accountDisplay").style.display = "none";
+        document.querySelector("#accountEdit").style.display = "flex";
+    },
+
+    updateAccount: function(){
+        event.preventDefault();
+
+        let data = {
+            name: document.querySelector("#accountName").value,
+            email: document.querySelector("#accountEmail").value
+        }
+
+        if(validator.isSanitary(name)){
+            axios.post("/merchant/update", data)
+                .then((response)=>{
+                    if(typeof(response.data) === "string"){
+                        banner.createError(response.data);
+                    }else{
+                        merchant.name = data.name;
+                        merchant.email = data.email;
+
+                        document.querySelector("#accountDisplay").style.display = "flex";
+                        document.querySelector("#accountEdit").style.display = "none";
+
+                        let labels = document.querySelector("#accountDisplay label");
+                        labels[0].children[0].innerText = merchant.name;
+                        labels[1].children[0].innerText = merchant.email;
+                    }
+                })
+                .catch((err)=>{
+                    banner.createError("Error: Your data could not be updated");
+                });
+        }
+    },
+
+    editPassword: function(){
+
+    },
+
+    updatePassword: function(){
+
     }
 }

+ 4 - 0
views/inventoryPage/addIngredient.js

@@ -87,6 +87,10 @@
         display: flex;
     }
 
+    #accountEdit{
+        display: none;
+    }
+
 /* Add Ingredient Action */
 #addIngredientAction{
     flex-direction: column;

+ 25 - 1
views/inventoryPage/inventory.ejs

@@ -16,6 +16,7 @@
 
         <strand-selector></strand-selector>
 
+
         <div id="inventoryStrand" class="strand">
             <div class="options">
                 <button class="button" onclick="addIngredientObj.display()">Add Ingredient</button>
@@ -43,6 +44,7 @@
             </table>
         </div>
 
+
         <div id="recipesStrand" class="strand">
             <div>
                 <% if(merchant.pos !== "none"){ %>
@@ -53,8 +55,9 @@
             <div id="recipesContainer"></div>
         </div>
 
+
         <div id="accountStrand" class="strand">
-            <form onsubmit="accountObj.submitForm()">
+            <form id="accountDisplay" onsubmit="accountObj.editAccount()">
                 <label>Name:&nbsp;&nbsp;
                     <p><%=merchant.name%></p>
                 </label>
@@ -62,9 +65,26 @@
                 <label>Email:&nbsp;&nbsp;
                     <p><%=merchant.email%></p>
                 </label>
+
+                <button class="button">Edit</button>
+            </form>
+
+            <form id="accountEdit" onsubmit="accountObj.updateAccount()">
+                <label>Name:&nbsp;&nbsp;
+                    <input id="accountName" type="text" value="<%=merchant.name%>">
+                </label>
+
+                <label>Email:&nbsp;&nbsp;
+                    <input id="accountEmail" type="email" value="<%=merchant.email%>">
+                </label>
+
+                <button class="button">Save</button>
             </form>
+
+            <button class="button" onclick="accountObj.passChangeDisplay()">Change password</button>
         </div>
 
+
         <div id="addIngredientAction" class="action">
             <div class="container">
                 <form onsubmit="addIngredientObj.submitAdd()">
@@ -105,6 +125,7 @@
             </div>
         </div>
 
+
         <div id="enterTransactionsAction" class="action">
             <h1>Enter all sales</h1>
             <h3>Last updated: <span id="updated"></span></h3>
@@ -122,6 +143,7 @@
             <button class="button" onclick="enterTransactionsObj.submit()">Submit</button>
         </div>
 
+
         <div id="enterPurchaseAction" class="action">
             <h1>Enter Purchases</h1>
             
@@ -138,6 +160,7 @@
             <button class="button" onclick="enterPurchaseObj.submit()">Submit</button>
         </div>
 
+
         <div id="singleRecipeAction" class="action">
             <h2 id="recipeName"></h2>
 
@@ -157,6 +180,7 @@
             </table>
         </div>
 
+
         <script>
                 <% if(locals.error){ %>
                     let error = <%- JSON.stringify(error) %>;

+ 0 - 0
views/inventoryPage/inventory.js