order food

This commit is contained in:
2026-01-07 20:05:06 +03:30
parent 1a18ff9132
commit ad59941f50
3 changed files with 9 additions and 13 deletions
@@ -6,9 +6,6 @@ import { FindFoodsDto } from '../dto/find-foods.dto';
import { import {
ApiTags, ApiTags,
ApiOperation, ApiOperation,
ApiCreatedResponse,
ApiOkResponse,
ApiNotFoundResponse,
ApiQuery, ApiQuery,
ApiBody, ApiBody,
ApiParam, ApiParam,
+6 -7
View File
@@ -15,15 +15,11 @@ import { Inventory } from 'src/modules/inventory/entities/inventory.entity';
@Injectable() @Injectable()
export class FoodService { export class FoodService {
private readonly FOODS_BY_RESTAURANT_CACHE_KEY_PREFIX = 'foods:restaurant:';
private readonly FOODS_CACHE_TTL = 600; // 10 minutes in seconds
constructor( constructor(
private readonly foodRepository: FoodRepository, private readonly foodRepository: FoodRepository,
private readonly categoryRepository: CategoryRepository, private readonly categoryRepository: CategoryRepository,
private readonly restRepository: RestRepository, private readonly restRepository: RestRepository,
private readonly em: EntityManager, private readonly em: EntityManager,
private readonly cacheService: CacheService,
) { } ) { }
async create(restId: string, createFoodDto: CreateFoodDto) { async create(restId: string, createFoodDto: CreateFoodDto) {
@@ -127,11 +123,14 @@ export class FoodService {
const queryFilter: FilterQuery<Food> = { const queryFilter: FilterQuery<Food> = {
restaurant: { slug }, restaurant: { slug },
isActive: true, isActive: true,
// weekDays: { $contains: iranWeekDay }, weekDays: { $contains: iranWeekDay },
// ...(mealType ? { mealTypes: { $contains: mealType } } : {}), ...(mealType ? { mealTypes: { $contains: mealType } } : {}),
} as unknown as FilterQuery<Food>; } as unknown as FilterQuery<Food>;
return this.foodRepository.find(queryFilter, { populate: ['category'] }); return this.foodRepository.find(queryFilter, {
populate: ['category'],
orderBy: { order: 'asc' }
});
} }
/** /**
@@ -24,7 +24,7 @@ export class FoodRepository extends EntityRepository<Food> {
* Supports: search (title/content), categoryId, isActive, ordering. * Supports: search (title/content), categoryId, isActive, ordering.
*/ */
async findAllPaginated(restId: string, opts: FindFoodsOpts = {}): Promise<PaginatedResult<Food>> { async findAllPaginated(restId: string, opts: FindFoodsOpts = {}): Promise<PaginatedResult<Food>> {
const { page = 1, limit = 10, search, orderBy = 'order', order = 'ASC', categoryId, isActive } = opts; const { page = 1, limit = 10, search, orderBy = 'order', order = 'asc', categoryId, isActive } = opts;
const offset = (page - 1) * limit; const offset = (page - 1) * limit;