Artteiv commited on
Commit
6f39f03
1 Parent(s): 0b96899

refactor migrations

Browse files
backend/src/app.module.ts CHANGED
@@ -1,39 +1,39 @@
1
- import { MiddlewareConsumer, Module, NestModule } from '@nestjs/common';
2
- import { AppController } from './app.controller.js';
3
- import { AppService } from './app.service.js';
4
- import { ConfigModule } from '@nestjs/config';
5
- import { TypeOrmModule } from '@nestjs/typeorm';
6
- import { configuration } from './config/config.js';
7
- import { DatabaseConfigService } from './config/database.js';
8
- import { AppLoggerMiddleware } from './common/middlewares/app-logger.middleware.js';
9
- import { DeviceInfoMiddleware } from './common/middlewares/device-info.middleware.js';
10
- import { UserModule } from './modules/user/user.module.js';
11
- import { BranchModule } from './modules/branch/branch.module.js';
12
- import { AuthenticationModule } from './modules/authentication/authentication.module.js';
13
- import { MenuItemModule } from './modules/menu-item/menu-item.module.js';
14
- import { FeedsModule } from './modules/feeds/feeds.module.js';
15
- @Module({
16
- imports: [
17
- ConfigModule.forRoot({
18
- isGlobal: true,
19
- load: [configuration],
20
- }),
21
- TypeOrmModule.forRootAsync({
22
- imports: [ConfigModule],
23
- useClass: DatabaseConfigService,
24
- }),
25
- UserModule,
26
- BranchModule,
27
- AuthenticationModule,
28
- MenuItemModule,
29
- FeedsModule,
30
- ],
31
- controllers: [AppController],
32
- providers: [AppService],
33
- })
34
- export class AppModule implements NestModule {
35
- configure(consumer: MiddlewareConsumer): void {
36
- consumer.apply(AppLoggerMiddleware).forRoutes('*');
37
- consumer.apply(DeviceInfoMiddleware).forRoutes('*');
38
- }
39
- }
 
1
+ import { MiddlewareConsumer, Module, NestModule } from '@nestjs/common';
2
+ import { AppController } from './app.controller.js';
3
+ import { AppService } from './app.service.js';
4
+ import { ConfigModule } from '@nestjs/config';
5
+ import { TypeOrmModule } from '@nestjs/typeorm';
6
+ import { configuration } from './config/config.js';
7
+ import { DatabaseConfigService } from './config/database.js';
8
+ import { AppLoggerMiddleware } from './common/middlewares/app-logger.middleware.js';
9
+ import { DeviceInfoMiddleware } from './common/middlewares/device-info.middleware.js';
10
+ import { UserModule } from './modules/user/user.module.js';
11
+ import { BranchModule } from './modules/branch/branch.module.js';
12
+ import { AuthenticationModule } from './modules/authentication/authentication.module.js';
13
+ import { MenuItemModule } from './modules/menu-item/menu-item.module.js';
14
+ import { FeedsModule } from './modules/feeds/feeds.module.js';
15
+ @Module({
16
+ imports: [
17
+ ConfigModule.forRoot({
18
+ isGlobal: true,
19
+ load: [configuration],
20
+ }),
21
+ TypeOrmModule.forRootAsync({
22
+ imports: [ConfigModule],
23
+ useClass: DatabaseConfigService,
24
+ }),
25
+ UserModule,
26
+ BranchModule,
27
+ AuthenticationModule,
28
+ MenuItemModule,
29
+ FeedsModule,
30
+ ],
31
+ controllers: [AppController],
32
+ providers: [AppService],
33
+ })
34
+ export class AppModule implements NestModule {
35
+ configure(consumer: MiddlewareConsumer): void {
36
+ consumer.apply(AppLoggerMiddleware).forRoutes('*');
37
+ consumer.apply(DeviceInfoMiddleware).forRoutes('*');
38
+ }
39
+ }
backend/src/common/enums/OrderStatus.enum.ts CHANGED
@@ -1,7 +1,7 @@
1
- export enum OrderStatus {
2
- PENDING = 'pending', // KH đặt hàng đã thanh toán online, nhân viên chưa xác nhận <online>
3
- CONFIRMED = 'confirmed', // nhân viên xác nhận và chuyển sang trạng thái <online>
4
- PREPARING = 'preparing', // nhân viên xác nhận và sang trạng thái preparing này ngay lập tức <online/offline>
5
- DELIVERING = 'delivering', // dang giao hàng <online>
6
- DONE = 'done', // <online, offline>
7
- }
 
1
+ export enum OrderStatus {
2
+ PENDING = 'pending', // KH đặt hàng đã thanh toán online, nhân viên chưa xác nhận <online>
3
+ CONFIRMED = 'confirmed', // nhân viên xác nhận và chuyển sang trạng thái <online>
4
+ PREPARING = 'preparing', // nhân viên xác nhận và sang trạng thái preparing này ngay lập tức <online/offline>
5
+ DELIVERING = 'delivering', // dang giao hàng <online>
6
+ DONE = 'done', // <online, offline>
7
+ }
backend/src/common/enums/OrderType.enum.ts CHANGED
@@ -1,5 +1,5 @@
1
- export enum OrderType {
2
- TAKE_AWAY = 'take_away',
3
- OFFLINE = 'offline',
4
- ONLINE = 'online',
5
- }
 
1
+ export enum OrderType {
2
+ TAKE_AWAY = 'take_away',
3
+ OFFLINE = 'offline',
4
+ ONLINE = 'online',
5
+ }
backend/src/common/enums/PaymentMethod.enum.ts CHANGED
@@ -1,5 +1,5 @@
1
- export enum PaymentMethod {
2
- CASH = 'cash',
3
- CARD = 'card',
4
- ONLINE_PAYMENT = 'online_payment',
5
- }
 
1
+ export enum PaymentMethod {
2
+ CASH = 'cash',
3
+ CARD = 'card',
4
+ ONLINE_PAYMENT = 'online_payment',
5
+ }
backend/src/common/enums/role.enum.ts CHANGED
@@ -1,8 +1,8 @@
1
- export enum Role {
2
- CUSTOMER = 'CUSTOMER',
3
- ADMIN = 'ADMIN',
4
- BRANCH_MANAGER = 'BRANCH_MANAGER',
5
- AREA_MANAGER = 'AREA_MANAGER',
6
- STAFF = 'STAFF',
7
- SHIPPER = 'SHIPPER'
8
  }
 
1
+ export enum Role {
2
+ CUSTOMER = 'CUSTOMER',
3
+ ADMIN = 'ADMIN',
4
+ BRANCH_MANAGER = 'BRANCH_MANAGER',
5
+ AREA_MANAGER = 'AREA_MANAGER',
6
+ STAFF = 'STAFF',
7
+ SHIPPER = 'SHIPPER'
8
  }
backend/src/entities/branch.entity.ts CHANGED
@@ -1,35 +1,36 @@
1
- import {
2
- BaseEntity,
3
- Column,
4
- Entity,
5
- ManyToOne,
6
- OneToMany,
7
- PrimaryGeneratedColumn,
8
- Relation,
9
- } from 'typeorm';
10
- import { UserEntity } from './user.entity.js';
11
- import { BranchMenuEntity } from './branch-menu.entity.js';
12
-
13
- @Entity('branches')
14
- export class BranchEntity extends BaseEntity {
15
- @PrimaryGeneratedColumn('uuid')
16
- id: string;
17
-
18
- @Column()
19
- name: string;
20
-
21
- @Column()
22
- location: string;
23
-
24
- @Column()
25
- phone_number: string;
26
-
27
- @ManyToOne(() => UserEntity, (user) => user.branches)
28
- owner: Relation<UserEntity>;
29
-
30
- @OneToMany(() => BranchMenuEntity, (a) => a.branch)
31
- menu_items: Relation<BranchMenuEntity>[];
32
-
33
- @Column({ type: 'timestamp', default: () => 'CURRENT_TIMESTAMP' })
34
- create_at: Date;
35
- }
 
 
1
+ import {
2
+ BaseEntity,
3
+ Column,
4
+ CreateDateColumn,
5
+ Entity,
6
+ ManyToOne,
7
+ OneToMany,
8
+ PrimaryGeneratedColumn,
9
+ Relation,
10
+ } from 'typeorm';
11
+ import { UserEntity } from './user.entity.js';
12
+ import { BranchMenuEntity } from './branch-menu.entity.js';
13
+
14
+ @Entity('branches')
15
+ export class BranchEntity extends BaseEntity {
16
+ @PrimaryGeneratedColumn('uuid')
17
+ id: string;
18
+
19
+ @Column()
20
+ name: string;
21
+
22
+ @Column()
23
+ location: string;
24
+
25
+ @Column()
26
+ phone_number: string;
27
+
28
+ @ManyToOne(() => UserEntity, (user) => user.branches)
29
+ owner: Relation<UserEntity>;
30
+
31
+ @OneToMany(() => BranchMenuEntity, (a) => a.branch)
32
+ menu_items: Relation<BranchMenuEntity>[];
33
+
34
+ @CreateDateColumn()
35
+ create_at: Date;
36
+ }
backend/src/entities/feed.entity.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { Entity, Column, BaseEntity, PrimaryGeneratedColumn } from 'typeorm';
2
 
3
  @Entity('feeds')
4
  export class FeedEntity extends BaseEntity {
@@ -17,6 +17,6 @@ export class FeedEntity extends BaseEntity {
17
  @Column({ nullable: true })
18
  description: string;
19
 
20
- @Column({ type: 'timestamp', default: () => 'CURRENT_TIMESTAMP' })
21
  create_at: Date;
22
  }
 
1
+ import { Entity, Column, BaseEntity, PrimaryGeneratedColumn, CreateDateColumn } from 'typeorm';
2
 
3
  @Entity('feeds')
4
  export class FeedEntity extends BaseEntity {
 
17
  @Column({ nullable: true })
18
  description: string;
19
 
20
+ @CreateDateColumn()
21
  create_at: Date;
22
  }
backend/src/entities/menu-item.entity.ts CHANGED
@@ -1,6 +1,7 @@
1
  import {
2
  BaseEntity,
3
  Column,
 
4
  Entity,
5
  OneToMany,
6
  PrimaryColumn,
@@ -32,6 +33,6 @@ export class MenuItemEntity extends BaseEntity {
32
  @OneToMany(() => BranchMenuEntity, (a) => a.menu_item)
33
  branch_menus: Relation<BranchMenuEntity>[];
34
 
35
- @Column({ type: 'timestamp', default: () => 'CURRENT_TIMESTAMP' })
36
  create_at: Date;
37
  }
 
1
  import {
2
  BaseEntity,
3
  Column,
4
+ CreateDateColumn,
5
  Entity,
6
  OneToMany,
7
  PrimaryColumn,
 
33
  @OneToMany(() => BranchMenuEntity, (a) => a.menu_item)
34
  branch_menus: Relation<BranchMenuEntity>[];
35
 
36
+ @CreateDateColumn()
37
  create_at: Date;
38
  }
backend/src/entities/order-item.entity.ts CHANGED
@@ -1,37 +1,37 @@
1
- import {
2
- BaseEntity,
3
- Column,
4
- Entity,
5
- JoinColumn,
6
- ManyToOne,
7
- PrimaryGeneratedColumn,
8
- Relation,
9
- } from 'typeorm';
10
- import { BranchMenuEntity } from './branch-menu.entity.js';
11
- import { OrderEntity } from './order.entity.js';
12
-
13
- @Entity('order_items')
14
- export class OrderItemEntity extends BaseEntity {
15
- @PrimaryGeneratedColumn()
16
- id: number;
17
-
18
- @Column()
19
- order_id: string;
20
-
21
- @ManyToOne(() => OrderEntity, (a) => a.order_items)
22
- @JoinColumn({ name: 'order_id' })
23
- order: Relation<OrderEntity>;
24
-
25
- @Column()
26
- branch_menu_id: string;
27
-
28
- @ManyToOne(() => BranchMenuEntity)
29
- @JoinColumn({ name: 'menu_id' })
30
- branch_menu: Relation<BranchMenuEntity>;
31
-
32
- @Column()
33
- quantity: number;
34
-
35
- @Column()
36
- price: number;
37
- }
 
1
+ import {
2
+ BaseEntity,
3
+ Column,
4
+ Entity,
5
+ JoinColumn,
6
+ ManyToOne,
7
+ PrimaryGeneratedColumn,
8
+ Relation,
9
+ } from 'typeorm';
10
+ import { BranchMenuEntity } from './branch-menu.entity.js';
11
+ import { OrderEntity } from './order.entity.js';
12
+
13
+ @Entity('order_items')
14
+ export class OrderItemEntity extends BaseEntity {
15
+ @PrimaryGeneratedColumn()
16
+ id: number;
17
+
18
+ @Column()
19
+ order_id: string;
20
+
21
+ @ManyToOne(() => OrderEntity, (a) => a.order_items)
22
+ @JoinColumn({ name: 'order_id' })
23
+ order: Relation<OrderEntity>;
24
+
25
+ @Column()
26
+ branch_menu_id: string;
27
+
28
+ @ManyToOne(() => BranchMenuEntity)
29
+ @JoinColumn({ name: 'menu_id' })
30
+ branch_menu: Relation<BranchMenuEntity>;
31
+
32
+ @Column()
33
+ quantity: number;
34
+
35
+ @Column()
36
+ price: number;
37
+ }
backend/src/entities/order.entity.ts CHANGED
@@ -1,68 +1,69 @@
1
- import {
2
- BaseEntity,
3
- Column,
4
- Entity,
5
- JoinColumn,
6
- ManyToOne,
7
- OneToMany,
8
- OneToOne,
9
- PrimaryGeneratedColumn,
10
- Relation,
11
- } from 'typeorm';
12
- import { BranchEntity } from './branch.entity.js';
13
- import { UserEntity } from './user.entity.js';
14
- import { OrderType } from '../common/enums/OrderType.enum.js';
15
- import { OrderStatus } from '../common/enums/OrderStatus.enum.js';
16
- import { OrderItemEntity } from './order-item.entity.js';
17
- import { PaymentEntity } from './payment.entity.js';
18
-
19
- @Entity('orders')
20
- export class OrderEntity extends BaseEntity {
21
- @PrimaryGeneratedColumn('uuid')
22
- id: string;
23
-
24
- @Column({ nullable: true })
25
- customer_id: string;
26
-
27
- @ManyToOne(() => UserEntity, { nullable: true })
28
- customer: Relation<UserEntity>;
29
-
30
- @Column()
31
- branch_id: string;
32
-
33
- @ManyToOne(() => BranchEntity)
34
- @JoinColumn({ name: 'branch_id' })
35
- branch: Relation<BranchEntity>;
36
-
37
- @Column()
38
- employee_id: string;
39
-
40
- @ManyToOne(() => UserEntity)
41
- @JoinColumn({ name: 'employee_id' })
42
- employee: Relation<UserEntity>;
43
-
44
- @Column({ nullable: true })
45
- table_number: number;
46
-
47
- @Column()
48
- total_value: number;
49
-
50
- @Column({ type: 'timestamp', default: () => 'CURRENT_TIMESTAMP' })
51
- create_at: Date;
52
-
53
- @Column({ type: 'enum', enum: OrderType, default: OrderType.ONLINE })
54
- order_type: OrderType;
55
-
56
- @Column({ type: 'enum', enum: OrderStatus, default: OrderStatus.PENDING })
57
- order_status: OrderStatus;
58
-
59
- @OneToMany(() => OrderItemEntity, (a) => a.order)
60
- order_items: Relation<OrderItemEntity>[];
61
-
62
- @Column({ nullable: true })
63
- payment_id: number;
64
-
65
- @OneToOne(() => PaymentEntity, (a) => a.order)
66
- @JoinColumn()
67
- payment: Relation<PaymentEntity>;
68
- }
 
 
1
+ import {
2
+ BaseEntity,
3
+ Column,
4
+ CreateDateColumn,
5
+ Entity,
6
+ JoinColumn,
7
+ ManyToOne,
8
+ OneToMany,
9
+ OneToOne,
10
+ PrimaryGeneratedColumn,
11
+ Relation,
12
+ } from 'typeorm';
13
+ import { BranchEntity } from './branch.entity.js';
14
+ import { UserEntity } from './user.entity.js';
15
+ import { OrderType } from '../common/enums/OrderType.enum.js';
16
+ import { OrderStatus } from '../common/enums/OrderStatus.enum.js';
17
+ import { OrderItemEntity } from './order-item.entity.js';
18
+ import { PaymentEntity } from './payment.entity.js';
19
+
20
+ @Entity('orders')
21
+ export class OrderEntity extends BaseEntity {
22
+ @PrimaryGeneratedColumn('uuid')
23
+ id: string;
24
+
25
+ @Column({ nullable: true })
26
+ customer_id: string;
27
+
28
+ @ManyToOne(() => UserEntity, { nullable: true })
29
+ customer: Relation<UserEntity>;
30
+
31
+ @Column()
32
+ branch_id: string;
33
+
34
+ @ManyToOne(() => BranchEntity)
35
+ @JoinColumn({ name: 'branch_id' })
36
+ branch: Relation<BranchEntity>;
37
+
38
+ @Column()
39
+ employee_id: string;
40
+
41
+ @ManyToOne(() => UserEntity)
42
+ @JoinColumn({ name: 'employee_id' })
43
+ employee: Relation<UserEntity>;
44
+
45
+ @Column({ nullable: true })
46
+ table_number: number;
47
+
48
+ @Column()
49
+ total_value: number;
50
+
51
+ @CreateDateColumn()
52
+ create_at: Date;
53
+
54
+ @Column({ type: 'enum', enum: OrderType, default: OrderType.ONLINE })
55
+ order_type: OrderType;
56
+
57
+ @Column({ type: 'enum', enum: OrderStatus, default: OrderStatus.PENDING })
58
+ order_status: OrderStatus;
59
+
60
+ @OneToMany(() => OrderItemEntity, (a) => a.order)
61
+ order_items: Relation<OrderItemEntity>[];
62
+
63
+ @Column({ nullable: true })
64
+ payment_id: number;
65
+
66
+ @OneToOne(() => PaymentEntity, (a) => a.order)
67
+ @JoinColumn()
68
+ payment: Relation<PaymentEntity>;
69
+ }
backend/src/entities/payment.entity.ts CHANGED
@@ -1,28 +1,28 @@
1
- import {
2
- BaseEntity,
3
- Column,
4
- Entity,
5
- JoinColumn,
6
- ManyToOne,
7
- OneToOne,
8
- PrimaryGeneratedColumn,
9
- Relation,
10
- } from 'typeorm';
11
- import { BranchMenuEntity } from './branch-menu.entity.js';
12
- import { OrderEntity } from './order.entity.js';
13
- import { PaymentMethod } from '../common/enums/PaymentMethod.enum.js';
14
-
15
- @Entity('payments')
16
- export class PaymentEntity extends BaseEntity {
17
- @PrimaryGeneratedColumn()
18
- id: number;
19
-
20
- @OneToOne(() => OrderEntity, (a) => a.payment)
21
- order: Relation<OrderEntity>;
22
-
23
- @Column({ type: 'enum', enum: PaymentMethod, default: PaymentMethod.CASH })
24
- payment_method: PaymentMethod; // E.g., 'Cash', 'Credit Card', 'Online Payment'
25
-
26
- @Column()
27
- value: number;
28
- }
 
1
+ import {
2
+ BaseEntity,
3
+ Column,
4
+ Entity,
5
+ JoinColumn,
6
+ ManyToOne,
7
+ OneToOne,
8
+ PrimaryGeneratedColumn,
9
+ Relation,
10
+ } from 'typeorm';
11
+ import { BranchMenuEntity } from './branch-menu.entity.js';
12
+ import { OrderEntity } from './order.entity.js';
13
+ import { PaymentMethod } from '../common/enums/PaymentMethod.enum.js';
14
+
15
+ @Entity('payments')
16
+ export class PaymentEntity extends BaseEntity {
17
+ @PrimaryGeneratedColumn()
18
+ id: number;
19
+
20
+ @OneToOne(() => OrderEntity, (a) => a.payment)
21
+ order: Relation<OrderEntity>;
22
+
23
+ @Column({ type: 'enum', enum: PaymentMethod, default: PaymentMethod.CASH })
24
+ payment_method: PaymentMethod; // E.g., 'Cash', 'Credit Card', 'Online Payment'
25
+
26
+ @Column()
27
+ value: number;
28
+ }
backend/src/entities/user.entity.ts CHANGED
@@ -1,54 +1,55 @@
1
- import {
2
- Entity,
3
- Column,
4
- BaseEntity,
5
- PrimaryGeneratedColumn,
6
- OneToMany,
7
- ManyToOne,
8
- Relation,
9
- JoinColumn,
10
- } from 'typeorm';
11
- import { BranchEntity } from './branch.entity.js';
12
- import { IsOptional } from 'class-validator';
13
- import { Role } from '../common/enums/role.enum.js';
14
-
15
- @Entity('users')
16
- export class UserEntity extends BaseEntity {
17
- @PrimaryGeneratedColumn('uuid')
18
- id: string;
19
-
20
- @IsOptional()
21
- @Column({ nullable: true })
22
- avatar: string;
23
-
24
- @Column()
25
- full_name: string;
26
-
27
- @Column({ unique: true })
28
- phone_number: string;
29
-
30
- @IsOptional()
31
- @Column({ nullable: true })
32
- address: string;
33
-
34
- @Column({ nullable: true, unique: true })
35
- email: string;
36
-
37
- @Column({ type: 'enum', enum: Role, default: 'CUSTOMER' })
38
- role: Role;
39
-
40
- @Column()
41
- hash_password: string;
42
-
43
- @IsOptional()
44
- @Column({ default: true })
45
- is_valid: boolean;
46
-
47
- @IsOptional()
48
- @Column({ type: 'timestamp', default: () => 'CURRENT_TIMESTAMP' })
49
- create_at: Date;
50
-
51
- @IsOptional()
52
- @OneToMany(() => BranchEntity, (branch) => branch.owner)
53
- branches: Relation<BranchEntity>[];
54
- }
 
 
1
+ import {
2
+ Entity,
3
+ Column,
4
+ BaseEntity,
5
+ PrimaryGeneratedColumn,
6
+ OneToMany,
7
+ ManyToOne,
8
+ Relation,
9
+ JoinColumn,
10
+ CreateDateColumn,
11
+ } from 'typeorm';
12
+ import { BranchEntity } from './branch.entity.js';
13
+ import { IsOptional } from 'class-validator';
14
+ import { Role } from '../common/enums/role.enum.js';
15
+
16
+ @Entity('users')
17
+ export class UserEntity extends BaseEntity {
18
+ @PrimaryGeneratedColumn('uuid')
19
+ id: string;
20
+
21
+ @IsOptional()
22
+ @Column({ nullable: true })
23
+ avatar: string;
24
+
25
+ @Column()
26
+ full_name: string;
27
+
28
+ @Column({ unique: true })
29
+ phone_number: string;
30
+
31
+ @IsOptional()
32
+ @Column({ nullable: true })
33
+ address: string;
34
+
35
+ @Column({ nullable: true, unique: true })
36
+ email: string;
37
+
38
+ @Column({ type: 'enum', enum: Role, default: 'CUSTOMER' })
39
+ role: Role;
40
+
41
+ @Column()
42
+ hash_password: string;
43
+
44
+ @IsOptional()
45
+ @Column({ default: true })
46
+ is_valid: boolean;
47
+
48
+ @IsOptional()
49
+ @CreateDateColumn()
50
+ create_at: Date;
51
+
52
+ @IsOptional()
53
+ @OneToMany(() => BranchEntity, (branch) => branch.owner)
54
+ branches: Relation<BranchEntity>[];
55
+ }
backend/src/migrations/1729963419864-enum-role.ts DELETED
@@ -1,22 +0,0 @@
1
- import { MigrationInterface, QueryRunner } from "typeorm";
2
-
3
- export class EnumRole1729963419864 implements MigrationInterface {
4
- name = 'EnumRole1729963419864'
5
-
6
- public async up(queryRunner: QueryRunner): Promise<void> {
7
- await queryRunner.query(`ALTER TABLE "users" DROP CONSTRAINT "FK_a2cecd1a3531c0b041e29ba46e1"`);
8
- await queryRunner.query(`ALTER TABLE "users" RENAME COLUMN "role_id" TO "role"`);
9
- await queryRunner.query(`ALTER TABLE "users" DROP COLUMN "role"`);
10
- await queryRunner.query(`CREATE TYPE "public"."users_role_enum" AS ENUM('CUSTOMER', 'ADMIN', 'BRANCH_MANAGER', 'AREA_MANAGER', 'STAFF', 'SHIPPER')`);
11
- await queryRunner.query(`ALTER TABLE "users" ADD "role" "public"."users_role_enum" NOT NULL DEFAULT 'CUSTOMER'`);
12
- }
13
-
14
- public async down(queryRunner: QueryRunner): Promise<void> {
15
- await queryRunner.query(`ALTER TABLE "users" DROP COLUMN "role"`);
16
- await queryRunner.query(`DROP TYPE "public"."users_role_enum"`);
17
- await queryRunner.query(`ALTER TABLE "users" ADD "role" uuid NOT NULL DEFAULT 'f3750930-48ab-4c30-8681-d50e68e2bda7'`);
18
- await queryRunner.query(`ALTER TABLE "users" RENAME COLUMN "role" TO "role_id"`);
19
- await queryRunner.query(`ALTER TABLE "users" ADD CONSTRAINT "FK_a2cecd1a3531c0b041e29ba46e1" FOREIGN KEY ("role_id") REFERENCES "role"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`);
20
- }
21
-
22
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
backend/src/migrations/1730397685489-RemoveAllAndAdd.ts ADDED
@@ -0,0 +1,56 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { MigrationInterface, QueryRunner } from "typeorm";
2
+
3
+ export class RemoveAllAndAdd1730397685489 implements MigrationInterface {
4
+ name = 'RemoveAllAndAdd1730397685489'
5
+
6
+ public async up(queryRunner: QueryRunner): Promise<void> {
7
+ await queryRunner.query(`CREATE TABLE "feeds" ("id" SERIAL NOT NULL, "author_id" character varying, "image_url" character varying, "title" character varying NOT NULL, "description" character varying, "create_at" TIMESTAMP NOT NULL DEFAULT now(), CONSTRAINT "PK_3dafbf766ecbb1eb2017732153f" PRIMARY KEY ("id"))`);
8
+ await queryRunner.query(`CREATE TYPE "public"."users_role_enum" AS ENUM('CUSTOMER', 'ADMIN', 'BRANCH_MANAGER', 'AREA_MANAGER', 'STAFF', 'SHIPPER')`);
9
+ await queryRunner.query(`CREATE TABLE "users" ("id" uuid NOT NULL DEFAULT uuid_generate_v4(), "avatar" character varying, "full_name" character varying NOT NULL, "phone_number" character varying NOT NULL, "address" character varying, "email" character varying, "role" "public"."users_role_enum" NOT NULL DEFAULT 'CUSTOMER', "hash_password" character varying NOT NULL, "is_valid" boolean NOT NULL DEFAULT true, "create_at" TIMESTAMP NOT NULL DEFAULT now(), CONSTRAINT "UQ_17d1817f241f10a3dbafb169fd2" UNIQUE ("phone_number"), CONSTRAINT "UQ_97672ac88f789774dd47f7c8be3" UNIQUE ("email"), CONSTRAINT "PK_a3ffb1c0c8416b9fc6f907b7433" PRIMARY KEY ("id"))`);
10
+ await queryRunner.query(`CREATE TYPE "public"."menu_items_item_type_enum" AS ENUM('monchinh', 'trangmieng', 'giaikhat', 'khac')`);
11
+ await queryRunner.query(`CREATE TABLE "menu_items" ("id" character varying NOT NULL, "item_name" character varying NOT NULL, "image_url" character varying, "item_type" "public"."menu_items_item_type_enum" NOT NULL DEFAULT 'khac', "description" character varying NOT NULL, "price" integer NOT NULL, "create_at" TIMESTAMP NOT NULL DEFAULT now(), CONSTRAINT "PK_57e6188f929e5dc6919168620c8" PRIMARY KEY ("id"))`);
12
+ await queryRunner.query(`CREATE TABLE "branch_menu" ("id" uuid NOT NULL DEFAULT uuid_generate_v4(), "branch_id" character varying NOT NULL, "menu_id" character varying NOT NULL, "description" character varying NOT NULL, "is_open" boolean NOT NULL, "branchId" uuid, "menuItemId" character varying, CONSTRAINT "PK_977becffe98bbc626a56031b9e7" PRIMARY KEY ("id"))`);
13
+ await queryRunner.query(`CREATE TABLE "branches" ("id" uuid NOT NULL DEFAULT uuid_generate_v4(), "name" character varying NOT NULL, "location" character varying NOT NULL, "phone_number" character varying NOT NULL, "create_at" TIMESTAMP NOT NULL DEFAULT now(), "ownerId" uuid, CONSTRAINT "PK_7f37d3b42defea97f1df0d19535" PRIMARY KEY ("id"))`);
14
+ await queryRunner.query(`CREATE TYPE "public"."payments_payment_method_enum" AS ENUM('cash', 'card', 'online_payment')`);
15
+ await queryRunner.query(`CREATE TABLE "payments" ("id" SERIAL NOT NULL, "payment_method" "public"."payments_payment_method_enum" NOT NULL DEFAULT 'cash', "value" integer NOT NULL, CONSTRAINT "PK_197ab7af18c93fbb0c9b28b4a59" PRIMARY KEY ("id"))`);
16
+ await queryRunner.query(`CREATE TYPE "public"."orders_order_type_enum" AS ENUM('take_away', 'offline', 'online')`);
17
+ await queryRunner.query(`CREATE TYPE "public"."orders_order_status_enum" AS ENUM('pending', 'confirmed', 'preparing', 'delivering', 'done')`);
18
+ await queryRunner.query(`CREATE TABLE "orders" ("id" uuid NOT NULL DEFAULT uuid_generate_v4(), "customer_id" character varying, "branch_id" uuid NOT NULL, "employee_id" uuid NOT NULL, "table_number" integer, "total_value" integer NOT NULL, "create_at" TIMESTAMP NOT NULL DEFAULT now(), "order_type" "public"."orders_order_type_enum" NOT NULL DEFAULT 'online', "order_status" "public"."orders_order_status_enum" NOT NULL DEFAULT 'pending', "payment_id" integer, "customerId" uuid, "paymentId" integer, CONSTRAINT "REL_06a051324c76276ca2a9d1feb0" UNIQUE ("paymentId"), CONSTRAINT "PK_710e2d4957aa5878dfe94e4ac2f" PRIMARY KEY ("id"))`);
19
+ await queryRunner.query(`CREATE TABLE "order_items" ("id" SERIAL NOT NULL, "order_id" uuid NOT NULL, "branch_menu_id" character varying NOT NULL, "quantity" integer NOT NULL, "price" integer NOT NULL, "menu_id" uuid, CONSTRAINT "PK_005269d8574e6fac0493715c308" PRIMARY KEY ("id"))`);
20
+ await queryRunner.query(`ALTER TABLE "branch_menu" ADD CONSTRAINT "FK_e0c721a124fa03ea4cef6f28f42" FOREIGN KEY ("branchId") REFERENCES "branches"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`);
21
+ await queryRunner.query(`ALTER TABLE "branch_menu" ADD CONSTRAINT "FK_cbfb42df5887653593974e3e285" FOREIGN KEY ("menuItemId") REFERENCES "menu_items"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`);
22
+ await queryRunner.query(`ALTER TABLE "branches" ADD CONSTRAINT "FK_8c6ae9f9c654c4fac71bccbb7ed" FOREIGN KEY ("ownerId") REFERENCES "users"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`);
23
+ await queryRunner.query(`ALTER TABLE "orders" ADD CONSTRAINT "FK_e5de51ca888d8b1f5ac25799dd1" FOREIGN KEY ("customerId") REFERENCES "users"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`);
24
+ await queryRunner.query(`ALTER TABLE "orders" ADD CONSTRAINT "FK_17b723da2c12837f4bc21e33398" FOREIGN KEY ("branch_id") REFERENCES "branches"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`);
25
+ await queryRunner.query(`ALTER TABLE "orders" ADD CONSTRAINT "FK_f8a7411077c731327ca6e0b93b6" FOREIGN KEY ("employee_id") REFERENCES "users"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`);
26
+ await queryRunner.query(`ALTER TABLE "orders" ADD CONSTRAINT "FK_06a051324c76276ca2a9d1feb08" FOREIGN KEY ("paymentId") REFERENCES "payments"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`);
27
+ await queryRunner.query(`ALTER TABLE "order_items" ADD CONSTRAINT "FK_145532db85752b29c57d2b7b1f1" FOREIGN KEY ("order_id") REFERENCES "orders"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`);
28
+ await queryRunner.query(`ALTER TABLE "order_items" ADD CONSTRAINT "FK_564d2ba92c6bc3ec79c874e1458" FOREIGN KEY ("menu_id") REFERENCES "branch_menu"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`);
29
+ }
30
+
31
+ public async down(queryRunner: QueryRunner): Promise<void> {
32
+ await queryRunner.query(`ALTER TABLE "order_items" DROP CONSTRAINT "FK_564d2ba92c6bc3ec79c874e1458"`);
33
+ await queryRunner.query(`ALTER TABLE "order_items" DROP CONSTRAINT "FK_145532db85752b29c57d2b7b1f1"`);
34
+ await queryRunner.query(`ALTER TABLE "orders" DROP CONSTRAINT "FK_06a051324c76276ca2a9d1feb08"`);
35
+ await queryRunner.query(`ALTER TABLE "orders" DROP CONSTRAINT "FK_f8a7411077c731327ca6e0b93b6"`);
36
+ await queryRunner.query(`ALTER TABLE "orders" DROP CONSTRAINT "FK_17b723da2c12837f4bc21e33398"`);
37
+ await queryRunner.query(`ALTER TABLE "orders" DROP CONSTRAINT "FK_e5de51ca888d8b1f5ac25799dd1"`);
38
+ await queryRunner.query(`ALTER TABLE "branches" DROP CONSTRAINT "FK_8c6ae9f9c654c4fac71bccbb7ed"`);
39
+ await queryRunner.query(`ALTER TABLE "branch_menu" DROP CONSTRAINT "FK_cbfb42df5887653593974e3e285"`);
40
+ await queryRunner.query(`ALTER TABLE "branch_menu" DROP CONSTRAINT "FK_e0c721a124fa03ea4cef6f28f42"`);
41
+ await queryRunner.query(`DROP TABLE "order_items"`);
42
+ await queryRunner.query(`DROP TABLE "orders"`);
43
+ await queryRunner.query(`DROP TYPE "public"."orders_order_status_enum"`);
44
+ await queryRunner.query(`DROP TYPE "public"."orders_order_type_enum"`);
45
+ await queryRunner.query(`DROP TABLE "payments"`);
46
+ await queryRunner.query(`DROP TYPE "public"."payments_payment_method_enum"`);
47
+ await queryRunner.query(`DROP TABLE "branches"`);
48
+ await queryRunner.query(`DROP TABLE "branch_menu"`);
49
+ await queryRunner.query(`DROP TABLE "menu_items"`);
50
+ await queryRunner.query(`DROP TYPE "public"."menu_items_item_type_enum"`);
51
+ await queryRunner.query(`DROP TABLE "users"`);
52
+ await queryRunner.query(`DROP TYPE "public"."users_role_enum"`);
53
+ await queryRunner.query(`DROP TABLE "feeds"`);
54
+ }
55
+
56
+ }