Skip to content

Commit

Permalink
Fes 25 refactor concept variant option to attribute value (#34)
Browse files Browse the repository at this point in the history
* refactor part 1

* refactor concept part 2

* fix typing err and add the restaurant remove logic

---------

Co-authored-by: NHT <[email protected]>
  • Loading branch information
nfesta2023 and hoangtuan910 authored Jan 10, 2024
1 parent 0f26b2f commit 2d5e9ce
Show file tree
Hide file tree
Showing 14 changed files with 204 additions and 228 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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[];
Expand Down
54 changes: 54 additions & 0 deletions src/entity/sku-detail.entity.ts
Original file line number Diff line number Diff line change
@@ -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;
}
54 changes: 0 additions & 54 deletions src/entity/sku-menu-item-variant.entity.ts

This file was deleted.

6 changes: 3 additions & 3 deletions src/entity/sku.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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[];
Expand Down
6 changes: 3 additions & 3 deletions src/entity/taste-ext.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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;
}
8 changes: 4 additions & 4 deletions src/entity/taste-value-ext.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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;
}
16 changes: 8 additions & 8 deletions src/feature/common/common.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand All @@ -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],
Expand Down
Loading

0 comments on commit 2d5e9ce

Please sign in to comment.