Quellcode durchsuchen

Creating new merchant from settings page now gets/saves address (only if square).

Lee Morgan vor 5 Jahren
Ursprung
Commit
7bbaaee772
2 geänderte Dateien mit 23 neuen und 2 gelöschten Zeilen
  1. 22 1
      controllers/squareData.js
  2. 1 1
      views/dashboardPage/js/strands/account.js

+ 22 - 1
controllers/squareData.js

@@ -346,7 +346,28 @@ module.exports = {
 
                 let populateOwner = res.locals.owner.populate("merchants", "name").execPopulate();
 
-                return Promise.all([Recipe.create(recipes), res.locals.owner.save(), merchant.save(), populateOwner]);
+                let baseURL = "https://geocoding.geo.census.gov/geocoder/locations/onelineaddress/";
+                let address = response[0].data.location.address;
+                let geocode = axios.get(`${baseURL}?address=${address.address_line_1}+${address.locality}+${address.administrative_district_level_1}+${address.postal_code}&benchmark=2020&format=json`);
+
+                return Promise.all([geocode, Recipe.create(recipes), res.locals.owner.save(), populateOwner]);
+            })
+            .then((response)=>{
+                let addressData = response[0].data.result.addressMatches[0];
+
+                merchant.address = {
+                    full: addressData.matchedAddress,
+                    city: addressData.addressComponents.city,
+                    state: addressData.addressComponents.state,
+                    zip: addressData.addressComponents.zip
+                };
+
+                merchant.location = {
+                    type: "Point",
+                    coordinates: [addressData.coordinates.x, addressData.coordinates.y]
+                };
+
+                return merchant.save();
             })
             .then((response)=>{
                 req.session.merchant = merchant._id;

+ 1 - 1
views/dashboardPage/js/strands/account.js

@@ -92,7 +92,7 @@ let account = {
             current: document.getElementById("accountCurrentPassword").value,
             new: document.getElementById("accountNewPassword").value,
             confirm: document.getElementById("accountConfirmPassword").value
-        }
+        };
         
         if(data.new !== data.confirm){
             return controller.createBanner("PASSWORDS DO NOT MATCH");