category
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user