correct cascade delete options
This commit is contained in:
parent
e33dfdb845
commit
b1b714f44e
19 changed files with 207 additions and 52 deletions
|
|
@ -21,14 +21,12 @@ export class RecipeDtoEntityMapper extends AbstractDtoEntityMapper<RecipeEntity,
|
|||
dto.amountDescription = entity.amountDescription;
|
||||
|
||||
// map instructions
|
||||
const instructionStepEntities = entity.instructionSteps;
|
||||
const instructionStepDtos = instructionStepEntities.map((stepEntity) => this.instructionStepMapper.toDto(stepEntity));
|
||||
dto.instructions = instructionStepDtos;
|
||||
dto.instructions = entity.instructionSteps.map((stepEntity) => this.instructionStepMapper.toDto(stepEntity));
|
||||
// @todo map ids dto.instructions.forEach(step => step.recipeId = entity.id); // set recipe relation explicitly!
|
||||
|
||||
|
||||
// map ingredient groups
|
||||
const ingredientGroupEntities = entity.ingredientGroups;
|
||||
const ingredientGroupDtos = ingredientGroupEntities.map((groupEntity) => this.ingredientGroupMapper.toDto(groupEntity));
|
||||
dto.ingredientGroups = ingredientGroupDtos;
|
||||
dto.ingredientGroups = entity.ingredientGroups.map((groupEntity) => this.ingredientGroupMapper.toDto(groupEntity));
|
||||
|
||||
return dto;
|
||||
}
|
||||
|
|
@ -42,16 +40,47 @@ export class RecipeDtoEntityMapper extends AbstractDtoEntityMapper<RecipeEntity,
|
|||
entity.amountDescription = dto.amountDescription;
|
||||
|
||||
// map instructions
|
||||
const instructionStepDtos = dto.instructions;
|
||||
const instructionStepEntities = instructionStepDtos.map((stepDto) => this.instructionStepMapper.toEntity(stepDto));
|
||||
entity.instructionSteps = instructionStepEntities;
|
||||
entity.instructionSteps = dto.instructions.map((stepDto) => {
|
||||
const stepEntity = this.instructionStepMapper.toEntity(stepDto);
|
||||
|
||||
// Always set the relation
|
||||
stepEntity.recipe = entity;
|
||||
|
||||
// If it's a new step (no id from client), let DB generate a new UUID
|
||||
if (!stepDto.id) {
|
||||
delete (stepEntity as any).id;
|
||||
}
|
||||
|
||||
return stepEntity;
|
||||
});
|
||||
|
||||
// map ingredient groups
|
||||
const ingredientGroupDtos = dto.ingredientGroups;
|
||||
const ingredientGroupEntities = ingredientGroupDtos.map((ingredientGroupDto) => this.ingredientGroupMapper.toEntity(ingredientGroupDto));
|
||||
entity.ingredientGroups = ingredientGroupEntities;
|
||||
entity.ingredientGroups = dto.ingredientGroups.map((groupDto) => {
|
||||
const groupEntity = this.ingredientGroupMapper.toEntity(groupDto);
|
||||
groupEntity.recipe = entity;
|
||||
if (!groupDto.id) {
|
||||
delete (groupEntity as any).id;
|
||||
}
|
||||
return groupEntity;
|
||||
});
|
||||
|
||||
return entity;
|
||||
return entity;
|
||||
}
|
||||
|
||||
mergeDtoIntoEntity(dto: RecipeDto, entity: RecipeEntity): RecipeEntity {
|
||||
entity.title = dto.title;
|
||||
entity.amount = dto.amount;
|
||||
entity.amountDescription = dto.amountDescription;
|
||||
|
||||
// --- Instruction Steps ---
|
||||
entity.instructionSteps = this.instructionStepMapper.mergeDtoListIntoEntityList(dto.instructions, entity.instructionSteps);
|
||||
|
||||
// --- Ingredient Groups ---
|
||||
entity.ingredientGroups = this.ingredientGroupMapper.mergeDtoListIntoEntityList(dto.ingredientGroups, entity.ingredientGroups);
|
||||
return entity
|
||||
}
|
||||
|
||||
createNewEntity(): RecipeEntity {
|
||||
return new RecipeEntity();
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue