correct cascade delete options

This commit is contained in:
Anika Raemer 2025-10-04 18:01:46 +02:00
parent e33dfdb845
commit b1b714f44e
19 changed files with 207 additions and 52 deletions

View file

@ -6,6 +6,7 @@ import { RecipeInstructionStepDto } from "../dtos/RecipeInstructionStepDto.js";
import { RecipeIngredientGroupDto } from "../dtos/RecipeIngredientGroupDto.js";
import { RecipeIngredientDto } from "../dtos/RecipeIngredientDto.js";
import { Entity } from "typeorm";
import { RecipeEntity } from "../entities/RecipeEntity.js";
/**
* Controls all recipe specific actions
@ -38,9 +39,19 @@ export class RecipeController {
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);
const recipeId = dto.id
if(recipeId === undefined){
throw new ValidationError("Trying to update recipe without ID!")
}
// Load current version of recipe from database
const recipeEntity = await this.recipeRepository.findById(recipeId);
if(!recipeEntity){
throw new ValidationError("No recipe with ID " + recipeId + " found in database!")
}
// merge changes into entity
this.mapper.mergeDtoIntoEntity(dto, recipeEntity);
// persist changes
const savedEntity = await this.recipeRepository.update(recipeEntity);
return this.mapper.toDto(savedEntity);
}
/**