From 4beef77eb3800a8e481f3f9ec9227c95e00327cc Mon Sep 17 00:00:00 2001 From: AdisakKanthawilang Date: Tue, 11 Jun 2024 11:22:59 +0700 Subject: [PATCH] add entity AuthRole , AuthRoleAttr , AuthSys --- src/entities/AuthRole.ts | 35 ++++++++++++ src/entities/AuthRoleAttr.ts | 102 +++++++++++++++++++++++++++++++++++ src/entities/AuthSys.ts | 76 ++++++++++++++++++++++++++ 3 files changed, 213 insertions(+) create mode 100644 src/entities/AuthRole.ts create mode 100644 src/entities/AuthRoleAttr.ts create mode 100644 src/entities/AuthSys.ts diff --git a/src/entities/AuthRole.ts b/src/entities/AuthRole.ts new file mode 100644 index 00000000..70164983 --- /dev/null +++ b/src/entities/AuthRole.ts @@ -0,0 +1,35 @@ +import { Entity, Column, OneToMany } from "typeorm"; +import { EntityBase } from "./base/Base"; +import { AuthRoleAttr } from "./AuthRoleAttr"; + +@Entity("AuthRole") +export class AuthRole extends EntityBase { + @Column({ + nullable: true, + comment: "ชื่อบทบาท", + length: 255, + default: null, + }) + roleName: string; + + @Column({ + nullable: true, + comment: "รายละเอียด", + length: 255, + default: null, + }) + roleDescription: string; + + @OneToMany(() => AuthRoleAttr, (authRoleAttr) => authRoleAttr.authRoleAttrForRole) + authRoles: AuthRoleAttr[]; +} + +export class CreateAuthRole { + @Column() + roleName: string; + + @Column() + roleDescription: string; +} + +export type UpdateAuthRole = Partial; diff --git a/src/entities/AuthRoleAttr.ts b/src/entities/AuthRoleAttr.ts new file mode 100644 index 00000000..e0ff0a41 --- /dev/null +++ b/src/entities/AuthRoleAttr.ts @@ -0,0 +1,102 @@ +import { Entity, Column, OneToMany, ManyToOne, JoinColumn } from "typeorm"; +import { EntityBase } from "./base/Base"; +import { AuthSys } from "./AuthSys"; +import { AuthRole } from "./AuthRole"; + +@Entity("AuthRoleAttr") +export class AuthRoleAttr extends EntityBase { + @Column({ + nullable: true, + comment: "", + length: 255, + default: null, + }) + attrOwnership: string; + + @Column({ + comment: "", + default: false, + }) + attrIsCreate: boolean; + + @Column({ + comment: "", + default: false, + }) + attrIsList: boolean; + + @Column({ + comment: "", + default: false, + }) + attrIsGet: boolean; + + @Column({ + comment: "", + default: false, + }) + attrIsUpdate: boolean; + + @Column({ + comment: "", + default: false, + }) + attrIsDelete: boolean; + + @Column({ + nullable: true, + comment: "", + length: 255, + default: null, + }) + attrPrivilege: string; + + @Column({ + nullable: true, + length: 40, + comment: "คีย์นอก(FK)ของตาราง AuthRole", + default: null, + }) + authRoleId: string; + + @Column({ + nullable: true, + length: 255, + comment: "คีย์นอก(FK)ของตาราง AuthSys", + default: null, + }) + authSysId: string; + + @ManyToOne(() => AuthSys, (authSys) => authSys.authSys) + @JoinColumn({ name: "authSysId" }) + authRoleAttrForSys: AuthSys; + + @ManyToOne(() => AuthRole, (authRole) => authRole.authRoles) + @JoinColumn({ name: "authRoleId" }) + authRoleAttrForRole: AuthRole; +} + +export class CreateAuthRoleAttr { + @Column() + attrOwnership: string; + + @Column() + attrIsCreate: boolean; + + @Column() + attrIsList: boolean; + + @Column() + attrIsGet: boolean; + + @Column() + attrIsUpdate: boolean; + + @Column() + attrIsDelete: boolean; + + @Column() + attrPrivilege: string; +} + +export type UpdateAuthRoleAttr = Partial; diff --git a/src/entities/AuthSys.ts b/src/entities/AuthSys.ts new file mode 100644 index 00000000..32df3597 --- /dev/null +++ b/src/entities/AuthSys.ts @@ -0,0 +1,76 @@ +import { + Entity, + Column, + OneToMany, + CreateDateColumn, + UpdateDateColumn, + PrimaryColumn, +} from "typeorm"; +import { AuthRoleAttr } from "./AuthRoleAttr"; + +@Entity("AuthSys") +export class AuthSys { + @PrimaryColumn({ + comment: "ไอดีหลักของตาราง", + length: 255, + }) + id: string; + + @CreateDateColumn({ comment: "สร้างข้อมูลเมื่อ" }) + createdAt!: Date; + + @Column({ + comment: "User Id ที่สร้างข้อมูล", + length: 40, + default: "00000000-0000-0000-0000-000000000000", + }) + createdUserId!: String; + + @UpdateDateColumn({ comment: "แก้ไขข้อมูลล่าสุดเมื่อ" }) + lastUpdatedAt!: Date; + + @Column({ + comment: "User Id ที่แก้ไขข้อมูล", + length: 40, + default: "00000000-0000-0000-0000-000000000000", + }) + lastUpdateUserId!: String; + + @Column({ comment: "ชื่อ User ที่สร้างข้อมูล", length: 200, default: "string" }) + createdFullName!: String; + + @Column({ comment: "ชื่อ User ที่แก้ไขข้อมูลล่าสุด", length: 200, default: "string" }) + lastUpdateFullName!: String; + + @Column({ + nullable: true, + comment: "ชื่อระบบ", + length: 255, + default: null, + }) + sysName: string; + + @Column({ + nullable: true, + comment: "รายละเอียด", + length: 255, + default: null, + }) + sysDescription: string; + + @OneToMany(() => AuthRoleAttr, (authRoleAttr) => authRoleAttr.authRoleAttrForSys) + authSys: AuthRoleAttr[]; +} + +export class CreateAuthSys { + @PrimaryColumn() + id: string; + + @Column() + sysName: string; + + @Column() + sysDescription: string; +} + +export type UpdateAuthSys = Partial;