Bläddra i källkod

Bug fixes, currently unworking.

Lee Morgan 5 år sedan
förälder
incheckning
e137523ccd

+ 2 - 1
controllers/helper.js

@@ -207,10 +207,11 @@ module.exports = {
 
         do{
             let response = await axios.post(`${process.env.SQUARE_ADDRESS}/v2/orders/search`, body, options);
+            if(response.data.orders === undefined) break;
             body.cursor = response.data.cursor;
 
             let transactions = [];
-
+            
             for(let i = 0; i < response.data.orders.length; i++){
                 let transaction = new Transaction({
                     merchant: merchant._id,

+ 18 - 1
controllers/merchantData.js

@@ -369,6 +369,7 @@ module.exports = {
     */
     deleteMerchant: function(req, res){
         if(res.locals.owner.merchants.length === 1) throw "one";
+        console.log(res.locals.owner.merchants.id(res.locals.merchant._id));
         for(let i = 0; i < res.locals.owner.merchants.length; i++){
             if(res.locals.owner.merchants[i].toString() === res.locals.merchant._id.toString()){
                 res.locals.owner.merchants.splice(i, 1);
@@ -378,14 +379,30 @@ module.exports = {
 
         res.locals.merchant.removed = true;
 
+        let now = new Date();
+        let then = new Date(now.getFullYear(), now.getMonth() - 1, 1);
+
+        let transactions = Transaction.aggregate([
+            {$match: {
+                merchant: ObjectId(res.locals.merchant._id),
+                date: {$gte: then}
+            }},
+            {$sort: {date: -1}},
+            {$project: {
+                date: 1,
+                recipes: 1
+            }}
+        ]);
+
         Promise.all([
             Merchant.findOne({_id: res.locals.owner.merchants[0]._id}).populate("inventory.ingredient").populate("recipes"),
             res.locals.owner.save(),
             res.locals.merchant.save(),
             res.locals.owner.populate("merchants", "name").execPopulate(),
-            Transaction.find({merchant: res.locals.owner.merchants[0]._id})
+            transactions
         ])
             .then((response)=>{
+                console.log(response[4]);
                 let responseOwner = {
                     _id: res.locals.owner._id,
                     email: res.locals.owner.email,

+ 1 - 0
views/dashboardPage/dashboard.css

@@ -210,6 +210,7 @@ Home Strand
         flex-basis: 100px;
         flex-grow: 1;
         margin: 15px 0;
+        max-height: 43%;
     }
 
 #revenueCard{

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

@@ -120,7 +120,7 @@ let modal = {
 
     addSquareMerchant: function(id){
         let loader = document.getElementById("loaderContainer");
-        loader.style.display = "none";
+        loader.style.display = "flex";
 
         fetch(`/square/add/${id}`)
             .then(response => response.json())

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

@@ -169,6 +169,7 @@ let account = {
 
                     controller.closeModal();
                     controller.openStrand("home");
+                    controller.createBanner("MERCHANT DELETED", "success");
                 }
             })
             .catch((err)=>{