implement update recipe - does not create new ingredient groups, incredients or instruction steps yet
This commit is contained in:
parent
21742e3b24
commit
e33dfdb845
3 changed files with 152 additions and 1 deletions
|
|
@ -7,6 +7,7 @@ import { RecipeDto } from "../dtos/RecipeDto.js";
|
|||
import { RecipeIngredientDtoEntityMapper } from "../mappers/RecipeIngredientDtoEntityMapper.js";
|
||||
import { RecipeIngredientGroupDtoEntityMapper } from "../mappers/RecipeIngredientGroupDtoEntityMapper.js";
|
||||
import { RecipeInstructionStepDtoEntityMapper } from "../mappers/RecipeInstructionStepDtoEntityMapper.js";
|
||||
import { ValidationError } from "../errors/httpErrors.js";
|
||||
|
||||
/**
|
||||
* Handles all recipe related routes
|
||||
|
|
@ -40,6 +41,19 @@ router.get(
|
|||
const responseDto = await recipeController.getRecipeById(id);
|
||||
res.status(201).json(responseDto);
|
||||
})
|
||||
)
|
||||
);
|
||||
|
||||
router.put(
|
||||
"/:id",
|
||||
asyncHandler(async(req, res) =>{
|
||||
const id = req.params.id;
|
||||
const recipeDto : RecipeDto = req.body;
|
||||
if(id != recipeDto.id){
|
||||
throw new ValidationError("Cannot save recipe! ID in request body " + recipeDto.id + " doesn't match ID in path " + id +"!")
|
||||
}
|
||||
const responseDto = await recipeController.updateRecipe(recipeDto);
|
||||
res.status(201).json(responseDto);
|
||||
})
|
||||
);
|
||||
|
||||
export default router;
|
||||
Loading…
Add table
Add a link
Reference in a new issue