Ver código fonte

Update creating new merchant from square to use the proper process.
Update the storage of square API data on the merchant.

Lee Morgan 5 anos atrás
pai
commit
41c6d28689

+ 0 - 1
controllers/merchantData.js

@@ -46,7 +46,6 @@ module.exports = {
             email: req.body.email.toLowerCase(),
             password: hash,
             pos: "none",
-            lastUpdatedTime: Date.now(),
             createdAt: Date.now(),
             status: ["unverified"],
             inventory: [],

+ 1 - 4
controllers/recipeData.js

@@ -90,10 +90,7 @@ module.exports = {
 
     //DELETE - removes a single recipe from the merchant and the database
     removeRecipe: function(req, res){
-        if(res.locals.merchant.pos === "clover"){
-            return res.json("YOU MUST EDIT YOUR RECIPES INSIDE CLOVER");
-        }
-        if(res.locals.merchant.pos === "square"){
+        if(res.locals.merchant.square !== undefined){
             return res.json("YOU MUST EDIT YOUR RECIPES INSIDE SQUARE");
         }
         

+ 8 - 13
controllers/renderer.js

@@ -34,17 +34,11 @@ module.exports = {
             .populate("recipes")
             .execPopulate()
             .then(async (merchant)=>{
-                if(res.locals.merchant.status.includes("unverified")){
-                    throw "unverified";
-                }
+                if(res.locals.merchant.status.includes("unverified")) throw "unverified";
 
-                if(res.locals.merchant.pos === "clover"){
-                    await helper.getCloverData(res.locals.merchant);
-                }else if(res.locals.merchant.pos === "square"){
-                    await helper.getSquareData(res.locals.merchant);
-                }else{
-                    return;
-                }
+                // if(res.locals.merchant.square !== undefined){
+                //     await helper.getSquareData(res.locals.merchant);
+                // }
 
                 return res.locals.merchant.save();
             })
@@ -66,14 +60,15 @@ module.exports = {
             })
             .then((transactions)=>{
                 res.locals.merchant._id = undefined;
-                res.locals.merchant.posAccessToken = undefined;
-                res.locals.merchant.lastUpdatedTime = undefined;
-                res.locals.merchant.accountStatus = undefined;
+                res.locals.password = undefined;
                 res.locals.merchant.status = undefined;
+                res.locals.square = undefined;
+                res.locals.session = undefined;
 
                 return res.render("dashboardPage/dashboard", {merchant: res.locals.merchant, transactions: transactions});
             })
             .catch((err)=>{
+                console.log(err);
                 if(err === "unverified"){
                     req.session.error = "PLEASE VERIFY YOUR EMAIL ADDRESS";
                     return res.redirect(`/verify/email/${res.locals.merchant._id}`);

+ 1 - 44
controllers/squareData.js

@@ -55,49 +55,6 @@ module.exports = {
             });
     },
 
-    //GET: Used by square. This route is used for the authentication code
-    //Redirects to either dashboard or new merchant creation
-    // authorize: 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.session.sessionId;
-    //                         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("/");
-    //         });
-    // },
-
     //GET: Gathers all data from square to create our merchant
     //Redirects to the dashboard
     createMerchant: function(req, res){
@@ -304,7 +261,7 @@ module.exports = {
                     object_types: ["ITEM"]
                 }, {
                     headers: {
-                        Authorization: `Bearer ${merchant.posAccessToken}`
+                        Authorization: `Bearer ${merchant.square.accessToken}`
                     }
                 });
             })

+ 1 - 12
models/merchant.js

@@ -25,10 +25,6 @@ const MerchantSchema = new mongoose.Schema({
         index: true
     },
     password: String,
-    pos: {
-        type: String,
-        required: true
-    },
     square: {
         id: String,
         accessToken: String,
@@ -36,18 +32,11 @@ const MerchantSchema = new mongoose.Schema({
         refreshToken: String,
         location: String
     },
-    posId: String,
-    posAccessToken: String,
-    lastUpdatedTime: {
-        type: String,
-        default: Date.now()
-    },
     createdAt: {
         type: Date,
-        default: Date.now
+        default: new Date()
     },
     status: [],
-    squareLocation: String,
     inventory: [{
         ingredient: {
             type: mongoose.Schema.Types.ObjectId,

+ 1 - 1
views/dashboardPage/ejs/sidebars/recipeDetails.ejs

@@ -14,7 +14,7 @@
             </svg>
         </button>
 
-        <% if(merchant.pos === "none"){ %>
+        <% if(merchant.square === undefined){ %>
             <button id="removeRecipeBtn" class="iconButton">
                 <svg width="30" height="30" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
                     <polyline points="3 6 5 6 21 6"></polyline>