From b7ca6795cba12af8fb3c7b0312ccffe20bcb6475 Mon Sep 17 00:00:00 2001 From: Bright Date: Wed, 15 May 2024 14:34:21 +0700 Subject: [PATCH 1/2] Fix Entity --- src/entities/ProfileFamilyCouple.ts | 7 +-- src/entities/ProfileFamilyCoupleHistory.ts | 54 ++++++++++++++++------ src/entities/ProfileFamilyFather.ts | 7 +-- src/entities/ProfileFamilyFatherHistory.ts | 4 +- src/entities/ProfileFamilyMother.ts | 7 +-- src/entities/ProfileFamilyMotherHistory.ts | 5 +- 6 files changed, 49 insertions(+), 35 deletions(-) diff --git a/src/entities/ProfileFamilyCouple.ts b/src/entities/ProfileFamilyCouple.ts index 0157177c..243542f6 100644 --- a/src/entities/ProfileFamilyCouple.ts +++ b/src/entities/ProfileFamilyCouple.ts @@ -90,11 +90,8 @@ export class ProfileFamilyCouple extends EntityBase { }) profileEmployeeId: string; - @OneToMany( - () => ProfileFamilyCoupleHistory, - (v) => v.histories, - ) - profileFamilyCouple: ProfileFamilyCoupleHistory[]; + @OneToMany(() => ProfileFamilyCoupleHistory, (v) => v.profileFamilyCouple) + histories: ProfileFamilyCoupleHistory[]; @ManyToOne(() => Profile, (v) => v.profileFamilyCouple) @JoinColumn({ name: "profileId" }) diff --git a/src/entities/ProfileFamilyCoupleHistory.ts b/src/entities/ProfileFamilyCoupleHistory.ts index d831bf3a..a350fc59 100644 --- a/src/entities/ProfileFamilyCoupleHistory.ts +++ b/src/entities/ProfileFamilyCoupleHistory.ts @@ -7,54 +7,78 @@ export class ProfileFamilyCoupleHistory extends EntityBase { @Column({ nullable: true, default: null, - comment: "คำนำหน้าบิดา", + type: "boolean", }) - fatherPrefix: string; + couple: boolean; @Column({ nullable: true, default: null, - comment: "ชื่อบิดา", + comment: "คำนำหน้าคู่สมรส", }) - fatherFirstName: string; + couplePrefix: string; @Column({ nullable: true, default: null, - comment: "นามสกุลบิดา", + comment: "ชื่อคู่สมรส", }) - fatherLastName: string; + coupleFirstName: string; @Column({ nullable: true, default: null, - comment: "อาชีพบิดา", + comment: "นามสกุลคู่สมรส", }) - fatherCareer: string; + coupleLastName: string; @Column({ nullable: true, default: null, - comment: "เลขที่บัตรประชาชนบิดา", + comment: "นามสกุลคู่สมรส(เดิม)", }) - fatherCitizenId: string; + coupleLastNameOld: string; @Column({ nullable: true, default: null, - comment: "มีชีวิตบิดา", + comment: "อาชีพคู่สมรส", }) - fatherLive: boolean; + coupleCareer: string; + @Column({ + nullable: true, + default: null, + length: 13, + comment: "เลขที่บัตรประชาชนคู่สมรส", + }) + coupleCitizenId: string; + + @Column({ + nullable: true, + default: null, + type: "boolean", + comment: "มีชีวิตคู่สมรส", + }) + coupleLive: boolean; + + @Column({ + nullable: true, + comment: "ความสัมพันธ์", + length: 40, + default: null, + }) + relationship: string; + @Column({ nullable: true, length: 40, - comment: "คีย์นอก(FK)ของตาราง ProfileFamilyFather", + comment: "คีย์นอก(FK)ของตาราง ProfileFamilyCouple", default: null, }) profileFamilyCoupleId: string; - @ManyToOne(() => ProfileFamilyCouple, (v) => v.profileFamilyCouple) + @ManyToOne(() => ProfileFamilyCouple, (v) => v.histories) @JoinColumn({ name: "profileFamilyCoupleId" }) - histories: ProfileFamilyCouple; + profileFamilyCouple: ProfileFamilyCouple; } diff --git a/src/entities/ProfileFamilyFather.ts b/src/entities/ProfileFamilyFather.ts index 8b56d64e..407afb2d 100644 --- a/src/entities/ProfileFamilyFather.ts +++ b/src/entities/ProfileFamilyFather.ts @@ -66,11 +66,8 @@ export class ProfileFamilyFather extends EntityBase { }) profileEmployeeId: string; - @OneToMany( - () => ProfileFamilyFatherHistory, - (v) => v.histories, - ) - profileFamilyFather: ProfileFamilyFatherHistory[]; + @OneToMany(() => ProfileFamilyFatherHistory, (v) => v.profileFamilyFather) + histories: ProfileFamilyFatherHistory[]; @ManyToOne(() => Profile, (v) => v.profileFamilyFather) @JoinColumn({ name: "profileId" }) diff --git a/src/entities/ProfileFamilyFatherHistory.ts b/src/entities/ProfileFamilyFatherHistory.ts index dd99f6be..3c471b2c 100644 --- a/src/entities/ProfileFamilyFatherHistory.ts +++ b/src/entities/ProfileFamilyFatherHistory.ts @@ -54,7 +54,7 @@ export class ProfileFamilyFatherHistory extends EntityBase { }) profileFamilyFatherId: string; - @ManyToOne(() => ProfileFamilyFather, (v) => v.profileFamilyFather) + @ManyToOne(() => ProfileFamilyFather, (v) => v.histories) @JoinColumn({ name: "profileFamilyFatherId" }) - histories: ProfileFamilyFather; + profileFamilyFather: ProfileFamilyFather; } diff --git a/src/entities/ProfileFamilyMother.ts b/src/entities/ProfileFamilyMother.ts index c143237d..93bd5b4c 100644 --- a/src/entities/ProfileFamilyMother.ts +++ b/src/entities/ProfileFamilyMother.ts @@ -66,11 +66,8 @@ export class ProfileFamilyMother extends EntityBase { }) profileEmployeeId: string; - @OneToMany( - () => ProfileFamilyMotherHistory, - (v) => v.histories, - ) - profileFamilyMother: ProfileFamilyMotherHistory[]; + @OneToMany(() => ProfileFamilyMotherHistory, (v) => v.profileFamilyMother) + histories: ProfileFamilyMotherHistory[]; @ManyToOne(() => Profile, (v) => v.profileFamilyMother) @JoinColumn({ name: "profileId" }) diff --git a/src/entities/ProfileFamilyMotherHistory.ts b/src/entities/ProfileFamilyMotherHistory.ts index 90fd6a90..f43b667d 100644 --- a/src/entities/ProfileFamilyMotherHistory.ts +++ b/src/entities/ProfileFamilyMotherHistory.ts @@ -4,7 +4,6 @@ import { ProfileFamilyMother } from "./ProfileFamilyMother"; @Entity("profileFamilyMotherHistory") export class ProfileFamilyMotherHistory extends EntityBase { - @Column({ nullable: true, default: null, @@ -55,7 +54,7 @@ export class ProfileFamilyMotherHistory extends EntityBase { }) profileFamilyMotherId: string; - @ManyToOne(() => ProfileFamilyMother, (v) => v.profileFamilyMother) + @ManyToOne(() => ProfileFamilyMother, (v) => v.histories) @JoinColumn({ name: "profileFamilyMotherId" }) - histories: ProfileFamilyMother; + profileFamilyMother: ProfileFamilyMother; } From 9365c6c62e884517a4f37c41184279a1dae88e16 Mon Sep 17 00:00:00 2001 From: Kittapath Date: Wed, 15 May 2024 15:29:23 +0700 Subject: [PATCH 2/2] no message --- src/controllers/ProfileAvatarController.ts | 7 ++- src/entities/Profile.ts | 7 +++ src/entities/ProfileAvatar.ts | 7 +++ .../1715760265657-add_table_avatarName.ts | 58 +++++++++++++++++++ 4 files changed, 77 insertions(+), 2 deletions(-) create mode 100644 src/migration/1715760265657-add_table_avatarName.ts diff --git a/src/controllers/ProfileAvatarController.ts b/src/controllers/ProfileAvatarController.ts index f98b202e..70d5d99a 100644 --- a/src/controllers/ProfileAvatarController.ts +++ b/src/controllers/ProfileAvatarController.ts @@ -42,13 +42,16 @@ export class ProfileAvatarController extends Controller { Object.assign(data, { ...body, ...meta }); await this.avatarRepository.save(data); - let avatar = `ทะเบียนประวัติ/โปรไฟล์/${profile.id}/profile-${data.id}`; + let avatar = `ทะเบียนประวัติ/โปรไฟล์/${profile.id}`; + let fileName = `profile-${data.id}`; data.avatar = avatar; + data.avatarName = fileName; await this.avatarRepository.save(data); profile.avatar = avatar; + profile.avatarName = fileName; await this.profileRepository.save(profile); - return new HttpSuccess(avatar); + return new HttpSuccess({ avatar: avatar, avatarName: fileName }); } @Delete("{avatarId}") diff --git a/src/entities/Profile.ts b/src/entities/Profile.ts index e5ab9173..8be9074f 100644 --- a/src/entities/Profile.ts +++ b/src/entities/Profile.ts @@ -36,6 +36,13 @@ export class Profile extends EntityBase { }) avatar: string; + @Column({ + nullable: true, + comment: "รูปถ่าย", + default: null, + }) + avatarName: string; + @Column({ nullable: true, comment: "ยศ", diff --git a/src/entities/ProfileAvatar.ts b/src/entities/ProfileAvatar.ts index 0f4b03ed..45364479 100644 --- a/src/entities/ProfileAvatar.ts +++ b/src/entities/ProfileAvatar.ts @@ -12,6 +12,13 @@ export class ProfileAvatar extends EntityBase { }) avatar: string; + @Column({ + nullable: true, + comment: "รูปถ่าย", + default: null, + }) + avatarName: string; + @Column({ nullable: true, length: 40, diff --git a/src/migration/1715760265657-add_table_avatarName.ts b/src/migration/1715760265657-add_table_avatarName.ts new file mode 100644 index 00000000..86281d94 --- /dev/null +++ b/src/migration/1715760265657-add_table_avatarName.ts @@ -0,0 +1,58 @@ +import { MigrationInterface, QueryRunner } from "typeorm"; + +export class AddTableAvatarName1715760265657 implements MigrationInterface { + name = 'AddTableAvatarName1715760265657' + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`profileFamilyCoupleHistory\` DROP COLUMN \`fatherCareer\``); + await queryRunner.query(`ALTER TABLE \`profileFamilyCoupleHistory\` DROP COLUMN \`fatherCitizenId\``); + await queryRunner.query(`ALTER TABLE \`profileFamilyCoupleHistory\` DROP COLUMN \`fatherFirstName\``); + await queryRunner.query(`ALTER TABLE \`profileFamilyCoupleHistory\` DROP COLUMN \`fatherLastName\``); + await queryRunner.query(`ALTER TABLE \`profileFamilyCoupleHistory\` DROP COLUMN \`fatherLive\``); + await queryRunner.query(`ALTER TABLE \`profileFamilyCoupleHistory\` DROP COLUMN \`fatherPrefix\``); + await queryRunner.query(`ALTER TABLE \`profileAvatar\` ADD \`avatarName\` varchar(255) NULL COMMENT 'รูปถ่าย'`); + await queryRunner.query(`ALTER TABLE \`profileFamilyCoupleHistory\` ADD \`couple\` tinyint NULL`); + await queryRunner.query(`ALTER TABLE \`profileFamilyCoupleHistory\` ADD \`couplePrefix\` varchar(255) NULL COMMENT 'คำนำหน้าคู่สมรส'`); + await queryRunner.query(`ALTER TABLE \`profileFamilyCoupleHistory\` ADD \`coupleFirstName\` varchar(255) NULL COMMENT 'ชื่อคู่สมรส'`); + await queryRunner.query(`ALTER TABLE \`profileFamilyCoupleHistory\` ADD \`coupleLastName\` varchar(255) NULL COMMENT 'นามสกุลคู่สมรส'`); + await queryRunner.query(`ALTER TABLE \`profileFamilyCoupleHistory\` ADD \`coupleLastNameOld\` varchar(255) NULL COMMENT 'นามสกุลคู่สมรส(เดิม)'`); + await queryRunner.query(`ALTER TABLE \`profileFamilyCoupleHistory\` ADD \`coupleCareer\` varchar(255) NULL COMMENT 'อาชีพคู่สมรส'`); + await queryRunner.query(`ALTER TABLE \`profileFamilyCoupleHistory\` ADD \`coupleCitizenId\` varchar(13) NULL COMMENT 'เลขที่บัตรประชาชนคู่สมรส'`); + await queryRunner.query(`ALTER TABLE \`profileFamilyCoupleHistory\` ADD \`coupleLive\` tinyint NULL COMMENT 'มีชีวิตคู่สมรส'`); + await queryRunner.query(`ALTER TABLE \`profileFamilyCoupleHistory\` ADD \`relationship\` varchar(40) NULL COMMENT 'ความสัมพันธ์'`); + await queryRunner.query(`ALTER TABLE \`profile\` ADD \`avatarName\` varchar(255) NULL COMMENT 'รูปถ่าย'`); + await queryRunner.query(`ALTER TABLE \`profileHistory\` ADD \`avatarName\` varchar(255) NULL COMMENT 'รูปถ่าย'`); + await queryRunner.query(`ALTER TABLE \`profileFamilyCoupleHistory\` DROP FOREIGN KEY \`FK_849255f4788774b559b7dca8eda\``); + await queryRunner.query(`ALTER TABLE \`profileFamilyCoupleHistory\` CHANGE \`profileFamilyCoupleId\` \`profileFamilyCoupleId\` varchar(40) NULL COMMENT 'คีย์นอก(FK)ของตาราง ProfileFamilyCouple'`); + await queryRunner.query(`ALTER TABLE \`profile\` CHANGE \`dateRetire\` \`dateRetire\` datetime NULL COMMENT 'วันครบเกษียณอายุ'`); + await queryRunner.query(`ALTER TABLE \`profileHistory\` CHANGE \`dateRetire\` \`dateRetire\` datetime NULL COMMENT 'วันครบเกษียณอายุ'`); + await queryRunner.query(`ALTER TABLE \`profileFamilyCoupleHistory\` ADD CONSTRAINT \`FK_849255f4788774b559b7dca8eda\` FOREIGN KEY (\`profileFamilyCoupleId\`) REFERENCES \`profileFamilyCouple\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`); + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`profileFamilyCoupleHistory\` DROP FOREIGN KEY \`FK_849255f4788774b559b7dca8eda\``); + await queryRunner.query(`ALTER TABLE \`profileHistory\` CHANGE \`dateRetire\` \`dateRetire\` datetime NULL COMMENT 'วันที่พักราชการ'`); + await queryRunner.query(`ALTER TABLE \`profile\` CHANGE \`dateRetire\` \`dateRetire\` datetime NULL COMMENT 'วันที่พักราชการ'`); + await queryRunner.query(`ALTER TABLE \`profileFamilyCoupleHistory\` CHANGE \`profileFamilyCoupleId\` \`profileFamilyCoupleId\` varchar(40) NULL COMMENT 'คีย์นอก(FK)ของตาราง ProfileFamilyFather'`); + await queryRunner.query(`ALTER TABLE \`profileFamilyCoupleHistory\` ADD CONSTRAINT \`FK_849255f4788774b559b7dca8eda\` FOREIGN KEY (\`profileFamilyCoupleId\`) REFERENCES \`profileFamilyCouple\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`); + await queryRunner.query(`ALTER TABLE \`profileHistory\` DROP COLUMN \`avatarName\``); + await queryRunner.query(`ALTER TABLE \`profile\` DROP COLUMN \`avatarName\``); + await queryRunner.query(`ALTER TABLE \`profileFamilyCoupleHistory\` DROP COLUMN \`relationship\``); + await queryRunner.query(`ALTER TABLE \`profileFamilyCoupleHistory\` DROP COLUMN \`coupleLive\``); + await queryRunner.query(`ALTER TABLE \`profileFamilyCoupleHistory\` DROP COLUMN \`coupleCitizenId\``); + await queryRunner.query(`ALTER TABLE \`profileFamilyCoupleHistory\` DROP COLUMN \`coupleCareer\``); + await queryRunner.query(`ALTER TABLE \`profileFamilyCoupleHistory\` DROP COLUMN \`coupleLastNameOld\``); + await queryRunner.query(`ALTER TABLE \`profileFamilyCoupleHistory\` DROP COLUMN \`coupleLastName\``); + await queryRunner.query(`ALTER TABLE \`profileFamilyCoupleHistory\` DROP COLUMN \`coupleFirstName\``); + await queryRunner.query(`ALTER TABLE \`profileFamilyCoupleHistory\` DROP COLUMN \`couplePrefix\``); + await queryRunner.query(`ALTER TABLE \`profileFamilyCoupleHistory\` DROP COLUMN \`couple\``); + await queryRunner.query(`ALTER TABLE \`profileAvatar\` DROP COLUMN \`avatarName\``); + await queryRunner.query(`ALTER TABLE \`profileFamilyCoupleHistory\` ADD \`fatherPrefix\` varchar(255) NULL COMMENT 'คำนำหน้าบิดา'`); + await queryRunner.query(`ALTER TABLE \`profileFamilyCoupleHistory\` ADD \`fatherLive\` tinyint NULL COMMENT 'มีชีวิตบิดา'`); + await queryRunner.query(`ALTER TABLE \`profileFamilyCoupleHistory\` ADD \`fatherLastName\` varchar(255) NULL COMMENT 'นามสกุลบิดา'`); + await queryRunner.query(`ALTER TABLE \`profileFamilyCoupleHistory\` ADD \`fatherFirstName\` varchar(255) NULL COMMENT 'ชื่อบิดา'`); + await queryRunner.query(`ALTER TABLE \`profileFamilyCoupleHistory\` ADD \`fatherCitizenId\` varchar(255) NULL COMMENT 'เลขที่บัตรประชาชนบิดา'`); + await queryRunner.query(`ALTER TABLE \`profileFamilyCoupleHistory\` ADD \`fatherCareer\` varchar(255) NULL COMMENT 'อาชีพบิดา'`); + } + +}