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 {
ApiTags,
ApiOperation,
ApiCreatedResponse,
ApiOkResponse,
ApiNotFoundResponse,
ApiQuery,
ApiBody,
ApiParam,
+8 -9
View File
@@ -15,15 +15,11 @@ import { Inventory } from 'src/modules/inventory/entities/inventory.entity';
@Injectable()
export class FoodService {
private readonly FOODS_BY_RESTAURANT_CACHE_KEY_PREFIX = 'foods:restaurant:';
private readonly FOODS_CACHE_TTL = 600; // 10 minutes in seconds
constructor(
private readonly foodRepository: FoodRepository,
private readonly categoryRepository: CategoryRepository,
private readonly restRepository: RestRepository,
private readonly em: EntityManager,
private readonly cacheService: CacheService,
) { }
async create(restId: string, createFoodDto: CreateFoodDto) {
@@ -105,7 +101,7 @@ export class FoodService {
* Admin food detail (scoped to the authenticated restaurant).
*/
async findAdminById(restId: string, id: string): Promise<Food> {
const food = await this.foodRepository.findOne({ id, restaurant: { id: restId } }, { populate: ['category','inventory'] });
const food = await this.foodRepository.findOne({ id, restaurant: { id: restId } }, { populate: ['category', 'inventory'] });
if (!food) throw new NotFoundException(FoodMessage.NOT_FOUND);
return food;
@@ -127,11 +123,14 @@ export class FoodService {
const queryFilter: FilterQuery<Food> = {
restaurant: { slug },
isActive: true,
// weekDays: { $contains: iranWeekDay },
// ...(mealType ? { mealTypes: { $contains: mealType } } : {}),
weekDays: { $contains: iranWeekDay },
...(mealType ? { mealTypes: { $contains: mealType } } : {}),
} as unknown as FilterQuery<Food>;
return this.foodRepository.find(queryFilter, { populate: ['category'] });
return this.foodRepository.find(queryFilter, {
populate: ['category'],
orderBy: { order: 'asc' }
});
}
/**
@@ -261,7 +260,7 @@ export class FoodService {
}
async getMyFavorites(userId: string,restId: string) {
async getMyFavorites(userId: string, restId: string) {
return this.em.find(Favorite, { user: userId, food: { restaurant: { id: restId } } }, { populate: ['food'] });
}
/**
@@ -24,7 +24,7 @@ export class FoodRepository extends EntityRepository<Food> {
* Supports: search (title/content), categoryId, isActive, ordering.
*/
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;