|
|
@@ -90,30 +90,12 @@ let createIngredientsObj = {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- if(isValid){
|
|
|
+ if(isValid && axiosIngredients.length > 0){
|
|
|
axios.post("/ingredients/create", axiosIngredients)
|
|
|
.then((response)=>{
|
|
|
if(typeof(response.data) === "string"){
|
|
|
banner.createError(response.data);
|
|
|
- }else{
|
|
|
- for(let ingredient of newIngredients){
|
|
|
- for(let createdIngredient of response.data){
|
|
|
- if(createdIngredient.name === ingredient.ingredient.name){
|
|
|
- ingredient.ingredient.id = createdIngredient._id;
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- controller.data.inventory.push(ingredient);
|
|
|
- }
|
|
|
-
|
|
|
- banner.createNotification("All ingredients have been created and added to your inventory");
|
|
|
-
|
|
|
- if(recipes){
|
|
|
- createRecipesObj.display();
|
|
|
- }else{
|
|
|
- nameRecipesObj.display();
|
|
|
- }
|
|
|
+ return;
|
|
|
}
|
|
|
})
|
|
|
.catch((err)=>{
|
|
|
@@ -121,5 +103,22 @@ let createIngredientsObj = {
|
|
|
console.log(err);
|
|
|
});
|
|
|
}
|
|
|
+
|
|
|
+ for(let ingredient of newIngredients){
|
|
|
+ for(let createdIngredient of response.data){
|
|
|
+ if(createdIngredient.name === ingredient.ingredient.name){
|
|
|
+ ingredient.ingredient.id = createdIngredient._id;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ controller.data.inventory.push(ingredient);
|
|
|
+ }
|
|
|
+
|
|
|
+ if(recipes){
|
|
|
+ createRecipesObj.display();
|
|
|
+ }else{
|
|
|
+ nameRecipesObj.display();
|
|
|
+ }
|
|
|
}
|
|
|
}
|