diff --git a/src/dto/sku.dto.ts b/src/dto/sku.dto.ts index bc96e12..4f958b0 100644 --- a/src/dto/sku.dto.ts +++ b/src/dto/sku.dto.ts @@ -1,4 +1,5 @@ export class SkuDTO { + sku_id: number; price: number; price_after_discount: number; unit: string; diff --git a/src/feature/food/food.controller.ts b/src/feature/food/food.controller.ts index 601ade1..7064033 100644 --- a/src/feature/food/food.controller.ts +++ b/src/feature/food/food.controller.ts @@ -17,9 +17,6 @@ export class FoodController { @MessagePattern({ cmd: 'get_list_of_sku_by_id' }) async getListOfSkuById(id: number) { - if (this.flagService.isFeatureEnabled('fes-16-get-list-of-skus')) { - return await this.foodService.getListOfSkuById(id); - } - //CURRENT LOGIC + return await this.foodService.getListOfSkuById(id); } } diff --git a/src/feature/food/food.service.ts b/src/feature/food/food.service.ts index 29c4783..69abacf 100644 --- a/src/feature/food/food.service.ts +++ b/src/feature/food/food.service.ts @@ -456,90 +456,82 @@ export class FoodService { } async getListOfSkuById(id: number) { - if (this.flagService.isFeatureEnabled('fes-16-get-list-of-skus')) { - const result = new GeneralResponse(200, ''); - - const data: SkuDTO[] = []; - - const rawSKUs = await this.entityManager - .createQueryBuilder(SKU, 'sku') - .leftJoinAndSelect('sku.menu_item_variants', 'variant') - .leftJoinAndSelect('variant.attribute', 'attribute') - .where('sku.menu_item_id = :id', { id }) - .andWhere('sku.is_active = :active', { active: TRUE }) - .getMany(); - - if (rawSKUs.length === 0) { - result.statusCode = 404; - result.message = 'SKUs not found'; - return result; - } + const result = new GeneralResponse(200, ''); - const priceUnit = await this.getMenuItemPriceUnit(id); - - for (const rawSKU of rawSKUs) { - const sku: SkuDTO = { - price: rawSKU.price, - price_after_discount: - await this.commonService.getAvailableDiscountPrice(rawSKU), - unit: priceUnit, - is_standard: Boolean(rawSKU.is_standard), - calorie_kcal: rawSKU.calorie_kcal, - carb_g: rawSKU.carbohydrate_g, - protein_g: rawSKU.protein_g, - fat_g: rawSKU.fat_g, - portion_customization: rawSKU.menu_item_variants - .filter((i) => i.attribute.type == 'portion') - .map((e) => { - return { - option_id: e.variant.toString(), - value_id: e.option.toString(), - }; - }), - }; + const data: SkuDTO[] = []; - data.push(sku); - } + const rawSKUs = await this.entityManager + .createQueryBuilder(SKU, 'sku') + .leftJoinAndSelect('sku.menu_item_variants', 'variant') + .leftJoinAndSelect('variant.attribute', 'attribute') + .where('sku.menu_item_id = :id', { id }) + .andWhere('sku.is_active = :active', { active: TRUE }) + .getMany(); - result.statusCode = 200; - result.message = 'Getting List Of SKUs Successfully'; - result.data = data; + if (rawSKUs.length === 0) { + result.statusCode = 404; + result.message = 'SKUs not found'; return result; } - //CURRENT LOGIC + + const priceUnit = await this.getMenuItemPriceUnit(id); + + for (const rawSKU of rawSKUs) { + const sku: SkuDTO = { + sku_id: rawSKU.sku_id, + price: rawSKU.price, + price_after_discount: + await this.commonService.getAvailableDiscountPrice(rawSKU), + unit: priceUnit, + is_standard: Boolean(rawSKU.is_standard), + calorie_kcal: rawSKU.calorie_kcal, + carb_g: rawSKU.carbohydrate_g, + protein_g: rawSKU.protein_g, + fat_g: rawSKU.fat_g, + portion_customization: rawSKU.menu_item_variants + .filter((i) => i.attribute.type == 'portion') + .map((e) => { + return { + option_id: e.variant.toString(), + value_id: e.option.toString(), + }; + }), + }; + + data.push(sku); + } + + result.statusCode = 200; + result.message = 'Getting List Of SKUs Successfully'; + result.data = data; + return result; } async getSkuPriceUnit(sku_id: number) { - if (this.flagService.isFeatureEnabled('fes-16-get-list-of-skus')) { - const unit = await this.entityManager - .createQueryBuilder(Unit, 'unit') - .leftJoin(Restaurant, 'restaurant', 'restaurant.unit = unit.unit_id') - .leftJoin( - MenuItem, - 'menuItem', - 'menuItem.restaurant_id = restaurant.restaurant_id', - ) - .leftJoin(SKU, 'sku', 'sku.menu_item_id = menuItem.menu_item_id') - .where('sku.sku_id = :sku_id', { sku_id }) - .getOne(); - return unit.symbol; - } - //CURRENT LOGIC + const unit = await this.entityManager + .createQueryBuilder(Unit, 'unit') + .leftJoin(Restaurant, 'restaurant', 'restaurant.unit = unit.unit_id') + .leftJoin( + MenuItem, + 'menuItem', + 'menuItem.restaurant_id = restaurant.restaurant_id', + ) + .leftJoin(SKU, 'sku', 'sku.menu_item_id = menuItem.menu_item_id') + .where('sku.sku_id = :sku_id', { sku_id }) + .getOne(); + return unit.symbol; } async getMenuItemPriceUnit(menu_item_id: number) { - if (this.flagService.isFeatureEnabled('fes-16-get-list-of-skus')) { - const unit = await this.entityManager - .createQueryBuilder(Unit, 'unit') - .leftJoin(Restaurant, 'restaurant', 'restaurant.unit = unit.unit_id') - .leftJoin( - MenuItem, - 'menuItem', - 'menuItem.restaurant_id = restaurant.restaurant_id', - ) - .where('menuItem.menu_item_id = :menu_item_id', { menu_item_id }) - .getOne(); - return unit.symbol; - } - //CURRENT LOGIC + const unit = await this.entityManager + .createQueryBuilder(Unit, 'unit') + .leftJoin(Restaurant, 'restaurant', 'restaurant.unit = unit.unit_id') + .leftJoin( + MenuItem, + 'menuItem', + 'menuItem.restaurant_id = restaurant.restaurant_id', + ) + .where('menuItem.menu_item_id = :menu_item_id', { menu_item_id }) + .getOne(); + return unit.symbol; } }