From 9d45d6b0e7482c96951a21af90bc146e06d06386 Mon Sep 17 00:00:00 2001 From: waruneeauy Date: Fri, 6 Jun 2025 15:13:41 +0700 Subject: [PATCH] add save child name --- src/controllers/PersonalController.ts | 14 +- src/entities/Personal.ts | 393 +++++++++--------- .../1749186876022-personal-add-child-name.ts | 20 + 3 files changed, 235 insertions(+), 192 deletions(-) create mode 100644 src/migration/1749186876022-personal-add-child-name.ts diff --git a/src/controllers/PersonalController.ts b/src/controllers/PersonalController.ts index 7bcb1f7..09d9c18 100644 --- a/src/controllers/PersonalController.ts +++ b/src/controllers/PersonalController.ts @@ -89,10 +89,16 @@ export class PersonalController extends Controller { personalData.child4 = requestBody.child4; personalData.rootDna = requestBody.rootDna; - personalData.child1Dna = requestBody.child1Dna; - personalData.child2Dna = requestBody.child2Dna; - personalData.child3Dna = requestBody.child3Dna; - personalData.child4Dna = requestBody.child4Dna; + personalData.child1Dna = requestBody.orgChild1Dna; + personalData.child2Dna = requestBody.orgChild2Dna; + personalData.child3Dna = requestBody.orgChild3Dna; + personalData.child4Dna = requestBody.orgChild4Dna; + + const getFieldValue = (field: string | null | undefined): string => field ?? ""; + personalData.orgChild1Name = getFieldValue(requestBody.orgChild1Name); + personalData.orgChild2Name = getFieldValue(requestBody.orgChild2Name); + personalData.orgChild3Name = getFieldValue(requestBody.orgChild3Name); + personalData.orgChild4Name = getFieldValue(requestBody.orgChild4Name); const before = null; const personal = await this.personalRepository.save(personalData, { diff --git a/src/entities/Personal.ts b/src/entities/Personal.ts index 6e3217e..e72fd85 100644 --- a/src/entities/Personal.ts +++ b/src/entities/Personal.ts @@ -1,230 +1,247 @@ -import { Entity, Column, PrimaryGeneratedColumn, OneToOne, JoinColumn, OneToMany } from "typeorm" -import { EntityBase } from "./base/Base" -import { Assign } from "./Assign" -import { Appoint } from "./Appoint" -import { Survey } from "./Survey" +import { Entity, Column, PrimaryGeneratedColumn, OneToOne, JoinColumn, OneToMany } from "typeorm"; +import { EntityBase } from "./base/Base"; +import { Assign } from "./Assign"; +import { Appoint } from "./Appoint"; +import { Survey } from "./Survey"; @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; - @Column({ nullable: true, comment: "id หน่วยงาน root", default: null }) - rootDna: string + @Column({ nullable: true, comment: "id หน่วยงาน root", default: null }) + rootDna: string; - @Column({ nullable: true, comment: "id หน่วยงาน child1", default: null }) - child1Dna: string + @Column({ nullable: true, comment: "id หน่วยงาน child1", default: null }) + child1Dna: string; - @Column({ nullable: true, comment: "id หน่วยงาน child2", default: null }) - child2Dna: string + @Column({ nullable: true, comment: "id หน่วยงาน child2", default: null }) + child2Dna: string; - @Column({ nullable: true, comment: "id หน่วยงาน child3", default: null }) - child3Dna: string + @Column({ nullable: true, comment: "id หน่วยงาน child3", default: null }) + child3Dna: string; - @Column({ nullable: true, comment: "id หน่วยงาน child4", default: null }) - child4Dna: string + @Column({ nullable: true, comment: "id หน่วยงาน child4", default: null }) + child4Dna: string; - @OneToMany(() => Assign, (assign: Assign) => assign.personal_id) - @JoinColumn({ name: "id" }) - assign: Assign[] + @Column({ nullable: true, comment: "ชื่อ หน่วยงาน child1", default: null }) + orgChild1Name: string; - @OneToOne(() => Appoint, appoint => appoint.personal) - @JoinColumn() - appoint: Appoint + @Column({ nullable: true, comment: "ชื่อ หน่วยงาน child2", default: null }) + orgChild2Name: string; - @OneToOne(() => Survey, { nullable: true }) - survey: Survey | null + @Column({ nullable: true, comment: "ชื่อ หน่วยงาน child3", default: null }) + orgChild3Name: string; + + @Column({ nullable: true, comment: "ชื่อ หน่วยงาน child4", default: null }) + orgChild4Name: string; + + @OneToMany(() => Assign, (assign: Assign) => assign.personal_id) + @JoinColumn({ name: "id" }) + assign: Assign[]; + + @OneToOne(() => Appoint, (appoint) => appoint.personal) + @JoinColumn() + appoint: Appoint; + + @OneToOne(() => Survey, { nullable: true }) + survey: Survey | null; } 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; - rootDna?: string | null - child1Dna?: string | null - child2Dna?: string | null - child3Dna?: string | null - child4Dna?: string | null + rootDna?: string | null; + child1Dna?: string | null; + child2Dna?: string | null; + child3Dna?: string | null; + child4Dna?: string | null; + + orgChild1Dna?: string | null; + orgChild2Dna?: string | null; + orgChild3Dna?: string | null; + orgChild4Dna?: string | null; } -export type UpdatePersonal = Partial +export type UpdatePersonal = Partial; diff --git a/src/migration/1749186876022-personal-add-child-name.ts b/src/migration/1749186876022-personal-add-child-name.ts new file mode 100644 index 0000000..1997ac6 --- /dev/null +++ b/src/migration/1749186876022-personal-add-child-name.ts @@ -0,0 +1,20 @@ +import { MigrationInterface, QueryRunner } from "typeorm"; + +export class PersonalAddChildName1749186876022 implements MigrationInterface { + name = 'PersonalAddChildName1749186876022' + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`personal\` ADD \`orgChild1Name\` varchar(255) NULL COMMENT 'ชื่อ หน่วยงาน child1'`); + await queryRunner.query(`ALTER TABLE \`personal\` ADD \`orgChild2Name\` varchar(255) NULL COMMENT 'ชื่อ หน่วยงาน child2'`); + await queryRunner.query(`ALTER TABLE \`personal\` ADD \`orgChild3Name\` varchar(255) NULL COMMENT 'ชื่อ หน่วยงาน child3'`); + await queryRunner.query(`ALTER TABLE \`personal\` ADD \`orgChild4Name\` varchar(255) NULL COMMENT 'ชื่อ หน่วยงาน child4'`); + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`personal\` DROP COLUMN \`orgChild4Name\``); + await queryRunner.query(`ALTER TABLE \`personal\` DROP COLUMN \`orgChild3Name\``); + await queryRunner.query(`ALTER TABLE \`personal\` DROP COLUMN \`orgChild2Name\``); + await queryRunner.query(`ALTER TABLE \`personal\` DROP COLUMN \`orgChild1Name\``); + } + +}