diff --git a/back/src/modules/categories/categories.service.ts b/back/src/modules/categories/categories.service.ts index 25996a2..04286d6 100644 --- a/back/src/modules/categories/categories.service.ts +++ b/back/src/modules/categories/categories.service.ts @@ -81,6 +81,13 @@ export class CategoriesService { await this.categoryRepo.delete(id); } + private async countApisRecursively(categoryId: string): Promise { + const direct = await this.apiRepo.count({ where: { categoryId } }); + const children = await this.categoryRepo.find({ where: { parentId: categoryId }, select: ['id'] }); + const childCounts = await Promise.all(children.map((c) => this.countApisRecursively(c.id))); + return direct + childCounts.reduce((sum, n) => sum + n, 0); + } + async browse(categoryId: string | null): Promise { /* 1. Charge la catégorie courante */ let currentCategory: CategoryEntity | null = null; @@ -111,7 +118,7 @@ export class CategoriesService { const subcategories: CategoryWithCounts[] = await Promise.all( directChildren.map(async (child) => { const subcategoryCount = await this.categoryRepo.count({ where: { parentId: child.id } }); - const apiCount = await this.apiRepo.count({ where: { categoryId: child.id } }); + const apiCount = await this.countApisRecursively(child.id); return { ...toCategory(child), subcategoryCount, apiCount }; }), ); diff --git a/front-public/src/app/pages/browse/browse.component.ts b/front-public/src/app/pages/browse/browse.component.ts index 2e60fed..25fa76c 100644 --- a/front-public/src/app/pages/browse/browse.component.ts +++ b/front-public/src/app/pages/browse/browse.component.ts @@ -86,6 +86,18 @@ import { forkJoin } from 'rxjs';

{{ cat.name }} + + @if (cat.apiCount === 0 && cat.subcategoryCount === 0) { + + }

@if (cat.description) {

{{ cat.description }}

@@ -93,18 +105,6 @@ import { forkJoin } from 'rxjs';

{{ cat.subcategoryCount }} sous-catégorie(s) · {{ cat.apiCount }} API(s)

-
- - @if (cat.apiCount === 0 && cat.subcategoryCount === 0) { - - } -