This commit is contained in:
2025-11-25 09:58:13 +03:30
parent fdbc3c9dbe
commit a5992d8e29
4 changed files with 36 additions and 27 deletions
@@ -5,7 +5,8 @@ import { CategoryRepository } from '../repositories/category.repository';
import { EntityManager } from '@mikro-orm/postgresql';
import { RequiredEntityData, FilterQuery } from '@mikro-orm/core';
import { Category } from '../entities/category.entity';
import { CategoryMessage } from 'src/common/enums/message.enum';
import { CategoryMessage, RestMessage } from 'src/common/enums/message.enum';
import { Restaurant } from 'src/modules/restaurants/entities/restaurant.entity';
@Injectable()
export class CategoryService {
@@ -28,6 +29,14 @@ export class CategoryService {
return category;
}
async findAllByRestaurant(slug: string): Promise<Category[]> {
const restaurant = await this.em.findOne(Restaurant, { slug });
if (!restaurant || !restaurant.id) {
throw new NotFoundException(RestMessage.NOT_FOUND);
}
return this.categoryRepository.find({ restId: restaurant.id.toString() });
}
async findAll(opts?: { restId?: string; isActive?: boolean }): Promise<Category[]> {
const where: FilterQuery<Category> = {};
if (opts?.restId) where.restId = opts.restId;