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