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
|
|
@ -5,6 +5,7 @@ import { NotFoundError, ValidationError } from "../errors/httpErrors.js";
|
|||
import { RecipeInstructionStepDto } from "../dtos/RecipeInstructionStepDto.js";
|
||||
import { RecipeIngredientGroupDto } from "../dtos/RecipeIngredientGroupDto.js";
|
||||
import { RecipeIngredientDto } from "../dtos/RecipeIngredientDto.js";
|
||||
import { Entity } from "typeorm";
|
||||
|
||||
/**
|
||||
* Controls all recipe specific actions
|
||||
|
|
@ -15,6 +16,11 @@ export class RecipeController {
|
|||
private mapper: RecipeDtoEntityMapper
|
||||
) { }
|
||||
|
||||
/**
|
||||
* Load a specific recipe
|
||||
* @param id recipe id
|
||||
* @returns RecipeDto for requested recipe
|
||||
*/
|
||||
async getRecipeById(id: string){
|
||||
const recipeEntity = await this.recipeRepository.findById(id);
|
||||
if(recipeEntity === null){
|
||||
|
|
@ -23,6 +29,20 @@ export class RecipeController {
|
|||
const recipeDto = this.mapper.toDto(recipeEntity);
|
||||
return recipeDto;
|
||||
}
|
||||
/**
|
||||
* Update recipe data
|
||||
* @param RecipeDto containing the entire updated recipe
|
||||
* @returns Up-to-date RecipeDto as saved in the database
|
||||
*/
|
||||
async updateRecipe(dto: RecipeDto){
|
||||
if (!this.isRecipeDtoValid(dto)) {
|
||||
throw new ValidationError("recipe data is not valid!")
|
||||
}
|
||||
const recipeEntity = this.mapper.toEntity(dto);
|
||||
// @todo doesn't create new ingredient groups, ingredients or instruction steps yet
|
||||
const savedEntity = await this.recipeRepository.save(recipeEntity);
|
||||
return this.mapper.toDto(savedEntity);
|
||||
}
|
||||
/**
|
||||
* Create a new recipe
|
||||
* @param dto RecipeDto containing the new recipe
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue