瀏覽代碼

Bug fix: could not upload recipe spreadsheets due to the square stuff that was aborted.

Lee Morgan 5 年之前
父節點
當前提交
3b575bf55a
共有 3 個文件被更改,包括 2 次插入38 次删除
  1. 1 33
      controllers/recipeData.js
  2. 0 1
      routes.js
  3. 1 4
      views/dashboardPage/js/sidebars/newRecipe.js

+ 1 - 33
controllers/recipeData.js

@@ -212,6 +212,7 @@ module.exports = {
                 return res.json(recipes);
             })
             .catch((err)=>{
+                console.log(err);
                 if(typeof(err) === "string"){
                     return res.json(err);
                 }
@@ -222,39 +223,6 @@ module.exports = {
             });
     },
 
-    spreadsheetUpSquare: function(req, res){
-        let workbook = xlsx.readFile(req.file.path);
-        fs.unlink(req.file.path, ()=>{});
-        let array = xlsx.utils.sheet_to_json(workbook.Sheets.Items, {header: 1});
-
-        let recipes = [];
-        for(let i = 1; i < array.length; i++){
-            let name = array[i][1];
-            if(array[i][6] !== "") name = `${name} (${array[i][6]})`;
-
-            let recipe = new Recipe({
-                posId: array[i][0],
-                merchant: res.locals.merchant._id,
-                name: name,
-                price: parseInt(array[i][7] * 100) || 0,
-                ingredients: []
-            });
-
-            recipes.push(recipe);
-            res.locals.merchant.recipes.push(recipe);
-        }
-
-
-        Promise.all([Recipe.create(recipes), res.locals.merchant.save()])
-            .then((response)=>{
-                return res.json(response[0]);
-            })
-            .catch((err)=>{
-                if(err.name === "ValidationError") return res.json(err.errors[Object.keys(err.errors)[0]].properties.message);
-                return res.json("ERROR: UNABLE TO CREATE YOUR RECIPES");
-            });
-    },
-
     spreadsheetTemplate: function(req, res){
         res.locals.merchant
             .populate("inventory.ingredient")

+ 0 - 1
routes.js

@@ -45,7 +45,6 @@ module.exports = function(app){
     app.put("/recipe/update", session, recipeData.updateRecipe);
     app.delete("/recipe/remove/:id", session, recipeData.removeRecipe);
     app.post("/recipes/create/spreadsheet", session, upload.single("recipes"), recipeData.createFromSpreadsheet);
-    app.post("/recipes/create/spreadsheet/square", session, upload.single("recipes"), recipeData.spreadsheetUpSquare);
     app.get("/recipes/download/spreadsheet", session, recipeData.spreadsheetTemplate);
 
     //Orders

+ 1 - 4
views/dashboardPage/js/sidebars/newRecipe.js

@@ -116,9 +116,6 @@ let newRecipe = {
         event.preventDefault();
         controller.closeModal();
 
-        let checkbox = document.getElementById("spreadsheetRecipeIsSquare");
-        let route = (checkbox.checked === true) ? "/recipes/create/spreadsheet/square": "/recipes/create/spreadsheet";
-
         const file = document.getElementById("spreadsheetInput").files[0];
         let data = new FormData();
         data.append("recipes", file);
@@ -126,7 +123,7 @@ let newRecipe = {
         let loader = document.getElementById("loaderContainer");
         loader.style.display = "flex";
 
-        fetch(route, {
+        fetch("/recipes/create/spreadsheet", {
             method: "post",
             body: data
         })