Forráskód Böngészése

Bug fix: recipes were not updating for square.
Recipes now populate based on the merchant location.

Lee Morgan 5 éve
szülő
commit
e6d2352359

+ 4 - 1
controllers/helper.js

@@ -173,11 +173,14 @@ module.exports = {
                     recipes.push(recipe);
                 }
             }else{
+                let priceMoney = squareItems[i].item_data.variations[0].item_variation_data.price_money;
+                let price = (priceMoney === undefined) ? 0 : priceMoney.amount;
+
                 let recipe = new Recipe({
                     posId: squareItems[i].item_data.variations[0].id,
                     merchant: merchantId,
                     name: squareItems[i].item_data.name,
-                    price: squareItems[i].item_data.variations[0].item_variation_data.price_money.amount,
+                    price: price,
                     ingredients: []
                 });
 

+ 8 - 7
controllers/squareData.js

@@ -160,8 +160,8 @@ module.exports = {
 
         let populate = res.locals.merchant.populate("recipes").execPopulate();
 
-        let squareRecipes = axios.post(`${process.env.SQUARE_ADDRESS}/v2/catalog/search`, {
-                object_types: ["ITEM"]
+        let squareRecipes = axios.post(`${process.env.SQUARE_ADDRESS}/v2/catalog/search-catalog-items`, {
+                enabled_location_ids: [res.locals.merchant.locationId]
             }, {
                 headers: {
                     Authorization: `Bearer ${res.locals.owner.square.accessToken}`
@@ -172,8 +172,8 @@ module.exports = {
             .then((response)=>{
                 merchantRecipes = res.locals.merchant.recipes.slice();
     
-                for(let i = 0; i < response[1].data.objects.length; i++){
-                    let itemData = response[1].data.objects[i].item_data;
+                for(let i = 0; i < response[1].data.items.length; i++){
+                    let itemData = response[1].data.items[i].item_data;
                     for(let j = 0; j < itemData.variations.length; j++){
                         let isFound = false;
     
@@ -187,11 +187,14 @@ module.exports = {
                         }
     
                         if(!isFound){
+                            let priceMoney = itemData.variations[j].item_variation_data.price_money;
+                            let price = (priceMoney === undefined) ? 0 : priceMoney.amount;
+
                             let newRecipe = new Recipe({
                                 posId: itemData.variations[j].id,
                                 merchant: res.locals.merchant._id,
                                 name: "",
-                                price: itemData.variations[j].item_variation_data.price_money.amount,
+                                price: price,
                                 ingredients: []
                             });
     
@@ -282,7 +285,6 @@ module.exports = {
     response = [Owner, Merchant]
     */
     addMerchant: function(req, res){
-        console.log(req.params.location);
         let merchant = new Merchant({
             owner: res.locals.owner._id,
             pos: "square",
@@ -333,7 +335,6 @@ module.exports = {
                 helper.getAllMerchantTransactions(merchant, res.locals.owner.square.accessToken);
             })
             .catch((err)=>{
-                console.log(err.response.data);
                 if(err.name === "ValidationError") return req.session.err = err.errors[Object.keys(err.errors)[0]].properties.message;
                 return res.json("ERROR: UNABLE TO CREATE NEW MERCHANT");
             });

+ 0 - 1
views/dashboardPage/js/modal.js

@@ -135,7 +135,6 @@ let modal = {
                 }
             })
             .catch((err)=>{
-                console.log(err);
                 controller.createBanner("SOMETHING WENT WRONG. PLEASE REFRESH THE PAGE", "error");
             })
             .finally(()=>{

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

@@ -193,7 +193,6 @@ let account = {
                 }
             })
             .catch((err)=>{
-                console.log(err);
                 controller.createBanner("SOMETHING WENT WRONG. PLEASE REFRESH THE PAGE", "error");
             })
             .finally(()=>{

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

@@ -100,8 +100,8 @@ let recipeBook = {
                         }
                     }
 
+                    state.updateRecipes();
                     controller.createBanner("RECIPES SUCCESSFULLY UPDATED", "success");
-                    this.display();
                 }
             })
             .catch((err)=>{