소스 검색

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);
                 return res.json(response);
             })
             })
             .catch((err)=>{
             .catch((err)=>{
-                console.log(err);
                 if(typeof(err) === "string"){
                 if(typeof(err) === "string"){
                     return res.json(err);
                     return res.json(err);
                 }
                 }

+ 24 - 18
views/dashboardPage/bundle.js

@@ -3184,30 +3184,36 @@ let analytics = {
                 }else{
                 }else{
                     this.transactionsByDate = [];
                     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(
                             currentTransactions.push(new Transaction(
-                                response[i]._id,
-                                response[i].date,
-                                response[i].recipes,
+                                response[transactionIndex]._id,
+                                response[transactionIndex].date,
+                                response[transactionIndex].recipes,
                                 merchant
                                 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)=>{
             .catch((err)=>{

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

@@ -72,30 +72,36 @@ let analytics = {
                 }else{
                 }else{
                     this.transactionsByDate = [];
                     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(
                             currentTransactions.push(new Transaction(
-                                response[i]._id,
-                                response[i].date,
-                                response[i].recipes,
+                                response[transactionIndex]._id,
+                                response[transactionIndex].date,
+                                response[transactionIndex].recipes,
                                 merchant
                                 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)=>{
             .catch((err)=>{