summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTucker Evans <tuckerevans24@gmail.com>2019-12-08 17:26:32 -0500
committerTucker Evans <tuckerevans24@gmail.com>2019-12-08 17:26:32 -0500
commit2a46419961ab4db50146434945a57859893f8d54 (patch)
treebc42a10b22ef6402bdbb41794eee584a56737920
parentbb1ecccbf324c59097a828a862a10201f76d02a9 (diff)
Fix remove accessing private values of Recipe/Ingredient/Step
-rw-r--r--recipeBuddy/src/app/add-recipe/add-recipe.component.ts26
1 files changed, 9 insertions, 17 deletions
diff --git a/recipeBuddy/src/app/add-recipe/add-recipe.component.ts b/recipeBuddy/src/app/add-recipe/add-recipe.component.ts
index bc88eb7..407997c 100644
--- a/recipeBuddy/src/app/add-recipe/add-recipe.component.ts
+++ b/recipeBuddy/src/app/add-recipe/add-recipe.component.ts
@@ -90,45 +90,37 @@ export class AddRecipeComponent {
var ingredients = []
var i;
for (i = 0; i < formData.ingredients.length; i++) {
+ var tmp_amount = parseFloat(formData.ingredients[0].amount)
ingredients.push(new Ingredient(formData.ingredients[0].ingrName,
- parseFloat(formData.ingredients[0].amount),
+ (isNaN(tmp_amount) ? 0 : tmp_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++) {
+ var tmp_timer = parseInt(formData.steps[0].timer)
steps.push(new Step(formData.steps[0].instruct,
- parseInt(formData.steps[0].timer)
+ (isNaN(tmp_timer) ? 0 : tmp_timer)
));
- if (isNaN(steps[steps.length - 1].timer)) {
- steps[steps.length - 1].timer = 0;
- }
}
+ var servingsTmp = parseFloat(formData.servingSize)
+ var cookTimeTmp = parseInt(formData.cookTime)
+
var recipe = new Recipe (0, //id
formData.recipeName, //name
formData.desc, //description
ingredients, //ingredients
steps, //steps
- parseFloat(formData.servingSize), //servingSize
- parseInt(formData.cookTime), //cookTime
+ (isNaN(servingsTmp) ? 0 :servingsTmp), //servingSize
+ (isNaN(cookTimeTmp) ? 0 :cookTimeTmp), //cookTime
0, //timesCooked
0, //rating
formData.tags.split(','), //tags
formData.photos.split(',') //photos
);
- if (isNaN(recipe.servingSize)) {
- recipe.servingSize = 0;
- }
-
- if (isNaN(recipe.cookTime)) {
- recipe.cookTime = 0;
- }
this.restService.createRecipe(recipe).subscribe()
}
}