浏览代码

Fix transaction getting from analytics into a working state.
Change backend to not order transactions by date.
Add code to frontend to order transactions by date for analytics.
This ensure that the ordering is done by the local time of the machine.

Lee Morgan 5 年之前
父节点
当前提交
f1b095b973
共有 3 个文件被更改,包括 49 次插入38 次删除
  1. 0 1
      controllers/transactionData.js
  2. 24 18
      views/dashboardPage/bundle.js
  3. 25 19
      views/dashboardPage/js/strands/analytics.js

+ 0 - 1
controllers/transactionData.js

@@ -112,7 +112,6 @@ module.exports = {
                 return res.json(response);
             })
             .catch((err)=>{
-                console.log(err);
                 if(typeof(err) === "string"){
                     return res.json(err);
                 }

+ 24 - 18
views/dashboardPage/bundle.js

@@ -3184,30 +3184,36 @@ let analytics = {
                 }else{
                     this.transactionsByDate = [];
 
+                    let startOfDay = new Date(from.getTime());
+                    startOfDay.setHours(0, 0, 0, 0);
+                    let endOfDay = new Date(from.getTime());
+                    endOfDay.setDate(endOfDay.getDate() + 1);
+                    endOfDay.setHours(0, 0, 0, 0);
+                    
+                    let transactionIndex = 0;
+                    while(startOfDay <= to){
+                        let currentTransactions = [];
 
-                    let nextDay = new Date(from.getTime());
-                    nextDay.setDate(nextDay.getDate() + 1);
-                    let currentTransactions = [];
-                    for(let i = 0; i < response.length; i++){
-                        response[i].date = new Date(response[i].date);
-                        if(response[i].date >= from && response[i].date < nextDay){
+                        while(transactionIndex < response.length && new Date(response[transactionIndex].date) < endOfDay){
                             currentTransactions.push(new Transaction(
-                                response[i]._id,
-                                response[i].date,
-                                response[i].recipes,
+                                response[transactionIndex]._id,
+                                response[transactionIndex].date,
+                                response[transactionIndex].recipes,
                                 merchant
                             ));
-                        }else{
-                            this.transactionsByDate.push({
-                                date: new Date(from.getTime()),
-                                transactions: currentTransactions
-                            });
-                            from.setDate(from.getDate() + 1);
-                            nextDay.setDate(nextDay.getDate() + 1);
-                            currentTransactions = [];
+
+                            transactionIndex++;
                         }
-                    }
 
+                        let thing = {
+                            date: new Date(startOfDay.getTime()),
+                            transactions: currentTransactions
+                        };
+                        this.transactionsByDate.push(thing);
+
+                        startOfDay.setDate(startOfDay.getDate() + 1);
+                        endOfDay.setDate(endOfDay.getDate() + 1);
+                    }
                 }
             })
             .catch((err)=>{

+ 25 - 19
views/dashboardPage/js/strands/analytics.js

@@ -72,30 +72,36 @@ let analytics = {
                 }else{
                     this.transactionsByDate = [];
 
-
-                    let nextDay = new Date(from.getTime());
-                    nextDay.setDate(nextDay.getDate() + 1);
-                    let currentTransactions = [];
-                    for(let i = 0; i < response.length; i++){
-                        response[i].date = new Date(response[i].date);
-                        if(response[i].date >= from && response[i].date < nextDay){
+                    let startOfDay = new Date(from.getTime());
+                    startOfDay.setHours(0, 0, 0, 0);
+                    let endOfDay = new Date(from.getTime());
+                    endOfDay.setDate(endOfDay.getDate() + 1);
+                    endOfDay.setHours(0, 0, 0, 0);
+                    
+                    let transactionIndex = 0;
+                    while(startOfDay <= to){
+                        let currentTransactions = [];
+
+                        while(transactionIndex < response.length && new Date(response[transactionIndex].date) < endOfDay){
                             currentTransactions.push(new Transaction(
-                                response[i]._id,
-                                response[i].date,
-                                response[i].recipes,
+                                response[transactionIndex]._id,
+                                response[transactionIndex].date,
+                                response[transactionIndex].recipes,
                                 merchant
                             ));
-                        }else{
-                            this.transactionsByDate.push({
-                                date: new Date(from.getTime()),
-                                transactions: currentTransactions
-                            });
-                            from.setDate(from.getDate() + 1);
-                            nextDay.setDate(nextDay.getDate() + 1);
-                            currentTransactions = [];
+
+                            transactionIndex++;
                         }
-                    }
 
+                        let thing = {
+                            date: new Date(startOfDay.getTime()),
+                            transactions: currentTransactions
+                        };
+                        this.transactionsByDate.push(thing);
+
+                        startOfDay.setDate(startOfDay.getDate() + 1);
+                        endOfDay.setDate(endOfDay.getDate() + 1);
+                    }
                 }
             })
             .catch((err)=>{