From 3cbab81e0f94eb557f10f9a3c4397d80a1ed4a03 Mon Sep 17 00:00:00 2001 From: morteza-mortezai Date: Sat, 15 Nov 2025 10:23:31 +0330 Subject: [PATCH] up --- .../foods/providers/category.service.ts | 26 +++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/src/modules/foods/providers/category.service.ts b/src/modules/foods/providers/category.service.ts index 6f92d73..b0c70bf 100644 --- a/src/modules/foods/providers/category.service.ts +++ b/src/modules/foods/providers/category.service.ts @@ -31,13 +31,35 @@ export class CategoryService { const where: FilterQuery = {}; if (opts?.restId) where.restId = opts.restId; if (opts && typeof opts.isActive === 'boolean') where.isActive = opts.isActive; - return this.categoryRepository.find(where, { populate: ['foods'] }); + const cats = await this.categoryRepository.find(where, { populate: ['foods'] }); + + // Return plain objects to avoid circular references during JSON serialization + return cats.map(cat => ({ + id: cat.id, + title: cat.title, + isActive: cat.isActive, + restId: cat.restId, + avatarUrl: cat.avatarUrl, + createdAt: cat.createdAt, + updatedAt: cat.updatedAt, + foods: cat.foods.getItems().map(f => ({ id: f.id, title: f.title })), + })) as unknown as Category[]; } async findOne(id: string): Promise { const cat = await this.categoryRepository.findOne({ id }, { populate: ['foods'] }); if (!cat) throw new NotFoundException(CategoryMessage.NOT_FOUND); - return cat; + + return { + id: cat.id, + title: cat.title, + isActive: cat.isActive, + restId: cat.restId, + avatarUrl: cat.avatarUrl, + createdAt: cat.createdAt, + updatedAt: cat.updatedAt, + foods: cat.foods.getItems().map(f => ({ id: f.id, title: f.title })), + } as unknown as Category; } async update(id: string, dto: UpdateCategoryDto): Promise {