Trần Viết Sơn commited on
Commit
ef52ba3
·
unverified ·
2 Parent(s): 394f721 a3b1339

Merge pull request #39 from PBL6-team-CATS/feat/db-enum

Browse files
backend/src/entities/menu-item.entity.ts CHANGED
@@ -21,8 +21,8 @@ export class MenuItemEntity extends BaseEntity {
21
  @Column({ nullable: true })
22
  image_url: string;
23
 
24
- @Column({ type: 'enum', enum: MenuItemType, default: 'khac' })
25
- item_type: MenuItemType;
26
 
27
  @Column()
28
  description: string;
 
21
  @Column({ nullable: true })
22
  image_url: string;
23
 
24
+ @Column({ default: 0 })
25
+ item_type: number;
26
 
27
  @Column()
28
  description: string;
backend/src/entities/order.entity.ts CHANGED
@@ -52,11 +52,11 @@ export class OrderEntity extends BaseEntity {
52
  @CreateDateColumn()
53
  create_at: Date;
54
 
55
- @Column({ type: 'enum', enum: OrderType, default: OrderType.ONLINE })
56
- order_type: OrderType;
57
 
58
- @Column({ type: 'enum', enum: OrderStatus, default: OrderStatus.PENDING })
59
- order_status: OrderStatus;
60
 
61
  @OneToMany(() => OrderItemEntity, (a) => a.order)
62
  order_items: Relation<OrderItemEntity>[];
 
52
  @CreateDateColumn()
53
  create_at: Date;
54
 
55
+ @Column({ default: 0 })
56
+ order_type: number;
57
 
58
+ @Column({ default: 0 })
59
+ order_status: number;
60
 
61
  @OneToMany(() => OrderItemEntity, (a) => a.order)
62
  order_items: Relation<OrderItemEntity>[];
backend/src/entities/payment.entity.ts CHANGED
@@ -17,8 +17,8 @@ export class PaymentEntity extends BaseEntity {
17
  @OneToOne(() => OrderEntity, (a) => a.payment)
18
  order: Relation<OrderEntity>;
19
 
20
- @Column({ type: 'enum', enum: PaymentMethod, default: PaymentMethod.CASH })
21
- payment_method: PaymentMethod; // E.g., 'Cash', 'Credit Card', 'Online Payment'
22
 
23
  @Column()
24
  value: number;
 
17
  @OneToOne(() => OrderEntity, (a) => a.payment)
18
  order: Relation<OrderEntity>;
19
 
20
+ @Column({ default: 0 })
21
+ payment_method: number; // E.g., 'Cash', 'Credit Card', 'Online Payment'
22
 
23
  @Column()
24
  value: number;
backend/src/migrations/1730549959767-RemoveEnums.ts ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { MigrationInterface, QueryRunner } from "typeorm";
2
+
3
+ export class RemoveEnums1730549959767 implements MigrationInterface {
4
+ name = 'RemoveEnums1730549959767'
5
+
6
+ public async up(queryRunner: QueryRunner): Promise<void> {
7
+ await queryRunner.query(`ALTER TABLE "menu_items" DROP COLUMN "item_type"`);
8
+ await queryRunner.query(`DROP TYPE "public"."menu_items_item_type_enum"`);
9
+ await queryRunner.query(`ALTER TABLE "menu_items" ADD "item_type" integer NOT NULL DEFAULT '0'`);
10
+ await queryRunner.query(`ALTER TABLE "payments" DROP COLUMN "payment_method"`);
11
+ await queryRunner.query(`DROP TYPE "public"."payments_payment_method_enum"`);
12
+ await queryRunner.query(`ALTER TABLE "payments" ADD "payment_method" integer NOT NULL DEFAULT '0'`);
13
+ await queryRunner.query(`ALTER TABLE "orders" DROP COLUMN "order_type"`);
14
+ await queryRunner.query(`DROP TYPE "public"."orders_order_type_enum"`);
15
+ await queryRunner.query(`ALTER TABLE "orders" ADD "order_type" integer NOT NULL DEFAULT '0'`);
16
+ await queryRunner.query(`ALTER TABLE "orders" DROP COLUMN "order_status"`);
17
+ await queryRunner.query(`DROP TYPE "public"."orders_order_status_enum"`);
18
+ await queryRunner.query(`ALTER TABLE "orders" ADD "order_status" integer NOT NULL DEFAULT '0'`);
19
+ }
20
+
21
+ public async down(queryRunner: QueryRunner): Promise<void> {
22
+ await queryRunner.query(`ALTER TABLE "orders" DROP COLUMN "order_status"`);
23
+ await queryRunner.query(`CREATE TYPE "public"."orders_order_status_enum" AS ENUM('pending', 'confirmed', 'preparing', 'delivering', 'done')`);
24
+ await queryRunner.query(`ALTER TABLE "orders" ADD "order_status" "public"."orders_order_status_enum" NOT NULL DEFAULT 'pending'`);
25
+ await queryRunner.query(`ALTER TABLE "orders" DROP COLUMN "order_type"`);
26
+ await queryRunner.query(`CREATE TYPE "public"."orders_order_type_enum" AS ENUM('take_away', 'offline', 'online')`);
27
+ await queryRunner.query(`ALTER TABLE "orders" ADD "order_type" "public"."orders_order_type_enum" NOT NULL DEFAULT 'online'`);
28
+ await queryRunner.query(`ALTER TABLE "payments" DROP COLUMN "payment_method"`);
29
+ await queryRunner.query(`CREATE TYPE "public"."payments_payment_method_enum" AS ENUM('cash', 'card', 'online_payment')`);
30
+ await queryRunner.query(`ALTER TABLE "payments" ADD "payment_method" "public"."payments_payment_method_enum" NOT NULL DEFAULT 'cash'`);
31
+ await queryRunner.query(`ALTER TABLE "menu_items" DROP COLUMN "item_type"`);
32
+ await queryRunner.query(`CREATE TYPE "public"."menu_items_item_type_enum" AS ENUM('monchinh', 'trangmieng', 'giaikhat', 'khac')`);
33
+ await queryRunner.query(`ALTER TABLE "menu_items" ADD "item_type" "public"."menu_items_item_type_enum" NOT NULL DEFAULT 'khac'`);
34
+ }
35
+
36
+ }