Trần Viết Sơn commited on
Commit
0bc0e28
2 Parent(s): c14fe98 9ec4f32

Merge pull request #3 from PBL6-team-CATS/feature/login

Browse files
backend/src/entities/role.entity.ts ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import{
2
+ Entity,
3
+ Column,
4
+ BaseEntity,
5
+ PrimaryGeneratedColumn,
6
+ } from 'typeorm'
7
+
8
+ @Entity('role')
9
+ export class RoleEntity extends BaseEntity{
10
+ @PrimaryGeneratedColumn('uuid')
11
+ id: number;
12
+
13
+ @Column({ nullable: false})
14
+ role_name: string;
15
+
16
+ @Column({ nullable: true })
17
+ description: string;
18
+ }
backend/src/entities/user.entity.ts CHANGED
@@ -4,9 +4,12 @@ import {
4
  BaseEntity,
5
  PrimaryGeneratedColumn,
6
  OneToMany,
 
7
  Relation,
 
8
  } from 'typeorm';
9
  import { BranchEntity } from './branch.entity.js';
 
10
 
11
  @Entity('users')
12
  export class UserEntity extends BaseEntity {
@@ -42,4 +45,8 @@ export class UserEntity extends BaseEntity {
42
 
43
  @OneToMany(() => BranchEntity, (branch) => branch.owner)
44
  branches: Relation<BranchEntity>[];
 
 
 
 
45
  }
 
4
  BaseEntity,
5
  PrimaryGeneratedColumn,
6
  OneToMany,
7
+ ManyToOne,
8
  Relation,
9
+ JoinColumn,
10
  } from 'typeorm';
11
  import { BranchEntity } from './branch.entity.js';
12
+ import { RoleEntity } from './role.entity.js';
13
 
14
  @Entity('users')
15
  export class UserEntity extends BaseEntity {
 
45
 
46
  @OneToMany(() => BranchEntity, (branch) => branch.owner)
47
  branches: Relation<BranchEntity>[];
48
+
49
+ @ManyToOne(() => RoleEntity)
50
+ @JoinColumn({ name: 'role_id'})
51
+ role: RoleEntity;
52
  }
backend/src/migrations/1729070527478-Create-Role-Entity.ts ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { MigrationInterface, QueryRunner } from "typeorm";
2
+
3
+ export class CreateRoleEntity1729070527478 implements MigrationInterface {
4
+ name = 'CreateRoleEntity1729070527478'
5
+
6
+ public async up(queryRunner: QueryRunner): Promise<void> {
7
+ await queryRunner.query(`CREATE TABLE "role" ("id" uuid NOT NULL DEFAULT uuid_generate_v4(), "role_name" character varying NOT NULL, "description" character varying, CONSTRAINT "PK_b36bcfe02fc8de3c57a8b2391c2" PRIMARY KEY ("id"))`);
8
+ await queryRunner.query(`ALTER TABLE "users" DROP COLUMN "role_id"`);
9
+ await queryRunner.query(`ALTER TABLE "users" ADD "role_id" uuid`);
10
+ 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`);
11
+ }
12
+
13
+ public async down(queryRunner: QueryRunner): Promise<void> {
14
+ await queryRunner.query(`ALTER TABLE "users" DROP CONSTRAINT "FK_a2cecd1a3531c0b041e29ba46e1"`);
15
+ await queryRunner.query(`ALTER TABLE "users" DROP COLUMN "role_id"`);
16
+ await queryRunner.query(`ALTER TABLE "users" ADD "role_id" integer`);
17
+ await queryRunner.query(`DROP TABLE "role"`);
18
+ }
19
+
20
+ }