order food
This commit is contained in:
@@ -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,
|
||||||
|
|||||||
@@ -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) {
|
||||||
@@ -105,7 +101,7 @@ export class FoodService {
|
|||||||
* Admin food detail (scoped to the authenticated restaurant).
|
* Admin food detail (scoped to the authenticated restaurant).
|
||||||
*/
|
*/
|
||||||
async findAdminById(restId: string, id: string): Promise<Food> {
|
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);
|
if (!food) throw new NotFoundException(FoodMessage.NOT_FOUND);
|
||||||
return food;
|
return food;
|
||||||
@@ -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' }
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -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'] });
|
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.
|
* 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;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user