|
@@ -80,21 +80,26 @@ let singleRecipeObj = {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
axios.post("/merchant/recipes/ingredients/create", {recipeId: recipe._id, item: item})
|
|
axios.post("/merchant/recipes/ingredients/create", {recipeId: recipe._id, item: item})
|
|
|
- .then((newMerchant)=>{
|
|
|
|
|
- if(typeof(newMerchant.data) === "string"){
|
|
|
|
|
- banner.createError(newMerchant.data);
|
|
|
|
|
|
|
+ .then((response)=>{
|
|
|
|
|
+ if(typeof(response.data) === "string"){
|
|
|
|
|
+ banner.createError(response.data);
|
|
|
}else{
|
|
}else{
|
|
|
- let addIngredient = merchant.inventory.find(i => i.ingredient._id === ingredientId);
|
|
|
|
|
- recipe.ingredients.push({
|
|
|
|
|
- ingredient: addIngredient.ingredient,
|
|
|
|
|
- quantity: item.quantity
|
|
|
|
|
- });
|
|
|
|
|
|
|
+ for(let i = 0; i < merchant.recipes.length; i++){
|
|
|
|
|
+ if(merchant.recipes[i]._id === recipe._id){
|
|
|
|
|
+ merchant.recipes.splice(i, 1);
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ merchant.recipes.push(response.data);
|
|
|
|
|
+ recipesObj.isPopulated = false;
|
|
|
|
|
|
|
|
//Change row from displaying options to showing default display
|
|
//Change row from displaying options to showing default display
|
|
|
while(row.children.length > 0){
|
|
while(row.children.length > 0){
|
|
|
row.removeChild(row.firstChild);
|
|
row.removeChild(row.firstChild);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ let addIngredient = merchant.inventory.find(i => i.ingredient._id === ingredientId);
|
|
|
|
|
+
|
|
|
let name = document.createElement("td");
|
|
let name = document.createElement("td");
|
|
|
name.innerText = addIngredient.ingredient.name;
|
|
name.innerText = addIngredient.ingredient.name;
|
|
|
row.appendChild(name);
|
|
row.appendChild(name);
|
|
@@ -115,8 +120,6 @@ let singleRecipeObj = {
|
|
|
removeButton.innerText = "Remove";
|
|
removeButton.innerText = "Remove";
|
|
|
removeButton.onclick = ()=>{this.deleteIngredient(recipe._id, ingredientId, row);};
|
|
removeButton.onclick = ()=>{this.deleteIngredient(recipe._id, ingredientId, row);};
|
|
|
actions.appendChild(removeButton);
|
|
actions.appendChild(removeButton);
|
|
|
-
|
|
|
|
|
- banner.createNotification("Ingredient successfully added to database");
|
|
|
|
|
}
|
|
}
|
|
|
})
|
|
})
|
|
|
.catch((err)=>{
|
|
.catch((err)=>{
|