瀏覽代碼

Add frontend for requesting to add a new merchant from a location.

Lee Morgan 5 年之前
父節點
當前提交
33f217fd60
共有 3 個文件被更改,包括 34 次插入5 次删除
  1. 12 2
      controllers/squareData.js
  2. 2 1
      routes.js
  3. 20 2
      views/dashboardPage/js/modal.js

+ 12 - 2
controllers/squareData.js

@@ -356,10 +356,11 @@ module.exports = {
     /*
     GET: add another merchant to an owner with another square location
     response = [{
-
+        name: String,
+        id: String
     }]
     */
-    addMerchant: function(req, res){
+    getLocations: function(req, res){
         axios.get(`${process.env.SQUARE_ADDRESS}/v2/locations`, {
             headers: {
                 "Authorization": `Bearer ${res.locals.owner.square.accessToken}`,
@@ -380,5 +381,14 @@ module.exports = {
             .catch((err)=>{
                 return res.json("ERROR: UNABLE TO RETRIEVE LOCATION DATA FROM SQUARE");
             })
+    },
+
+    /*
+    GET: create new merchant from square location and add to owner
+    response = [Owner, Merchant]
+    */
+    addMerchant: function(req, res){
+        console.log("adding merchant");
+        console.log(req.params);
     }
 }

+ 2 - 1
routes.js

@@ -88,5 +88,6 @@ module.exports = function(app){
     app.post("/squarelogin", squareData.redirect);
     app.get("/squareauth", squareData.createMerchant);
     app.get("/recipes/update/square", session, squareData.updateRecipes);
-    app.get("/merchant/add/square", session, squareData.addMerchant);
+    app.get("/square/locations", session, squareData.getLocations);
+    app.get("/square/add/:location", session, squareData.addMerchant);
 }

+ 20 - 2
views/dashboardPage/js/modal.js

@@ -100,7 +100,7 @@ let modal = {
         let loader = document.getElementById("loaderContainer");
         loader.style.display = "flex";
 
-        fetch("/merchant/add/square")
+        fetch("/square/locations")
             .then(response => response.json())
             .then((response)=>{
                 if(typeof(response) === "string"){
@@ -137,7 +137,25 @@ let modal = {
     },
 
     createSquareLocation: function(id){
-        console.log(id);
+        let loader = document.getElementById("loaderContainer");
+        loader.style.display = "flex";
+
+        fetch(`/square/add/${id}`)
+            .then(response => response.json())
+            .then((response)=>{
+                if(typeof(response) === "string"){
+                    controller.createBanner(response, "error");
+                }else{
+                    console.log(response);
+                }
+            })
+            .catch((err)=>{
+                console.log(err);
+                controller.createBanner("SOMETHING WENT WRONG. PLEASE REFRESH THE PAGE", "error");
+            })
+            .finally(()=>{
+                loader.style.display = "none";
+            });
     }
 };