From bb1ecccbf324c59097a828a862a10201f76d02a9 Mon Sep 17 00:00:00 2001 From: Tucker Evans Date: Sun, 8 Dec 2019 16:41:39 -0500 Subject: Add recipe is now sent to backend from add form --- .../src/app/add-recipe/add-recipe.component.ts | 27 ++++++++++++++++------ 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/recipeBuddy/src/app/add-recipe/add-recipe.component.ts b/recipeBuddy/src/app/add-recipe/add-recipe.component.ts index 50ea1cd..bc88eb7 100644 --- a/recipeBuddy/src/app/add-recipe/add-recipe.component.ts +++ b/recipeBuddy/src/app/add-recipe/add-recipe.component.ts @@ -91,17 +91,23 @@ export class AddRecipeComponent { var i; for (i = 0; i < formData.ingredients.length; i++) { ingredients.push(new Ingredient(formData.ingredients[0].ingrName, - formData.ingredients[0].amount, + parseFloat(formData.ingredients[0].amount), formData.ingredients[0].unit, "" )); + if (isNaN(ingredients[ingredients.length - 1].amount)) { + ingredients[ingredients.length - 1].amount = 0; + } } var steps = [] for (i = 0; i < formData.ingredients.length; i++) { steps.push(new Step(formData.steps[0].instruct, - formData.steps[0].timer + parseInt(formData.steps[0].timer) )); + if (isNaN(steps[steps.length - 1].timer)) { + steps[steps.length - 1].timer = 0; + } } var recipe = new Recipe (0, //id @@ -109,13 +115,20 @@ export class AddRecipeComponent { formData.desc, //description ingredients, //ingredients steps, //steps - formData.servingSize, //servingSize - formData.cookTime, //cookTime + parseFloat(formData.servingSize), //servingSize + parseInt(formData.cookTime), //cookTime 0, //timesCooked 0, //rating - formData.tags, //tags - formData.photos //photos + formData.tags.split(','), //tags + formData.photos.split(',') //photos ); - console.log(JSON.stringify(recipe)) + if (isNaN(recipe.servingSize)) { + recipe.servingSize = 0; + } + + if (isNaN(recipe.cookTime)) { + recipe.cookTime = 0; + } + this.restService.createRecipe(recipe).subscribe() } } -- cgit v1.1