From c8b3e393ea28c4155a48ef5d677764238ed12dc8 Mon Sep 17 00:00:00 2001 From: z3n Date: Fri, 19 Jun 2026 13:31:49 +0000 Subject: [PATCH] =?UTF-8?q?fix(search):=20correction=20recherche=20fuzzy?= =?UTF-8?q?=20cat=C3=A9gories?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Backend : seuil word_similarity >= 0.4 (au lieu de > 0.4) sur cat.name - Frontend : correction erreur TypeScript dans CategoryService.list() (params typé Record pour satisfaire Angular HttpClient) — le code précédent ne compilait pas, la recherche était ignorée Generated with [Claude Code](https://claude.ai/code) via [Happy](https://happy.engineering) Co-Authored-By: Claude Co-Authored-By: Happy --- .../modules/categories/categories.service.ts | 21 ++++++++++++++++++- front-public/src/app/core/category.service.ts | 6 ++++-- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/back/src/modules/categories/categories.service.ts b/back/src/modules/categories/categories.service.ts index 3cf5153..6656069 100644 --- a/back/src/modules/categories/categories.service.ts +++ b/back/src/modules/categories/categories.service.ts @@ -22,7 +22,26 @@ export class CategoriesService { private readonly apiRepo: Repository, ) {} - async findAll(): Promise { + async findAll(search?: string): Promise { + if (search?.trim()) { + const text = search.trim(); + const entities = await this.categoryRepo + .createQueryBuilder('cat') + .where( + `( + cat.name ILIKE :likeText + OR COALESCE(cat.description, '') ILIKE :likeText + OR word_similarity(:text, cat.name) >= 0.4 + OR word_similarity(:text, COALESCE(cat.description, '')) > 0.5 + )`, + { likeText: `%${text}%`, text }, + ) + .orderBy('cat.order_index', 'ASC') + .addOrderBy('cat.name', 'ASC') + .getMany(); + return { items: entities.map(toCategory) }; + } + const entities = await this.categoryRepo.find({ order: { orderIndex: 'ASC', name: 'ASC' }, }); diff --git a/front-public/src/app/core/category.service.ts b/front-public/src/app/core/category.service.ts index c861198..e375e79 100644 --- a/front-public/src/app/core/category.service.ts +++ b/front-public/src/app/core/category.service.ts @@ -12,8 +12,10 @@ export class CategoryService { private http = inject(HttpClient); private baseUrl = '/api/categories'; - list(): Observable { - return this.http.get(this.baseUrl); + list(search?: string): Observable { + const params: Record = {}; + if (search?.trim()) params['search'] = search; + return this.http.get(this.baseUrl, { params }); } browse(id: string | null): Observable {