load recipe by id

This commit is contained in:
Anika Raemer 2025-09-28 20:14:19 +02:00
parent 3638909761
commit 21742e3b24
5 changed files with 54 additions and 5 deletions

View file

@ -1,4 +1,4 @@
import { Repository, DeepPartial, ObjectLiteral } from "typeorm";
import { Repository, DeepPartial } from "typeorm";
import { AppDataSource } from "../data-source.js";
import { AbstractEntity } from "../entities/AbstractEntity.js";

View file

@ -5,4 +5,21 @@ export class RecipeRepository extends AbstractRepository<RecipeEntity> {
constructor() {
super(RecipeEntity);
}
/**
* Find recipe including all relations by id
* @param id Recipe id
* @returns RecipeEntity including all relations such as ingredients groups, ingredients and instruction steps
*/
async findById(id: string): Promise<RecipeEntity | null> {
return this.repo.findOne(
{ where: { id } as any,
relations: [
'ingredientGroups',
'ingredientGroups.ingredients',
'instructionSteps'
]
});
}
}