add relation ids to DTOs

This commit is contained in:
Anika Raemer 2025-10-10 20:22:14 +02:00
parent 0587153829
commit 81f1c3668b
3 changed files with 19 additions and 5 deletions

View file

@ -4,5 +4,5 @@ import { AbstractDto } from "./AbstractDto.js";
export class RecipeInstructionStepDto extends AbstractDto{ export class RecipeInstructionStepDto extends AbstractDto{
text!: string; text!: string;
sortOrder!: number; sortOrder!: number;
recipeId?: UUID; recipeId?: string;
} }

View file

@ -1,4 +1,6 @@
import { RecipeDto } from "../dtos/RecipeDto.js"; import { RecipeDto } from "../dtos/RecipeDto.js";
import { RecipeIngredientGroupDto } from "../dtos/RecipeIngredientGroupDto.js";
import { RecipeInstructionStepDto } from "../dtos/RecipeInstructionStepDto.js";
import { RecipeEntity } from "../entities/RecipeEntity.js"; import { RecipeEntity } from "../entities/RecipeEntity.js";
import { AbstractDtoEntityMapper } from "./AbstractDtoEntityMapper.js"; import { AbstractDtoEntityMapper } from "./AbstractDtoEntityMapper.js";
import { RecipeIngredientGroupDtoEntityMapper } from "./RecipeIngredientGroupDtoEntityMapper.js"; import { RecipeIngredientGroupDtoEntityMapper } from "./RecipeIngredientGroupDtoEntityMapper.js";
@ -21,12 +23,19 @@ export class RecipeDtoEntityMapper extends AbstractDtoEntityMapper<RecipeEntity,
dto.amountDescription = entity.amountDescription; dto.amountDescription = entity.amountDescription;
// map instructions // map instructions
dto.instructions = entity.instructionSteps.map((stepEntity) => this.instructionStepMapper.toDto(stepEntity)); dto.instructions = entity.instructionSteps.map((stepEntity) => {
// @todo map ids dto.instructions.forEach(step => step.recipeId = entity.id); // set recipe relation explicitly! const instructionStep : RecipeInstructionStepDto = this.instructionStepMapper.toDto(stepEntity);
instructionStep.recipeId = entity.id;
return instructionStep;
});
// map ingredient groups // map ingredient groups
dto.ingredientGroups = entity.ingredientGroups.map((groupEntity) => this.ingredientGroupMapper.toDto(groupEntity)); dto.ingredientGroups = entity.ingredientGroups.map((groupEntity) => {
const ingredientGroup :RecipeIngredientGroupDto = this.ingredientGroupMapper.toDto(groupEntity);
ingredientGroup.recipeId = entity.id;
return ingredientGroup;
});
return dto; return dto;
} }

View file

@ -1,3 +1,4 @@
import { RecipeIngredientDto } from "../dtos/RecipeIngredientDto.js";
import { RecipeIngredientGroupDto } from "../dtos/RecipeIngredientGroupDto.js"; import { RecipeIngredientGroupDto } from "../dtos/RecipeIngredientGroupDto.js";
import { RecipeIngredientGroupEntity } from "../entities/RecipeIngredientGroupEntity.js"; import { RecipeIngredientGroupEntity } from "../entities/RecipeIngredientGroupEntity.js";
import { AbstractDtoEntityMapper } from "./AbstractDtoEntityMapper.js"; import { AbstractDtoEntityMapper } from "./AbstractDtoEntityMapper.js";
@ -18,7 +19,11 @@ export class RecipeIngredientGroupDtoEntityMapper extends AbstractDtoEntityMappe
dto.sortOrder = entity.sortOrder dto.sortOrder = entity.sortOrder
// map ingredients // map ingredients
dto.ingredients = entity.ingredients?.map((ingredientEntity) => this.ingredientMapper.toDto(ingredientEntity)); dto.ingredients = entity.ingredients?.map((ingredientEntity) => {
const ingredientDto : RecipeIngredientDto = this.ingredientMapper.toDto(ingredientEntity);
ingredientDto.ingredientGroupId = entity.id;
return ingredientDto;
});
return dto; return dto;
} }