Skip to content

Commit

Permalink
fes-18-get-restaurant-detail (#26)
Browse files Browse the repository at this point in the history
* clear flag
Co-authored-by: NHT <[email protected]>
  • Loading branch information
nfesta2023 authored Jan 2, 2024
1 parent dae468b commit ea90d73
Show file tree
Hide file tree
Showing 3 changed files with 154 additions and 227 deletions.
123 changes: 30 additions & 93 deletions src/feature/common/common.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,35 +31,33 @@ export class CommonService {
limit: number,
order: 'ASC' | 'DESC',
): Promise<Review[]> {
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<SkuDiscount> {
Expand Down Expand Up @@ -103,67 +101,6 @@ export class CommonService {
menuItem: MenuItem,
correspondingRestaurant: DeliveryRestaurant = null,
): Promise<FoodDTO> {
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)) {
Expand All @@ -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,
Expand All @@ -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,
Expand Down
5 changes: 1 addition & 4 deletions src/feature/restaurant/restaurant.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Loading

0 comments on commit ea90d73

Please sign in to comment.