diff --git a/src/entities/Appoint.ts b/src/entities/Appoint.ts index 1970f69..8415b62 100644 --- a/src/entities/Appoint.ts +++ b/src/entities/Appoint.ts @@ -1,73 +1,75 @@ -import { Entity, Column, PrimaryGeneratedColumn, OneToMany, JoinColumn, OneToOne } from "typeorm" -import { EntityBase } from "./base/Base" -import { AppointDirector } from "./AppointDirector" -import { Personal } from "./Personal" +import { Entity, Column, PrimaryGeneratedColumn, OneToMany, JoinColumn, OneToOne } from "typeorm"; +import { EntityBase } from "./base/Base"; +import { AppointDirector } from "./AppointDirector"; +import { Personal } from "./Personal"; @Entity("appoint") export class Appoint extends EntityBase { - @PrimaryGeneratedColumn("uuid") - id: string + @PrimaryGeneratedColumn("uuid") + id: string; - @Column({ - nullable: false, - comment: "id ของคนทดลองงาน", - }) - profileId: string + @Column({ + nullable: false, + comment: "id ของคนทดลองงาน", + }) + profileId: string; - @Column({ - nullable: false, - comment: "หัวข้อ", - default: 0, - }) - topic: string + @Column({ + nullable: false, + comment: "หัวข้อ", + default: 0, + }) + topic: string; - @Column({ - nullable: true, - comment: "เลขที่คำสั่ง", - }) - commandNo: string + @Column({ + nullable: true, + comment: "เลขที่คำสั่ง", + }) + commandNo: string; - @Column({ - type: "enum", - enum: ["PENDING", "REPORT", "DONE"], - nullable: false, - default: "PENDING", - }) - status: string + @Column({ + type: "enum", + enum: ["PENDING", "REPORT", "DONE"], + nullable: false, + default: "PENDING", + }) + status: string; - @OneToMany(() => AppointDirector, (director: AppointDirector) => director.appoint) - @JoinColumn({ name: "id" }) - directors: AppointDirector[] + @OneToMany(() => AppointDirector, (director: AppointDirector) => director.appoint) + @JoinColumn({ name: "id" }) + directors: AppointDirector[]; - @OneToOne(() => Personal, (personal: Personal) => personal.personal_id) - @JoinColumn({ name: "profileId" }) - personal: Personal + @OneToOne(() => Personal, (personal) => personal.appoint, { cascade: true }) + personal: Personal; + // @OneToOne(() => Personal, (personal: Personal) => personal.personal_id) + // @JoinColumn({ name: "profileId" }) + // personal: Personal } export class CreateAppoint { - @Column() - topic: string - profileId: string + @Column() + topic: string; + profileId: string; } export type Person = { - profileId: string - name: string | null - position?: string | null - positionType?: string | null - positionLevel?: string | null - role: string | null - posNo?: string | null - actFullName?: string | null - prefix?: string | null - firstName?: string | null - lastName?: string | null - citizenId?: string | null - rootId?: string | null -} + profileId: string; + name: string | null; + position?: string | null; + positionType?: string | null; + positionLevel?: string | null; + role: string | null; + posNo?: string | null; + actFullName?: string | null; + prefix?: string | null; + firstName?: string | null; + lastName?: string | null; + citizenId?: string | null; + rootId?: string | null; +}; export class UpdateAppoint { - @Column() - topic: string - persons: Person[] + @Column() + topic: string; + persons: Person[]; } diff --git a/src/entities/Personal.ts b/src/entities/Personal.ts index 30650c2..a4946b7 100644 --- a/src/entities/Personal.ts +++ b/src/entities/Personal.ts @@ -1,205 +1,208 @@ -import { Entity, Column, PrimaryGeneratedColumn, OneToOne, JoinColumn, OneToMany } from "typeorm" -import { EntityBase } from "./base/Base" -import { Assign } from "./Assign" -import { Appoint } from "./Appoint" +import { Entity, Column, PrimaryGeneratedColumn, OneToOne, JoinColumn, OneToMany } from "typeorm"; +import { EntityBase } from "./base/Base"; +import { Assign } from "./Assign"; +import { Appoint } from "./Appoint"; @Entity("personal") export class Personal extends EntityBase { - @PrimaryGeneratedColumn("uuid") - personal_id: string + @PrimaryGeneratedColumn("uuid") + personal_id: string; - @Column({ - nullable: true, - comment: "เลขที่คำสั่งบรรจุ", - }) - order_number!: string + @Column({ + nullable: true, + comment: "เลขที่คำสั่งบรรจุ", + }) + order_number!: string; - @Column({ - nullable: false, - comment: - "1 อยู่ระหว่างการทดลองปฏิบัติหน้าที่ราชการ, 2 พ้นการทดลองปฏิบัติหน้าที่ราชการ, 3 ไม่พ้นการทดลองปฏิบัติหน้าที่ราชการ, 4 ยุติการทดลองปฏิบัติหน้าที่ราชการเนื่องจากเปลี่ยนตำแหน่ง, 5 ยุติการทดลองปฏิบัติหน้าที่ราชการเนื่องจากลาออก, 6 ยุติการทดลองปฏิบัติหน้าที่ราชการเนื่องจากถึงแก่กรรม, 7 ขยายระยะเวลาทดลองปฏิบัติหน้าที่ราชการ, 8 ดึงรายชื่อไปออกคำสั่งแล้ว", - default: 1, - }) - probation_status: number + @Column({ + nullable: false, + comment: + "1 อยู่ระหว่างการทดลองปฏิบัติหน้าที่ราชการ, 2 พ้นการทดลองปฏิบัติหน้าที่ราชการ, 3 ไม่พ้นการทดลองปฏิบัติหน้าที่ราชการ, 4 ยุติการทดลองปฏิบัติหน้าที่ราชการเนื่องจากเปลี่ยนตำแหน่ง, 5 ยุติการทดลองปฏิบัติหน้าที่ราชการเนื่องจากลาออก, 6 ยุติการทดลองปฏิบัติหน้าที่ราชการเนื่องจากถึงแก่กรรม, 7 ขยายระยะเวลาทดลองปฏิบัติหน้าที่ราชการ, 8 ดึงรายชื่อไปออกคำสั่งแล้ว", + default: 1, + }) + probation_status: number; - @Column({ - nullable: false, - comment: "สถานะการใช้งาน 1 คือใช้งานปกติ, 0 คือไม่ใช้งาน", - default: 1, - }) - active: number + @Column({ + nullable: false, + comment: "สถานะการใช้งาน 1 คือใช้งานปกติ, 0 คือไม่ใช้งาน", + default: 1, + }) + active: number; - @Column({ - nullable: true, - comment: "คำนำหน้าชื่อ", - }) - prefixName: string + @Column({ + nullable: true, + comment: "คำนำหน้าชื่อ", + }) + prefixName: string; - @Column({ - nullable: false, - comment: "ชื่อ", - }) - firstName: string + @Column({ + nullable: false, + comment: "ชื่อ", + }) + firstName: string; - @Column({ - nullable: false, - comment: "นามสกุล", - }) - lastName: string + @Column({ + nullable: false, + comment: "นามสกุล", + }) + lastName: string; - @Column({ - type: Boolean, - comment: "สถานะการทดลองงาน 1 คืออยู่ระหว่างการทดลองงาน, 0 คือไม่อยู่ระหว่างการทดลองงาน", - default: 0, - }) - isProbation: number + @Column({ + type: Boolean, + comment: "สถานะการทดลองงาน 1 คืออยู่ระหว่างการทดลองงาน, 0 คือไม่อยู่ระหว่างการทดลองงาน", + default: 0, + }) + isProbation: number; - @Column({ - nullable: true, - comment: "ตำแหน่งในสายงาน", - }) - positionName: string + @Column({ + nullable: true, + comment: "ตำแหน่งในสายงาน", + }) + positionName: string; - @Column({ - nullable: true, - comment: "เลขที่ตำแหน่ง", - }) - posNo: string + @Column({ + nullable: true, + comment: "เลขที่ตำแหน่ง", + }) + posNo: string; - @Column({ - nullable: true, - comment: "ระดับตำแหน่ง", - }) - positionLevelName: string + @Column({ + nullable: true, + comment: "ระดับตำแหน่ง", + }) + positionLevelName: string; - @Column({ - nullable: true, - comment: "ด้าน/สาขา", - }) - positionLineName: string + @Column({ + nullable: true, + comment: "ด้าน/สาขา", + }) + positionLineName: string; - @Column({ - nullable: true, - comment: "ประเภทตำแหน่ง", - }) - positionTypeName: string + @Column({ + nullable: true, + comment: "ประเภทตำแหน่ง", + }) + positionTypeName: string; - @Column({ - nullable: true, - comment: "หน่วยงาน", - }) - orgRootName: string + @Column({ + nullable: true, + comment: "หน่วยงาน", + }) + orgRootName: string; - @Column({ - nullable: true, - comment: "สังกัด", - }) - organization: string + @Column({ + nullable: true, + comment: "สังกัด", + }) + organization: string; - @Column({ - nullable: true, - comment: "เลขบัตรประจำตัวประชาชน", - }) - idcard: string + @Column({ + nullable: true, + comment: "เลขบัตรประจำตัวประชาชน", + }) + idcard: string; - @Column({ nullable: true, comment: "id หน่วยงาน root", default: null }) - root: string + @Column({ nullable: true, comment: "id หน่วยงาน root", default: null }) + root: string; - @Column({ nullable: true, comment: "id หน่วยงาน child1", default: null }) - child1: string + @Column({ nullable: true, comment: "id หน่วยงาน child1", default: null }) + child1: string; - @Column({ nullable: true, comment: "id หน่วยงาน child2", default: null }) - child2: string + @Column({ nullable: true, comment: "id หน่วยงาน child2", default: null }) + child2: string; - @Column({ nullable: true, comment: "id หน่วยงาน child3", default: null }) - child3: string + @Column({ nullable: true, comment: "id หน่วยงาน child3", default: null }) + child3: string; - @Column({ nullable: true, comment: "id หน่วยงาน child4", default: null }) - child4: string + @Column({ nullable: true, comment: "id หน่วยงาน child4", default: null }) + child4: string; - @OneToMany(() => Assign, (assign: Assign) => assign.personal_id) - @JoinColumn({ name: "id" }) - assign: Assign[] + @OneToMany(() => Assign, (assign: Assign) => assign.personal_id) + @JoinColumn({ name: "id" }) + assign: Assign[]; - @OneToOne(() => Appoint, (appoint: Appoint) => appoint.profileId) - @JoinColumn({ name: "personal_id" }) - appoint: Appoint + @OneToOne(() => Appoint, (appoint) => appoint.personal) + @JoinColumn() + appoint: Appoint; + // @OneToOne(() => Appoint, (appoint: Appoint) => appoint.profileId) + // @JoinColumn({ name: "personal_id" }) + // appoint: Appoint } export class CreatePersonal { - @Column() - personal_id: string - @Column() - order_number: string - @Column() - probation_status: number - // @Column() - // profiles: PersonalProfile; - @Column() - createdUserId: string - @Column() - createdFullName: string - @Column() - updateUserId: string - @Column() - updateFullName: string - @Column() - prefixName: string - @Column() - firstName: string - @Column() - lastName: string - @Column() - isProbation: number - @Column() - positionName: string - @Column() - posNo: string - @Column() - positionLevelName: string - @Column() - positionTypeName: string - @Column() - positionLineName: string - @Column() - orgRootName: string - @Column() - organization: string - @Column() - idcard: string + @Column() + personal_id: string; + @Column() + order_number: string; + @Column() + probation_status: number; + // @Column() + // profiles: PersonalProfile; + @Column() + createdUserId: string; + @Column() + createdFullName: string; + @Column() + updateUserId: string; + @Column() + updateFullName: string; + @Column() + prefixName: string; + @Column() + firstName: string; + @Column() + lastName: string; + @Column() + isProbation: number; + @Column() + positionName: string; + @Column() + posNo: string; + @Column() + positionLevelName: string; + @Column() + positionTypeName: string; + @Column() + positionLineName: string; + @Column() + orgRootName: string; + @Column() + organization: string; + @Column() + idcard: string; } export class PostPersonal { - id: string - prefix: string - firstName: string - lastName: string - isProbation: boolean - posTypeName?: string | null - posLevelName: string | null - position: string | null - posLineName?: string | null - posNo?: string | null - organization?: string - orgRootName: string | null - orgChild1Name?: string | null - orgChild2Name?: string | null - orgChild3Name?: string | null - orgChild4Name?: string | null + id: string; + prefix: string; + firstName: string; + lastName: string; + isProbation: boolean; + posTypeName?: string | null; + posLevelName: string | null; + position: string | null; + posLineName?: string | null; + posNo?: string | null; + organization?: string; + orgRootName: string | null; + orgChild1Name?: string | null; + orgChild2Name?: string | null; + orgChild3Name?: string | null; + orgChild4Name?: string | null; - order_number?: string - rank?: string | null - idcard?: string - positionField?: string | null - positionArea?: string | null - posExecutiveName?: string | null - positionExecutiveField?: string | null + order_number?: string; + rank?: string | null; + idcard?: string; + positionField?: string | null; + positionArea?: string | null; + posExecutiveName?: string | null; + positionExecutiveField?: string | null; - root?: string | null - child1?: string | null - child2?: string | null - child3?: string | null - child4?: string | null + root?: string | null; + child1?: string | null; + child2?: string | null; + child3?: string | null; + child4?: string | null; } -export type UpdatePersonal = Partial +export type UpdatePersonal = Partial; diff --git a/src/migration/1735205130127-add_columns_appointDirector.ts b/src/migration/1735205130127-add_columns_appointDirector.ts deleted file mode 100644 index 0e034bc..0000000 --- a/src/migration/1735205130127-add_columns_appointDirector.ts +++ /dev/null @@ -1,30 +0,0 @@ -import { MigrationInterface, QueryRunner } from "typeorm"; - -export class AddColumnsAppointDirector1735205130127 implements MigrationInterface { - name = 'AddColumnsAppointDirector1735205130127' - - public async up(queryRunner: QueryRunner): Promise { - await queryRunner.query(`ALTER TABLE \`appointDirector\` ADD \`prefix\` varchar(40) NULL COMMENT 'คำนำหน้าชื่อ'`); - await queryRunner.query(`ALTER TABLE \`appointDirector\` ADD \`firstName\` varchar(255) NULL COMMENT 'ชื่อ'`); - await queryRunner.query(`ALTER TABLE \`appointDirector\` ADD \`lastName\` varchar(255) NULL COMMENT 'นามสกุล'`); - await queryRunner.query(`ALTER TABLE \`appointDirector\` ADD \`citizenId\` varchar(13) NULL COMMENT 'เลขประจำตัวประชาชน'`); - await queryRunner.query(`ALTER TABLE \`appointDirector\` ADD \`rootId\` varchar(40) NULL COMMENT 'คีย์นอก(FK)ของตาราง orgRoot'`); - await queryRunner.query(`ALTER TABLE \`appoint\` ADD UNIQUE INDEX \`IDX_46c617b30fd9def96938f43b6e\` (\`profileId\`)`); - await queryRunner.query(`CREATE UNIQUE INDEX \`REL_46c617b30fd9def96938f43b6e\` ON \`appoint\` (\`profileId\`)`); - await queryRunner.query(`ALTER TABLE \`appoint\` ADD CONSTRAINT \`FK_46c617b30fd9def96938f43b6ee\` FOREIGN KEY (\`profileId\`) REFERENCES \`personal\`(\`personal_id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`); - await queryRunner.query(`ALTER TABLE \`personal\` ADD CONSTRAINT \`FK_5abc77b4bd19c4295cabe6a3bf5\` FOREIGN KEY (\`personal_id\`) REFERENCES \`appoint\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`); - } - - public async down(queryRunner: QueryRunner): Promise { - await queryRunner.query(`ALTER TABLE \`personal\` DROP FOREIGN KEY \`FK_5abc77b4bd19c4295cabe6a3bf5\``); - await queryRunner.query(`ALTER TABLE \`appoint\` DROP FOREIGN KEY \`FK_46c617b30fd9def96938f43b6ee\``); - await queryRunner.query(`DROP INDEX \`REL_46c617b30fd9def96938f43b6e\` ON \`appoint\``); - await queryRunner.query(`ALTER TABLE \`appoint\` DROP INDEX \`IDX_46c617b30fd9def96938f43b6e\``); - await queryRunner.query(`ALTER TABLE \`appointDirector\` DROP COLUMN \`rootId\``); - await queryRunner.query(`ALTER TABLE \`appointDirector\` DROP COLUMN \`citizenId\``); - await queryRunner.query(`ALTER TABLE \`appointDirector\` DROP COLUMN \`lastName\``); - await queryRunner.query(`ALTER TABLE \`appointDirector\` DROP COLUMN \`firstName\``); - await queryRunner.query(`ALTER TABLE \`appointDirector\` DROP COLUMN \`prefix\``); - } - -} diff --git a/src/migration/1736239463356-updated.ts b/src/migration/1736239463356-updated.ts new file mode 100644 index 0000000..159fab0 --- /dev/null +++ b/src/migration/1736239463356-updated.ts @@ -0,0 +1,26 @@ +import { MigrationInterface, QueryRunner } from "typeorm"; + +export class Updated1736239463356 implements MigrationInterface { + name = 'Updated1736239463356' + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`appoint\` DROP FOREIGN KEY \`FK_46c617b30fd9def96938f43b6ee\``); + await queryRunner.query(`ALTER TABLE \`personal\` DROP FOREIGN KEY \`FK_5abc77b4bd19c4295cabe6a3bf5\``); + await queryRunner.query(`DROP INDEX \`REL_46c617b30fd9def96938f43b6e\` ON \`appoint\``); + await queryRunner.query(`ALTER TABLE \`personal\` ADD \`appointId\` varchar(36) NULL`); + await queryRunner.query(`ALTER TABLE \`personal\` ADD UNIQUE INDEX \`IDX_5c42dcafb9ff2c3785b9bf447a\` (\`appointId\`)`); + await queryRunner.query(`CREATE UNIQUE INDEX \`REL_5c42dcafb9ff2c3785b9bf447a\` ON \`personal\` (\`appointId\`)`); + await queryRunner.query(`ALTER TABLE \`personal\` ADD CONSTRAINT \`FK_5c42dcafb9ff2c3785b9bf447a3\` FOREIGN KEY (\`appointId\`) REFERENCES \`appoint\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`); + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`personal\` DROP FOREIGN KEY \`FK_5c42dcafb9ff2c3785b9bf447a3\``); + await queryRunner.query(`DROP INDEX \`REL_5c42dcafb9ff2c3785b9bf447a\` ON \`personal\``); + await queryRunner.query(`ALTER TABLE \`personal\` DROP INDEX \`IDX_5c42dcafb9ff2c3785b9bf447a\``); + await queryRunner.query(`ALTER TABLE \`personal\` DROP COLUMN \`appointId\``); + await queryRunner.query(`CREATE UNIQUE INDEX \`REL_46c617b30fd9def96938f43b6e\` ON \`appoint\` (\`profileId\`)`); + await queryRunner.query(`ALTER TABLE \`personal\` ADD CONSTRAINT \`FK_5abc77b4bd19c4295cabe6a3bf5\` FOREIGN KEY (\`personal_id\`) REFERENCES \`appoint\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`); + await queryRunner.query(`ALTER TABLE \`appoint\` ADD CONSTRAINT \`FK_46c617b30fd9def96938f43b6ee\` FOREIGN KEY (\`profileId\`) REFERENCES \`personal\`(\`personal_id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`); + } + +}