diff --git a/src/app.ts b/src/app.ts index 0c8d8450..14ac7424 100644 --- a/src/app.ts +++ b/src/app.ts @@ -4,8 +4,8 @@ import cors from "cors"; import express from "express"; import swaggerUi from "swagger-ui-express"; import swaggerDocument from "./swagger.json"; -import database from "./database/data-source"; import error from "./middlewares/error"; +import { database } from "./database/data-source"; import { RegisterRoutes } from "./routes"; async function main() { diff --git a/src/controllers/OrgRevisionController.ts b/src/controllers/OrgRevisionController.ts new file mode 100644 index 00000000..1d490226 --- /dev/null +++ b/src/controllers/OrgRevisionController.ts @@ -0,0 +1,11 @@ +import { Controller, Get, Route, Security, Tags } from "tsoa"; +import { database } from "../database/data-source"; + +@Route("/hello") +@Security("bearerAuth") +export class AppController extends Controller { + @Get() + public async GET() { + return { message: "Hello World 1" }; + } +} diff --git a/src/database/data-source.ts b/src/database/data-source.ts index fadafe6f..37e101c2 100644 --- a/src/database/data-source.ts +++ b/src/database/data-source.ts @@ -2,7 +2,7 @@ import "dotenv/config"; import "reflect-metadata"; import { DataSource } from "typeorm"; -const database = new DataSource({ +export const database = new DataSource({ type: "mysql", database: process.env.DB_NAME, host: process.env.DB_HOST, @@ -16,4 +16,4 @@ const database = new DataSource({ subscribers: [], }); -export default database; +// export default database; diff --git a/src/entities/OrgChild1.ts b/src/entities/OrgChild1.ts new file mode 100644 index 00000000..218b6bea --- /dev/null +++ b/src/entities/OrgChild1.ts @@ -0,0 +1,112 @@ +import { Entity, Column, ManyToOne, JoinColumn, OneToOne, OneToMany } from "typeorm"; +import { EntityBase } from "./base/Base"; +import { OrgRoot } from "./OrgRoot"; +import { OrgChild2 } from "./OrgChild2"; +import { OrgChild3 } from "./OrgChild3"; +import { OrgChild4 } from "./OrgChild4"; + +// ENUM orgChild1Rank +enum OrgChild1Rank { + DEPARTMENT = "department", + OFFICE = "office", + DIVISION = "division", + SECTION = "section", +} + +export class OrgChild1 extends EntityBase { +// @Column({ +// comment: "", +// length: 40, +// default: "00000000-0000-0000-0000-000000000000", +// }) +// orgChild1Id: string; + + @Column({ + nullable: true, + comment: "ชื่อส่วนราชการ", + length: 255, + default: "string", + }) + orgChild1Name: string; + + @Column({ + nullable: true, + comment: "ชื่อย่อส่วนราชการ", + length: 16, + default: "string", + }) + orgChild1ShortName: string; + + @Column({ + nullable: true, + comment: "รหัสส่วนราชการ", + length: 8, + default: "string", + }) + orgChild1Code: string; + + @Column({ + nullable: true, + comment: "ระดับส่วนราชการ", + type: "enum", + enum: OrgChild1Rank, + // default: OrgChild1Rank.DEPARTMENT, + }) + orgChild1Rank: OrgChild1Rank; + + @Column({ + nullable: true, + comment: "ลำดับที่ของส่วนราชการภายใน Child เดียวกัน", + }) + orgChild1Order: number; + + @Column({ + nullable: true, + length: 64, + comment: "หมายเลขโทรศัพท์ที่ติดต่อจากภายนอก", + }) + orgChild1PhoneEx: string; + + @Column({ + nullable: true, + length: 64, + comment: "หมายเลขโทรศัพท์ที่ติดต่อจากภายใน", + }) + orgChild1PhoneIn: string; + + @Column({ + nullable: true, + length: 64, + comment: "หมายเลขโทรสาร", + }) + orgChild1Fax: string; + + @Column({ + nullable: true, + type: "tinyint", + comment: "สถานะของหน่วยงาน", //ปกติ = 1 , ยุกเลิก = 0 + }) + orgChild1IsNormal: number; + + @Column({ + length: 40, + default: "00000000-0000-0000-0000-000000000000", + }) + fkOrgRootId: string; + + @ManyToOne(() => OrgRoot, orgRoot => orgRoot.orgChild1s) + @JoinColumn({ name: "fkOrgRootId" }) + orgRoot: OrgRoot; + + //child table 2,3,4 + @OneToMany(() => OrgChild2, orgChild2 => orgChild2.orgChild1) + orgChild2s: OrgChild2[]; + + @OneToMany(() => OrgChild3, orgChild3 => orgChild3.orgChild1) + orgChild3s: OrgChild3[]; + + @OneToMany(() => OrgChild4, orgChild4 => orgChild4.orgChild1) + orgChild4s: OrgChild4[]; + +} +export type UpdateOrgChild1 = Partial; diff --git a/src/entities/OrgChild2.ts b/src/entities/OrgChild2.ts new file mode 100644 index 00000000..ce7d2c63 --- /dev/null +++ b/src/entities/OrgChild2.ts @@ -0,0 +1,119 @@ +import { Entity, Column, ManyToOne, JoinColumn, OneToOne, OneToMany } from "typeorm"; +import { EntityBase } from "./base/Base"; +import { OrgRoot } from "./OrgRoot"; +import { OrgChild1 } from "./OrgChild1"; +import { OrgChild3 } from "./OrgChild3"; +import { OrgChild4 } from "./OrgChild4"; + +// ENUM orgChild2Rank +enum OrgChild2Rank { + DEPARTMENT = "department", + OFFICE = "office", + DIVISION = "division", + SECTION = "section", +} + +export class OrgChild2 extends EntityBase { +// @Column({ +// comment: "", +// length: 40, +// default: "00000000-0000-0000-0000-000000000000", +// }) +// orgChild2Id: string; + + @Column({ + nullable: true, + comment: "ชื่อส่วนราชการ", + length: 255, + default: "string", + }) + orgChild2Name: string; + + @Column({ + nullable: true, + comment: "ชื่อย่อส่วนราชการ", + length: 16, + default: "string", + }) + orgChild2ShortName: string; + + @Column({ + nullable: true, + comment: "รหัสส่วนราชการ", + length: 8, + default: "string", + }) + orgChild2Code: string; + + @Column({ + nullable: true, + comment: "ระดับส่วนราชการ", + type: "enum", + enum: OrgChild2Rank, + // default: OrgChild2Rank.DEPARTMENT, + }) + orgChild2Rank: OrgChild2Rank; + + @Column({ + nullable: true, + comment: "ลำดับที่ของส่วนราชการภายใน Child เดียวกัน", + }) + orgChild2Order: number; + + @Column({ + nullable: true, + length: 64, + comment: "หมายเลขโทรศัพท์ที่ติดต่อจากภายนอก", + }) + orgChild2PhoneEx: string; + + @Column({ + nullable: true, + length: 64, + comment: "หมายเลขโทรศัพท์ที่ติดต่อจากภายใน", + }) + orgChild2PhoneIn: string; + + @Column({ + nullable: true, + length: 64, + comment: "หมายเลขโทรสาร", + }) + orgChild2Fax: string; + + @Column({ + nullable: true, + type: "tinyint", + comment: "สถานะของหน่วยงาน", //ปกติ = 1 , ยุกเลิก = 0 + }) + orgChild2IsNormal: number; + + @Column({ + length: 40, + default: "00000000-0000-0000-0000-000000000000", + }) + fkOrgRootId: string; + + @Column({ + length: 40, + default: "00000000-0000-0000-0000-000000000000", + }) + fkOrgChild1Id: string; + + @ManyToOne(() => OrgRoot, orgRoot => orgRoot.orgChild2s) + @JoinColumn({ name: "fkOrgRootId" }) + orgRoot: OrgRoot; + + @ManyToOne(() => OrgChild1, orgChild1 => orgChild1.orgChild2s) + @JoinColumn({ name: "fkOrgChild1Id" }) + orgChild1: OrgChild1; + + //child table 3,4 + @OneToMany(() => OrgChild3, orgChild3 => orgChild3.orgChild2) + orgChild3s: OrgChild3[]; + + @OneToMany(() => OrgChild4, orgChild4 => orgChild4.orgChild2) + orgChild4s: OrgChild4[]; + +} +export type UpdateOrgChild2 = Partial; diff --git a/src/entities/OrgChild3.ts b/src/entities/OrgChild3.ts new file mode 100644 index 00000000..29be5195 --- /dev/null +++ b/src/entities/OrgChild3.ts @@ -0,0 +1,125 @@ +import { Entity, Column, ManyToOne, JoinColumn, OneToOne, OneToMany } from "typeorm"; +import { EntityBase } from "./base/Base"; +import { OrgRoot } from "./OrgRoot"; +import { OrgChild1 } from "./OrgChild1"; +import { OrgChild2 } from "./OrgChild2"; +import { OrgChild4 } from "./OrgChild4"; +// ENUM orgChild3Rank +enum OrgChild3Rank { + DEPARTMENT = "department", + OFFICE = "office", + DIVISION = "division", + SECTION = "section", +} + +export class OrgChild3 extends EntityBase { +// @Column({ +// comment: "", +// length: 40, +// default: "00000000-0000-0000-0000-000000000000", +// }) +// orgChild3Id: string; + + @Column({ + nullable: true, + comment: "ชื่อส่วนราชการ", + length: 255, + default: "string", + }) + orgChild3Name: string; + + @Column({ + nullable: true, + comment: "ชื่อย่อส่วนราชการ", + length: 16, + default: "string", + }) + orgChild3ShortName: string; + + @Column({ + nullable: true, + comment: "รหัสส่วนราชการ", + length: 8, + default: "string", + }) + orgChild3Code: string; + + @Column({ + nullable: true, + comment: "ระดับส่วนราชการ", + type: "enum", + enum: OrgChild3Rank, + // default: OrgChild3Rank.DEPARTMENT, + }) + orgChild3Rank: OrgChild3Rank; + + @Column({ + nullable: true, + comment: "ลำดับที่ของส่วนราชการภายใน Child เดียวกัน", + }) + orgChild3Order: number; + + @Column({ + nullable: true, + length: 64, + comment: "หมายเลขโทรศัพท์ที่ติดต่อจากภายนอก", + }) + orgChild3PhoneEx: string; + + @Column({ + nullable: true, + length: 64, + comment: "หมายเลขโทรศัพท์ที่ติดต่อจากภายใน", + }) + orgChild3PhoneIn: string; + + @Column({ + nullable: true, + length: 64, + comment: "หมายเลขโทรสาร", + }) + orgChild3Fax: string; + + @Column({ + nullable: true, + type: "tinyint", + comment: "สถานะของหน่วยงาน", //ปกติ = 1 , ยุกเลิก = 0 + }) + orgChild3IsNormal: number; + + @Column({ + length: 40, + default: "00000000-0000-0000-0000-000000000000", + }) + fkOrgRootId: string; + + @Column({ + length: 40, + default: "00000000-0000-0000-0000-000000000000", + }) + fkOrgChild1Id: string; + + @Column({ + length: 40, + default: "00000000-0000-0000-0000-000000000000", + }) + fkOrgChild2Id: string; + + @ManyToOne(() => OrgRoot, orgRoot => orgRoot.orgChild3s) + @JoinColumn({ name: "fkOrgRootId" }) + orgRoot: OrgRoot; + + @ManyToOne(() => OrgChild1, orgChild1 => orgChild1.orgChild3s) + @JoinColumn({ name: "fkOrgChild1Id" }) + orgChild1: OrgChild1; + + @ManyToOne(() => OrgChild2, orgChild2 => orgChild2.orgChild3s) + @JoinColumn({ name: "fkOrgChild2Id" }) + orgChild2: OrgChild2; + + //child table 4 + @OneToMany(() => OrgChild4, orgChild4 => orgChild4.orgChild3) + orgChild4s: OrgChild4[]; + +} +export type UpdateOrgChild3 = Partial; diff --git a/src/entities/OrgChild4.ts b/src/entities/OrgChild4.ts new file mode 100644 index 00000000..acf4c8af --- /dev/null +++ b/src/entities/OrgChild4.ts @@ -0,0 +1,130 @@ +import { Entity, Column, ManyToOne, JoinColumn, OneToOne } from "typeorm"; +import { EntityBase } from "./base/Base"; +import { OrgRoot } from "./OrgRoot"; +import { OrgChild1 } from "./OrgChild1"; +import { OrgChild2 } from "./OrgChild2"; +import { OrgChild3 } from "./OrgChild3"; +// ENUM orgChild4Rank +enum OrgChild4Rank { + DEPARTMENT = "department", + OFFICE = "office", + DIVISION = "division", + SECTION = "section", +} + +export class OrgChild4 extends EntityBase { +// @Column({ +// comment: "", +// length: 40, +// default: "00000000-0000-0000-0000-000000000000", +// }) +// orgChild4Id: string; + + @Column({ + nullable: true, + comment: "ชื่อส่วนราชการ", + length: 255, + default: "string", + }) + orgChild4Name: string; + + @Column({ + nullable: true, + comment: "ชื่อย่อส่วนราชการ", + length: 16, + default: "string", + }) + orgChild4ShortName: string; + + @Column({ + nullable: true, + comment: "รหัสส่วนราชการ", + length: 8, + default: "string", + }) + orgChild4Code: string; + + @Column({ + nullable: true, + comment: "ระดับส่วนราชการ", + type: "enum", + enum: OrgChild4Rank, + // default: OrgChild4Rank.DEPARTMENT, + }) + orgChild4Rank: OrgChild4Rank; + + @Column({ + nullable: true, + comment: "ลำดับที่ของส่วนราชการภายใน Child เดียวกัน", + }) + orgChild4Order: number; + + @Column({ + nullable: true, + length: 64, + comment: "หมายเลขโทรศัพท์ที่ติดต่อจากภายนอก", + }) + orgChild4PhoneEx: string; + + @Column({ + nullable: true, + length: 64, + comment: "หมายเลขโทรศัพท์ที่ติดต่อจากภายใน", + }) + orgChild4PhoneIn: string; + + @Column({ + nullable: true, + length: 64, + comment: "หมายเลขโทรสาร", + }) + orgChild4Fax: string; + + @Column({ + nullable: true, + type: "tinyint", + comment: "สถานะของหน่วยงาน", //ปกติ = 1 , ยุกเลิก = 0 + }) + orgChild4IsNormal: number; + + @Column({ + length: 40, + default: "00000000-0000-0000-0000-000000000000", + }) + fkOrgRootId: string; + + @Column({ + length: 40, + default: "00000000-0000-0000-0000-000000000000", + }) + fkOrgChild1Id: string; + + @Column({ + length: 40, + default: "00000000-0000-0000-0000-000000000000", + }) + fkOrgChild2Id: string; + + @Column({ + length: 40, + default: "00000000-0000-0000-0000-000000000000", + }) + fkOrgChild3Id: string; + + @ManyToOne(() => OrgRoot, orgRoot => orgRoot.orgChild4s) + @JoinColumn({ name: "fkOrgRootId" }) + orgRoot: OrgRoot; + + @ManyToOne(() => OrgChild1, orgChild1 => orgChild1.orgChild4s) + @JoinColumn({ name: "fkOrgChild1Id" }) + orgChild1: OrgChild1; + + @ManyToOne(() => OrgChild2, orgChild2 => orgChild2.orgChild4s) + @JoinColumn({ name: "fkOrgChild2Id" }) + orgChild2: OrgChild2; + + @ManyToOne(() => OrgChild3, orgChild3 => orgChild3.orgChild4s) + @JoinColumn({ name: "fkOrgChild3Id" }) + orgChild3: OrgChild3; +} +export type UpdateOrgChild4 = Partial; diff --git a/src/entities/OrgRevision.ts b/src/entities/OrgRevision.ts new file mode 100644 index 00000000..ef70223c --- /dev/null +++ b/src/entities/OrgRevision.ts @@ -0,0 +1,42 @@ +import { Entity, Column, ManyToOne, JoinColumn, OneToOne } from "typeorm"; +import { EntityBase } from "./base/Base"; + +@Entity("orgRevision") +export class OrgRevision extends EntityBase { + @Column({ + comment: "", + length: 40, + default: "00000000-0000-0000-0000-000000000000", + }) + orgRevisionId: string; + + @Column({ + comment: "", + length: 255, + default: "string", + }) + orgRevisionName: string; + + @Column({ + nullable: true, + type: "tinyint", + comment: "", + }) + orgRevisionIsCurrent: number; + + @Column({ + nullable: true, + type: "datetime", + comment: "", + }) + orgRevisionCreatedAt: Date; + + @Column({ + nullable: true, + type: "tinyint", + comment: "", + }) + orgRevisionIsDraft: number; +} + +export type UpdateOrgRevision = Partial; diff --git a/src/entities/OrgRoot.ts b/src/entities/OrgRoot.ts new file mode 100644 index 00000000..6c850c24 --- /dev/null +++ b/src/entities/OrgRoot.ts @@ -0,0 +1,113 @@ +import { Entity, Column, ManyToOne, JoinColumn, OneToOne, OneToMany } from "typeorm"; +import { EntityBase } from "./base/Base"; +import { OrgChild1 } from "./OrgChild1"; +import { OrgChild2 } from "./OrgChild2"; +import { OrgChild3 } from "./OrgChild3"; +import { OrgChild4 } from "./OrgChild4"; + +// ENUM orgRootRank +enum OrgRootRank { + DEPARTMENT = "department", + OFFICE = "office", + DIVISION = "division", + SECTION = "section", +} + +@Entity("orgRoot") +export class OrgRoot extends EntityBase { +// @Column({ +// comment: "", +// length: 40, +// default: "00000000-0000-0000-0000-000000000000", +// }) +// orgRootId: string; + + @Column({ + nullable: true, + comment: "ชื่อหน่วยงาน", + length: 255, + default: "string", + }) + orgRootName: string; + + @Column({ + nullable: true, + comment: "ชื่อย่อหน่วยงาน", + length: 16, + default: "string", + }) + orgRootShortName: string; + + @Column({ + nullable: true, + comment: "รหัสหน่วยงาน", + length: 8, + default: "string", + }) + orgRootCode: string; + + @Column({ + nullable: true, + comment: "ระดับของหน่วยงาน", + type: "enum", + enum: OrgRootRank, + default: OrgRootRank.DEPARTMENT, + }) + orgRootRank: OrgRootRank; + + @Column({ + nullable: true, + comment: "ลำดับที่ของหน่วยงาน", + }) + orgRootOrder: number; + + @Column({ + nullable: true, + length: 64, + comment: "หมายเลขโทรศัพท์ที่ติดต่อจากภายนอก", + }) + orgRootPhoneEx: string; + + @Column({ + nullable: true, + length: 64, + comment: "หมายเลขโทรศัพท์ที่ติดต่อจากภายใน", + }) + orgRootPhoneIn: string; + + @Column({ + nullable: true, + length: 64, + comment: "หมายเลขโทรสาร", + }) + orgRootFax: string; + + @Column({ + nullable: true, + type: "tinyint", + comment: "สถานะของหน่วยงาน", //ปกติ = 1 , ยุกเลิก = 0 + }) + orgRootIsNormal: number; + + @Column({ + length: 40, + default: "00000000-0000-0000-0000-000000000000", + }) + fkOrgRevisionId: string; + + //child table 1,2,3,4 + @OneToMany(() => OrgChild1, orgChild1 => orgChild1.orgRoot) + orgChild1s: OrgChild1[]; + + @OneToMany(() => OrgChild2, orgChild2 => orgChild2.orgRoot) + orgChild2s: OrgChild2[]; + + @OneToMany(() => OrgChild3, orgChild3 => orgChild3.orgRoot) + orgChild3s: OrgChild3[]; + + @OneToMany(() => OrgChild4, orgChild4 => orgChild4.orgRoot) + orgChild4s: OrgChild4[]; + +} + +export type UpdateOrgRoot = Partial;