|
@@ -107,6 +107,7 @@ module.exports = {
|
|
|
});
|
|
});
|
|
|
})
|
|
})
|
|
|
.then((response)=>{
|
|
.then((response)=>{
|
|
|
|
|
+ console.log("axiosed");
|
|
|
merchant.locationId = response.data.merchant.main_location_id;
|
|
merchant.locationId = response.data.merchant.main_location_id;
|
|
|
owner.name = response.data.merchant.business_name;
|
|
owner.name = response.data.merchant.business_name;
|
|
|
|
|
|
|
@@ -127,6 +128,7 @@ module.exports = {
|
|
|
return Promise.all([items, location]);
|
|
return Promise.all([items, location]);
|
|
|
})
|
|
})
|
|
|
.then((response)=>{
|
|
.then((response)=>{
|
|
|
|
|
+ console.log("again");
|
|
|
let location = response[1].data.location;
|
|
let location = response[1].data.location;
|
|
|
if(owner.email === location.business_email.toLowerCase()) owner.status = [];
|
|
if(owner.email === location.business_email.toLowerCase()) owner.status = [];
|
|
|
merchant.name = location.name;
|
|
merchant.name = location.name;
|
|
@@ -137,11 +139,23 @@ module.exports = {
|
|
|
let baseURL = "https://geocoding.geo.census.gov/geocoder/locations/onelineaddress/";
|
|
let baseURL = "https://geocoding.geo.census.gov/geocoder/locations/onelineaddress/";
|
|
|
let address = location.address;
|
|
let address = 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`);
|
|
let geocode = axios.get(`${baseURL}?address=${address.address_line_1}+${address.locality}+${address.administrative_district_level_1}+${address.postal_code}&benchmark=2020&format=json`);
|
|
|
|
|
+
|
|
|
|
|
+ console.log(owner.square.accessToken);
|
|
|
|
|
+ let categories = axios.post(`${process.env.SQUARE_ADDRESS}/v2/catalog/search`, {
|
|
|
|
|
+ objects_types: ["CATEGORY"]
|
|
|
|
|
+ },{
|
|
|
|
|
+ headers: {
|
|
|
|
|
+ Authorization: `Bearer ${owner.square.accessToken}`
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
|
|
|
- return Promise.all([Recipe.create(recipes), geocode, owner.save()]);
|
|
|
|
|
|
|
+ return Promise.all([Recipe.create(recipes), geocode, owner.save()], categories);
|
|
|
})
|
|
})
|
|
|
.then((response)=>{
|
|
.then((response)=>{
|
|
|
|
|
+ console.log("again again");
|
|
|
let addressData = response[1].data.result.addressMatches[0];
|
|
let addressData = response[1].data.result.addressMatches[0];
|
|
|
|
|
+ console.log("something");
|
|
|
|
|
+ console.log(response[2].data);
|
|
|
|
|
|
|
|
merchant.address = {
|
|
merchant.address = {
|
|
|
full: addressData.matchedAddress,
|
|
full: addressData.matchedAddress,
|
|
@@ -166,6 +180,7 @@ module.exports = {
|
|
|
helper.getAllMerchantTransactions(merchant, owner.square.accessToken);
|
|
helper.getAllMerchantTransactions(merchant, owner.square.accessToken);
|
|
|
})
|
|
})
|
|
|
.catch((err)=>{
|
|
.catch((err)=>{
|
|
|
|
|
+ console.log(err);
|
|
|
if(typeof(err) === "string"){
|
|
if(typeof(err) === "string"){
|
|
|
req.session.error = err;
|
|
req.session.error = err;
|
|
|
}else if(err.name === "ValidationError"){
|
|
}else if(err.name === "ValidationError"){
|
|
@@ -386,4 +401,4 @@ module.exports = {
|
|
|
return res.json("ERROR: UNABLE TO CREATE NEW MERCHANT");
|
|
return res.json("ERROR: UNABLE TO CREATE NEW MERCHANT");
|
|
|
});
|
|
});
|
|
|
}
|
|
}
|
|
|
-}
|
|
|
|
|
|
|
+}
|