Lee Morgan 6 лет назад
Родитель
Сommit
ecb69abc8f
3 измененных файлов с 9 добавлено и 15 удалено
  1. 6 4
      controllers/transactionData.js
  2. 3 1
      views/dataPage/graph.js
  3. 0 10
      views/shared/graphs.js

+ 6 - 4
controllers/transactionData.js

@@ -114,9 +114,11 @@ module.exports = {
         }
 
         function randomDate() {
-            let start = new Date(2020, 0, 1);
-            let end = new Date(2020, 11, 31);
-            return new Date(start.getTime() + Math.random() * (end.getTime() - start.getTime()));
+            let now = new Date();
+            let start = new Date();
+            start.setFullYear(now.getFullYear() - 1);
+            // let end = new Date(2020, 11, 31);
+            return new Date(start.getTime() + Math.random() * (now.getTime() - start.getTime()));
         }
 
         Merchant.findOne({_id: req.session.user})
@@ -148,7 +150,7 @@ module.exports = {
                 Transaction.create(newTransactions)
                     .then((transactions)=>{
                         console.log("completed");
-                        return;
+                        return res.redirect("/data");
                     })
                     .catch((err)=>{
                         console.log(err);

+ 3 - 1
views/dataPage/graph.js

@@ -19,7 +19,9 @@ window.graphObj = {
                         for(let merchRecipe of data.merchant.recipes){
                             if(merchRecipe._id === recipe.recipe){
                                 for(let ingredient of merchRecipe.ingredients){
-                                    dataList[Math.abs(diff)] += ingredient.quantity;
+                                    if(ingredient.ingredient === id){
+                                        dataList[Math.abs(diff)] += ingredient.quantity;
+                                    }
                                 }
                                 break;
                             }

+ 0 - 10
views/shared/graphs.js

@@ -29,16 +29,6 @@ let graph = {
         context.lineTo(right, bottom);
         context.stroke();
 
-        context.beginPath();
-        context.moveTo(right, bottom);
-        context.lineTo(right, top);
-        context.stroke();
-
-        context.beginPath();
-        context.moveTo(left, top);
-        context.lineTo(right, top);
-        context.stroke();
-
         for(let i = 0; i < data.length - 1; i++){
             context.beginPath();
             context.moveTo(left + (horizontalMultiplier * i), bottom - (verticalMultiplier * data[i]));