This commit is contained in:
2025-11-15 10:23:31 +03:30
parent 58e6390ddb
commit 3cbab81e0f
@@ -31,13 +31,35 @@ export class CategoryService {
const where: FilterQuery<Category> = {};
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<Category> {
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<Category> {