category order

This commit is contained in:
2026-01-07 20:08:06 +03:30
parent ad59941f50
commit fa0e8caed8
@@ -42,28 +42,11 @@ export class CategoryService {
} }
async findAllByRestaurantId(restId: string): Promise<Category[]> { async findAllByRestaurantId(restId: string): Promise<Category[]> {
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<Category[]> {
// const where: FilterQuery<Category> = {};
// 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<Category> { async findOne(restId: string, id: string): Promise<Category> {
const cat = await this.categoryRepository.findOne({ id, restaurant: { id: restId } }, { populate: ['foods'] }); const cat = await this.categoryRepository.findOne({ id, restaurant: { id: restId } }, { populate: ['foods'] });
if (!cat) throw new NotFoundException(CategoryMessage.NOT_FOUND); if (!cat) throw new NotFoundException(CategoryMessage.NOT_FOUND);
@@ -80,20 +63,6 @@ export class CategoryService {
} as unknown as Category; } as unknown as Category;
} }
async findRestaurantCategories(restId: string): Promise<Category> {
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<Category> { async update(restId: string, id: string, dto: UpdateCategoryDto): Promise<Category> {
const cat = await this.categoryRepository.findOne({ id, restaurant: { id: restId } }); const cat = await this.categoryRepository.findOne({ id, restaurant: { id: restId } });