From c78267b0f22695f3ce70c6273fb9c18536fc86ed Mon Sep 17 00:00:00 2001 From: nfesta2023 <142601504+nfesta2023@users.noreply.github.com> Date: Fri, 15 Mar 2024 11:45:29 +0700 Subject: [PATCH] fix no restaurant found case (#77) Co-authored-by: NHT --- src/feature/food/food.service.ts | 3 +++ src/feature/recommendation/recommendation.controller.ts | 4 +++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/feature/food/food.service.ts b/src/feature/food/food.service.ts index d643729..9e70f11 100644 --- a/src/feature/food/food.service.ts +++ b/src/feature/food/food.service.ts @@ -63,6 +63,9 @@ export class FoodService { } // end of getPriceRangeByMenuItem async getFoodsWithListOfRestaurants(restaurantIds: number[]) { + if (!restaurantIds || restaurantIds.length === 0) { + return []; + } const foodList = await this.menuItemRepo .createQueryBuilder('menuItem') .leftJoinAndSelect('menuItem.menuItemExt', 'menuItemExt') diff --git a/src/feature/recommendation/recommendation.controller.ts b/src/feature/recommendation/recommendation.controller.ts index 40881c3..fb07a58 100644 --- a/src/feature/recommendation/recommendation.controller.ts +++ b/src/feature/recommendation/recommendation.controller.ts @@ -1,4 +1,4 @@ -import { Controller, HttpException } from '@nestjs/common'; +import { Controller, HttpException, Logger } from '@nestjs/common'; import { RecommendationService } from './recommendation.service'; import { MessagePattern } from '@nestjs/microservices'; import { FoodRecommendationRequest } from './dto/food-recommendation-request.dto'; @@ -8,6 +8,7 @@ import { RestaurantRecommendationResponse } from './dto/restaurant-recommendatio @Controller() export class RecommendationController { + private readonly logger = new Logger(RecommendationController.name); constructor(private readonly recommendationService: RecommendationService) {} @MessagePattern({ cmd: 'get_general_food_recomendation' }) @@ -26,6 +27,7 @@ export class RecommendationController { res.message = 'Get food recommendation successfully'; res.data = food; } catch (error) { + this.logger.error(error); if (error instanceof HttpException) { res.statusCode = error.getStatus(); res.message = error.getResponse();