add search for recipe title

This commit is contained in:
Anika Raemer 2025-10-04 21:04:05 +02:00
parent 7e831cfb64
commit 7ec4324fde
3 changed files with 37 additions and 2 deletions

View file

@ -1,6 +1,7 @@
import { AbstractRepository } from "./AbstractRepository.js";
import { RecipeEntity } from "../entities/RecipeEntity.js";
import { AppDataSource } from "../data-source.js";
import { Like } from "typeorm";
export class RecipeRepository extends AbstractRepository<RecipeEntity> {
constructor() {
@ -23,6 +24,23 @@ export class RecipeRepository extends AbstractRepository<RecipeEntity> {
});
}
/**
* Find all recipes matching the search. Currently it only searches on the title. Fetches only recipe header data but no relations.
* @param searchString String to search for
* @returns List of recipe entities matching the search criteria
*/
async findCompactRecipeBySearch(searchString : string): Promise<RecipeEntity[] | null>{
// @todo doesn't work like expected...
return this.repo.find(
{ where: {title: Like(`%${searchString}%`)}}
);
}
/**
* Update recipe and relations
* @param entity Updated entity
* @returns Updated Entity
*/
async updateRecipe(entity: RecipeEntity): Promise<RecipeEntity> {
return AppDataSource.transaction(async (em) => {
// load existing data