optimize foods list
deploy to danak / build_and_deploy (push) Has been cancelled

This commit is contained in:
2026-06-03 15:15:00 +03:30
parent 8124938720
commit 974bc6bc5f
4 changed files with 10532 additions and 21 deletions
+10498
View File
File diff suppressed because it is too large Load Diff
@@ -30,7 +30,7 @@ export class FoodController {
@ApiHeader(API_HEADER_SLUG)
@ApiParam({ name: 'slug', required: true, description: 'Restaurant Slug' })
findAllByRestaurant(@Param('slug') slug: string) {
return this.foodsService.findByWeekDateAndMealType(slug);
return this.foodsService.findByRestuarantSlug(slug);
}
@Get('public/foods/:foodId')
@@ -9,8 +9,6 @@ import { Favorite } from './favorite.entity';
@Entity({ tableName: 'foods' })
@Index({ properties: ['restaurant', 'isActive'] })
@Index({ properties: ['category', 'isActive'] })
@Index({ properties: ['isActive'] })
export class Food extends BaseEntity {
@ManyToOne(() => Restaurant)
restaurant: Restaurant;
+33 -18
View File
@@ -11,6 +11,7 @@ import { Favorite } from '../entities/favorite.entity';
import { MealType } from '../interface/food.interface';
import { Inventory } from 'src/modules/inventory/entities/inventory.entity';
import { RestaurantsService } from 'src/modules/restaurants/providers/restaurants.service';
import { Restaurant } from 'src/modules/restaurants/entities/restaurant.entity';
@Injectable()
export class FoodService {
@@ -110,40 +111,54 @@ export class FoodService {
* @param slug - Restaurant slug identifier
* @returns Array of active foods matching current day and meal time
*/
async findByWeekDateAndMealType(slug: string): Promise<Food[]> {
const { iranWeekDay, mealType } = this.getCurrentIranTimeContext();
async findByRestuarantSlug(slug: string) {
const restaurant = await this.restService.findBySlug(slug);
const queryFilter: FilterQuery<Food> = {
restaurant: { slug },
restaurant: restaurant.id,
isActive: true,
weekDays: { $contains: iranWeekDay },
...(mealType ? { mealTypes: { $contains: mealType } } : {}),
} as unknown as FilterQuery<Food>;
};
return this.foodRepository.find(queryFilter, {
populate: ['category'],
fields: ['id', 'title', 'price', 'content', 'desc', 'images', 'category',
'inPlaceServe', 'pickupServe', 'discount', 'isSpecialOffer'],
orderBy: { order: 'asc' }
});
}
// async findByWeekDateAndMealType(slug: string): Promise<Food[]> {
// const { iranWeekDay, mealType } = this.getCurrentIranTimeContext();
// const queryFilter: FilterQuery<Food> = {
// restaurant: { slug },
// isActive: true,
// weekDays: { $contains: iranWeekDay },
// ...(mealType ? { mealTypes: { $contains: mealType } } : {}),
// } as unknown as FilterQuery<Food>;
// return this.foodRepository.find(queryFilter, {
// populate: ['category'],
// orderBy: { order: 'asc' }
// });
// }
/**
* Get current Iran timezone context (weekday and meal type).
* @returns Object containing Iran weekday (0-6, where 0=Saturday) and current meal type
*/
private getCurrentIranTimeContext(): { iranWeekDay: number; mealType: MealType | null } {
const nowInIran = new Date(new Date().toLocaleString('en-US', { timeZone: 'Asia/Tehran' }));
const weekDay = nowInIran.getDay(); // 0 = Sunday, 6 = Saturday
const currentHour = nowInIran.getHours();
// private getCurrentIranTimeContext(): { iranWeekDay: number; mealType: MealType | null } {
// const nowInIran = new Date(new Date().toLocaleString('en-US', { timeZone: 'Asia/Tehran' }));
// const weekDay = nowInIran.getDay(); // 0 = Sunday, 6 = Saturday
// const currentHour = nowInIran.getHours();
// Convert to Iran weekday: Saturday=0, Sunday=1, ..., Friday=6
// JavaScript: Sunday=0, Monday=1, ..., Saturday=6
// Iran week: Saturday=0, Sunday=1, ..., Friday=6
const iranWeekDay = (weekDay + 1) % 7;
// // Convert to Iran weekday: Saturday=0, Sunday=1, ..., Friday=6
// // JavaScript: Sunday=0, Monday=1, ..., Saturday=6
// // Iran week: Saturday=0, Sunday=1, ..., Friday=6
// const iranWeekDay = (weekDay + 1) % 7;
const mealType = this.getMealTypeByHour(currentHour);
// const mealType = this.getMealTypeByHour(currentHour);
return { iranWeekDay, mealType };
}
// return { iranWeekDay, mealType };
// }
/**
* Determine meal type based on current hour in Iran timezone.