From 6311c9cb0dfc43db3652bb97098fe27c53ae7cc5 Mon Sep 17 00:00:00 2001 From: Kittapath Date: Tue, 14 May 2024 15:06:31 +0700 Subject: [PATCH 1/9] migrate --- ...15673906573-update_table_node_add_duty1.ts | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 src/migration/1715673906573-update_table_node_add_duty1.ts diff --git a/src/migration/1715673906573-update_table_node_add_duty1.ts b/src/migration/1715673906573-update_table_node_add_duty1.ts new file mode 100644 index 00000000..f3abaa7d --- /dev/null +++ b/src/migration/1715673906573-update_table_node_add_duty1.ts @@ -0,0 +1,22 @@ +import { MigrationInterface, QueryRunner } from "typeorm"; + +export class UpdateTableNodeAddDuty11715673906573 implements MigrationInterface { + name = 'UpdateTableNodeAddDuty11715673906573' + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`orgChild4\` ADD \`duty\` varchar(255) NULL COMMENT 'หน้าที่ความรับผิดชอบ'`); + await queryRunner.query(`ALTER TABLE \`orgChild3\` ADD \`duty\` varchar(255) NULL COMMENT 'หน้าที่ความรับผิดชอบ'`); + await queryRunner.query(`ALTER TABLE \`orgChild2\` ADD \`duty\` varchar(255) NULL COMMENT 'หน้าที่ความรับผิดชอบ'`); + await queryRunner.query(`ALTER TABLE \`orgChild1\` ADD \`duty\` varchar(255) NULL COMMENT 'หน้าที่ความรับผิดชอบ'`); + await queryRunner.query(`ALTER TABLE \`orgRoot\` CHANGE \`duty\` \`duty\` varchar(255) NULL COMMENT 'หน้าที่ความรับผิดชอบ'`); + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`orgRoot\` CHANGE \`duty\` \`duty\` varchar(255) NULL COMMENT 'หน้าที่ความรับผิดชอบ '`); + await queryRunner.query(`ALTER TABLE \`orgChild1\` DROP COLUMN \`duty\``); + await queryRunner.query(`ALTER TABLE \`orgChild2\` DROP COLUMN \`duty\``); + await queryRunner.query(`ALTER TABLE \`orgChild3\` DROP COLUMN \`duty\``); + await queryRunner.query(`ALTER TABLE \`orgChild4\` DROP COLUMN \`duty\``); + } + +} From fa6b7c91bfa7516990fa7fbed3506c7dcedd0b75 Mon Sep 17 00:00:00 2001 From: Bright Date: Tue, 14 May 2024 15:28:26 +0700 Subject: [PATCH 2/9] no message --- .../ProfileGovernmentEmployeeController.ts | 76 +++++++++---------- 1 file changed, 38 insertions(+), 38 deletions(-) diff --git a/src/controllers/ProfileGovernmentEmployeeController.ts b/src/controllers/ProfileGovernmentEmployeeController.ts index 1e09d6c1..b84718ee 100644 --- a/src/controllers/ProfileGovernmentEmployeeController.ts +++ b/src/controllers/ProfileGovernmentEmployeeController.ts @@ -114,34 +114,34 @@ export class ProfileGovernmentEmployeeController extends Controller { return new HttpSuccess(record); } - /** - * - * @summary เพิ่มข้อมูลราชการ - * - */ - @Post() - public async newGov(@Request() req: RequestWithUser, @Body() body: CreateProfileEmployeeGovernment) { - if (!body.profileEmployeeId) { - throw new HttpError(HttpStatus.BAD_REQUEST, "กรุณากรอก profileEmployeeId"); - } + // /** + // * + // * @summary เพิ่มข้อมูลราชการ + // * + // */ + // @Post() + // public async newGov(@Request() req: RequestWithUser, @Body() body: CreateProfileEmployeeGovernment) { + // if (!body.profileEmployeeId) { + // throw new HttpError(HttpStatus.BAD_REQUEST, "กรุณากรอก profileEmployeeId"); + // } - const profile = await this.profileEmployeeRepo.findOneBy({ id: body.profileEmployeeId }); - if (!profile) { - throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); - } + // const profile = await this.profileEmployeeRepo.findOneBy({ id: body.profileEmployeeId }); + // if (!profile) { + // throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); + // } - const data = new ProfileGovernment(); - const meta = { - createdUserId: req.user.sub, - createdFullName: req.user.name, - lastUpdateUserId: req.user.sub, - lastUpdateFullName: req.user.name, - }; + // const data = new ProfileGovernment(); + // const meta = { + // createdUserId: req.user.sub, + // createdFullName: req.user.name, + // lastUpdateUserId: req.user.sub, + // lastUpdateFullName: req.user.name, + // }; - Object.assign(data, { ...body, ...meta }); - await this.govRepo.save(data); - return new HttpSuccess(); - } + // Object.assign(data, { ...body, ...meta }); + // await this.govRepo.save(data); + // return new HttpSuccess(); + // } /** * @@ -172,17 +172,17 @@ export class ProfileGovernmentEmployeeController extends Controller { return new HttpSuccess(); } - /** - * - * @summary ลบข้อมูลราชการ - * - */ - @Delete("{profileEmployeeId}") - public async deleteGov(@Path() profileEmployeeId: string) { - const result = await this.govRepo.delete({ profileEmployeeId: profileEmployeeId }); - if (result.affected == undefined || result.affected <= 0) { - throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); - } - return new HttpSuccess(); - } + // /** + // * + // * @summary ลบข้อมูลราชการ + // * + // */ + // @Delete("{profileEmployeeId}") + // public async deleteGov(@Path() profileEmployeeId: string) { + // const result = await this.govRepo.delete({ profileEmployeeId: profileEmployeeId }); + // if (result.affected == undefined || result.affected <= 0) { + // throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); + // } + // return new HttpSuccess(); + // } } \ No newline at end of file From 2eee5404a145c8d7e77886e69c36aa7457f3cce8 Mon Sep 17 00:00:00 2001 From: Kittapath Date: Tue, 14 May 2024 15:29:05 +0700 Subject: [PATCH 3/9] migrate responsibility --- src/controllers/ProfileAvatarController.ts | 59 ++++++++++++++++++ .../ProfileAvatarEmployeeController.ts | 62 +++++++++++++++++++ src/entities/OrgChild1.ts | 8 +-- src/entities/OrgChild2.ts | 5 +- src/entities/OrgChild3.ts | 4 +- src/entities/OrgChild4.ts | 4 +- src/entities/OrgRoot.ts | 4 +- src/entities/Profile.ts | 57 ++++++++++------- src/entities/ProfileAvatar.ts | 52 ++++++++++++++++ src/entities/ProfileEmployee.ts | 11 ++++ ...27-update_table_node_add_responsibility.ts | 56 +++++++++++++++++ 11 files changed, 285 insertions(+), 37 deletions(-) create mode 100644 src/controllers/ProfileAvatarController.ts create mode 100644 src/controllers/ProfileAvatarEmployeeController.ts create mode 100644 src/entities/ProfileAvatar.ts create mode 100644 src/migration/1715675159227-update_table_node_add_responsibility.ts diff --git a/src/controllers/ProfileAvatarController.ts b/src/controllers/ProfileAvatarController.ts new file mode 100644 index 00000000..6d105a11 --- /dev/null +++ b/src/controllers/ProfileAvatarController.ts @@ -0,0 +1,59 @@ +import { Body, Controller, Delete, Get, Path, Post, Request, Route, Security, Tags } from "tsoa"; +import { AppDataSource } from "../database/data-source"; +import HttpSuccess from "../interfaces/http-success"; +import HttpStatus from "../interfaces/http-status"; +import HttpError from "../interfaces/http-error"; +import { RequestWithUser } from "../middlewares/user"; +import { Profile } from "../entities/Profile"; +import { CreateProfileAvatar, ProfileAvatar } from "../entities/ProfileAvatar"; + +@Route("api/v1/org/profile/avatar") +@Tags("ProfileAvatar") +@Security("bearerAuth") +export class ProfileAvatarController extends Controller { + private profileRepository = AppDataSource.getRepository(Profile); + private avatarRepository = AppDataSource.getRepository(ProfileAvatar); + + @Get("{profileId}") + public async getAvatar(@Path() profileId: string) { + const lists = await this.avatarRepository.find({ + where: { profileId: profileId }, + }); + return new HttpSuccess(lists); + } + + @Post() + public async newAvatar(@Request() req: RequestWithUser, @Body() body: CreateProfileAvatar) { + const profile = await this.profileRepository.findOneBy({ id: body.profileId }); + + if (!profile) { + throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); + } + + const data = new ProfileAvatar(); + + const meta = { + createdUserId: req.user.sub, + createdFullName: req.user.name, + lastUpdateUserId: req.user.sub, + lastUpdateFullName: req.user.name, + }; + + Object.assign(data, { ...body, ...meta }); + + await this.avatarRepository.save(data); + + return new HttpSuccess(); + } + + @Delete("{avatarId}") + public async deleteAvatar(@Path() avatarId: string) { + const result = await this.avatarRepository.delete({ id: avatarId }); + + if (result.affected == undefined || result.affected <= 0) { + throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); + } + + return new HttpSuccess(); + } +} diff --git a/src/controllers/ProfileAvatarEmployeeController.ts b/src/controllers/ProfileAvatarEmployeeController.ts new file mode 100644 index 00000000..2cc3ce65 --- /dev/null +++ b/src/controllers/ProfileAvatarEmployeeController.ts @@ -0,0 +1,62 @@ +import { Body, Controller, Delete, Get, Path, Post, Request, Route, Security, Tags } from "tsoa"; +import { AppDataSource } from "../database/data-source"; +import HttpSuccess from "../interfaces/http-success"; +import HttpStatus from "../interfaces/http-status"; +import HttpError from "../interfaces/http-error"; +import { RequestWithUser } from "../middlewares/user"; +import { CreateProfileEmployeeAvatar, ProfileAvatar } from "../entities/ProfileAvatar"; +import { ProfileEmployee } from "../entities/ProfileEmployee"; + +@Route("api/v1/org/profile-employee/avatar") +@Tags("ProfileAvatar") +@Security("bearerAuth") +export class ProfileAvatarController extends Controller { + private profileRepository = AppDataSource.getRepository(ProfileEmployee); + private avatarRepository = AppDataSource.getRepository(ProfileAvatar); + + @Get("{profileId}") + public async getAvatar(@Path() profileId: string) { + const lists = await this.avatarRepository.find({ + where: { profileEmployeeId: profileId }, + }); + return new HttpSuccess(lists); + } + + @Post() + public async newAvatar( + @Request() req: RequestWithUser, + @Body() body: CreateProfileEmployeeAvatar, + ) { + const profile = await this.profileRepository.findOneBy({ id: body.profileEmployeeId }); + + if (!profile) { + throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); + } + + const data = new ProfileAvatar(); + + const meta = { + createdUserId: req.user.sub, + createdFullName: req.user.name, + lastUpdateUserId: req.user.sub, + lastUpdateFullName: req.user.name, + }; + + Object.assign(data, { ...body, ...meta }); + + await this.avatarRepository.save(data); + + return new HttpSuccess(); + } + + @Delete("{avatarId}") + public async deleteAvatar(@Path() avatarId: string) { + const result = await this.avatarRepository.delete({ id: avatarId }); + + if (result.affected == undefined || result.affected <= 0) { + throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); + } + + return new HttpSuccess(); + } +} diff --git a/src/entities/OrgChild1.ts b/src/entities/OrgChild1.ts index cc1b87a0..12b77ba2 100644 --- a/src/entities/OrgChild1.ts +++ b/src/entities/OrgChild1.ts @@ -108,14 +108,13 @@ export class OrgChild1 extends EntityBase { }) ancestorDNA: string; - @Column({ nullable: true, length: 255, comment: "หน้าที่ความรับผิดชอบ", default: null, }) - duty: string; + responsibility: string; @ManyToOne(() => OrgRevision, (orgRevision) => orgRevision.orgChild1s) @JoinColumn({ name: "orgRevisionId" }) @@ -165,10 +164,9 @@ export class CreateOrgChild1 { @Column("uuid") orgRootId: string; - - @Column() - duty?: string; + @Column() + responsibility?: string; } export type UpdateOrgChild1 = Partial & { orgChild1Rank?: OrgChild1Rank }; diff --git a/src/entities/OrgChild2.ts b/src/entities/OrgChild2.ts index bc9b9896..91822992 100644 --- a/src/entities/OrgChild2.ts +++ b/src/entities/OrgChild2.ts @@ -119,7 +119,7 @@ export class OrgChild2 extends EntityBase { comment: "หน้าที่ความรับผิดชอบ", default: null, }) - duty: string; + responsibility: string; @ManyToOne(() => OrgRevision, (orgRevision) => orgRevision.orgChild2s) @JoinColumn({ name: "orgRevisionId" }) @@ -172,7 +172,6 @@ export class CreateOrgChild2 { orgChild1Id: string; @Column() - duty?: string; - + responsibility?: string; } export type UpdateOrgChild2 = Partial & { orgChild2Rank?: OrgChild2Rank }; diff --git a/src/entities/OrgChild3.ts b/src/entities/OrgChild3.ts index 4b6659ba..d49c283b 100644 --- a/src/entities/OrgChild3.ts +++ b/src/entities/OrgChild3.ts @@ -126,7 +126,7 @@ export class OrgChild3 extends EntityBase { comment: "หน้าที่ความรับผิดชอบ", default: null, }) - duty: string; + responsibility: string; @ManyToOne(() => OrgRevision, (orgRevision) => orgRevision.orgChild3s) @JoinColumn({ name: "orgRevisionId" }) @@ -180,7 +180,7 @@ export class CreateOrgChild3 { orgChild2Id: string; @Column() - duty?: string; + responsibility?: string; } export type UpdateOrgChild3 = Partial & { orgChild3Rank?: OrgChild3Rank }; diff --git a/src/entities/OrgChild4.ts b/src/entities/OrgChild4.ts index d1a9fe27..23a34bde 100644 --- a/src/entities/OrgChild4.ts +++ b/src/entities/OrgChild4.ts @@ -131,7 +131,7 @@ export class OrgChild4 extends EntityBase { comment: "หน้าที่ความรับผิดชอบ", default: null, }) - duty: string; + responsibility: string; @ManyToOne(() => OrgRevision, (orgRevision) => orgRevision.orgChild4s) @JoinColumn({ name: "orgRevisionId" }) @@ -186,6 +186,6 @@ export class CreateOrgChild4 { orgChild3Id: string; @Column() - duty?: string; + responsibility?: string; } export type UpdateOrgChild4 = Partial; diff --git a/src/entities/OrgRoot.ts b/src/entities/OrgRoot.ts index 853c865e..e258735c 100644 --- a/src/entities/OrgRoot.ts +++ b/src/entities/OrgRoot.ts @@ -102,7 +102,7 @@ export class OrgRoot extends EntityBase { comment: "หน้าที่ความรับผิดชอบ", default: null, }) - duty: string; + responsibility: string; @Column({ length: 40, @@ -156,7 +156,7 @@ export class CreateOrgRoot { orgRootFax?: string; @Column() - duty?: string; + responsibility?: string; @Column("uuid") orgRevisionId: string; diff --git a/src/entities/Profile.ts b/src/entities/Profile.ts index 744791e5..1d7b8d04 100644 --- a/src/entities/Profile.ts +++ b/src/entities/Profile.ts @@ -21,9 +21,17 @@ import { ProfileGovernment } from "./ProfileGovernment"; import { Province } from "./Province"; import { SubDistrict } from "./SubDistrict"; import { District } from "./District"; +import { ProfileAvatar } from "./ProfileAvatar"; @Entity("profile") export class Profile extends EntityBase { + @Column({ + nullable: true, + comment: "รูปถ่าย", + default: null, + }) + avatar: string; + @Column({ nullable: true, comment: "ยศ", @@ -294,6 +302,9 @@ export class Profile extends EntityBase { @OneToMany(() => ProfileOther, (profileOther) => profileOther.profile) profileOthers: ProfileOther[]; + @OneToMany(() => ProfileAvatar, (profileAvatar) => profileAvatar.profile) + profileAvatars: ProfileAvatar[]; + @OneToMany(() => ProfileFamilyHistory, (profileFamily) => profileFamily.profile) profileFamily: ProfileFamilyHistory[]; @@ -576,35 +587,35 @@ export class CreateProfileAllFields { posLevelId: string | null; posTypeId: string | null; email: string | null; - phone: string | null; + phone: string | null; keycloak: string | null; isProbation: boolean | null; - isLeave : boolean | null; - dateRetire : Date | null; - dateAppoint : Date | null; - dateStart: Date | null; + isLeave: boolean | null; + dateRetire: Date | null; + dateAppoint: Date | null; + dateStart: Date | null; govAgeAbsent: number | null; govAgePlus: number | null; birthDate: Date | null; - reasonSameDate : Date | null; - ethnicity : string | null; - telephoneNumber : string | null; - nationality : string | null; - gender : string | null; - relationship : string | null; - religion : string | null; - bloodGroup : string | null; - registrationAddress : string | null; - registrationProvinceId : string | null; + reasonSameDate: Date | null; + ethnicity: string | null; + telephoneNumber: string | null; + nationality: string | null; + gender: string | null; + relationship: string | null; + religion: string | null; + bloodGroup: string | null; + registrationAddress: string | null; + registrationProvinceId: string | null; registrationDistrictId: string | null; - registrationSubDistrictId : string | null; - registrationZipCode : string | null; - currentAddress : string | null; - currentProvinceId : string | null; - currentDistrictId : string | null; - currentSubDistrictId : string | null; - currentZipCode : string | null; -}; + registrationSubDistrictId: string | null; + registrationZipCode: string | null; + currentAddress: string | null; + currentProvinceId: string | null; + currentDistrictId: string | null; + currentSubDistrictId: string | null; + currentZipCode: string | null; +} export type UpdateProfile = { rank?: string | null; diff --git a/src/entities/ProfileAvatar.ts b/src/entities/ProfileAvatar.ts new file mode 100644 index 00000000..1469a806 --- /dev/null +++ b/src/entities/ProfileAvatar.ts @@ -0,0 +1,52 @@ +import { Entity, Column, ManyToOne, JoinColumn } from "typeorm"; +import { EntityBase } from "./base/Base"; +import { Profile } from "./Profile"; +import { ProfileEmployee } from "./ProfileEmployee"; + +@Entity("profileAvatar") +export class ProfileAvatar extends EntityBase { + @Column({ + nullable: true, + comment: "รูปถ่าย", + default: null, + }) + avatar: string; + + @Column({ + nullable: true, + length: 40, + comment: "คีย์นอก(FK)ของตาราง Profile", + default: null, + }) + profileId: string; + + @Column({ + nullable: true, + length: 40, + comment: "คีย์นอก(FK)ของตาราง ProfileEmployee", + default: null, + }) + profileEmployeeId: string; + + @ManyToOne(() => Profile, (profile) => profile.profileAvatars) + @JoinColumn({ name: "profileId" }) + profile: Profile; + + @ManyToOne(() => ProfileEmployee, (ProfileEmployee) => ProfileEmployee.profileAvatars) + @JoinColumn({ name: "profileEmployeeId" }) + profileEmployee: ProfileEmployee; +} + +export class CreateProfileAvatar { + profileId: string; + avatar: string | null; +} + +export class CreateProfileEmployeeAvatar { + profileEmployeeId: string; + avatar: string | null; +} + +export type UpdateProfileAvatar = { + avatar?: string | null; +}; diff --git a/src/entities/ProfileEmployee.ts b/src/entities/ProfileEmployee.ts index b3ba3146..28533d27 100644 --- a/src/entities/ProfileEmployee.ts +++ b/src/entities/ProfileEmployee.ts @@ -19,8 +19,16 @@ import { ProfileChildren, ProfileFamilyHistory } from "./ProfileFamily"; import { ProfileEducation } from "./ProfileEducation"; import { ProfileAbility } from "./ProfileAbility"; import { ProfileOther } from "./ProfileOther"; +import { ProfileAvatar } from "./ProfileAvatar"; @Entity("profileEmployee") export class ProfileEmployee extends EntityBase { + @Column({ + nullable: true, + comment: "รูปถ่าย", + default: null, + }) + avatar: string; + @Column({ nullable: true, comment: "ประเภทลูกจ้าง (perm->ลูกจ้างประจำ temp->ลูกจ้างชั่วคราว)", @@ -255,6 +263,9 @@ export class ProfileEmployee extends EntityBase { @OneToMany(() => ProfileOther, (v) => v.profileEmployee) profileOthers: ProfileOther[]; + @OneToMany(() => ProfileAvatar, (v) => v.profileEmployee) + profileAvatars: ProfileAvatar[]; + @ManyToOne(() => EmployeePosLevel, (v) => v.profiles) posLevel: EmployeePosLevel; diff --git a/src/migration/1715675159227-update_table_node_add_responsibility.ts b/src/migration/1715675159227-update_table_node_add_responsibility.ts new file mode 100644 index 00000000..b60fc1b7 --- /dev/null +++ b/src/migration/1715675159227-update_table_node_add_responsibility.ts @@ -0,0 +1,56 @@ +import { MigrationInterface, QueryRunner } from "typeorm"; + +export class UpdateTableNodeAddResponsibility1715675159227 implements MigrationInterface { + name = 'UpdateTableNodeAddResponsibility1715675159227' + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`orgChild4\` CHANGE \`duty\` \`responsibility\` varchar(255) NULL COMMENT 'หน้าที่ความรับผิดชอบ'`); + await queryRunner.query(`ALTER TABLE \`orgChild3\` CHANGE \`duty\` \`responsibility\` varchar(255) NULL COMMENT 'หน้าที่ความรับผิดชอบ'`); + await queryRunner.query(`ALTER TABLE \`orgChild2\` CHANGE \`duty\` \`responsibility\` varchar(255) NULL COMMENT 'หน้าที่ความรับผิดชอบ'`); + await queryRunner.query(`ALTER TABLE \`orgChild1\` CHANGE \`duty\` \`responsibility\` varchar(255) NULL COMMENT 'หน้าที่ความรับผิดชอบ'`); + await queryRunner.query(`ALTER TABLE \`orgRoot\` CHANGE \`duty\` \`responsibility\` varchar(255) NULL COMMENT 'หน้าที่ความรับผิดชอบ'`); + await queryRunner.query(`CREATE TABLE \`profileAvatar\` (\`id\` varchar(36) NOT NULL, \`createdAt\` datetime(6) NOT NULL COMMENT 'สร้างข้อมูลเมื่อ' DEFAULT CURRENT_TIMESTAMP(6), \`createdUserId\` varchar(40) NOT NULL COMMENT 'User Id ที่สร้างข้อมูล' DEFAULT '00000000-0000-0000-0000-000000000000', \`lastUpdatedAt\` datetime(6) NOT NULL COMMENT 'แก้ไขข้อมูลล่าสุดเมื่อ' DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6), \`lastUpdateUserId\` varchar(40) NOT NULL COMMENT 'User Id ที่แก้ไขข้อมูล' DEFAULT '00000000-0000-0000-0000-000000000000', \`createdFullName\` varchar(200) NOT NULL COMMENT 'ชื่อ User ที่สร้างข้อมูล' DEFAULT 'string', \`lastUpdateFullName\` varchar(200) NOT NULL COMMENT 'ชื่อ User ที่แก้ไขข้อมูลล่าสุด' DEFAULT 'string', \`avatar\` varchar(255) NULL COMMENT 'รูปถ่าย', \`profileId\` varchar(40) NULL COMMENT 'คีย์นอก(FK)ของตาราง Profile', \`profileEmployeeId\` varchar(40) NULL COMMENT 'คีย์นอก(FK)ของตาราง ProfileEmployee', PRIMARY KEY (\`id\`)) ENGINE=InnoDB`); + await queryRunner.query(`ALTER TABLE \`profileEmployee\` ADD \`avatar\` varchar(255) NULL COMMENT 'รูปถ่าย'`); + await queryRunner.query(`ALTER TABLE \`profileEmployeeHistory\` ADD \`avatar\` varchar(255) NULL COMMENT 'รูปถ่าย'`); + await queryRunner.query(`ALTER TABLE \`profile\` ADD \`avatar\` varchar(255) NULL COMMENT 'รูปถ่าย'`); + await queryRunner.query(`ALTER TABLE \`profileHistory\` ADD \`avatar\` varchar(255) NULL COMMENT 'รูปถ่าย'`); + await queryRunner.query(`ALTER TABLE \`orgChild4\` DROP COLUMN \`responsibility\``); + await queryRunner.query(`ALTER TABLE \`orgChild4\` ADD \`responsibility\` varchar(255) NULL COMMENT 'หน้าที่ความรับผิดชอบ'`); + await queryRunner.query(`ALTER TABLE \`orgChild3\` DROP COLUMN \`responsibility\``); + await queryRunner.query(`ALTER TABLE \`orgChild3\` ADD \`responsibility\` varchar(255) NULL COMMENT 'หน้าที่ความรับผิดชอบ'`); + await queryRunner.query(`ALTER TABLE \`orgChild2\` DROP COLUMN \`responsibility\``); + await queryRunner.query(`ALTER TABLE \`orgChild2\` ADD \`responsibility\` varchar(255) NULL COMMENT 'หน้าที่ความรับผิดชอบ'`); + await queryRunner.query(`ALTER TABLE \`orgChild1\` DROP COLUMN \`responsibility\``); + await queryRunner.query(`ALTER TABLE \`orgChild1\` ADD \`responsibility\` varchar(255) NULL COMMENT 'หน้าที่ความรับผิดชอบ'`); + await queryRunner.query(`ALTER TABLE \`orgRoot\` DROP COLUMN \`responsibility\``); + await queryRunner.query(`ALTER TABLE \`orgRoot\` ADD \`responsibility\` varchar(255) NULL COMMENT 'หน้าที่ความรับผิดชอบ'`); + await queryRunner.query(`ALTER TABLE \`profileAvatar\` ADD CONSTRAINT \`FK_e0db5c1a2f1facf02f03fbf78ea\` FOREIGN KEY (\`profileId\`) REFERENCES \`profile\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`); + await queryRunner.query(`ALTER TABLE \`profileAvatar\` ADD CONSTRAINT \`FK_fb52fa49388a6e73b41ba8259a3\` FOREIGN KEY (\`profileEmployeeId\`) REFERENCES \`profileEmployee\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`); + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`profileAvatar\` DROP FOREIGN KEY \`FK_fb52fa49388a6e73b41ba8259a3\``); + await queryRunner.query(`ALTER TABLE \`profileAvatar\` DROP FOREIGN KEY \`FK_e0db5c1a2f1facf02f03fbf78ea\``); + await queryRunner.query(`ALTER TABLE \`orgRoot\` DROP COLUMN \`responsibility\``); + await queryRunner.query(`ALTER TABLE \`orgRoot\` ADD \`responsibility\` varchar(255) NULL COMMENT 'หน้าที่ความรับผิดชอบ'`); + await queryRunner.query(`ALTER TABLE \`orgChild1\` DROP COLUMN \`responsibility\``); + await queryRunner.query(`ALTER TABLE \`orgChild1\` ADD \`responsibility\` varchar(255) NULL COMMENT 'หน้าที่ความรับผิดชอบ'`); + await queryRunner.query(`ALTER TABLE \`orgChild2\` DROP COLUMN \`responsibility\``); + await queryRunner.query(`ALTER TABLE \`orgChild2\` ADD \`responsibility\` varchar(255) NULL COMMENT 'หน้าที่ความรับผิดชอบ'`); + await queryRunner.query(`ALTER TABLE \`orgChild3\` DROP COLUMN \`responsibility\``); + await queryRunner.query(`ALTER TABLE \`orgChild3\` ADD \`responsibility\` varchar(255) NULL COMMENT 'หน้าที่ความรับผิดชอบ'`); + await queryRunner.query(`ALTER TABLE \`orgChild4\` DROP COLUMN \`responsibility\``); + await queryRunner.query(`ALTER TABLE \`orgChild4\` ADD \`responsibility\` varchar(255) NULL COMMENT 'หน้าที่ความรับผิดชอบ'`); + await queryRunner.query(`ALTER TABLE \`profileHistory\` DROP COLUMN \`avatar\``); + await queryRunner.query(`ALTER TABLE \`profile\` DROP COLUMN \`avatar\``); + await queryRunner.query(`ALTER TABLE \`profileEmployeeHistory\` DROP COLUMN \`avatar\``); + await queryRunner.query(`ALTER TABLE \`profileEmployee\` DROP COLUMN \`avatar\``); + await queryRunner.query(`DROP TABLE \`profileAvatar\``); + await queryRunner.query(`ALTER TABLE \`orgRoot\` CHANGE \`responsibility\` \`duty\` varchar(255) NULL COMMENT 'หน้าที่ความรับผิดชอบ'`); + await queryRunner.query(`ALTER TABLE \`orgChild1\` CHANGE \`responsibility\` \`duty\` varchar(255) NULL COMMENT 'หน้าที่ความรับผิดชอบ'`); + await queryRunner.query(`ALTER TABLE \`orgChild2\` CHANGE \`responsibility\` \`duty\` varchar(255) NULL COMMENT 'หน้าที่ความรับผิดชอบ'`); + await queryRunner.query(`ALTER TABLE \`orgChild3\` CHANGE \`responsibility\` \`duty\` varchar(255) NULL COMMENT 'หน้าที่ความรับผิดชอบ'`); + await queryRunner.query(`ALTER TABLE \`orgChild4\` CHANGE \`responsibility\` \`duty\` varchar(255) NULL COMMENT 'หน้าที่ความรับผิดชอบ'`); + } + +} From 566b4db692ef86236b0577be9c3e3996b9226998 Mon Sep 17 00:00:00 2001 From: Kittapath Date: Tue, 14 May 2024 15:43:24 +0700 Subject: [PATCH 4/9] =?UTF-8?q?path=20=E0=B8=A3=E0=B8=B9=E0=B8=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/ProfileAvatarController.ts | 5 +++++ src/controllers/ProfileAvatarEmployeeController.ts | 9 +++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/controllers/ProfileAvatarController.ts b/src/controllers/ProfileAvatarController.ts index 6d105a11..492636a7 100644 --- a/src/controllers/ProfileAvatarController.ts +++ b/src/controllers/ProfileAvatarController.ts @@ -42,6 +42,11 @@ export class ProfileAvatarController extends Controller { Object.assign(data, { ...body, ...meta }); await this.avatarRepository.save(data); + let avatar = `ทะเบียนประวัติ/โปรไฟล์/${profile.id}/profile-${data.id}`; + data.avatar = avatar; + await this.avatarRepository.save(data); + profile.avatar = avatar; + await this.profileRepository.save(profile); return new HttpSuccess(); } diff --git a/src/controllers/ProfileAvatarEmployeeController.ts b/src/controllers/ProfileAvatarEmployeeController.ts index 2cc3ce65..e1a7a7d0 100644 --- a/src/controllers/ProfileAvatarEmployeeController.ts +++ b/src/controllers/ProfileAvatarEmployeeController.ts @@ -10,7 +10,7 @@ import { ProfileEmployee } from "../entities/ProfileEmployee"; @Route("api/v1/org/profile-employee/avatar") @Tags("ProfileAvatar") @Security("bearerAuth") -export class ProfileAvatarController extends Controller { +export class ProfileAvatarEmployeeController extends Controller { private profileRepository = AppDataSource.getRepository(ProfileEmployee); private avatarRepository = AppDataSource.getRepository(ProfileAvatar); @@ -45,8 +45,13 @@ export class ProfileAvatarController extends Controller { Object.assign(data, { ...body, ...meta }); await this.avatarRepository.save(data); + let avatar = `ทะเบียนประวัติ/โปรไฟล์/${profile.id}/profile-employee-${data.id}`; + data.avatar = avatar; + await this.avatarRepository.save(data); + profile.avatar = avatar; + await this.profileRepository.save(profile); - return new HttpSuccess(); + return new HttpSuccess(avatar); } @Delete("{avatarId}") From dd06c1f71f33dbb9850acca4f630ae37e7cab6f9 Mon Sep 17 00:00:00 2001 From: AnandaTon Date: Tue, 14 May 2024 16:16:24 +0700 Subject: [PATCH 5/9] fix bug salary / nopaid --- src/controllers/ProfileNopaidController.ts | 2 +- .../ProfileNopaidEmployeeController.ts | 2 +- .../ProfileSalaryEmployeeController.ts | 21 +++++++++---------- src/entities/ProfileEmployee.ts | 2 +- src/entities/ProfileSalary.ts | 4 ---- 5 files changed, 13 insertions(+), 18 deletions(-) diff --git a/src/controllers/ProfileNopaidController.ts b/src/controllers/ProfileNopaidController.ts index 65ec27ec..d2a531fd 100644 --- a/src/controllers/ProfileNopaidController.ts +++ b/src/controllers/ProfileNopaidController.ts @@ -137,7 +137,7 @@ export class ProfileNopaidController extends Controller { } @Delete("{nopaidId}") - public async deleteTraning(@Path() nopaidId: string) { + public async deleteNopaid(@Path() nopaidId: string) { await this.nopaidHistoryRepository.delete({ profileNopaidId: nopaidId, }); diff --git a/src/controllers/ProfileNopaidEmployeeController.ts b/src/controllers/ProfileNopaidEmployeeController.ts index f7bba569..fc54a656 100644 --- a/src/controllers/ProfileNopaidEmployeeController.ts +++ b/src/controllers/ProfileNopaidEmployeeController.ts @@ -122,7 +122,7 @@ export class ProfileNopaidEmployeeController extends Controller { } @Delete("{nopaidId}") - public async deleteTraning(@Path() nopaidId: string) { + public async deleteNopaid(@Path() nopaidId: string) { await this.nopaidHistoryRepository.delete({ profileNopaidId: nopaidId, }); diff --git a/src/controllers/ProfileSalaryEmployeeController.ts b/src/controllers/ProfileSalaryEmployeeController.ts index d9ef1b7f..724dcbe0 100644 --- a/src/controllers/ProfileSalaryEmployeeController.ts +++ b/src/controllers/ProfileSalaryEmployeeController.ts @@ -15,15 +15,14 @@ import { import { AppDataSource } from "../database/data-source"; import { CreateProfileSalaryEmployee, - ProfileSalary, - UpdateProfileSalary, -} from "../entities/ProfileSalary"; + ProfileSalaryEmployee, + UpdateProfileSalaryEmployee, +} from "../entities/ProfileSalaryEmployee"; import HttpSuccess from "../interfaces/http-success"; import HttpStatus from "../interfaces/http-status"; import HttpError from "../interfaces/http-error"; import { ProfileSalaryHistory } from "../entities/ProfileSalaryHistory"; import { RequestWithUser } from "../middlewares/user"; -import { Profile } from "../entities/Profile"; import { ProfileEmployee } from "../entities/ProfileEmployee"; import { LessThan, MoreThan } from "typeorm"; @@ -32,13 +31,13 @@ import { LessThan, MoreThan } from "typeorm"; @Security("bearerAuth") export class ProfileSalaryEmployeeController extends Controller { private profileRepo = AppDataSource.getRepository(ProfileEmployee); - private salaryRepo = AppDataSource.getRepository(ProfileSalary); + private salaryRepo = AppDataSource.getRepository(ProfileSalaryEmployee); private salaryHistoryRepo = AppDataSource.getRepository(ProfileSalaryHistory); @Get("{profileId}") public async getSalary(@Path() profileId: string) { const record = await this.salaryRepo.find({ - where: { profileEmployeeId: profileId }, + where: { profileId: profileId }, order: { order: "ASC" }, }); return new HttpSuccess(record); @@ -57,22 +56,22 @@ export class ProfileSalaryEmployeeController extends Controller { @Request() req: RequestWithUser, @Body() body: CreateProfileSalaryEmployee, ) { - if (!body.profileEmployeeId) { + if (!body.profileId) { throw new HttpError(HttpStatus.BAD_REQUEST, "กรุณากรอก profileId"); } - const profile = await this.profileRepo.findOneBy({ id: body.profileEmployeeId }); + const profile = await this.profileRepo.findOneBy({ id: body.profileId }); if (!profile) { throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); } const dest_item = await this.salaryRepo.findOne({ - where: { profileId: body.profileEmployeeId }, + where: { profileId: body.profileId }, order: { order: "DESC" }, }); - const data = new ProfileSalary(); + const data = new ProfileSalaryEmployee(); const meta = { order: dest_item == null ? 1 : dest_item.order + 1, @@ -92,7 +91,7 @@ export class ProfileSalaryEmployeeController extends Controller { @Patch("{salaryId}") public async editSalary( @Request() req: RequestWithUser, - @Body() body: UpdateProfileSalary, + @Body() body: UpdateProfileSalaryEmployee, @Path() salaryId: string, ) { const record = await this.salaryRepo.findOneBy({ id: salaryId }); diff --git a/src/entities/ProfileEmployee.ts b/src/entities/ProfileEmployee.ts index 28533d27..4c1c1d7a 100644 --- a/src/entities/ProfileEmployee.ts +++ b/src/entities/ProfileEmployee.ts @@ -243,7 +243,7 @@ export class ProfileEmployee extends EntityBase { profileNopaids: ProfileNopaid[]; @OneToMany(() => ProfileDiscipline, (v) => v.profileEmployee) - profileDisciplines: ProfileNopaid[]; + profileDisciplines: ProfileDiscipline[]; @OneToMany(() => ProfileChangeName, (v) => v.profileEmployee) profileChangeNames: ProfileChangeName[]; diff --git a/src/entities/ProfileSalary.ts b/src/entities/ProfileSalary.ts index 4068e669..908f8db6 100644 --- a/src/entities/ProfileSalary.ts +++ b/src/entities/ProfileSalary.ts @@ -146,10 +146,6 @@ export class ProfileSalary extends EntityBase { @ManyToOne(() => Profile, (profile) => profile.profileSalary) @JoinColumn({ name: "profileId" }) profile: Profile; - - @ManyToOne(() => ProfileEmployee, (ProfileEmployee) => ProfileEmployee.profileSalary) - @JoinColumn({ name: "profileEmployeeId" }) - profileEmployee: ProfileEmployee; } export class CreateProfileSalary { From 0d86a02f5b35643fea332bcdf41fb6002f9e7e0c Mon Sep 17 00:00:00 2001 From: Bright Date: Tue, 14 May 2024 16:20:18 +0700 Subject: [PATCH 6/9] =?UTF-8?q?=E0=B8=9B=E0=B8=A3=E0=B8=B1=E0=B8=9Arelatio?= =?UTF-8?q?n=20geverment?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/entities/ProfileEmployee.ts | 4 ++++ src/entities/ProfileGovernment.ts | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/entities/ProfileEmployee.ts b/src/entities/ProfileEmployee.ts index 28533d27..a284db06 100644 --- a/src/entities/ProfileEmployee.ts +++ b/src/entities/ProfileEmployee.ts @@ -20,6 +20,7 @@ import { ProfileEducation } from "./ProfileEducation"; import { ProfileAbility } from "./ProfileAbility"; import { ProfileOther } from "./ProfileOther"; import { ProfileAvatar } from "./ProfileAvatar"; +import { ProfileGovernment } from "./ProfileGovernment"; @Entity("profileEmployee") export class ProfileEmployee extends EntityBase { @Column({ @@ -274,6 +275,9 @@ export class ProfileEmployee extends EntityBase { @OneToMany(() => ProfileEmployeeHistory, (v) => v.profileEmployee) histories: ProfileEmployeeHistory[]; + + @OneToMany(() => ProfileGovernment, (v) => v.profileEmployee) + profileGovernment: ProfileGovernment[]; } @Entity("profileEmployeeHistory") diff --git a/src/entities/ProfileGovernment.ts b/src/entities/ProfileGovernment.ts index 0f675353..f02b89c0 100644 --- a/src/entities/ProfileGovernment.ts +++ b/src/entities/ProfileGovernment.ts @@ -62,7 +62,7 @@ export class ProfileGovernment extends EntityBase { @JoinColumn({ name: "profileId" }) profile: Profile; - @ManyToOne(() => ProfileEmployee, (ProfileEmployee) => ProfileEmployee.profileTrainings) + @ManyToOne(() => ProfileEmployee, (v) => v.profileGovernment) @JoinColumn({ name: "profileEmployeeId" }) profileEmployee: ProfileEmployee; } From b8cbbb3a6f1eacf0a3437c3b4ade1d4d630f8a47 Mon Sep 17 00:00:00 2001 From: Kittapath Date: Tue, 14 May 2024 16:20:36 +0700 Subject: [PATCH 7/9] no message --- src/controllers/ProfileAvatarController.ts | 2 +- src/entities/ProfileAvatar.ts | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/controllers/ProfileAvatarController.ts b/src/controllers/ProfileAvatarController.ts index 492636a7..f98b202e 100644 --- a/src/controllers/ProfileAvatarController.ts +++ b/src/controllers/ProfileAvatarController.ts @@ -48,7 +48,7 @@ export class ProfileAvatarController extends Controller { profile.avatar = avatar; await this.profileRepository.save(profile); - return new HttpSuccess(); + return new HttpSuccess(avatar); } @Delete("{avatarId}") diff --git a/src/entities/ProfileAvatar.ts b/src/entities/ProfileAvatar.ts index 1469a806..0f4b03ed 100644 --- a/src/entities/ProfileAvatar.ts +++ b/src/entities/ProfileAvatar.ts @@ -39,12 +39,12 @@ export class ProfileAvatar extends EntityBase { export class CreateProfileAvatar { profileId: string; - avatar: string | null; + // avatar: string | null; } export class CreateProfileEmployeeAvatar { profileEmployeeId: string; - avatar: string | null; + // avatar: string | null; } export type UpdateProfileAvatar = { From e99bd89b1e2818c7f5a5003225bf8ca9adcd9969 Mon Sep 17 00:00:00 2001 From: Bright Date: Tue, 14 May 2024 16:20:18 +0700 Subject: [PATCH 8/9] =?UTF-8?q?=E0=B8=9B=E0=B8=A3=E0=B8=B1=E0=B8=9Arelatio?= =?UTF-8?q?n=20geverment?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/entities/ProfileEmployee.ts | 4 ++++ src/entities/ProfileGovernment.ts | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/entities/ProfileEmployee.ts b/src/entities/ProfileEmployee.ts index 4c1c1d7a..53d5b1cd 100644 --- a/src/entities/ProfileEmployee.ts +++ b/src/entities/ProfileEmployee.ts @@ -20,6 +20,7 @@ import { ProfileEducation } from "./ProfileEducation"; import { ProfileAbility } from "./ProfileAbility"; import { ProfileOther } from "./ProfileOther"; import { ProfileAvatar } from "./ProfileAvatar"; +import { ProfileGovernment } from "./ProfileGovernment"; @Entity("profileEmployee") export class ProfileEmployee extends EntityBase { @Column({ @@ -274,6 +275,9 @@ export class ProfileEmployee extends EntityBase { @OneToMany(() => ProfileEmployeeHistory, (v) => v.profileEmployee) histories: ProfileEmployeeHistory[]; + + @OneToMany(() => ProfileGovernment, (v) => v.profileEmployee) + profileGovernment: ProfileGovernment[]; } @Entity("profileEmployeeHistory") diff --git a/src/entities/ProfileGovernment.ts b/src/entities/ProfileGovernment.ts index 0f675353..f02b89c0 100644 --- a/src/entities/ProfileGovernment.ts +++ b/src/entities/ProfileGovernment.ts @@ -62,7 +62,7 @@ export class ProfileGovernment extends EntityBase { @JoinColumn({ name: "profileId" }) profile: Profile; - @ManyToOne(() => ProfileEmployee, (ProfileEmployee) => ProfileEmployee.profileTrainings) + @ManyToOne(() => ProfileEmployee, (v) => v.profileGovernment) @JoinColumn({ name: "profileEmployeeId" }) profileEmployee: ProfileEmployee; } From fcbbdbf4d1fe4bf836bd22230d7dc6fdc6b2362f Mon Sep 17 00:00:00 2001 From: AnandaTon Date: Tue, 14 May 2024 17:24:38 +0700 Subject: [PATCH 9/9] =?UTF-8?q?fix=20bug=20=E0=B9=81=E0=B8=81=E0=B9=89?= =?UTF-8?q?=E0=B8=8A=E0=B8=B7=E0=B9=88=E0=B8=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../OrganizationUnauthorizeController.ts | 8 +- src/controllers/ProfileController.ts | 64 ++++++----- .../ProfileDisciplineController.ts | 2 +- .../ProfileDisciplineEmployeeController.ts | 2 +- src/controllers/ProfileDutyController.ts | 2 +- .../ProfileDutyEmployeeController.ts | 2 +- src/controllers/ProfileEmployeeController.ts | 4 +- src/controllers/ProfileLeaveController.ts | 2 +- .../ProfileLeaveEmployeeController.ts | 2 +- src/controllers/ProfileOtherController.ts | 2 +- .../ProfileOtherEmployeeController.ts | 2 +- src/entities/Profile.ts | 4 +- src/entities/ProfileDiscipline.ts | 2 +- src/entities/ProfileDisciplineEmployee.ts | 106 ------------------ .../ProfileDisciplineEmployeeHistory.ts | 74 ------------ src/entities/ProfileEmployee.ts | 4 - 16 files changed, 50 insertions(+), 232 deletions(-) delete mode 100644 src/entities/ProfileDisciplineEmployee.ts delete mode 100644 src/entities/ProfileDisciplineEmployeeHistory.ts 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/ProfileController.ts b/src/controllers/ProfileController.ts index e1d76c73..3e91d89d 100644 --- a/src/controllers/ProfileController.ts +++ b/src/controllers/ProfileController.ts @@ -218,7 +218,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 +755,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 +777,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 +1726,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 +1887,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 +1934,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 +1958,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..3df03f86 100644 --- a/src/controllers/ProfileEmployeeController.ts +++ b/src/controllers/ProfileEmployeeController.ts @@ -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 1d7b8d04..28e0763d 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"; @@ -22,6 +21,7 @@ import { Province } from "./Province"; import { SubDistrict } from "./SubDistrict"; import { District } from "./District"; import { ProfileAvatar } from "./ProfileAvatar"; +import { ProfileDiscipline } from "./ProfileDiscipline"; @Entity("profile") export class Profile extends EntityBase { @@ -267,7 +267,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 53d5b1cd..db38a05c 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"; @@ -216,9 +215,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[];