diff --git a/src/entity/menu-item-variant-ext.entity.ts b/src/entity/menu-item-attribute-ext.entity.ts similarity index 55% rename from src/entity/menu-item-variant-ext.entity.ts rename to src/entity/menu-item-attribute-ext.entity.ts index b2a9a58..f2e567d 100644 --- a/src/entity/menu-item-variant-ext.entity.ts +++ b/src/entity/menu-item-attribute-ext.entity.ts @@ -6,12 +6,12 @@ import { ManyToOne, JoinColumn, } from 'typeorm'; -import { MenuItemVariant } from './menu-item-variant.entity'; +import { MenuItemAttribute } from './menu-item-attribute.entity'; -@Entity('Menu_Item_Variant_Ext') -export class MenuItemVariantExt { +@Entity('Menu_Item_Attribute_Ext') +export class MenuItemAttributeExt { @PrimaryColumn() - public menu_item_variant_id: number; + public attribute_id: number; @PrimaryColumn() public ISO_language_code: string; @@ -30,12 +30,12 @@ export class MenuItemVariantExt { //RELATIONSHIPS @ManyToOne( - () => MenuItemVariant, - (menu_item_variant) => menu_item_variant.menu_item_variant_ext_obj, + () => MenuItemAttribute, + (attribute) => attribute.menu_item_attribute_ext_obj, ) @JoinColumn({ - name: 'menu_item_variant_id', - referencedColumnName: 'menu_item_variant_id', + name: 'attribute_id', + referencedColumnName: 'attribute_id', }) - public menu_item_variant_obj: MenuItemVariant; + public menu_item_attribute_obj: MenuItemAttribute; } diff --git a/src/entity/menu-item-variant-option.entity.ts b/src/entity/menu-item-attribute-value.entity.ts similarity index 72% rename from src/entity/menu-item-variant-option.entity.ts rename to src/entity/menu-item-attribute-value.entity.ts index 4f3b75a..96cbb3e 100644 --- a/src/entity/menu-item-variant-option.entity.ts +++ b/src/entity/menu-item-attribute-value.entity.ts @@ -7,17 +7,17 @@ import { JoinColumn, OneToMany, } from 'typeorm'; -import { MenuItemVariant } from './menu-item-variant.entity'; +import { MenuItemAttribute } from './menu-item-attribute.entity'; import { Unit } from './unit.entity'; import { TasteValueExt } from './taste-value-ext.entity'; -@Entity('Menu_Item_Variant_Option') -export class MenuItemVariantOpion { +@Entity('Menu_Item_Attribute_Value') +export class MenuItemAttributeValue { @PrimaryGeneratedColumn() - public menu_item_variant_option_id: number; + public value_id: number; @Column({ type: 'int', nullable: false, unique: false }) - public menu_item_variant_id: number; + public attribute_id: number; @Column({ type: 'int', nullable: true, unique: false }) public value: number; @@ -42,14 +42,14 @@ export class MenuItemVariantOpion { //RELATIONSHIP @ManyToOne( - () => MenuItemVariant, - (menuItemVariant) => menuItemVariant.options, + () => MenuItemAttribute, + (menuItemAttribute) => menuItemAttribute.values, ) @JoinColumn({ - name: 'menu_item_variant_id', - referencedColumnName: 'menu_item_variant_id', + name: 'attribute_id', + referencedColumnName: 'attribute_id', }) - public menu_item_variant_obj: MenuItemVariant; + public attribute_obj: MenuItemAttribute; @ManyToOne(() => Unit) @JoinColumn({ diff --git a/src/entity/menu-item-variant.entity.ts b/src/entity/menu-item-attribute.entity.ts similarity index 55% rename from src/entity/menu-item-variant.entity.ts rename to src/entity/menu-item-attribute.entity.ts index 5376267..0f76971 100644 --- a/src/entity/menu-item-variant.entity.ts +++ b/src/entity/menu-item-attribute.entity.ts @@ -5,20 +5,20 @@ import { Column, OneToMany, } from 'typeorm'; -import { MenuItemVariantExt } from './menu-item-variant-ext.entity'; -import { MenuItemVariantOpion } from './menu-item-variant-option.entity'; +import { MenuItemAttributeExt } from './menu-item-attribute-ext.entity'; +import { MenuItemAttributeValue } from './menu-item-attribute-value.entity'; import { TasteExt } from './taste-ext.entity'; -@Entity('Menu_Item_Variant') -export class MenuItemVariant { +@Entity('Menu_Item_Attribute') +export class MenuItemAttribute { @PrimaryGeneratedColumn() - public menu_item_variant_id: number; + public attribute_id: number; @Column({ type: 'int', nullable: false, unique: false }) public menu_item_id: number; @Column({ type: 'varchar', length: 45, nullable: true, unique: false }) - public type: string; + public type_id: string; @Column({ type: 'varchar', length: 45, nullable: true, unique: false }) public taste_id: string; @@ -32,17 +32,11 @@ export class MenuItemVariant { public created_at: Date; //RELATIONSHIPS - @OneToMany( - () => MenuItemVariantExt, - (menuItemVariantExt) => menuItemVariantExt.menu_item_variant_obj, - ) - public menu_item_variant_ext_obj: MenuItemVariantExt[]; - - @OneToMany( - () => MenuItemVariantOpion, - (option) => option.menu_item_variant_obj, - ) - public options: MenuItemVariantOpion[]; + @OneToMany(() => MenuItemAttributeExt, (ext) => ext.menu_item_attribute_obj) + public menu_item_attribute_ext_obj: MenuItemAttributeExt[]; + + @OneToMany(() => MenuItemAttributeValue, (value) => value.attribute_obj) + public values: MenuItemAttributeValue[]; @OneToMany(() => TasteExt, (tasteExt) => tasteExt.taste) public taste_ext: TasteExt[]; diff --git a/src/entity/sku-detail.entity.ts b/src/entity/sku-detail.entity.ts new file mode 100644 index 0000000..dec7b33 --- /dev/null +++ b/src/entity/sku-detail.entity.ts @@ -0,0 +1,54 @@ +import { + Entity, + CreateDateColumn, + PrimaryColumn, + Column, + ManyToOne, + JoinColumn, +} from 'typeorm'; +import { SKU } from './sku.entity'; +import { MenuItemAttribute } from './menu-item-attribute.entity'; +import { MenuItemAttributeValue } from './menu-item-attribute-value.entity'; + +@Entity('SKU_Detail') +export class SkuDetail { + @PrimaryColumn() + public sku_id: number; + + @PrimaryColumn() + public attribute_id: number; + + @Column({ type: 'int', nullable: false, unique: false }) + public value_id: number; + + @CreateDateColumn({ + type: 'datetime', + nullable: false, + unique: false, + default: () => 'CURRENT_TIMESTAMP', + }) + public created_at: Date; + + //RELATIONSHIPS + + @ManyToOne(() => SKU, (sku) => sku.detail) + @JoinColumn({ + name: 'sku_id', + referencedColumnName: 'sku_id', + }) + public sku_obj: SKU; + + @ManyToOne(() => MenuItemAttribute) + @JoinColumn({ + name: 'attribute_id', + referencedColumnName: 'attribute_id', + }) + public attribute_obj: MenuItemAttribute; + + @ManyToOne(() => MenuItemAttributeValue) + @JoinColumn({ + name: 'value_id', + referencedColumnName: 'value_id', + }) + public value_obj: MenuItemAttributeValue; +} diff --git a/src/entity/sku-menu-item-variant.entity.ts b/src/entity/sku-menu-item-variant.entity.ts deleted file mode 100644 index 6e57da3..0000000 --- a/src/entity/sku-menu-item-variant.entity.ts +++ /dev/null @@ -1,54 +0,0 @@ -import { - Entity, - CreateDateColumn, - PrimaryColumn, - Column, - ManyToOne, - JoinColumn, -} from 'typeorm'; -import { SKU } from './sku.entity'; -import { MenuItemVariant } from './menu-item-variant.entity'; -import { MenuItemVariantOpion } from './menu-item-variant-option.entity'; - -@Entity('SKU_Menu_Item_Variant') -export class SkuMenuItemVariant { - @PrimaryColumn() - public sku_id: number; - - @PrimaryColumn() - public variant: number; - - @Column({ type: 'int', nullable: false, unique: false }) - public option: number; - - @CreateDateColumn({ - type: 'datetime', - nullable: false, - unique: false, - default: () => 'CURRENT_TIMESTAMP', - }) - public created_at: Date; - - //RELATIONSHIPS - - @ManyToOne(() => SKU, (sku) => sku.menu_item_variants) - @JoinColumn({ - name: 'sku_id', - referencedColumnName: 'sku_id', - }) - public sku_obj: SKU; - - @ManyToOne(() => MenuItemVariant) - @JoinColumn({ - name: 'variant', - referencedColumnName: 'menu_item_variant_id', - }) - public attribute: MenuItemVariant; - - @ManyToOne(() => MenuItemVariantOpion) - @JoinColumn({ - name: 'option', - referencedColumnName: 'menu_item_variant_option_id', - }) - public value: MenuItemVariantOpion; -} diff --git a/src/entity/sku.entity.ts b/src/entity/sku.entity.ts index 9f5fcbb..e961e5b 100644 --- a/src/entity/sku.entity.ts +++ b/src/entity/sku.entity.ts @@ -9,7 +9,7 @@ import { } from 'typeorm'; import { MenuItem } from './menu-item.entity'; import { OrderSKU } from './order-sku.entity'; -import { SkuMenuItemVariant } from './sku-menu-item-variant.entity'; +import { SkuDetail } from './sku-detail.entity'; import { SkuDiscount } from './sku-discount.entity'; @Entity('SKU') @@ -96,8 +96,8 @@ export class SKU { @OneToMany(() => OrderSKU, (orderSKU) => orderSKU.sku_obj) public order_sku_obj: OrderSKU[]; - @OneToMany(() => SkuMenuItemVariant, (variant) => variant.sku_obj) - public menu_item_variants: SkuMenuItemVariant[]; + @OneToMany(() => SkuDetail, (detail) => detail.sku_obj) + public detail: SkuDetail[]; @OneToMany(() => SkuDiscount, (discount) => discount.sku_obj) public discount: SkuDiscount[]; diff --git a/src/entity/taste-ext.entity.ts b/src/entity/taste-ext.entity.ts index 9859dee..a83bc6f 100644 --- a/src/entity/taste-ext.entity.ts +++ b/src/entity/taste-ext.entity.ts @@ -6,7 +6,7 @@ import { ManyToOne, JoinColumn, } from 'typeorm'; -import { MenuItemVariant } from './menu-item-variant.entity'; +import { MenuItemAttribute } from './menu-item-attribute.entity'; @Entity('Taste_Ext') export class TasteExt { @@ -31,10 +31,10 @@ export class TasteExt { public created_at: Date; //RELATIONSHIPS - @ManyToOne(() => MenuItemVariant, (variant) => variant.taste_ext) + @ManyToOne(() => MenuItemAttribute, (attribute) => attribute.taste_ext) @JoinColumn({ name: 'taste_id', referencedColumnName: 'taste_id', }) - public taste: MenuItemVariant; + public taste: MenuItemAttribute; } diff --git a/src/entity/taste-value-ext.entity.ts b/src/entity/taste-value-ext.entity.ts index 6ff16c8..aa9a88b 100644 --- a/src/entity/taste-value-ext.entity.ts +++ b/src/entity/taste-value-ext.entity.ts @@ -6,7 +6,7 @@ import { ManyToOne, JoinColumn, } from 'typeorm'; -import { MenuItemVariantOpion } from './menu-item-variant-option.entity'; +import { MenuItemAttributeValue } from './menu-item-attribute-value.entity'; @Entity('Taste_Value_Ext') export class TasteValueExt { @@ -33,12 +33,12 @@ export class TasteValueExt { //RELATIONSHIPS @ManyToOne( - () => MenuItemVariantOpion, - (menuItemVariantOpion) => menuItemVariantOpion.taste_value_ext, + () => MenuItemAttributeValue, + (attValue) => attValue.taste_value_ext, ) @JoinColumn({ name: 'value_id', referencedColumnName: 'taste_value', }) - public taste_value_obj: MenuItemVariantOpion; + public taste_value_obj: MenuItemAttributeValue; } diff --git a/src/feature/common/common.module.ts b/src/feature/common/common.module.ts index 54007df..afe2566 100644 --- a/src/feature/common/common.module.ts +++ b/src/feature/common/common.module.ts @@ -12,15 +12,15 @@ import { FoodRating } from 'src/entity/food-rating.entity'; import { OrderSKU } from 'src/entity/order-sku.entity'; import { Packaging } from 'src/entity/packaging.entity'; import { PackagingExt } from 'src/entity/packaging-ext.entity'; -import { MenuItemVariant } from 'src/entity/menu-item-variant.entity'; -import { MenuItemVariantExt } from 'src/entity/menu-item-variant-ext.entity'; -import { MenuItemVariantOpion } from 'src/entity/menu-item-variant-option.entity'; +import { MenuItemAttribute } from 'src/entity/menu-item-attribute.entity'; +import { MenuItemAttributeExt } from 'src/entity/menu-item-attribute-ext.entity'; +import { MenuItemAttributeValue } from 'src/entity/menu-item-attribute-value.entity'; import { TasteExt } from 'src/entity/taste-ext.entity'; import { TasteValueExt } from 'src/entity/taste-value-ext.entity'; import { BasicCustomization } from 'src/entity/basic-customization.entity'; import { NoAddingExt } from 'src/entity/no-adding-ext.entity'; import { RestaurantExt } from 'src/entity/restaurant-ext.entity'; -import { SkuMenuItemVariant } from 'src/entity/sku-menu-item-variant.entity'; +import { SkuDetail } from 'src/entity/sku-detail.entity'; @Global() @Module({ @@ -37,15 +37,15 @@ import { SkuMenuItemVariant } from 'src/entity/sku-menu-item-variant.entity'; OrderSKU, Packaging, PackagingExt, - MenuItemVariant, - MenuItemVariantExt, - MenuItemVariantOpion, + MenuItemAttribute, + MenuItemAttributeExt, + MenuItemAttributeValue, TasteExt, TasteValueExt, BasicCustomization, NoAddingExt, RestaurantExt, - SkuMenuItemVariant, + SkuDetail, ]), ], exports: [CommonService], diff --git a/src/feature/common/common.service.ts b/src/feature/common/common.service.ts index 792aee0..b24db5e 100644 --- a/src/feature/common/common.service.ts +++ b/src/feature/common/common.service.ts @@ -18,10 +18,10 @@ import { SKU } from 'src/entity/sku.entity'; import { PERCENTAGE } from 'src/constant/unit.constant'; import { MenuItem } from 'src/entity/menu-item.entity'; import { FoodDTO } from 'src/dto/food.dto'; -import { MenuItemVariant } from 'src/entity/menu-item-variant.entity'; -import { MenuItemVariantOpion } from 'src/entity/menu-item-variant-option.entity'; +import { MenuItemAttribute } from 'src/entity/menu-item-attribute.entity'; +import { MenuItemAttributeValue } from 'src/entity/menu-item-attribute-value.entity'; import { NoAddingExt } from 'src/entity/no-adding-ext.entity'; -import { SkuMenuItemVariant } from 'src/entity/sku-menu-item-variant.entity'; +import { SkuDetail } from 'src/entity/sku-detail.entity'; import { BasicCustomization } from 'src/entity/basic-customization.entity'; @Injectable() @@ -186,64 +186,61 @@ export class CommonService { return result; } - const menuItemVariantIds = obj_list.map((i) => i.option_id); - const menuItemVariants = await this.entityManager - .createQueryBuilder(MenuItemVariant, 'menuItemVariant') - .leftJoinAndSelect('menuItemVariant.taste_ext', 'taseExt') - .where( - 'menuItemVariant.menu_item_variant_id IN (:...menuItemVariantIds)', - { menuItemVariantIds }, - ) - .andWhere('menuItemVariant.type = :type', { type: 'taste' }) + const menuItemAttributeIds = obj_list.map((i) => i.option_id); + const menuItemAttributes = await this.entityManager + .createQueryBuilder(MenuItemAttribute, 'menuItemAttribute') + .leftJoinAndSelect('menuItemAttribute.taste_ext', 'taseExt') + .where('menuItemAttribute.attribute_id IN (:...menuItemAttributeIds)', { + menuItemAttributeIds, + }) + .andWhere('menuItemAttribute.type_id = :type', { type: 'taste' }) .andWhere('taseExt.ISO_language_code = :lang', { lang }) .getMany(); - const menuItemVariantOptionIds = obj_list.map((i) => i.value_id); - const menuItemVariantOptions = await this.entityManager - .createQueryBuilder(MenuItemVariantOpion, 'option') - .leftJoinAndSelect('option.taste_value_ext', 'ext') - .where( - 'option.menu_item_variant_option_id IN (:...menuItemVariantOptionIds)', - { menuItemVariantOptionIds }, - ) - .andWhere('option.taste_value <> :tasteVal', { tasteVal: 'original' }) //dont generate note for original options + const menuItemAttributeValueIds = obj_list.map((i) => i.value_id); + const menuItemAttributeValues = await this.entityManager + .createQueryBuilder(MenuItemAttributeValue, 'attValue') + .leftJoinAndSelect('attValue.taste_value_ext', 'ext') + .where('attValue.value_id IN (:...menuItemAttributeValueIds)', { + menuItemAttributeValueIds, + }) + .andWhere('attValue.taste_value <> :tasteVal', { tasteVal: 'original' }) //dont generate note for original options .andWhere('ext.ISO_language_code = :lang', { lang }) .getMany(); const strArr = []; for (const option of obj_list) { let str = ''; - const menuItemVariant = menuItemVariants.find( - (i) => i.menu_item_variant_id.toString() == option.option_id, + const menuItemAttribute = menuItemAttributes.find( + (i) => i.attribute_id.toString() == option.option_id, ); //check if the option_id has been filtered out - if (!menuItemVariant) { + if (!menuItemAttribute) { continue; } - const menuItemVariantOption = menuItemVariantOptions.find( - (i) => i.menu_item_variant_option_id.toString() == option.value_id, + const menuItemAttributeValue = menuItemAttributeValues.find( + (i) => i.value_id.toString() == option.value_id, ); // check if the value_id has been filtered out - if (!menuItemVariantOption) { + if (!menuItemAttributeValue) { continue; } - //check if the option_id and value_id is consistent - belong to the same menu_item_variant_id + //check if the option_id and value_id is consistent - belong to the same attribute_id if ( - menuItemVariantOption.menu_item_variant_id != - menuItemVariant.menu_item_variant_id + menuItemAttributeValue.attribute_id != menuItemAttribute.attribute_id ) { console.log( - 'menuItemVariantOption ', - menuItemVariantOption.menu_item_variant_option_id, - ' does not belong to menuItemVariant ', - menuItemVariant.menu_item_variant_id, + 'menuItemAttributeValue ', + menuItemAttributeValue.value_id, + ' does not belong to menuItemAttribute ', + menuItemAttribute.attribute_id, ); continue; } str = - menuItemVariantOption.taste_value_ext[0].name + + menuItemAttributeValue.taste_value_ext[0].name + ' ' + - menuItemVariant.taste_ext[0].name; + menuItemAttribute.taste_ext[0].name; strArr.push(str); } @@ -296,31 +293,31 @@ export class CommonService { if (this.flagService.isFeatureEnabled('fes-24-add-to-cart')) { let result: string = ''; - const variants = await this.entityManager - .createQueryBuilder(SkuMenuItemVariant, 'variant') - .leftJoinAndSelect('variant.attribute', 'attribute') + const skuDetail = await this.entityManager + .createQueryBuilder(SkuDetail, 'skuDetail') + .leftJoinAndSelect('skuDetail.attribute_obj', 'attribute') .leftJoinAndSelect( - 'attribute.menu_item_variant_ext_obj', + 'attribute.menu_item_attribute_ext_obj', 'attributeExt', ) - .leftJoinAndSelect('variant.value', 'value') + .leftJoinAndSelect('skuDetail.value_obj', 'value') .leftJoinAndSelect('value.unit_obj', 'unit') - .where('variant.sku_id = :sku_id', { sku_id }) + .where('skuDetail.sku_id = :sku_id', { sku_id }) .andWhere('attributeExt.ISO_language_code = :lang', { lang }) .getMany(); - if (variants.length == 0) { + if (skuDetail.length == 0) { result = ''; return result; } - result = variants + result = skuDetail .map((i) => { return ( - i.attribute.menu_item_variant_ext_obj[0].name + + i.attribute_obj.menu_item_attribute_ext_obj[0].name + ' ' + - i.value.value + - i.value.unit_obj.symbol + i.value_obj.value + + i.value_obj.unit_obj.symbol ); }) .join(' - '); @@ -343,14 +340,14 @@ export class CommonService { } async getTasteCustomizationByMenuItemId( menu_item_id: number, - ): Promise { + ): Promise { const data = await this.entityManager - .createQueryBuilder(MenuItemVariant, 'variant') - .leftJoinAndSelect('variant.options', 'options') - .leftJoinAndSelect('variant.taste_ext', 'tasteExt') - .leftJoinAndSelect('options.taste_value_ext', 'tasteValueExt') - .where('variant.menu_item_id = :menu_item_id', { menu_item_id }) - .andWhere("variant.type = 'taste'") + .createQueryBuilder(MenuItemAttribute, 'attribute') + .leftJoinAndSelect('attribute.values', 'values') + .leftJoinAndSelect('attribute.taste_ext', 'tasteExt') + .leftJoinAndSelect('values.taste_value_ext', 'tasteValueExt') + .where('attribute.menu_item_id = :menu_item_id', { menu_item_id }) + .andWhere("attribute.type_id = 'taste'") .getMany(); return data; } @@ -368,17 +365,17 @@ export class CommonService { }; const avaibleAdvanceTasteCustomizationList = await this.entityManager - .createQueryBuilder(MenuItemVariant, 'variant') - .leftJoinAndSelect('variant.options', 'options') - .where('variant.menu_item_id = :menu_item_id', { + .createQueryBuilder(MenuItemAttribute, 'attribute') + .leftJoinAndSelect('attribute.values', 'values') + .where('attribute.menu_item_id = :menu_item_id', { menu_item_id, }) - .andWhere("variant.type = 'taste'") + .andWhere("attribute.type_id = 'taste'") .getMany(); for (const obj of obj_list) { //find the attribute const attribute = avaibleAdvanceTasteCustomizationList.find( - (i) => i.menu_item_variant_id.toString() == obj.option_id, + (i) => i.attribute_id.toString() == obj.option_id, ); if (!attribute) { result.isValid = false; @@ -386,8 +383,8 @@ export class CommonService { break; } //check the value - const value = attribute.options.find( - (i) => i.menu_item_variant_option_id.toString() == obj.value_id, + const value = attribute.values.find( + (i) => i.value_id.toString() == obj.value_id, ); if (!value) { result.isValid = false; diff --git a/src/feature/food/food.module.ts b/src/feature/food/food.module.ts index 76ea8d9..d1ac9bf 100644 --- a/src/feature/food/food.module.ts +++ b/src/feature/food/food.module.ts @@ -13,12 +13,12 @@ import { FoodRating } from 'src/entity/food-rating.entity'; import { OrderSKU } from 'src/entity/order-sku.entity'; import { Packaging } from 'src/entity/packaging.entity'; import { PackagingExt } from 'src/entity/packaging-ext.entity'; -import { MenuItemVariant } from 'src/entity/menu-item-variant.entity'; -import { MenuItemVariantExt } from 'src/entity/menu-item-variant-ext.entity'; -import { MenuItemVariantOpion } from 'src/entity/menu-item-variant-option.entity'; +import { MenuItemAttribute } from 'src/entity/menu-item-attribute.entity'; +import { MenuItemAttributeExt } from 'src/entity/menu-item-attribute-ext.entity'; +import { MenuItemAttributeValue } from 'src/entity/menu-item-attribute-value.entity'; import { TasteExt } from 'src/entity/taste-ext.entity'; import { TasteValueExt } from 'src/entity/taste-value-ext.entity'; -import { SkuMenuItemVariant } from 'src/entity/sku-menu-item-variant.entity'; +import { SkuDetail } from 'src/entity/sku-detail.entity'; import { BasicCustomization } from 'src/entity/basic-customization.entity'; import { NoAddingExt } from 'src/entity/no-adding-ext.entity'; import { MainSideDish } from 'src/entity/main-side-dish.entity'; @@ -37,12 +37,12 @@ import { MainSideDish } from 'src/entity/main-side-dish.entity'; OrderSKU, Packaging, PackagingExt, - MenuItemVariant, - MenuItemVariantExt, - MenuItemVariantOpion, + MenuItemAttribute, + MenuItemAttributeExt, + MenuItemAttributeValue, TasteExt, TasteValueExt, - SkuMenuItemVariant, + SkuDetail, BasicCustomization, NoAddingExt, MainSideDish, diff --git a/src/feature/food/food.service.ts b/src/feature/food/food.service.ts index 9efbad5..a1d38ea 100644 --- a/src/feature/food/food.service.ts +++ b/src/feature/food/food.service.ts @@ -20,11 +20,10 @@ import { FoodRating } from 'src/entity/food-rating.entity'; import { Media } from 'src/entity/media.entity'; import { Packaging } from 'src/entity/packaging.entity'; import { Recipe } from 'src/entity/recipe.entity'; -import { MenuItemVariant } from 'src/entity/menu-item-variant.entity'; +import { MenuItemAttribute } from 'src/entity/menu-item-attribute.entity'; import { SkuDTO } from 'src/dto/sku.dto'; import { Unit } from 'src/entity/unit.entity'; import { Restaurant } from 'src/entity/restaurant.entity'; -import { BasicCustomization } from 'src/entity/basic-customization.entity'; import { CommonService } from '../common/common.service'; import { GetSideDishRequest } from './dto/get-side-dish-request.dto'; import { GetSideDishResonse } from './dto/get-side-dish-response.dto'; @@ -50,6 +49,7 @@ export class FoodService { 'SELECT min(sku.price) as min, max(sku.price) as max FROM SKU as sku where sku.menu_item_id IN (' + menuItemList.join(',') + ') and sku.is_standard = 1'; + const rawData = await this.menuItemRepo.query(query); const range: PriceRange = { min: rawData[0].min, @@ -330,45 +330,18 @@ export class FoodService { async getPortionCustomizationByMenuItemId( menu_item_id: number, - ): Promise { + ): Promise { const data = await this.entityManager - .createQueryBuilder(MenuItemVariant, 'variant') - .leftJoinAndSelect('variant.menu_item_variant_ext_obj', 'ext') - .leftJoinAndSelect('variant.options', 'options') - .leftJoinAndSelect('options.unit_obj', 'unit') - .where('variant.menu_item_id = :menu_item_id', { menu_item_id }) - .andWhere("variant.type = 'portion'") + .createQueryBuilder(MenuItemAttribute, 'attribute') + .leftJoinAndSelect('attribute.menu_item_attribute_ext_obj', 'ext') + .leftJoinAndSelect('attribute.values', 'values') + .leftJoinAndSelect('values.unit_obj', 'unit') + .where('attribute.menu_item_id = :menu_item_id', { menu_item_id }) + .andWhere("attribute.type_id = 'portion'") .getMany(); return data; } - // async getTasteCustomizationByMenuItemId( - // menu_item_id: number, - // ): Promise { - // const data = await this.entityManager - // .createQueryBuilder(MenuItemVariant, 'variant') - // .leftJoinAndSelect('variant.options', 'options') - // .leftJoinAndSelect('variant.taste_ext', 'tasteExt') - // .leftJoinAndSelect('options.taste_value_ext', 'tasteValueExt') - // .where('variant.menu_item_id = :menu_item_id', { menu_item_id }) - // .andWhere("variant.type = 'taste'") - // .getMany(); - // return data; - // } - - // async getBasicCustomizationByMenuItemId( - // menu_item_id: number, - // ): Promise { - // const data = await this.entityManager - // .createQueryBuilder(BasicCustomization, 'basicCustomization') - // .leftJoinAndSelect('basicCustomization.extension', 'ext') - // .where('basicCustomization.menu_item_id = :menu_item_id', { - // menu_item_id, - // }) - // .getMany(); - // return data; - // } - async generatePackageSentenceByLang(packageInfo: Packaging[]) { const sentenceByLang: TextByLang[] = []; for (const item of packageInfo) { @@ -384,17 +357,17 @@ export class FoodService { } async convertPortionCustomization( - portionCustomization: MenuItemVariant[], + portionCustomization: MenuItemAttribute[], ): Promise { const options: Option[] = []; for (const item of portionCustomization) { const option: Option = { - option_id: item.menu_item_variant_id.toString(), + option_id: item.attribute_id.toString(), option_name: [], option_values: [], }; //Option Name - item.menu_item_variant_ext_obj.forEach((ext) => { + item.menu_item_attribute_ext_obj.forEach((ext) => { const optionNameExt: TextByLang = { ISO_language_code: ext.ISO_language_code, text: ext.name, @@ -403,9 +376,9 @@ export class FoodService { }); //Option Values - item.options.forEach((optionValue) => { + item.values.forEach((optionValue) => { const value = {} as OptionValue; - value.value_id = optionValue.menu_item_variant_option_id.toString(); + value.value_id = optionValue.value_id.toString(); value.value_nubmer = optionValue.value; value.value_unit = optionValue.unit_obj.symbol; option.option_values.push(value); @@ -417,12 +390,12 @@ export class FoodService { } async convertTasteCustomization( - tasteCustomization: MenuItemVariant[], + tasteCustomization: MenuItemAttribute[], ): Promise { const options: Option[] = []; for (const item of tasteCustomization) { const option: Option = { - option_id: item.menu_item_variant_id.toString(), + option_id: item.attribute_id.toString(), option_name: [], option_values: [], }; @@ -436,9 +409,9 @@ export class FoodService { }); //Option Values - item.options.forEach((optionValue) => { + item.values.forEach((optionValue) => { const value = {} as OptionValue; - value.value_id = optionValue.menu_item_variant_option_id.toString(); + value.value_id = optionValue.value_id.toString(); value.value_txt = optionValue.taste_value_ext.map((ext) => { return { ISO_language_code: ext.ISO_language_code, @@ -460,8 +433,8 @@ export class FoodService { const rawSKUs = await this.entityManager .createQueryBuilder(SKU, 'sku') - .leftJoinAndSelect('sku.menu_item_variants', 'variant') - .leftJoinAndSelect('variant.attribute', 'attribute') + .leftJoinAndSelect('sku.detail', 'skuDetail') + .leftJoinAndSelect('skuDetail.attribute_obj', 'attribute') .where('sku.menu_item_id = :id', { id }) .andWhere('sku.is_active = :active', { active: TRUE }) .getMany(); @@ -486,12 +459,12 @@ export class FoodService { 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') + portion_customization: rawSKU.detail + .filter((i) => i.attribute_obj.type_id == 'portion') .map((e) => { return { - option_id: e.variant.toString(), - value_id: e.option.toString(), + option_id: e.attribute_id.toString(), + value_id: e.value_id.toString(), }; }), }; diff --git a/src/feature/recommendation/recommendation.service.ts b/src/feature/recommendation/recommendation.service.ts index a04c2d2..8fafae2 100644 --- a/src/feature/recommendation/recommendation.service.ts +++ b/src/feature/recommendation/recommendation.service.ts @@ -71,6 +71,11 @@ export class RecommendationService { for (const restaurant of restaurants) { const menuItems = await restaurant.menu_items; + + //remove the restaurant which having no menu item + if (menuItems.length <= 0) { + continue; + } const priceRange: PriceRange = await this.foodService.getPriceRangeByMenuItem( menuItems.map((item) => item.menu_item_id), diff --git a/src/feature/restaurant/restaurant.service.ts b/src/feature/restaurant/restaurant.service.ts index 8ce13ba..788b027 100644 --- a/src/feature/restaurant/restaurant.service.ts +++ b/src/feature/restaurant/restaurant.service.ts @@ -116,6 +116,13 @@ export class RestaurantService { }); const deliveryRestaurants: DeliveryRestaurant[] = []; for (const restaurant of restaurants) { + //remove the restaurant which having no menu item + const menuItems = await restaurant.menu_items; + console.log('menuItems', menuItems); + if (menuItems.length <= 0) { + continue; + } + const timeAnhDistance = await this.ahamoveService.estimateTimeAndDistance( { lat: lat,