diff --git a/src/feature/common/common.service.ts b/src/feature/common/common.service.ts index b336d8a..6b42ef8 100644 --- a/src/feature/common/common.service.ts +++ b/src/feature/common/common.service.ts @@ -31,35 +31,33 @@ export class CommonService { limit: number, order: 'ASC' | 'DESC', ): Promise { - if (this.flagService.isFeatureEnabled('fes-18-get-restaurant-detail')) { - const reviews: Review[] = []; - const data = await this.entityManager - .createQueryBuilder(FoodRating, 'foodRating') - .leftJoin('foodRating.order_sku_obj', 'orderSKU') - .leftJoin('orderSKU.sku_obj', 'sku') - .leftJoin('sku.menu_item', 'menuItem') - .where('menuItem.restaurant_id = :restaurant_id', { restaurant_id }) - .andWhere('foodRating.is_active = :active', { active: TRUE }) - .select([ - 'foodRating.food_rating_id', - 'foodRating.score', - 'foodRating.remarks', - ]) - .limit(limit) - .offset(0) - .orderBy('foodRating.created_at', order) - .getMany(); - for (const item of data) { - const review: Review = { - food_rating_id: item.food_rating_id, - score: item.score, - remarks: item.remarks, - }; - reviews.push(review); - } - - return reviews; + const reviews: Review[] = []; + const data = await this.entityManager + .createQueryBuilder(FoodRating, 'foodRating') + .leftJoin('foodRating.order_sku_obj', 'orderSKU') + .leftJoin('orderSKU.sku_obj', 'sku') + .leftJoin('sku.menu_item', 'menuItem') + .where('menuItem.restaurant_id = :restaurant_id', { restaurant_id }) + .andWhere('foodRating.is_active = :active', { active: TRUE }) + .select([ + 'foodRating.food_rating_id', + 'foodRating.score', + 'foodRating.remarks', + ]) + .limit(limit) + .offset(0) + .orderBy('foodRating.created_at', order) + .getMany(); + for (const item of data) { + const review: Review = { + food_rating_id: item.food_rating_id, + score: item.score, + remarks: item.remarks, + }; + reviews.push(review); } + + return reviews; } async getAvailableSkuDiscountBySkuId(skuId: number): Promise { @@ -103,67 +101,6 @@ export class CommonService { menuItem: MenuItem, correspondingRestaurant: DeliveryRestaurant = null, ): Promise { - if (this.flagService.isFeatureEnabled('fes-18-get-restaurant-detail')) { - //Defind Logic of Top Label later, currently just present the vegeterian sign - let topLabel = ''; - if (Boolean(menuItem.is_vegetarian)) { - topLabel = 'CHAY'; - } - - const foodNameByLang: TextByLang[] = menuItem.menuItemExt.map((ext) => { - return { - ISO_language_code: ext.ISO_language_code, - text: ext.short_name, - }; - }); - - const mainCookingMethodByLang: TextByLang[] = menuItem.menuItemExt.map( - (ext) => { - return { - ISO_language_code: ext.ISO_language_code, - text: ext.main_cooking_method, - }; - }, - ); - - const restaurantNameByLang: TextByLang[] = - correspondingRestaurant?.restaurant_ext.map((ext) => { - return { - ISO_language_code: ext.ISO_language_code, - text: ext.name, - }; - }) || null; - - return { - id: menuItem.menu_item_id, - image: menuItem.image_obj.url, - top_label: topLabel, - bottom_label: null, - name: foodNameByLang, - restaurant_name: restaurantNameByLang, - restaurant_id: menuItem.restaurant_id, - calorie_kcal: menuItem.skus[0].calorie_kcal, - rating: menuItem.rating, - distance_km: correspondingRestaurant?.distance_km || null, - delivery_time_s: correspondingRestaurant?.delivery_time_s || null, - main_cooking_method: mainCookingMethodByLang, - ingredient_brief_vie: menuItem.ingredient_brief_vie, - ingredient_brief_eng: menuItem.ingredient_brief_eng, - price: menuItem.skus[0].price, - price_after_discount: await this.getAvailableDiscountPrice( - menuItem.skus[0], - ), - promotion: menuItem.promotion, - cutoff_time: menuItem.cutoff_time, - preparing_time_s: menuItem.preparing_time_s, - cooking_time_s: menuItem.cooking_time_s, - quantity_available: menuItem.quantity_available, - is_vegetarian: Boolean(menuItem.is_vegetarian), - cooking_schedule: menuItem.cooking_schedule, - units_sold: menuItem.units_sold, - }; - } - //CURRENT LOGIC //Defind Logic of Top Label later, currently just present the vegeterian sign let topLabel = ''; if (Boolean(menuItem.is_vegetarian)) { @@ -187,12 +124,12 @@ export class CommonService { ); const restaurantNameByLang: TextByLang[] = - correspondingRestaurant.restaurant_ext.map((ext) => { + correspondingRestaurant?.restaurant_ext.map((ext) => { return { ISO_language_code: ext.ISO_language_code, text: ext.name, }; - }); + }) || null; return { id: menuItem.menu_item_id, @@ -204,8 +141,8 @@ export class CommonService { restaurant_id: menuItem.restaurant_id, calorie_kcal: menuItem.skus[0].calorie_kcal, rating: menuItem.rating, - distance_km: correspondingRestaurant.distance_km, - delivery_time_s: correspondingRestaurant.delivery_time_s, + distance_km: correspondingRestaurant?.distance_km || null, + delivery_time_s: correspondingRestaurant?.delivery_time_s || null, main_cooking_method: mainCookingMethodByLang, ingredient_brief_vie: menuItem.ingredient_brief_vie, ingredient_brief_eng: menuItem.ingredient_brief_eng, diff --git a/src/feature/restaurant/restaurant.controller.ts b/src/feature/restaurant/restaurant.controller.ts index 8212e45..1f52d5d 100644 --- a/src/feature/restaurant/restaurant.controller.ts +++ b/src/feature/restaurant/restaurant.controller.ts @@ -12,9 +12,6 @@ export class RestaurantController { @MessagePattern({ cmd: 'get_restaurant_details' }) async getRestaurantDetails(restaurant_id: number) { - if (this.flagService.isFeatureEnabled('fes-18-get-restaurant-detail')) { - return await this.restaurantService.getRestaurantDetails(restaurant_id); - } - //CURRENT LOGIC + return await this.restaurantService.getRestaurantDetails(restaurant_id); } } diff --git a/src/feature/restaurant/restaurant.service.ts b/src/feature/restaurant/restaurant.service.ts index ca547d4..8ce13ba 100644 --- a/src/feature/restaurant/restaurant.service.ts +++ b/src/feature/restaurant/restaurant.service.ts @@ -181,157 +181,150 @@ export class RestaurantService { } async getRestaurantDetails(restaurant_id: number) { - if (this.flagService.isFeatureEnabled('fes-18-get-restaurant-detail')) { - const result = new GeneralResponse(200, ''); + const result = new GeneralResponse(200, ''); - const restaurant = await this.entityManager - .createQueryBuilder(Restaurant, 'restaurant') - .leftJoinAndSelect('restaurant.restaurant_ext', 'extension') - .leftJoinAndSelect('restaurant.logo', 'logo') - .leftJoinAndSelect('restaurant.unit_obj', 'unit') - .leftJoinAndSelect('restaurant.address', 'address') - .leftJoinAndSelect('restaurant.menu_items', 'menuItem') - .leftJoinAndSelect('menuItem.menuItemExt', 'menuItemExt') - .leftJoinAndSelect('menuItem.image_obj', 'image') - .leftJoinAndSelect('menuItem.skus', 'sku') - .where('restaurant.restaurant_id = :restaurant_id', { restaurant_id }) - .andWhere('restaurant.is_active = 1') - .andWhere('sku.is_standard = :standard', { - standard: TRUE, - }) - .andWhere('sku.is_active = :active', { active: TRUE }) - .getOne(); + const restaurant = await this.entityManager + .createQueryBuilder(Restaurant, 'restaurant') + .leftJoinAndSelect('restaurant.restaurant_ext', 'extension') + .leftJoinAndSelect('restaurant.logo', 'logo') + .leftJoinAndSelect('restaurant.unit_obj', 'unit') + .leftJoinAndSelect('restaurant.address', 'address') + .leftJoinAndSelect('restaurant.menu_items', 'menuItem') + .leftJoinAndSelect('menuItem.menuItemExt', 'menuItemExt') + .leftJoinAndSelect('menuItem.image_obj', 'image') + .leftJoinAndSelect('menuItem.skus', 'sku') + .where('restaurant.restaurant_id = :restaurant_id', { restaurant_id }) + .andWhere('restaurant.is_active = 1') + .andWhere('sku.is_standard = :standard', { + standard: TRUE, + }) + .andWhere('sku.is_active = :active', { active: TRUE }) + .getOne(); - if (!restaurant) { - result.statusCode = 404; - result.message = 'Restaurant not found'; - return result; - } - - //Get medias - const medias = await this.getAllMediaByRestaurantId(restaurant_id); - - //Convert Restaurant Extension to TextByLang format - const restaurant_ext = await this.convertRestaurantExtToTextByLang( - restaurant.restaurant_ext, - ); + if (!restaurant) { + result.statusCode = 404; + result.message = 'Restaurant not found'; + return result; + } - //Get reviews - const reviews = await this.commonService.getReviewsByRestaurantId( - restaurant_id, - 5, - 'DESC', - ); + //Get medias + const medias = await this.getAllMediaByRestaurantId(restaurant_id); - //Get menu - const menuItems = await restaurant.menu_items; - const convertedMenuItems: FoodDTO[] = []; - let having_vegeterian_food: boolean = false; - const cutoff_time = []; - for (const menuItem of menuItems) { - //Check if having vegeterian food - if (menuItem.is_vegetarian === 1) { - having_vegeterian_food = true; - } + //Convert Restaurant Extension to TextByLang format + const restaurant_ext = await this.convertRestaurantExtToTextByLang( + restaurant.restaurant_ext, + ); - //push cutoff time - cutoff_time.push(menuItem.cutoff_time); + //Get reviews + const reviews = await this.commonService.getReviewsByRestaurantId( + restaurant_id, + 5, + 'DESC', + ); - //Convert to FoodDTO - const foodDTO = await this.commonService.convertIntoFoodDTO(menuItem); - convertedMenuItems.push(foodDTO); + //Get menu + const menuItems = await restaurant.menu_items; + const convertedMenuItems: FoodDTO[] = []; + let having_vegeterian_food: boolean = false; + const cutoff_time = []; + for (const menuItem of menuItems) { + //Check if having vegeterian food + if (menuItem.is_vegetarian === 1) { + having_vegeterian_food = true; } - cutoff_time.sort(); - //Mapping data with output - const data: RestaurantDetailDTO = { - restaurant_id: restaurant.restaurant_id, - medias: medias.map((media) => { - return { - type: media.type, - url: media.url, - }; - }), - address: { - address_line: restaurant.address.address_line, - city: restaurant.address.city, - district: restaurant.address.district, - ward: restaurant.address.ward, - country: restaurant.address.country, - latitude: restaurant.address.latitude, - longitude: restaurant.address.longitude, - }, - logo_img: restaurant.logo.url, - rating: restaurant.rating, - top_food: restaurant.top_food, - promotion: restaurant.promotion, - reviews: reviews, - name: restaurant_ext.name, - specialty: restaurant_ext.specialty, - introduction: restaurant_ext.introduction, - review_total_count: restaurant.review_total_count, - cutoff_time: cutoff_time, - having_vegeterian_food: having_vegeterian_food, - unit: restaurant.unit_obj.symbol, - menu: convertedMenuItems, - }; + //push cutoff time + cutoff_time.push(menuItem.cutoff_time); - result.statusCode = 200; - result.message = 'Getting Restaurant Details Successfully'; - result.data = data; - return result; + //Convert to FoodDTO + const foodDTO = await this.commonService.convertIntoFoodDTO(menuItem); + convertedMenuItems.push(foodDTO); } - //CURRENT LOGIC + cutoff_time.sort(); + + //Mapping data with output + const data: RestaurantDetailDTO = { + restaurant_id: restaurant.restaurant_id, + medias: medias.map((media) => { + return { + type: media.type, + url: media.url, + }; + }), + address: { + address_line: restaurant.address.address_line, + city: restaurant.address.city, + district: restaurant.address.district, + ward: restaurant.address.ward, + country: restaurant.address.country, + latitude: restaurant.address.latitude, + longitude: restaurant.address.longitude, + }, + logo_img: restaurant.logo.url, + rating: restaurant.rating, + top_food: restaurant.top_food, + promotion: restaurant.promotion, + reviews: reviews, + name: restaurant_ext.name, + specialty: restaurant_ext.specialty, + introduction: restaurant_ext.introduction, + review_total_count: restaurant.review_total_count, + cutoff_time: cutoff_time, + having_vegeterian_food: having_vegeterian_food, + unit: restaurant.unit_obj.symbol, + menu: convertedMenuItems, + }; + + result.statusCode = 200; + result.message = 'Getting Restaurant Details Successfully'; + result.data = data; + return result; } async convertRestaurantExtToTextByLang( restaurant_ext: RestaurantExt[], ): Promise { - if (this.flagService.isFeatureEnabled('fes-18-get-restaurant-detail')) { - const result = { - name: [], - specialty: [], - introduction: [], + const result = { + name: [], + specialty: [], + introduction: [], + }; + for (const ext of restaurant_ext) { + //name + const nameByLang: TextByLang = { + ISO_language_code: ext.ISO_language_code, + text: ext.name, }; - for (const ext of restaurant_ext) { - //name - const nameByLang: TextByLang = { - ISO_language_code: ext.ISO_language_code, - text: ext.name, - }; - result.name.push(nameByLang); + result.name.push(nameByLang); - //specialty - const specialtyByLang: TextByLang = { - ISO_language_code: ext.ISO_language_code, - text: ext.specialty, - }; - result.specialty.push(specialtyByLang); + //specialty + const specialtyByLang: TextByLang = { + ISO_language_code: ext.ISO_language_code, + text: ext.specialty, + }; + result.specialty.push(specialtyByLang); - //introduction - const introductionByLang: TextByLang = { - ISO_language_code: ext.ISO_language_code, - text: ext.introduction, - }; - result.introduction.push(introductionByLang); - } - return result; + //introduction + const introductionByLang: TextByLang = { + ISO_language_code: ext.ISO_language_code, + text: ext.introduction, + }; + result.introduction.push(introductionByLang); } + return result; } async getAllMediaByRestaurantId(restaurant_id: number): Promise { - if (this.flagService.isFeatureEnabled('fes-18-get-restaurant-detail')) { - const data = await this.entityManager - .createQueryBuilder(Media, 'media') - .leftJoin( - Restaurant, - 'restaurant', - 'restaurant.intro_video = media.media_id', - ) - .where('restaurant.restaurant_id = :restaurant_id', { restaurant_id }) - .orWhere('media.restaurant_id = :restaurant_id', { restaurant_id }) - .getMany(); - return data; - } + const data = await this.entityManager + .createQueryBuilder(Media, 'media') + .leftJoin( + Restaurant, + 'restaurant', + 'restaurant.intro_video = media.media_id', + ) + .where('restaurant.restaurant_id = :restaurant_id', { restaurant_id }) + .orWhere('media.restaurant_id = :restaurant_id', { restaurant_id }) + .getMany(); + return data; } }