From e9ee39ccb126cf3067a115e8a8d1540ef35bfa18 Mon Sep 17 00:00:00 2001 From: Alexander <0074.sanu@gmail.com> Date: Wed, 18 Sep 2024 22:21:28 +0300 Subject: [PATCH] Fix category service * handle empty categories --- lib/shared/modules/category/category.service.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/shared/modules/category/category.service.ts b/lib/shared/modules/category/category.service.ts index 7013cbe..78ebb30 100644 --- a/lib/shared/modules/category/category.service.ts +++ b/lib/shared/modules/category/category.service.ts @@ -44,11 +44,17 @@ export class CategoryService { where: { code }, relations: CATEGORY_RELATIONS, }); + if (!cat) { + return null; + } const res = await this.catRep.findDescendantsTree(cat, { depth, relations: CATEGORY_RELATIONS, }); - res.children?.forEach((cat) => this.sort(cat)); + if (!res.children?.length) { + return res; + } + res.children.forEach((cat) => this.sort(cat)); this.sort(res); return res; }