From fa0e8caed8f1a179d160aa35c99ff4bbf583319b Mon Sep 17 00:00:00 2001 From: morteza-mortezai Date: Wed, 7 Jan 2026 20:08:06 +0330 Subject: [PATCH] category order --- .../foods/providers/category.service.ts | 37 ++----------------- 1 file changed, 3 insertions(+), 34 deletions(-) diff --git a/src/modules/foods/providers/category.service.ts b/src/modules/foods/providers/category.service.ts index b5ea3af..2443825 100644 --- a/src/modules/foods/providers/category.service.ts +++ b/src/modules/foods/providers/category.service.ts @@ -42,28 +42,11 @@ export class CategoryService { } async findAllByRestaurantId(restId: string): Promise { - return this.categoryRepository.find({ restaurant: { id: restId } }); + return this.categoryRepository.find( + { restaurant: { id: restId } }, + { orderBy: { order: 'asc' } }); } - // async findAll(opts?: { restId?: string; isActive?: boolean }): Promise { - // const where: FilterQuery = {}; - // if (opts?.restId) where.restId = opts.restId; - // if (opts && typeof opts.isActive === 'boolean') where.isActive = opts.isActive; - // 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(restId: string, id: string): Promise { const cat = await this.categoryRepository.findOne({ id, restaurant: { id: restId } }, { populate: ['foods'] }); if (!cat) throw new NotFoundException(CategoryMessage.NOT_FOUND); @@ -80,20 +63,6 @@ export class CategoryService { } as unknown as Category; } - async findRestaurantCategories(restId: string): Promise { - const cat = await this.categoryRepository.findOne({ restaurant: { id: restId } }, { populate: ['foods'] }); - if (!cat) throw new NotFoundException(CategoryMessage.NOT_FOUND); - - return { - id: cat.id, - title: cat.title, - isActive: cat.isActive, - restaurant: cat.restaurant, - avatarUrl: cat.avatarUrl, - createdAt: cat.createdAt, - updatedAt: cat.updatedAt, - } as unknown as Category; - } async update(restId: string, id: string, dto: UpdateCategoryDto): Promise { const cat = await this.categoryRepository.findOne({ id, restaurant: { id: restId } });