load recipe by id
This commit is contained in:
parent
3638909761
commit
21742e3b24
5 changed files with 54 additions and 5 deletions
|
|
@ -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";
|
||||
|
||||
|
|
|
|||
|
|
@ -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'
|
||||
]
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue