diff --git a/src/controllers/OrganizationUnauthorizeController.ts b/src/controllers/OrganizationUnauthorizeController.ts index 6be5ae66..eb232e63 100644 --- a/src/controllers/OrganizationUnauthorizeController.ts +++ b/src/controllers/OrganizationUnauthorizeController.ts @@ -60,7 +60,7 @@ export class OrganizationUnauthorizeController extends Controller { .leftJoinAndSelect("posMaster.positions", "positions") .leftJoinAndSelect("positions.posExecutive", "posExecutive") .leftJoinAndSelect("current_holder.profileSalary", "profileSalary") - .leftJoinAndSelect("current_holder.profileDiscipline", "profileDiscipline") + .leftJoinAndSelect("current_holder.profileDisciplines", "profileDisciplines") .leftJoinAndSelect("current_holder.posLevel", "posLevel") .leftJoinAndSelect("current_holder.posType", "posType") .where({ @@ -219,7 +219,7 @@ export class OrganizationUnauthorizeController extends Controller { result: null, duration: null, isPunish: - item.current_holder.profileDiscipline.filter( + item.current_holder.profileDisciplines.filter( (x: any) => new Date( `${new Date(x.date).getFullYear()}-${String(new Date(x.date).getMonth() + 1).padStart(2, "0")}-${String(new Date(x.date).getDate() + 1).padStart(2, "0")}T00:00:00.000Z`, @@ -278,7 +278,7 @@ export class OrganizationUnauthorizeController extends Controller { .leftJoinAndSelect("employeePosMaster.orgChild4", "orgChild4") .leftJoinAndSelect("employeePosMaster.positions", "positions") .leftJoinAndSelect("current_holder.profileSalary", "profileSalary") - .leftJoinAndSelect("current_holder.profileDiscipline", "profileDiscipline") + .leftJoinAndSelect("current_holder.profileDisciplines", "profileDisciplines") .leftJoinAndSelect("current_holder.posLevel", "posLevel") .leftJoinAndSelect("current_holder.posType", "posType") .where({ @@ -426,7 +426,7 @@ export class OrganizationUnauthorizeController extends Controller { result: null, duration: null, isPunish: - item.current_holder.profileDiscipline.filter( + item.current_holder.profileDisciplines.filter( (x: any) => new Date( `${new Date(x.date).getFullYear()}-${String(new Date(x.date).getMonth() + 1).padStart(2, "0")}-${String(new Date(x.date).getDate() + 1).padStart(2, "0")}T00:00:00.000Z`, diff --git a/src/controllers/ProfileChangeNameController.ts b/src/controllers/ProfileChangeNameController.ts index b7785d20..9d995cde 100644 --- a/src/controllers/ProfileChangeNameController.ts +++ b/src/controllers/ProfileChangeNameController.ts @@ -126,6 +126,11 @@ export class ProfileChangeNameController extends Controller { await this.changeNameRepository.save(data); + profile.firstName = body.firstName ?? profile.firstName; + profile.lastName = body.lastName ?? profile.lastName; + profile.prefix = body.prefix ?? profile.prefix; + await this.profileRepository.save(profile); + return new HttpSuccess(data.id); } @@ -152,6 +157,25 @@ export class ProfileChangeNameController extends Controller { this.changeNameHistoryRepository.save(history), ]); + const chkLastRecord = await this.changeNameRepository.findOne({ + where:{ + profileEmployeeId: record.profileEmployeeId + }, + order:{ + createdAt: "DESC" + } + }) + if (!chkLastRecord) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); + + const profile = await this.profileRepository.findOneBy({ id: record.profileId }); + + if (profile && chkLastRecord.id === record.id) { + profile.firstName = body.firstName ?? profile.firstName; + profile.lastName = body.lastName ?? profile.lastName; + profile.prefix = body.prefix ?? profile.prefix; + await this.profileRepository.save(profile); + } + return new HttpSuccess(); } diff --git a/src/controllers/ProfileChangeNameEmployeeController.ts b/src/controllers/ProfileChangeNameEmployeeController.ts index 9ccefb2c..fcdcfbaf 100644 --- a/src/controllers/ProfileChangeNameEmployeeController.ts +++ b/src/controllers/ProfileChangeNameEmployeeController.ts @@ -128,6 +128,11 @@ export class ProfileChangeNameEmployeeController extends Controller { await this.changeNameRepository.save(data); + profile.firstName = body.firstName ?? profile.firstName; + profile.lastName = body.lastName ?? profile.lastName; + profile.prefix = body.prefix ?? profile.prefix; + await this.profileEmployeeRepo.save(profile); + return new HttpSuccess(data.id); } @@ -154,7 +159,26 @@ export class ProfileChangeNameEmployeeController extends Controller { this.changeNameHistoryRepository.save(history), ]); - return new HttpSuccess(); + const chkLastRecord = await this.changeNameRepository.findOne({ + where:{ + profileEmployeeId: record.profileEmployeeId + }, + order:{ + createdAt: "DESC" + } + }) + if (!chkLastRecord) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); + + const profile = await this.profileEmployeeRepo.findOneBy({ id: record.profileEmployeeId }); + + if (profile && chkLastRecord.id === record.id) { + profile.firstName = body.firstName ?? profile.firstName; + profile.lastName = body.lastName ?? profile.lastName; + profile.prefix = body.prefix ?? profile.prefix; + await this.profileEmployeeRepo.save(profile); + } + + return new HttpSuccess([chkLastRecord.id,record.id]); } @Delete("{changeNameId}") diff --git a/src/controllers/ProfileController.ts b/src/controllers/ProfileController.ts index e1d76c73..154195ca 100644 --- a/src/controllers/ProfileController.ts +++ b/src/controllers/ProfileController.ts @@ -195,6 +195,10 @@ export class ProfileController extends Controller { throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลประเภทตำแหน่งนี้"); } + if (body.citizenId && (await this.profileRepo.findOneBy({ citizenId: body.citizenId }))) { + throw new HttpError(HttpStatus.NOT_FOUND, "ข้อมูลรหัสบัตรประจำตัวประชาชนนี้มีอยู่ในระบบแล้ว"); + } + const profile = Object.assign(new Profile(), body); profile.isProbation = false; profile.isLeave = false; @@ -218,7 +222,7 @@ export class ProfileController extends Controller { @Request() request: RequestWithUser, @Body() body: CreateProfileAllFields, ) { - const profileExist = await this.profileRepo.findOneBy({ citizenId: body.citizenId }) + const profileExist = await this.profileRepo.findOneBy({ citizenId: body.citizenId }); if (profileExist) { return new HttpSuccess(profileExist.id); } @@ -755,11 +759,11 @@ export class ProfileController extends Controller { ? null : profile.current_holders.find((x) => x.orgRevisionId == orgRevisionPublish.id); - const position = await this.positionRepository.findOne({ + const position = await this.positionRepository.findOne({ relations: ["posExecutive"], - where: { - posMasterId: posMaster?.id - } + where: { + posMasterId: posMaster?.id, + }, }); const _profile: any = { @@ -777,15 +781,16 @@ export class ProfileController extends Controller { posTypeName: profile.posType == null ? null : profile.posType.posTypeName, posTypeRank: profile.posType == null ? null : profile.posType.posTypeRank, posTypeId: profile.posType == null ? null : profile.posType.id, - posExecutiveName: position == null || position.posExecutive == null - ? null - : position.posExecutive.posExecutiveName, - posExecutivePriority: position == null || position.posExecutive == null - ? null - : position.posExecutive.posExecutivePriority, - posExecutiveId: position == null || position.posExecutive == null - ? null - : position.posExecutive.id, + posExecutiveName: + position == null || position.posExecutive == null + ? null + : position.posExecutive.posExecutiveName, + posExecutivePriority: + position == null || position.posExecutive == null + ? null + : position.posExecutive.posExecutivePriority, + posExecutiveId: + position == null || position.posExecutive == null ? null : position.posExecutive.id, rootId: profile.current_holders == null || profile.current_holders.find((x) => x.orgRevisionId == orgRevisionPublish.id)?.orgRoot == @@ -1725,7 +1730,7 @@ export class ProfileController extends Controller { .leftJoinAndSelect("posMaster.positions", "positions") .leftJoinAndSelect("positions.posExecutive", "posExecutive") .leftJoinAndSelect("current_holder.profileSalary", "profileSalary") - .leftJoinAndSelect("current_holder.profileDiscipline", "profileDiscipline") + .leftJoinAndSelect("current_holder.profileDisciplines", "profileDisciplines") .leftJoinAndSelect("current_holder.posLevel", "posLevel") .leftJoinAndSelect("current_holder.posType", "posType") .where((qb) => { @@ -1886,7 +1891,7 @@ export class ProfileController extends Controller { result: null, duration: null, isPunish: - item.current_holder.profileDiscipline.filter( + item.current_holder.profileDisciplines.filter( (x: any) => new Date( `${new Date(x.date).getFullYear()}-${String(new Date(x.date).getMonth() + 1).padStart(2, "0")}-${String(new Date(x.date).getDate() + 1).padStart(2, "0")}T00:00:00.000Z`, @@ -1933,14 +1938,14 @@ export class ProfileController extends Controller { const posMaster = await this.posMasterRepo.findOne({ where: { current_holderId: profile.id, - orgRevisionId: revisionId - } + orgRevisionId: revisionId, + }, }); - const position = await this.positionRepository.findOne({ + const position = await this.positionRepository.findOne({ relations: ["posExecutive"], - where: { - posMasterId: posMaster?.id - } + where: { + posMasterId: posMaster?.id, + }, }); const _profile = { @@ -1957,15 +1962,16 @@ export class ProfileController extends Controller { posTypeName: profile.posType == null ? null : profile.posType.posTypeName, posTypeRank: profile.posType == null ? null : profile.posType.posTypeRank, posTypeId: profile.posType == null ? null : profile.posType.id, - posExecutiveName: position == null || position.posExecutive == null - ? null - : position.posExecutive.posExecutiveName, - posExecutivePriority: position == null || position.posExecutive == null - ? null - : position.posExecutive.posExecutivePriority, - posExecutiveId: position == null || position.posExecutive == null - ? null - : position.posExecutive.id, + posExecutiveName: + position == null || position.posExecutive == null + ? null + : position.posExecutive.posExecutiveName, + posExecutivePriority: + position == null || position.posExecutive == null + ? null + : position.posExecutive.posExecutivePriority, + posExecutiveId: + position == null || position.posExecutive == null ? null : position.posExecutive.id, rootId: profile.current_holders == null || profile.current_holders.find((x) => x.orgRevisionId == revisionId) == null || diff --git a/src/controllers/ProfileDisciplineController.ts b/src/controllers/ProfileDisciplineController.ts index 62fc4256..e7690b77 100644 --- a/src/controllers/ProfileDisciplineController.ts +++ b/src/controllers/ProfileDisciplineController.ts @@ -169,7 +169,7 @@ export class ProfileDisciplineController extends Controller { } @Delete("{disciplineId}") - public async deleteTraning(@Path() disciplineId: string) { + public async deleteDiscipline(@Path() disciplineId: string) { await this.disciplineHistoryRepository.delete({ profileDisciplineId: disciplineId, }); diff --git a/src/controllers/ProfileDisciplineEmployeeController.ts b/src/controllers/ProfileDisciplineEmployeeController.ts index 9dc1ff47..9ed528c8 100644 --- a/src/controllers/ProfileDisciplineEmployeeController.ts +++ b/src/controllers/ProfileDisciplineEmployeeController.ts @@ -145,7 +145,7 @@ export class ProfileDisciplineEmployeeController extends Controller { } @Delete("{disciplineId}") - public async deleteTraning(@Path() disciplineId: string) { + public async deleteDiscipline(@Path() disciplineId: string) { await this.disciplineHistoryRepository.delete({ profileDisciplineId: disciplineId, }); diff --git a/src/controllers/ProfileDutyController.ts b/src/controllers/ProfileDutyController.ts index d2c0ba92..b88754c6 100644 --- a/src/controllers/ProfileDutyController.ts +++ b/src/controllers/ProfileDutyController.ts @@ -157,7 +157,7 @@ export class ProfileDutyController extends Controller { } @Delete("{dutyId}") - public async deleteTraning(@Path() dutyId: string) { + public async deleteDuty(@Path() dutyId: string) { await this.dutyHistoryRepository.delete({ profileDutyId: dutyId, }); diff --git a/src/controllers/ProfileDutyEmployeeController.ts b/src/controllers/ProfileDutyEmployeeController.ts index 25f40f0e..70077ec3 100644 --- a/src/controllers/ProfileDutyEmployeeController.ts +++ b/src/controllers/ProfileDutyEmployeeController.ts @@ -118,7 +118,7 @@ export class ProfileDutyEmployeeController extends Controller { } @Delete("{dutyId}") - public async deleteTraning(@Path() dutyId: string) { + public async deleteDuty(@Path() dutyId: string) { await this.dutyHistoryRepository.delete({ profileDutyId: dutyId, }); diff --git a/src/controllers/ProfileEmployeeController.ts b/src/controllers/ProfileEmployeeController.ts index a553539b..ec7dcb00 100644 --- a/src/controllers/ProfileEmployeeController.ts +++ b/src/controllers/ProfileEmployeeController.ts @@ -33,7 +33,7 @@ import { EmployeePosType } from "../entities/EmployeePosType"; import { RequestWithUser } from "../middlewares/user"; @Route("api/v1/org/profile-employee") -@Tags("Profile") +@Tags("ProfileEmployee") @Security("bearerAuth") @Response( HttpStatus.INTERNAL_SERVER_ERROR, @@ -975,7 +975,7 @@ export class ProfileEmployeeController extends Controller { .leftJoinAndSelect("employeePosMaster.orgChild4", "orgChild4") .leftJoinAndSelect("employeePosMaster.positions", "positions") .leftJoinAndSelect("current_holder.profileSalary", "profileSalary") - .leftJoinAndSelect("current_holder.profileDiscipline", "profileDiscipline") + .leftJoinAndSelect("current_holder.profileDisciplines", "profileDisciplines") .leftJoinAndSelect("current_holder.posLevel", "posLevel") .leftJoinAndSelect("current_holder.posType", "posType") .where((qb) => { @@ -1128,7 +1128,7 @@ export class ProfileEmployeeController extends Controller { result: null, duration: null, isPunish: - item.current_holder.profileDiscipline.filter( + item.current_holder.profileDisciplines.filter( (x: any) => new Date( `${new Date(x.date).getFullYear()}-${String(new Date(x.date).getMonth() + 1).padStart(2, "0")}-${String(new Date(x.date).getDate() + 1).padStart(2, "0")}T00:00:00.000Z`, diff --git a/src/controllers/ProfileLeaveController.ts b/src/controllers/ProfileLeaveController.ts index 54fb5d8e..6510dff1 100644 --- a/src/controllers/ProfileLeaveController.ts +++ b/src/controllers/ProfileLeaveController.ts @@ -221,7 +221,7 @@ export class ProfileLeaveController extends Controller { } @Delete("{leaveId}") - public async deleteTraning(@Path() leaveId: string) { + public async deleteLeave(@Path() leaveId: string) { await this.leaveHistoryRepo.delete({ profileLeaveId: leaveId, }); diff --git a/src/controllers/ProfileLeaveEmployeeController.ts b/src/controllers/ProfileLeaveEmployeeController.ts index 2a88b9a6..6fa06140 100644 --- a/src/controllers/ProfileLeaveEmployeeController.ts +++ b/src/controllers/ProfileLeaveEmployeeController.ts @@ -119,7 +119,7 @@ export class ProfileLeaveEmployeeController extends Controller { } @Delete("{leaveId}") - public async deleteTraning(@Path() leaveId: string) { + public async deleteLeave(@Path() leaveId: string) { await this.leaveHistoryRepo.delete({ profileLeaveId: leaveId, }); diff --git a/src/controllers/ProfileOtherController.ts b/src/controllers/ProfileOtherController.ts index f5e1f81e..1a4eeeed 100644 --- a/src/controllers/ProfileOtherController.ts +++ b/src/controllers/ProfileOtherController.ts @@ -134,7 +134,7 @@ export class ProfileOtherController extends Controller { } @Delete("{otherId}") - public async deleteTraning(@Path() otherId: string) { + public async deleteOther(@Path() otherId: string) { await this.otherHistoryRepository.delete({ profileOtherId: otherId, }); diff --git a/src/controllers/ProfileOtherEmployeeController.ts b/src/controllers/ProfileOtherEmployeeController.ts index c6312bba..c71ed332 100644 --- a/src/controllers/ProfileOtherEmployeeController.ts +++ b/src/controllers/ProfileOtherEmployeeController.ts @@ -105,7 +105,7 @@ export class ProfileOtherEmployeeController extends Controller { } @Delete("{otherId}") - public async deleteTraning(@Path() otherId: string) { + public async deleteOther(@Path() otherId: string) { await this.otherHistoryRepository.delete({ profileOtherId: otherId, }); diff --git a/src/entities/Profile.ts b/src/entities/Profile.ts index 7608089b..d1a91370 100644 --- a/src/entities/Profile.ts +++ b/src/entities/Profile.ts @@ -4,7 +4,6 @@ import { PosMaster } from "./PosMaster"; import { PosLevel } from "./PosLevel"; import { PosType } from "./PosType"; import { ProfileSalary } from "./ProfileSalary"; -import { ProfileDiscipline } from "./ProfileDiscipline"; import { ProfileCertificate } from "./ProfileCertificate"; import { ProfileEducation } from "./ProfileEducation"; import { ProfileTraining } from "./ProfileTraining"; @@ -23,6 +22,7 @@ import { SubDistrict } from "./SubDistrict"; import { District } from "./District"; import { ProfileAvatar } from "./ProfileAvatar"; import { ProfileChildren } from "./ProfileChildren"; +import { ProfileDiscipline } from "./ProfileDiscipline"; @Entity("profile") export class Profile extends EntityBase { @@ -268,7 +268,7 @@ export class Profile extends EntityBase { profileSalary: ProfileSalary[]; @OneToMany(() => ProfileDiscipline, (profileDiscipline) => profileDiscipline.profile) - profileDiscipline: ProfileDiscipline[]; + profileDisciplines: ProfileDiscipline[]; @OneToMany(() => ProfileCertificate, (profileCertificate) => profileCertificate.profile) profileCertificates: ProfileCertificate[]; diff --git a/src/entities/ProfileDiscipline.ts b/src/entities/ProfileDiscipline.ts index 0c93adf2..ca698a75 100644 --- a/src/entities/ProfileDiscipline.ts +++ b/src/entities/ProfileDiscipline.ts @@ -75,7 +75,7 @@ export class ProfileDiscipline extends EntityBase { ) profileDisciplineHistories: ProfileDisciplineHistory[]; - @ManyToOne(() => Profile, (profile) => profile.profileDiscipline) + @ManyToOne(() => Profile, (profile) => profile.profileDisciplines) @JoinColumn({ name: "profileId" }) profile: Profile; diff --git a/src/entities/ProfileDisciplineEmployee.ts b/src/entities/ProfileDisciplineEmployee.ts deleted file mode 100644 index 70cb6207..00000000 --- a/src/entities/ProfileDisciplineEmployee.ts +++ /dev/null @@ -1,106 +0,0 @@ -import { Entity, Column, ManyToOne, JoinColumn, OneToMany } from "typeorm"; -import { EntityBase } from "./base/Base"; -import { ProfileEmployee } from "./ProfileEmployee"; -import { ProfileDisciplineEmployeeHistory } from "./ProfileDisciplineEmployeeHistory"; - -@Entity("profileDisciplineEmployee") -export class ProfileDisciplineEmployee extends EntityBase { - @Column({ - nullable: true, - type: "datetime", - comment: "วันที่", - default: null, - }) - date: Date; - - @Column({ - length: 40, - comment: "ไอดีโปรไฟล์", - type: "uuid", - }) - profileId: string; - - @Column({ - comment: "สถานะการใช้งาน", - default: false, - }) - isActive: boolean; - - @Column({ - nullable: true, - comment: "ระดับความผิด", - type: "text", - default: null, - }) - level: string; - - @Column({ - nullable: true, - comment: "รายละเอียด", - type: "text", - default: null, - }) - detail: string; - - @Column({ - nullable: true, - type: "datetime", - comment: "เอกสารอ้างอิง (ลงวันที่)", - default: null, - }) - refCommandDate: Date; - - @Column({ - nullable: true, - comment: "เอกสารอ้างอิง (เลขที่คำสั่ง)", - type: "text", - default: null, - }) - refCommandNo: string; - - @Column({ - nullable: true, - comment: "ล้างมลทิน", - type: "text", - default: null, - }) - unStigma: string; - - @OneToMany( - () => ProfileDisciplineEmployeeHistory, - (profileDisciplineHistory) => profileDisciplineHistory.histories, - ) - profileDisciplineHistories: ProfileDisciplineEmployeeHistory[]; - - @ManyToOne(() => ProfileEmployee, (profile) => profile.profileDiscipline) - @JoinColumn({ name: "profileId" }) - profile: ProfileEmployee; -} - -export class CreateProfileDisciplineEmployee { - @Column() - date: Date | null; - - @Column() - profileId: string; - - @Column() - isActive: boolean | null; - - @Column() - level: string | null; - - @Column() - detail: string | null; - - @Column() - refCommandDate: Date | null; - - @Column() - refCommandNo: string | null; - - @Column() - unStigma: string | null; -} - -export type UpdateProfileDisciplineEmployee = Partial; diff --git a/src/entities/ProfileDisciplineEmployeeHistory.ts b/src/entities/ProfileDisciplineEmployeeHistory.ts deleted file mode 100644 index 2b8089c4..00000000 --- a/src/entities/ProfileDisciplineEmployeeHistory.ts +++ /dev/null @@ -1,74 +0,0 @@ -import { Entity, Column, ManyToOne, JoinColumn } from "typeorm"; -import { EntityBase } from "./base/Base"; -import { ProfileDisciplineEmployee } from "./ProfileDisciplineEmployee"; - -@Entity("profileDisciplineEmployeeHistory") -export class ProfileDisciplineEmployeeHistory extends EntityBase { - @Column({ - nullable: true, - type: "datetime", - comment: "วันที่", - default: null, - }) - date: Date; - - @Column({ - length: 40, - comment: "ล้างมลทิน", - type: "uuid", - }) - profileDisciplineId: string; - - @Column({ - comment: "สถานะการใช้งาน", - default: false, - }) - isActive: boolean; - - @Column({ - nullable: true, - comment: "ระดับความผิด", - type: "text", - default: null, - }) - level: string; - - @Column({ - nullable: true, - comment: "รายละเอียด", - type: "text", - default: null, - }) - detail: string; - - @Column({ - nullable: true, - type: "datetime", - comment: "เอกสารอ้างอิง (ลงวันที่)", - default: null, - }) - refCommandDate: Date; - - @Column({ - nullable: true, - comment: "เอกสารอ้างอิง (เลขที่คำสั่ง)", - type: "text", - default: null, - }) - refCommandNo: string; - - @Column({ - nullable: true, - comment: "ล้างมลทิน", - type: "text", - default: null, - }) - unStigma: string; - - @ManyToOne( - () => ProfileDisciplineEmployee, - (profileDiscipline) => profileDiscipline.profileDisciplineHistories, - ) - @JoinColumn({ name: "profileDisciplineId" }) - histories: ProfileDisciplineEmployee; -} diff --git a/src/entities/ProfileEmployee.ts b/src/entities/ProfileEmployee.ts index 9acd9ae0..82ed5fdd 100644 --- a/src/entities/ProfileEmployee.ts +++ b/src/entities/ProfileEmployee.ts @@ -4,7 +4,6 @@ import { EmployeePosLevel } from "./EmployeePosLevel"; import { EmployeePosType } from "./EmployeePosType"; import { EmployeePosMaster } from "./EmployeePosMaster"; import { ProfileSalaryEmployee } from "./ProfileSalaryEmployee"; -import { ProfileDisciplineEmployee } from "./ProfileDisciplineEmployee"; import { ProfileCertificate } from "./ProfileCertificate"; import { ProfileTraining } from "./ProfileTraining"; import { ProfileInsignia } from "./ProfileInsignia"; @@ -217,9 +216,6 @@ export class ProfileEmployee extends EntityBase { @OneToMany(() => ProfileSalaryEmployee, (v) => v.profile) profileSalary: ProfileSalaryEmployee[]; - @OneToMany(() => ProfileDisciplineEmployee, (v) => v.profile) - profileDiscipline: ProfileDisciplineEmployee[]; - @OneToMany(() => ProfileCertificate, (v) => v.profileEmployee) profileCertificates: ProfileCertificate[]; diff --git a/src/migration/1715682448384-add_table_ProfileChildren.ts b/src/migration/1715682448384-add_table_ProfileChildren.ts new file mode 100644 index 00000000..fe92e79c --- /dev/null +++ b/src/migration/1715682448384-add_table_ProfileChildren.ts @@ -0,0 +1,36 @@ +import { MigrationInterface, QueryRunner } from "typeorm"; + +export class AddTableProfileChildren1715682448384 implements MigrationInterface { + name = 'AddTableProfileChildren1715682448384' + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`profileChildrenHistory\` DROP FOREIGN KEY \`FK_a0467be33be13ab1ba0b21acc7a\``); + await queryRunner.query(`ALTER TABLE \`profileChildrenHistory\` DROP FOREIGN KEY \`FK_b357180653180284b853f0bb18d\``); + await queryRunner.query(`ALTER TABLE \`profileChildrenHistory\` DROP FOREIGN KEY \`FK_ff56943048f9616e96cd8e3507d\``); + await queryRunner.query(`ALTER TABLE \`profileChildrenHistory\` DROP FOREIGN KEY \`FK_6a37dfb48ea6108cba60b9d4f69\``); + await queryRunner.query(`ALTER TABLE \`profileChildren\` DROP FOREIGN KEY \`FK_b7de772d753b42334c98536eccb\``); + await queryRunner.query(`DROP INDEX \`FK_f5758428d496b6d2a051c8af92b\` ON \`profileSalary\``); + await queryRunner.query(`ALTER TABLE \`profileChildrenHistory\` DROP COLUMN \`profileEmployeeId\``); + await queryRunner.query(`ALTER TABLE \`profileChildrenHistory\` DROP COLUMN \`profileFamilyHistoryId\``); + await queryRunner.query(`ALTER TABLE \`profileChildrenHistory\` DROP COLUMN \`profileId\``); + await queryRunner.query(`ALTER TABLE \`profileChildrenHistory\` CHANGE \`profileChildrenId\` \`profileChildrenId\` varchar(40) NULL COMMENT 'คีย์นอก(FK)ของตาราง ProfileChildren'`); + await queryRunner.query(`ALTER TABLE \`profileChildrenHistory\` ADD CONSTRAINT \`FK_ff56943048f9616e96cd8e3507d\` FOREIGN KEY (\`profileChildrenId\`) REFERENCES \`profileChildren\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`); + await queryRunner.query(`ALTER TABLE \`profileChildren\` ADD CONSTRAINT \`FK_b7de772d753b42334c98536eccb\` FOREIGN KEY (\`profileId\`) REFERENCES \`profile\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`); + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`profileChildren\` DROP FOREIGN KEY \`FK_b7de772d753b42334c98536eccb\``); + await queryRunner.query(`ALTER TABLE \`profileChildrenHistory\` DROP FOREIGN KEY \`FK_ff56943048f9616e96cd8e3507d\``); + await queryRunner.query(`ALTER TABLE \`profileChildrenHistory\` CHANGE \`profileChildrenId\` \`profileChildrenId\` varchar(40) NULL COMMENT 'คีย์นอก(FK) ของตาราง Profile'`); + await queryRunner.query(`ALTER TABLE \`profileChildrenHistory\` ADD \`profileId\` varchar(40) NULL COMMENT 'คีย์นอก(FK) ของตาราง Profile'`); + await queryRunner.query(`ALTER TABLE \`profileChildrenHistory\` ADD \`profileFamilyHistoryId\` varchar(40) NULL COMMENT 'คีย์นอก(FK) ของตาราง Profile'`); + await queryRunner.query(`ALTER TABLE \`profileChildrenHistory\` ADD \`profileEmployeeId\` varchar(40) NULL COMMENT 'คีย์นอก(FK)ของตาราง ProfileEmployee'`); + await queryRunner.query(`CREATE INDEX \`FK_f5758428d496b6d2a051c8af92b\` ON \`profileSalary\` (\`profileEmployeeId\`)`); + await queryRunner.query(`ALTER TABLE \`profileChildren\` ADD CONSTRAINT \`FK_b7de772d753b42334c98536eccb\` FOREIGN KEY (\`profileId\`) REFERENCES \`profile\`(\`id\`) ON DELETE CASCADE ON UPDATE NO ACTION`); + await queryRunner.query(`ALTER TABLE \`profileChildrenHistory\` ADD CONSTRAINT \`FK_6a37dfb48ea6108cba60b9d4f69\` FOREIGN KEY (\`profileEmployeeId\`) REFERENCES \`profileEmployee\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`); + await queryRunner.query(`ALTER TABLE \`profileChildrenHistory\` ADD CONSTRAINT \`FK_ff56943048f9616e96cd8e3507d\` FOREIGN KEY (\`profileChildrenId\`) REFERENCES \`profileChildren\`(\`id\`) ON DELETE CASCADE ON UPDATE NO ACTION`); + await queryRunner.query(`ALTER TABLE \`profileChildrenHistory\` ADD CONSTRAINT \`FK_b357180653180284b853f0bb18d\` FOREIGN KEY (\`profileId\`) REFERENCES \`profile\`(\`id\`) ON DELETE CASCADE ON UPDATE NO ACTION`); + await queryRunner.query(`ALTER TABLE \`profileChildrenHistory\` ADD CONSTRAINT \`FK_a0467be33be13ab1ba0b21acc7a\` FOREIGN KEY (\`profileFamilyHistoryId\`) REFERENCES \`profileFamilyHistory\`(\`id\`) ON DELETE CASCADE ON UPDATE NO ACTION`); + } + +}