Просмотр исходного кода

Update transaction spreadsheet reader to accept the new format.
Fix a bug in orders spreadsheet reader.
Allow negative numbers for merchant ingredients.

Lee Morgan 5 лет назад
Родитель
Сommit
386842cb57
3 измененных файлов с 13 добавлено и 14 удалено
  1. 2 1
      controllers/orderData.js
  2. 10 11
      controllers/transactionData.js
  3. 1 2
      models/merchant.js

+ 2 - 1
controllers/orderData.js

@@ -1,8 +1,9 @@
 const Order = require("../models/order.js");
 const Merchant = require("../models/merchant.js");
 
-const ObjectId = require("mongoose").Types.ObjectId;
+const helper = require("./helper.js");
 
+const ObjectId = require("mongoose").Types.ObjectId;
 const xlsx = require("xlsx");
 const fs = require("fs");
 

+ 10 - 11
controllers/transactionData.js

@@ -2,6 +2,7 @@ const Transaction = require("../models/transaction");
 const Merchant = require("../models/merchant");
 
 const helper = require("./helper.js");
+
 const ObjectId = require("mongoose").Types.ObjectId;
 const xlsx = require("xlsx");
 const fs = require("fs");
@@ -153,7 +154,7 @@ module.exports = {
                 
                 let ingredients = [];
                 for(let i = 1; i < array.length; i++){
-                    if(array[i][locations.recipes] === undefined){
+                    if(array[i][locations.recipes] === undefined || array[i][locations.quantity === 0]){
                         continue;
                     }
 
@@ -202,7 +203,9 @@ module.exports = {
                 if(typeof(err) === "string"){
                     return res.json(err);
                 }
-
+                if(err.name === "ValidationError"){
+                    return res.json(err.errors.name.properties.message);
+                }
                 return res.json("ERROR: UNABLE TO CREATE YOUR TRANSACTION");
             });
     },
@@ -219,19 +222,15 @@ module.exports = {
                 let workbook = xlsx.utils.book_new();
                 workbook.SheetNames.push("Transaction");
                 let workbookData = [];
+                let now = new Date().toISOString();
 
-                workbookData.push(["Date", "Recipes", "Quantity", "", "Recipes Reference"]);
+                workbookData.push(["Date", "Recipes", "Quantity"]);
+                workbookData.push([now.slice(0, 10), merchant.recipes[0].name, 0]);
 
-                for(let i = 0; i < merchant.recipes.length; i++){
-                    workbookData.push(["", "", "", "", merchant.recipes[i].name]);
+                for(let i = 1; i < merchant.recipes.length; i++){
+                    workbookData.push(["", merchant.recipes[i].name, 0]);
                 }
 
-                workbookData[1][0] = "2020-02-29";
-                workbookData[1][1] = "Example Recipe 1";
-                workbookData[1][2] = 12;
-                workbookData[2][1] = "Example Recipe 2";
-                workbookData[2][2] = 7;
-
                 workbook.Sheets.Transaction = xlsx.utils.aoa_to_sheet(workbookData);
                 xlsx.writeFile(workbook, "SublineTransaction.xlsx");
                 return res.download("SublineTransaction.xlsx", (err)=>{

+ 1 - 2
models/merchant.js

@@ -51,8 +51,7 @@ const MerchantSchema = new mongoose.Schema({
         },
         quantity: {
             type: Number,
-            required: [true, "INGREDIENT QUANTITY IS REQUIRED"],
-            min: [0, "QUANTITY CANNOT BE A NEGATIVE NUMBER"]
+            required: [true, "INGREDIENT QUANTITY IS REQUIRED"]
         },
         defaultUnit: {
             type: String,