diff --git a/src/dtos/RecipeInstructionStepDto.ts b/src/dtos/RecipeInstructionStepDto.ts index 362e282..88ddb87 100644 --- a/src/dtos/RecipeInstructionStepDto.ts +++ b/src/dtos/RecipeInstructionStepDto.ts @@ -4,5 +4,5 @@ import { AbstractDto } from "./AbstractDto.js"; export class RecipeInstructionStepDto extends AbstractDto{ text!: string; sortOrder!: number; - recipeId?: UUID; + recipeId?: string; } \ No newline at end of file diff --git a/src/mappers/RecipeDtoEntityMapper.ts b/src/mappers/RecipeDtoEntityMapper.ts index eb8bdbc..ee97da9 100644 --- a/src/mappers/RecipeDtoEntityMapper.ts +++ b/src/mappers/RecipeDtoEntityMapper.ts @@ -1,4 +1,6 @@ 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 { AbstractDtoEntityMapper } from "./AbstractDtoEntityMapper.js"; import { RecipeIngredientGroupDtoEntityMapper } from "./RecipeIngredientGroupDtoEntityMapper.js"; @@ -21,12 +23,19 @@ export class RecipeDtoEntityMapper extends AbstractDtoEntityMapper this.instructionStepMapper.toDto(stepEntity)); - // @todo map ids dto.instructions.forEach(step => step.recipeId = entity.id); // set recipe relation explicitly! + dto.instructions = entity.instructionSteps.map((stepEntity) => { + const instructionStep : RecipeInstructionStepDto = this.instructionStepMapper.toDto(stepEntity); + instructionStep.recipeId = entity.id; + return instructionStep; + }); // 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; } diff --git a/src/mappers/RecipeIngredientGroupDtoEntityMapper.ts b/src/mappers/RecipeIngredientGroupDtoEntityMapper.ts index 9520138..3002695 100644 --- a/src/mappers/RecipeIngredientGroupDtoEntityMapper.ts +++ b/src/mappers/RecipeIngredientGroupDtoEntityMapper.ts @@ -1,3 +1,4 @@ +import { RecipeIngredientDto } from "../dtos/RecipeIngredientDto.js"; import { RecipeIngredientGroupDto } from "../dtos/RecipeIngredientGroupDto.js"; import { RecipeIngredientGroupEntity } from "../entities/RecipeIngredientGroupEntity.js"; import { AbstractDtoEntityMapper } from "./AbstractDtoEntityMapper.js"; @@ -18,7 +19,11 @@ export class RecipeIngredientGroupDtoEntityMapper extends AbstractDtoEntityMappe dto.sortOrder = entity.sortOrder // 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; }