@@ -449,11 +449,19 @@ const routeUserRecipe = async (req: any, res: any) => {
449
449
const validated = await auth . requestValidator ( req , res )
450
450
if ( ! validated ) return
451
451
452
- let recipe : RecipeData = req . body
453
- const recipeId = req . params . recipeId || recipe . id
454
452
const user : UserData = await users . getById ( userId )
455
- const asJson = recipe ? recipe [ "asJson" ] || false : false
453
+ if ( ! user ) {
454
+ return webserver . renderError ( req , res , `User ${ userId } not found` , 404 )
455
+ }
456
+
457
+ // Get and validate the recipe data.
458
+ const recipeId : string = req . params . recipeId || req . body ?. id
459
+ const recipe : RecipeData = req . body ?. title ? req . body : user . recipes [ recipeId ]
460
+ if ( ! recipe ) {
461
+ return webserver . renderError ( req , res , `Recipe ${ recipeId } not found` , 404 )
462
+ }
456
463
464
+ const asJson = recipe ? recipe [ "asJson" ] || false : false
457
465
if ( asJson ) {
458
466
delete recipe [ "asJson" ]
459
467
}
@@ -471,11 +479,6 @@ const routeUserRecipe = async (req: any, res: any) => {
471
479
}
472
480
}
473
481
474
- // User not found?
475
- if ( ! user ) {
476
- return webserver . renderError ( req , res , `User ${ userId } not found` , 404 )
477
- }
478
-
479
482
// If 2 conditions or less, we don't need to set a value for samePropertyOp, as we only use the default op.
480
483
if ( recipe . conditions ?. length <= 2 && recipe . samePropertyOp ) {
481
484
delete recipe . samePropertyOp
0 commit comments