فهرست منبع

Send other all of the owners merchants down when SPA is rendered.

Lee Morgan 5 سال پیش
والد
کامیت
d88f35f779

+ 0 - 1
controllers/helper.js

@@ -64,7 +64,6 @@ module.exports = {
                 return transactions;
             })
             .catch((err)=>{
-                console.log(err.response.data);
                 return "ERROR: UNABLE TO UPDATE DATA";
             });
     },

+ 13 - 3
controllers/renderer.js

@@ -42,7 +42,7 @@ module.exports = {
                 let date = new Date();
                 let firstDay = new Date(date.getFullYear(), date.getMonth() - 1, 1);
 
-                return Transaction.aggregate([
+                let transactions = Transaction.aggregate([
                     {$match: {
                         merchant: new ObjectId(merchant._id),
                         date: {$gte: firstDay},
@@ -52,9 +52,15 @@ module.exports = {
                         date: 1,
                         recipes: 1
                     }}
-                ]);      
+                ]);
+                
+                let merchants = res.locals.owner.populate("merchants", "name");
+
+                return Promise.all([transactions, merchants]);
             })
-            .then(async (transactions)=>{
+            .then(async (response)=>{
+                let transactions = response[0];
+
                 if(res.locals.merchant.pos !== "none"){
                     let latest = null;
                     if(transactions.length === 0){
@@ -112,6 +118,10 @@ module.exports = {
                 res.locals.owner.createdAt = undefined;
                 res.locals.owner.session = undefined;
 
+                for(let i = 0; i < res.locals.owner.merchants.length; i++){
+                    if(res.locals.owner.merchants[i]._id.toString() === res.locals.merchant._id.toString()) res.locals.owner.merchants.splice(i, 1);
+                }
+
                 return res.render("dashboardPage/dashboard", {owner: res.locals.owner, merchant: res.locals.merchant, transactions: transactions});
             })
             .catch((err)=>{

+ 0 - 1
controllers/squareData.js

@@ -126,7 +126,6 @@ module.exports = {
                 return Promise.all([items, location]);
             })
             .then((response)=>{
-                console.log(response[0].data);
                 if(owner.email === response[1].data.location.business_email) merchant.status = [];
                 let recipes = [];
                 

+ 3 - 1
views/dashboardPage/js/classes/Merchant.js

@@ -83,7 +83,8 @@ class Merchant{
             pos,
             ingredients,
             recipes,
-            transactions
+            transactions,
+            merchants
         ){
         this._name = name;
         this._email = email;
@@ -92,6 +93,7 @@ class Merchant{
         this._recipes = [];
         this._transactions = [];
         this._orders = [];
+        this._merchants = merchants;
         
         //populate ingredients
         for(let i = 0; i < ingredients.length; i++){

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

@@ -29,7 +29,8 @@ window.merchant = new Merchant(
     data.merchant.pos,
     data.merchant.inventory,
     data.merchant.recipes,
-    data.transactions
+    data.transactions,
+    data.owner.merchants
 );
 
 controller = {