|
@@ -212,6 +212,7 @@ module.exports = {
|
|
|
return res.json(recipes);
|
|
return res.json(recipes);
|
|
|
})
|
|
})
|
|
|
.catch((err)=>{
|
|
.catch((err)=>{
|
|
|
|
|
+ console.log(err);
|
|
|
if(typeof(err) === "string"){
|
|
if(typeof(err) === "string"){
|
|
|
return res.json(err);
|
|
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){
|
|
spreadsheetTemplate: function(req, res){
|
|
|
res.locals.merchant
|
|
res.locals.merchant
|
|
|
.populate("inventory.ingredient")
|
|
.populate("inventory.ingredient")
|