Pārlūkot izejas kodu

Merge branch 'square' into development

Lee Morgan 6 gadi atpakaļ
vecāks
revīzija
cceade797b

+ 185 - 0
controllers/helper.js

@@ -0,0 +1,185 @@
+const axios = require("axios");
+
+const Transaction = require("../models/transaction.js");
+
+module.exports = {
+    getCloverData: async function(merchant){
+        const subscriptionCheck = axios.get(`${process.env.CLOVER_ADDRESS}/v3/apps/${process.env.SUBLINE_CLOVER_APPID}/merchants/${merchant.posId}/billing_info?access_token=${merchant.posAccessToken}`);
+        const transactionRetrieval = axios.get(`${process.env.CLOVER_ADDRESS}/v3/merchants/${merchant.posId}/orders?filter=modifiedTime>=${merchant.lastUpdatedTime}&expand=lineItems&expand=payment&access_token=${merchant.posAccessToken}`);
+        await Promise.all([subscriptionCheck, transactionRetrieval])
+            .then((response)=>{
+                if(response[0].data.status !== "ACTIVE"){
+                    req.session.error = "SUBSCRIPTION EXPIRED.  PLEASE RENEW ON CLOVER";
+                    return res.redirect("/");
+                }
+
+                const updatedTime = Date.now();
+                
+                //Create Subline transactions from Clover Transactions
+                let transactions = [];
+                for(let i = 0; i < response[1].data.elements.length; i++){
+                    let order = response[1].data.elements[i];
+                    if(order.paymentState !== "PAID"){
+                        break;
+                    }
+                    let newTransaction = new Transaction({
+                        merchant: merchant._id,
+                        date: new Date(order.createdTime),
+                        device: order.device.id,
+                        posId: order.id
+                    });
+
+                    //Go through lineItems from Clover
+                    //Get the appropriate recipe from Subline
+                    //Add it to the transaction or increment if existing
+                    for(let j = 0; j < order.lineItems.elements.length; j++){
+                        let recipe = {}
+                        for(let k = 0; k < merchant.recipes.length; k++){
+                            if(merchant.recipes[k].posId === order.lineItems.elements[j].item.id){
+                                recipe = merchant.recipes[k];
+                                break;
+                            }
+                        }
+
+                        if(recipe){
+                            let isNewRecipe = true;
+                            for(let k = 0; k < newTransaction.recipes.length; k++){
+                                if(newTransaction.recipes[k].recipe === recipe._id){
+                                    newTransaction.recipes[k].quantity++;
+                                    isNewRecipe = false;
+                                    break;
+                                }
+                            }
+
+                            if(isNewRecipe){
+                                newTransaction.recipes.push({
+                                    recipe: recipe._id,
+                                    quantity: 1
+                                });
+                            }
+
+                            //Subtract ingredients from merchants total for each ingredient in a recipe
+                            for(let k = 0; k < recipe.ingredients.length; k++){
+                                let inventoryIngredient = {};
+                                for(let l = 0; l < merchant.inventory.length; l++){
+                                    if(merchant.inventory[l].ingredient._id.toString() === recipe.ingredients[k].ingredient._id.toString()){
+                                        inventoryIngredient = merchant.inventory[l];
+                                        break;
+                                    }
+                                }
+                                inventoryIngredient.quantity = inventoryIngredient.quantity - ingredient.quantity;
+                            }
+                        }
+                    }
+
+                    transactions.push(newTransaction);
+                }
+
+                merchant.lastUpdatedTime = updatedTime;
+
+                //Remove any existing orders so that they can be replaced
+                let ids = [];
+                for(let i = 0; i < transactions.length; i++){
+                    ids.push(transactions[i].posId);
+                }
+                Transaction.deleteMany({posId: {$in: ids}});
+
+                return Transaction.create(transactions);
+            })
+            .catch((err)=>{
+                req.session.error = "ERROR: UNABLE TO RETRIEVE DATA FROM CLOVER";
+                return res.redirect("/");
+            });
+    },
+
+    getSquareData: function(merchant){
+        let now = new Date().toISOString();
+        now = `${now.substring(0, now.length - 1)}+00:00`;
+        let before = new Date(merchant.lastUpdatedTime).toISOString();
+        before = `${before.substring(0, before.length - 1)}+00:00`;
+
+        let ingredients = {};
+
+        return axios.post(`${process.env.SQUARE_ADDRESS}/v2/orders/search`, {
+            location_ids: [merchant.squareLocation],
+            query: {
+                filter: {
+                    date_time_filter: {
+                        closed_at: {
+                            start_at: before,
+                            end_at: now
+                        }
+                    },
+                    state_filter: {
+                        states: ["COMPLETED"]
+                    }
+                },
+                sort: {
+                    sort_field: "CLOSED_AT",
+                    sort_order: "DESC"
+                }
+            }
+        }, {
+            headers: {
+                Authorization: `Bearer ${merchant.posAccessToken}`
+            }
+        })
+            .then((response)=>{
+                let transactions = [];
+
+                if(response.data.orders){
+                    for(let i = 0; i < response.data.orders.length; i++){
+                        let transaction = new Transaction({
+                            merchant: merchant,
+                            date: response.data.orders[i].created_at,
+                            posId: response.data.orders[i].id,
+                            recipes: []
+                        });
+
+                        for(let j = 0; j < response.data.orders[i].line_items.length; j++){
+                            for(let k = 0; k < merchant.recipes.length; k++){
+                                if(response.data.orders[i].line_items[j].catalog_object_id === merchant.recipes[k].posId){
+                                    let quantitySold = parseInt(response.data.orders[i].line_items[j].quantity);
+
+                                    transaction.recipes.push({
+                                        recipe: merchant.recipes[k],
+                                        quantity: quantitySold
+                                    });
+
+                                    for(let l = 0; l < merchant.recipes[k].ingredients.length; l++){
+                                        let ingredient = merchant.recipes[k].ingredients[l];
+                                        let quantity = quantitySold * ingredient.quantity
+                                        ingredients[ingredient.ingredient] = ingredients[ingredient.ingredient] + quantity || quantity;
+                                    }
+
+                                    break;
+                                }
+                            }
+                        }
+
+                        transactions.push(transaction);
+                    }
+                }
+
+                return Transaction.create(transactions);
+            })
+            .then((transactions)=>{
+                const keys = Object.keys(ingredients);
+                for(let i = 0; i < keys.length; i++){
+                    for(let j = 0; j < merchant.inventory.length; j++){
+                        if(keys[i] === merchant.inventory[j].ingredient._id.toString()){
+                            merchant.inventory[j].quantity -= ingredients[keys[i]];
+                            break;
+                        }
+                    }
+                }
+
+                merchant.lastUpdatedTime = new Date();
+
+                return transactions;
+            })
+            .catch((err)=>{
+                return "ERROR: UNABLE TO UPDATE TRANSACTION DATA";
+            });
+    }
+}

+ 80 - 0
controllers/merchantData.js

@@ -124,6 +124,86 @@ module.exports = {
             });
     },
 
+    createMerchantSquare: function(req, res){
+        let merchant = {}
+
+        axios.get(`${process.env.SQUARE_ADDRESS}/v2/merchants/${req.session.merchantId}`, {
+            headers: {
+                Authorization: `Bearer ${req.session.accessToken}`
+            }
+        })
+            .then((response)=>{
+                req.session.merchantId = undefined;
+
+                return new Merchant({
+                    name: response.data.merchant.business_name,
+                    pos: "square",
+                    posId: response.data.merchant.id,
+                    posAccessToken: req.session.accessToken,
+                    lastUpdatedTime: new Date(),
+                    createdAt: new Date(),
+                    squareLocation: response.data.merchant.main_location_id,
+                    inventory: [],
+                    recipes: []
+                });
+            })
+            .then((newMerchant)=>{
+                req.session.accessToken = undefined;
+                merchant = newMerchant;
+                
+                return axios.post(`${process.env.SQUARE_ADDRESS}/v2/catalog/search`, {
+                    object_types: ["ITEM"]
+                }, {
+                    headers: {
+                        Authorization: `Bearer ${merchant.posAccessToken}`
+                    }
+                });
+            })
+            .then((response)=>{
+                let recipes = [];
+                
+                for(let i = 0; i < response.data.objects.length; i++){
+                    if(response.data.objects[i].item_data.variations.length > 1){
+                        for(let j = 0; j < response.data.objects[i].item_data.variations.length; j++){
+                            let recipe = new Recipe({
+                                posId: response.data.objects[i].item_data.variations[j].id,
+                                merchant: merchant._id,
+                                name: `${response.data.objects[i].item_data.name} '${response.data.objects[i].item_data.variations[j].item_variation_data.name}'`,
+                                price: response.data.objects[i].item_data.variations[j].item_variation_data.price_money.amount
+                            });
+
+                            recipes.push(recipe);
+                            merchant.recipes.push(recipe);
+                        }
+                    }else{
+                        let recipe = new Recipe({
+                            posId: response.data.objects[i].item_data.variations[0].id,
+                            merchant: merchant._id,
+                            name: response.data.objects[i].item_data.name,
+                            price: response.data.objects[i].item_data.variations[0].item_variation_data.price_money.amount,
+                            ingredients: []
+                        });
+
+                        recipes.push(recipe);
+                        merchant.recipes.push(recipe);
+                    }
+                }
+
+                return Recipe.create(recipes);
+            })
+            .then((recipes)=>{
+                return merchant.save();
+            })
+            .then((merchant)=>{
+                req.session.user = merchant._id;
+
+                return res.redirect("/dashboard");
+            })
+            .catch((err)=>{
+                banner.createError("ERROR: UNABLE TO CREATE NEW USER AT THIS TIME");
+            });
+    },
+
     //DELETE - removes a single recipe from the merchant
     removeRecipe: function(req, res){
         if(!req.session.user){

+ 47 - 1
controllers/otherData.js

@@ -52,6 +52,11 @@ module.exports = {
         return res.redirect(`${process.env.CLOVER_ADDRESS}/oauth/authorize?client_id=${process.env.SUBLINE_CLOVER_APPID}&redirect_uri=${process.env.SUBLINE_CLOVER_URI}`);
     },
 
+    //GET - Redirects user to Square OAuth page
+    squareRedirect: function(req, res){
+        return res.redirect(`https://connect.squareupsandbox.com/oauth2/authorize?client_id=${process.env.SUBLINE_SQUARE_APPID}&scope=INVENTORY_READ+ITEMS_READ+MERCHANT_PROFILE_READ+ORDERS_READ+PAYMENTS_READ`);
+    },
+
     //GET - Get access token from clover and  redirect to merchant creation
     cloverAuth: function(req, res){
         let dataArr = req.url.slice(req.url.indexOf("?") + 1).split("&");
@@ -97,5 +102,46 @@ module.exports = {
                 req.session.error = "ERROR: UNABLE TO RETRIEVE DATA FROM CLOVER";
                 return res.redirect("/");
             });
+    },
+
+    squareAuth: function(req, res){
+        const code = req.url.slice(req.url.indexOf("code=") + 5, req.url.indexOf("&"));
+        const url = `${process.env.SQUARE_ADDRESS}/oauth2/token?`;
+        let data = {
+            client_id: process.env.SUBLINE_SQUARE_APPID,
+            client_secret: process.env.SUBLINE_SQUARE_APPSECRET,
+            grant_type: "authorization_code",
+            code: code
+        };
+
+        axios.post(url, data)
+            .then((response)=>{
+                data = response.data;
+                return Merchant.findOne({posId: data.merchant_id});
+            })
+            .then((merchant)=>{
+                if(merchant){
+                    merchant.posAccessToken = data.access_token;
+
+                    return merchant.save()
+                        .then((merchant)=>{
+                            req.session.user = merchant._id;
+                            return res.redirect("/dashboard");
+                        })
+                        .catch((err)=>{
+                            req.session.error = "ERROR: UNABLE TO CREATE NEW USER";
+                            return res.redirect("/");
+                        })
+                }else{
+                    req.session.merchantId = data.merchant_id;
+                    req.session.accessToken = data.access_token;
+
+                    return res.redirect("/merchant/create/square");
+                }
+            })
+            .catch((err)=>{
+                req.session.error = "ERROR: UNABLE TO RETRIEVE DATA FROM SQUARE";
+                return res.redirect("/");
+            });
     }
-} 
+}

+ 95 - 2
controllers/recipeData.js

@@ -1,9 +1,10 @@
+const axios = require("axios");
+
 const Recipe = require("../models/recipe.js");
 const Merchant = require("../models/merchant.js");
 const RecipeChange = require("../models/recipeChange.js");
 const Validator = require("./validator.js");
-
-const axios = require("axios");
+const merchant = require("../models/merchant.js");
 
 module.exports = {
     /*
@@ -225,5 +226,97 @@ module.exports = {
             .catch((err)=>{
                 return res.json("ERROR: UNABLE TO RETRIEVE MERCHANT DATA");
             });
+    },
+
+    updateRecipesSquare: function(req, res){
+        
+        if(!req.session.user){
+            req.session.error = "Must be logged in to do that";
+            return res.redirect("/");
+        }
+
+        let merchant = {};
+        let merchantRecipes = [];
+        let newRecipes = [];
+
+        Merchant.findOne({_id: req.session.user})
+            .populate("recipes")
+            .then((fetchedMerchant)=>{
+                merchant = fetchedMerchant;
+                return axios.post(`${process.env.SQUARE_ADDRESS}/v2/catalog/search`, {
+                    object_types: ["ITEM"]
+                }, {
+                    headers: {
+                        Authorization: `Bearer ${merchant.posAccessToken}`
+                    }
+                });
+            })
+            .then((response)=>{
+                merchantRecipes = merchant.recipes.slice();
+
+                
+                for(let i = 0; i < response.data.objects.length; i++){
+                    let itemData = response.data.objects[i].item_data;
+                    for(let j = 0; j < itemData.variations.length; j++){
+                        let isFound = false;
+
+                        for(let k = 0; k < merchantRecipes.length; k++){
+                            if(itemData.variations[j].id === merchantRecipes[k].posId){
+                                merchantRecipes.splice(k, 1);
+                                k--;
+                                isFound = true;
+                                break;
+                            }
+                        }
+
+                        if(!isFound){
+                            let newRecipe = new Recipe({
+                                posId: itemData.variations[j].id,
+                                merchant: merchant._id,
+                                name: "",
+                                price: itemData.variations[j].item_variation_data.price_money.amount,
+                                ingredients: []
+                            });
+
+                            if(itemData.variations.length > 1){
+                                newRecipe.name = `${itemData.name} '${itemData.variations[j].item_variation_data.name}'`;
+                            }else{
+                                newRecipe.name = itemData.name;
+                            }
+
+                            newRecipes.push(newRecipe);
+                            merchant.recipes.push(newRecipe);
+                        }
+                    }
+                }
+
+                let ids = [];
+                for(let i = 0; i < merchantRecipes.length; i++){
+                    ids.push(merchantRecipes[i]._id);
+                    for(let j = 0; j < merchant.recipes.length; j++){
+                        if(merchantRecipes[i]._id.toString() === merchant.recipes[j]._id.toString()){
+                            merchant.recipes.splice(j, 1);
+                            j--;
+                            break;
+                        }
+                    }
+                }
+
+                if(newRecipes.length > 0){
+                    Recipe.create(newRecipes);
+                }
+
+                if(merchantRecipes.length > 0){
+                    Recipe.deleteMany({_id: {$in: ids}});
+                }
+
+                return merchant.save();
+            })
+            .then((merchant)=>{
+                return res.json({new: newRecipes, removed: merchantRecipes});
+            })
+            .catch((err)=>{
+                return "ERROR: UNABLE TO RETRIEVE RECIPE DATA FROM SQUARE";
+            });
     }
 }

+ 16 - 96
controllers/renderer.js

@@ -1,10 +1,11 @@
-const axios = require("axios");
 const ObjectId = require("mongoose").Types.ObjectId;
 
 const Merchant = require("../models/merchant.js");
 const Transaction = require("../models/transaction.js");
 const Activity = require("../models/activity.js");
 
+const helper = require("./helper.js");
+
 module.exports = {
     /*
     GET - Shows the public landing page
@@ -61,105 +62,24 @@ module.exports = {
                 posAccessToken: 1,
                 lastUpdatedTime: 1,
                 inventory: 1,
-                recipes: 1
+                recipes: 1,
+                squareLocation: 1
             }
         )
             .populate("inventory.ingredient")
             .populate("recipes")
             .then(async (merchant)=>{
-                let promiseArray = [];
                 if(merchant.pos === "clover"){
-                    const subscriptionCheck = axios.get(`${process.env.CLOVER_ADDRESS}/v3/apps/${process.env.SUBLINE_CLOVER_APPID}/merchants/${merchant.posId}/billing_info?access_token=${merchant.posAccessToken}`);
-                    const transactionRetrieval = axios.get(`${process.env.CLOVER_ADDRESS}/v3/merchants/${merchant.posId}/orders?filter=modifiedTime>=${merchant.lastUpdatedTime}&expand=lineItems&expand=payment&access_token=${merchant.posAccessToken}`);
-                    await Promise.all([subscriptionCheck, transactionRetrieval])
-                        .then(async (response)=>{
-                            if(response[0].data.status !== "ACTIVE"){
-                                req.session.error = "SUBSCRIPTION EXPIRED.  PLEASE RENEW ON CLOVER";
-                                return res.redirect("/");
-                            }
-
-                            const updatedTime = Date.now();
-                            
-                            //Create Subline transactions from Clover Transactions
-                            let transactions = [];
-                            for(let i = 0; i < response[1].data.elements.length; i++){
-                                let order = response[1].data.elements[i];
-                                if(order.paymentState !== "PAID"){
-                                    break;
-                                }
-                                let newTransaction = new Transaction({
-                                    merchant: merchant._id,
-                                    date: new Date(order.createdTime),
-                                    device: order.device.id,
-                                    posId: order.id
-                                });
-
-                                //Go through lineItems from Clover
-                                //Get the appropriate recipe from Subline
-                                //Add it to the transaction or increment if existing
-                                for(let j = 0; j < order.lineItems.elements.length; j++){
-                                    let recipe = {}
-                                    for(let k = 0; k < merchant.recipes.length; k++){
-                                        if(merchant.recipes[k].posId === order.lineItems.elements[j].item.id){
-                                            recipe = merchant.recipes[k];
-                                            break;
-                                        }
-                                    }
-
-                                    if(recipe){
-                                        let isNewRecipe = true;
-                                        for(let k = 0; k < newTransaction.recipes.length; k++){
-                                            if(newTransaction.recipes[k].recipe === recipe._id){
-                                                newTransaction.recipes[k].quantity++;
-                                                isNewRecipe = false;
-                                                break;
-                                            }
-                                        }
-
-                                        if(isNewRecipe){
-                                            newTransaction.recipes.push({
-                                                recipe: recipe._id,
-                                                quantity: 1
-                                            });
-                                        }
-
-                                        //Subtract ingredients from merchants total for each ingredient in a recipe
-                                        for(let k = 0; k < recipe.ingredients.length; k++){
-                                            let inventoryIngredient = {};
-                                            for(let l = 0; l < merchant.inventory.length; l++){
-                                                if(merchant.inventory[l].ingredient._id.toString() === recipe.ingredients[k].ingredient._id.toString()){
-                                                    inventoryIngredient = merchant.inventory[l];
-                                                    break;
-                                                }
-                                            }
-                                            inventoryIngredient.quantity = inventoryIngredient.quantity - ingredient.quantity;
-                                        }
-                                    }
-                                }
-
-                                transactions.push(newTransaction);
-                            }
-
-                            merchant.lastUpdatedTime = updatedTime;
-
-                            //Remove any existing orders so that they can be replaced
-                            let ids = [];
-                            for(let i = 0; i < transactions.length; i++){
-                                ids.push(transactions[i].posId);
-                            }
-                            Transaction.deleteMany({posId: {$in: ids}});
-
-                            promiseArray.push(Transaction.create(transactions));
-                        })
-                        .catch((err)=>{
-                            req.session.error = "ERROR: UNABLE TO RETRIEVE DATA FROM CLOVER";
-                            return res.redirect("/");
-                        });
+                    await helper.getCloverData(merchant);
+                }else if(merchant.pos === "square"){
+                    await helper.getSquareData(merchant);
+                }else{
+                    return;
                 }
 
-                return Promise.all([merchant.save()].concat(promiseArray));
+                return merchant.save();
             })
-            .then((response)=>{
+            .then((merchant)=>{
                 let date = new Date();
                 let firstDay = new Date(date.getFullYear(), date.getMonth() - 1, 1);
 
@@ -175,12 +95,12 @@ module.exports = {
                     }}
                 ])
                     .then((transactions)=>{
-                        response[0]._id = undefined;
-                        response[0].posAccessToken = undefined;
-                        response[0].lastUpdatedTime = undefined;
-                        response[0].accountStatus = undefined;
+                        merchant._id = undefined;
+                        merchant.posAccessToken = undefined;
+                        merchant.lastUpdatedTime = undefined;
+                        merchant.accountStatus = undefined;
 
-                        return res.render("dashboardPage/dashboard", {merchant: response[0], transactions: transactions});
+                        return res.render("dashboardPage/dashboard", {merchant: merchant, transactions: transactions});
                     })
                     .catch((err)=>{});
             })

+ 1 - 0
models/merchant.js

@@ -28,6 +28,7 @@ const MerchantSchema = new mongoose.Schema({
         status: String,
         expiration: Date,
     },
+    squareLocation: String,
     inventory: [{
         ingredient: {
             type: mongoose.Schema.Types.ObjectId,

+ 5 - 1
routes.js

@@ -16,6 +16,7 @@ module.exports = function(app){
     //Merchant
     app.post("/merchant/create/none", merchantData.createMerchantNone);
     app.get("/merchant/create/clover", merchantData.createMerchantClover);
+    app.get("/merchant/create/square", merchantData.createMerchantSquare);
     app.delete("/merchant/recipes/remove/:id", merchantData.removeRecipe);
     app.post("/merchant/ingredients/add", merchantData.addMerchantIngredient);
     app.delete("/merchant/ingredients/remove/:id", merchantData.removeMerchantIngredient);
@@ -31,6 +32,7 @@ module.exports = function(app){
     app.post("/recipe/create", recipeData.createRecipe);
     app.put("/recipe/update", recipeData.updateRecipe);
     app.get("/recipe/update/clover", recipeData.updateRecipesClover);
+    app.get("/recipe/update/square", recipeData.updateRecipesSquare);
 
     //Orders
     app.get("/order", orderData.getOrders);
@@ -48,5 +50,7 @@ module.exports = function(app){
     app.post("/login", otherData.login);
     app.get("/logout", otherData.logout);
     app.get("/cloverlogin", otherData.cloverRedirect);
-    app.get("/cloverauth*", otherData.cloverAuth);   
+    app.get("/squarelogin", otherData.squareRedirect);
+    app.get("/cloverauth*", otherData.cloverAuth);
+    app.get("/squareauth", otherData.squareAuth);
 }

Failā izmaiņas netiks attēlotas, jo tās ir par lielu
+ 62 - 0
views/dashboardPage/bundle.js


+ 1 - 1
views/dashboardPage/dashboard.ejs

@@ -213,7 +213,7 @@
 
                     <% if(merchant.pos === "none"){ %>
                         <button class="button mobileHide" onclick="controller.openSidebar('addRecipe')">NEW</button>
-                    <% }else if(merchant.pos === "clover"){ %>
+                    <% }else{ %>
                         <button id="posUpdateRecipe" class="button mobileHide">UPDATE</button>
                     <% } %>
                 </div>

+ 1 - 1
views/dashboardPage/js/dashboard.js

@@ -52,7 +52,7 @@ controller = {
             case "recipeBook":
                 activeButton = document.getElementById("recipeBookBtn");
                 document.getElementById("recipeBookStrand").style.display = "flex";
-                recipeBook.display();
+                recipeBook.display(Recipe);
                 break;
             case "orders":
                 activeButton = document.getElementById("ordersBtn");

+ 6 - 5
views/dashboardPage/js/recipeBook.js

@@ -2,12 +2,12 @@ let recipeBook = {
     isPopulated: false,
     recipeDivList: [],
 
-    display: function(){
+    display: function(Recipe){
         if(!this.isPopulated){
             this.populateRecipes();
 
-            if(merchant.pos === "clover"){
-                document.getElementById("posUpdateRecipe").onclick = ()=>{this.posUpdate()};
+            if(merchant.pos !== "none"){
+                document.getElementById("posUpdateRecipe").onclick = ()=>{this.posUpdate(Recipe)};
             }
             document.getElementById("recipeSearch").oninput = ()=>{this.search()};
             document.getElementById("recipeClearButton").onclick = ()=>{this.clearSorting()};
@@ -69,11 +69,12 @@ let recipeBook = {
         this.search();
     },
 
-    posUpdate: function(){
+    posUpdate: function(Recipe){
         let loader = document.getElementById("loaderContainer");
         loader.style.display = "flex";
+        let url = `/recipe/update/${merchant.pos}`;
 
-        fetch("/recipe/update/clover", {
+        fetch(url, {
             method: "GET",
             headers: {
                 "Content-Type": "application/json;charset=utf-8"

+ 5 - 3
views/dashboardPage/js/recipeDetails.js

@@ -35,7 +35,9 @@ let recipeDetails = {
         document.getElementById("recipeUpdate").style.display = "none";
 
         document.getElementById("editRecipeBtn").onclick = ()=>{this.edit()};
-        document.getElementById("removeRecipeBtn").onclick = ()=>{this.remove()};
+        if(merchant.pos === "none"){
+            document.getElementById("removeRecipeBtn").onclick = ()=>{this.remove()};
+        }
         document.getElementById("addRecIng").onclick = ()=>{this.displayAddIngredient()};
         document.getElementById("recipeUpdate").onclick = ()=>{this.update()};
     },
@@ -120,7 +122,7 @@ let recipeDetails = {
                 if(typeof(response) === "string"){
                     banner.createError(response);
                 }else{
-                    merchant.editRecipes([this.recipe]);
+                    window.merchant.editRecipes([this.recipe]);
                     banner.createNotification("RECIPE UPDATE");
                 }
             })
@@ -155,7 +157,7 @@ let recipeDetails = {
         template.name = "new";
         document.getElementById("recipeIngredientList").appendChild(template);
 
-        let categories = merchant.categorizeIngredients();
+        let categories = window.merchant.categorizeIngredients();
 
         for(let i = 0; i < categories.length; i++){
             let optGroup = document.createElement("optgroup");

+ 6 - 3
views/landingPage/landing.ejs

@@ -80,10 +80,11 @@
 
                 <h1>OR</h1>
 
-                <a class="button buttonWithBorder" href="/cloverlogin"> Sign Up with Clover </a>
+                <a class="button buttonWithBorder" href="/cloverlogin">Sign Up with Clover</a>
 
-                <h3 class="link" style="margin-top: 30px;" onclick="loginObj.display()"> Already have an account? Please Sign In </h3>
+                <a class="button buttonWithBorder" href="/squarelogin">Sign Up with Square</a>
 
+                <h3 class="link" style="margin-top: 30px;" onclick="loginObj.display()"> Already have an account? Please Sign In </h3>
             </form>
         </div>
 
@@ -103,7 +104,9 @@
 
                 <h1>OR</h1>
 
-                <a class="button buttonWithBorder" href="/cloverlogin"> Sign In with Clover </a>
+                <a class="button buttonWithBorder" href="/cloverlogin">Sign In with Clover</a>
+
+                <a class="button buttonWithBorder" href="/squarelogin">Sign In with Square</a>
 
                 <h3 class="link" style="margin-top: 30px;" onclick="registerObj.display()"> New Here? Please Sign Up </h3>
             </form>

Daži faili netika attēloti, jo izmaiņu fails ir pārāk liels