From d2426ca6e4a902738384ffe69935cf400842a67f Mon Sep 17 00:00:00 2001 From: Adisak Date: Tue, 25 Nov 2025 10:54:16 +0700 Subject: [PATCH 01/10] fix --- src/controllers/OrganizationUnauthorizeController.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/controllers/OrganizationUnauthorizeController.ts b/src/controllers/OrganizationUnauthorizeController.ts index 28c88db6..c5f67dee 100644 --- a/src/controllers/OrganizationUnauthorizeController.ts +++ b/src/controllers/OrganizationUnauthorizeController.ts @@ -517,8 +517,8 @@ export class OrganizationUnauthorizeController extends Controller { new Date( `${new Date(item.disCriplineDate).getFullYear()}-${String(new Date(item.disCriplineDate).getMonth() + 1).padStart(2, "0")}-${String(new Date(item.disCriplineDate).getDate() + 1).padStart(2, "0")}T00:00:00.000Z`, ) <= datePeriodEnd - ? true - : false, + ? false + : true, isSuspension: item.dateRetire == null ? false : true, isAbsent: item.profileDisciplineId ? true : false, isLeave: item.profileLeaveId ? true : false, @@ -971,8 +971,8 @@ export class OrganizationUnauthorizeController extends Controller { new Date( `${new Date(item.disCriplineDate).getFullYear()}-${String(new Date(item.disCriplineDate).getMonth() + 1).padStart(2, "0")}-${String(new Date(item.disCriplineDate).getDate() + 1).padStart(2, "0")}T00:00:00.000Z`, ) <= datePeriodEnd - ? true - : false, + ? false + : true, isSuspension: item.dateRetire == null ? false : true, isAbsent: item.profileDisciplineId ? true : false, isLeave: item.profileLeaveId ? true : false, From b26cbad5ee3d568ed1f4157205bff57bc41990b3 Mon Sep 17 00:00:00 2001 From: Adisak Date: Tue, 25 Nov 2025 12:01:06 +0700 Subject: [PATCH 02/10] fix duplicate salary list --- src/controllers/OrganizationUnauthorizeController.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/controllers/OrganizationUnauthorizeController.ts b/src/controllers/OrganizationUnauthorizeController.ts index c5f67dee..4510351c 100644 --- a/src/controllers/OrganizationUnauthorizeController.ts +++ b/src/controllers/OrganizationUnauthorizeController.ts @@ -340,6 +340,7 @@ export class OrganizationUnauthorizeController extends Controller { const [findPosMaster, total] = await AppDataSource.getRepository(viewPosMaster) .createQueryBuilder("viewPosMaster") .where({orgRevisionId: findRevision?.id}) + .andWhere({positionIsSelected: true}) // .andWhere("viewPosMaster.rootId IN (:...rootIds)", { rootIds }) .andWhere( new Brackets((qb) => { From 8f6637a6565698766dad92ce351a48d7bfc097fb Mon Sep 17 00:00:00 2001 From: Adisak Date: Tue, 25 Nov 2025 13:36:17 +0700 Subject: [PATCH 03/10] =?UTF-8?q?=E0=B8=AD=E0=B8=B1=E0=B8=9E=E0=B9=80?= =?UTF-8?q?=E0=B8=94=E0=B8=97=20view=5Fpos=5Fmaster?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/entities/view/viewPosMaster.ts | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/entities/view/viewPosMaster.ts b/src/entities/view/viewPosMaster.ts index 58d341d3..c44aa2d6 100644 --- a/src/entities/view/viewPosMaster.ts +++ b/src/entities/view/viewPosMaster.ts @@ -78,14 +78,18 @@ import { ViewColumn, ViewEntity } from "typeorm"; LEFT JOIN posExecutive ON position.posExecutiveId = posExecutive.id LEFT JOIN ( - SELECT * - FROM profileDiscipline pd1 - WHERE pd1.date = ( - SELECT MAX(pd2.date) - FROM profileDiscipline pd2 - WHERE pd2.profileId = pd1.profileId - ) - ) AS profileDiscipline ON profileDiscipline.profileId = profile.id + SELECT * + FROM ( + SELECT + pd.*, + ROW_NUMBER() OVER ( + PARTITION BY profileId + ORDER BY date DESC, id DESC + ) AS rn + FROM profileDiscipline pd + ) t + WHERE rn = 1 + ) AS profileDiscipline ON profileDiscipline.profileId = profile.id LEFT JOIN ( SELECT pl1.* FROM profileLeave pl1 From 4c3d3dceffadb8e21e9d970e7b11c25db0d4907a Mon Sep 17 00:00:00 2001 From: harid Date: Tue, 25 Nov 2025 17:11:51 +0700 Subject: [PATCH 04/10] =?UTF-8?q?=E0=B8=AD=E0=B8=B1=E0=B8=9E=E0=B9=80?= =?UTF-8?q?=E0=B8=94=E0=B8=95=E0=B8=9F=E0=B8=B4=E0=B8=A5=E0=B8=94=E0=B9=8C?= =?UTF-8?q?=20prefixMain=20#2033?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/CommandController.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/controllers/CommandController.ts b/src/controllers/CommandController.ts index 3435a0c7..b6b5fc7d 100644 --- a/src/controllers/CommandController.ts +++ b/src/controllers/CommandController.ts @@ -6041,6 +6041,7 @@ export class CommandController extends Controller { profile.isProbation = item.bodyProfile.isProbation; //เพิ่มใหม่จากรับโอน profile.prefix = item.bodyProfile.prefix ?? null; + profile.prefixMain = item.bodyProfile.prefix ?? null; profile.firstName = item.bodyProfile.firstName ?? null; profile.lastName = item.bodyProfile.lastName ?? null; profile.birthDate = item.bodyProfile.birthDate ?? null; @@ -6093,6 +6094,7 @@ export class CommandController extends Controller { profile.amountSpecial = item.bodyProfile.amountSpecial ?? null; profile.isProbation = item.bodyProfile.isProbation; profile.prefix = item.bodyProfile.prefix ?? null; + profile.prefixMain = item.bodyProfile.prefix ?? null; profile.firstName = item.bodyProfile.firstName ?? null; profile.lastName = item.bodyProfile.lastName ?? null; profile.birthDate = item.bodyProfile.birthDate ?? null; @@ -6152,6 +6154,7 @@ export class CommandController extends Controller { item.bodyProfile.prefix && item.bodyProfile.prefix != "" ? item.bodyProfile.prefix : profile.prefix; + profile.prefixMain = item.bodyProfile.prefix ?? null; profile.firstName = item.bodyProfile.firstName && item.bodyProfile.firstName != "" ? item.bodyProfile.firstName From 4f30ea9c6ba6a8195342e82ee24535ca2d64bbe8 Mon Sep 17 00:00:00 2001 From: Adisak Date: Wed, 26 Nov 2025 09:42:43 +0700 Subject: [PATCH 05/10] #2036 --- src/controllers/ProfileController.ts | 25 ++++---------------- src/controllers/ProfileEmployeeController.ts | 10 ++------ src/interfaces/extension.ts | 5 +--- 3 files changed, 8 insertions(+), 32 deletions(-) diff --git a/src/controllers/ProfileController.ts b/src/controllers/ProfileController.ts index 120a7fa5..6558f0ee 100644 --- a/src/controllers/ProfileController.ts +++ b/src/controllers/ProfileController.ts @@ -3302,10 +3302,7 @@ export class ProfileController extends Controller { citizenIdDigits[10] * 3 + citizenIdDigits[11] * 2; const calStp2 = cal % 11; - let chkDigit = 11 - calStp2; - if (chkDigit >= 10) { - chkDigit = 0; - } + const chkDigit = (11 - calStp2) % 10; if (citizenIdDigits[12] !== chkDigit) { throw new HttpError(HttpStatus.NOT_FOUND, "ข้อมูลรหัสบัตรประจำตัวประชาชนไม่ถูกต้อง"); @@ -3338,10 +3335,7 @@ export class ProfileController extends Controller { citizenIdDigits[10] * 3 + citizenIdDigits[11] * 2; const calStp2 = cal % 11; - let chkDigit = 11 - calStp2; - if (chkDigit >= 10) { - chkDigit = 0; - } + const chkDigit = (11 - calStp2) % 10; // else if(chkDigit === 11){ // chkDigit = cal % 10; // } @@ -3416,10 +3410,7 @@ export class ProfileController extends Controller { citizenIdDigits[10] * 3 + citizenIdDigits[11] * 2; const calStp2 = cal % 11; - let chkDigit = 11 - calStp2; - if (chkDigit >= 10) { - chkDigit = 0; - } + const chkDigit = (11 - calStp2) % 10; if (citizenIdDigits[12] !== chkDigit) { throw new HttpError(HttpStatus.NOT_FOUND, "ข้อมูลรหัสบัตรประจำตัวประชาชนไม่ถูกต้อง"); @@ -3484,10 +3475,7 @@ export class ProfileController extends Controller { citizenIdDigits[10] * 3 + citizenIdDigits[11] * 2; const calStp2 = cal % 11; - let chkDigit = 11 - calStp2; - if (chkDigit >= 10) { - chkDigit = 0; - } + const chkDigit = (11 - calStp2) % 10; if (citizenIdDigits[12] !== chkDigit) { throw new HttpError(HttpStatus.NOT_FOUND, "ข้อมูลรหัสบัตรประจำตัวประชาชนไม่ถูกต้อง"); @@ -5249,10 +5237,7 @@ export class ProfileController extends Controller { citizenIdDigits[10] * 3 + citizenIdDigits[11] * 2; const calStp2 = cal % 11; - let chkDigit = 11 - calStp2; - if (chkDigit >= 10) { - chkDigit = 0; - } + const chkDigit = (11 - calStp2) % 10; if (citizenIdDigits[12] !== chkDigit) { throw new HttpError(HttpStatus.NOT_FOUND, "ข้อมูลรหัสบัตรประจำตัวประชาชนไม่ถูกต้อง"); diff --git a/src/controllers/ProfileEmployeeController.ts b/src/controllers/ProfileEmployeeController.ts index cdbac600..ac5523bb 100644 --- a/src/controllers/ProfileEmployeeController.ts +++ b/src/controllers/ProfileEmployeeController.ts @@ -1891,10 +1891,7 @@ export class ProfileEmployeeController extends Controller { citizenIdDigits[10] * 3 + citizenIdDigits[11] * 2; const calStp2 = cal % 11; - let chkDigit = 11 - calStp2; - if (chkDigit >= 10) { - chkDigit = 0; - } + const chkDigit = (11 - calStp2) % 10; if (citizenIdDigits[12] !== chkDigit) { throw new HttpError(HttpStatus.NOT_FOUND, "ข้อมูลรหัสบัตรประจำตัวประชาชนไม่ถูกต้อง"); @@ -1983,10 +1980,7 @@ export class ProfileEmployeeController extends Controller { citizenIdDigits[10] * 3 + citizenIdDigits[11] * 2; const calStp2 = cal % 11; - let chkDigit = 11 - calStp2; - if (chkDigit >= 10) { - chkDigit = 0; - } + const chkDigit = (11 - calStp2) % 10; if (citizenIdDigits[12] !== chkDigit) { throw new HttpError(HttpStatus.NOT_FOUND, "ข้อมูลรหัสบัตรประจำตัวประชาชนไม่ถูกต้อง"); diff --git a/src/interfaces/extension.ts b/src/interfaces/extension.ts index c81e66c0..4a5dc5a3 100644 --- a/src/interfaces/extension.ts +++ b/src/interfaces/extension.ts @@ -275,10 +275,7 @@ class Extension { citizenIdDigits[10] * 3 + citizenIdDigits[11] * 2; const calStp2 = cal % 11; - let chkDigit = 11 - calStp2; - if (chkDigit >= 10) { - chkDigit = 0; - } + const chkDigit = (11 - calStp2) % 10; // if (citizenIdDigits[12] !== chkDigit) { // throw new HttpError(HttpStatus.NOT_FOUND, "ข้อมูลรหัสบัตรประจำตัวประชาชนไม่ถูกต้อง"); From a0f18b858feb22f6c6dd0d5ded3a03bfd99b9e2c Mon Sep 17 00:00:00 2001 From: Adisak Date: Wed, 26 Nov 2025 09:47:12 +0700 Subject: [PATCH 06/10] =?UTF-8?q?fix=20=E0=B8=A3=E0=B8=B2=E0=B8=A2?= =?UTF-8?q?=E0=B8=8A=E0=B8=B7=E0=B9=88=E0=B8=AD=E0=B8=A3=E0=B8=B2=E0=B8=8A?= =?UTF-8?q?=E0=B8=81=E0=B8=B2=E0=B8=A3=E0=B8=97=E0=B8=B5=E0=B9=88=E0=B9=80?= =?UTF-8?q?=E0=B8=A5=E0=B8=B7=E0=B9=88=E0=B8=AD=E0=B8=99=E0=B9=80=E0=B8=87?= =?UTF-8?q?=E0=B8=B4=E0=B8=99=E0=B9=80=E0=B8=94=E0=B8=B7=E0=B8=AD=E0=B8=99?= =?UTF-8?q?=20(isPunish)=20salary/gen=20=E0=B9=80=E0=B8=AA=E0=B9=89?= =?UTF-8?q?=E0=B8=99=E0=B9=80=E0=B8=81=E0=B9=88=E0=B8=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/OrganizationUnauthorizeController.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/controllers/OrganizationUnauthorizeController.ts b/src/controllers/OrganizationUnauthorizeController.ts index 4510351c..c72b600f 100644 --- a/src/controllers/OrganizationUnauthorizeController.ts +++ b/src/controllers/OrganizationUnauthorizeController.ts @@ -280,8 +280,8 @@ export class OrganizationUnauthorizeController extends Controller { `${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`, ) <= datePeriodEnd, ).length > 0 - ? true - : false, + ? false + : true, isSuspension: item.current_holder.dateRetire == null ? false : true, isAbsent: item.current_holder.profileDisciplines.length > 0 ? true : false, isLeave: item.current_holder.profileLeaves.length > 0 ? true : false, @@ -740,8 +740,8 @@ export class OrganizationUnauthorizeController extends Controller { `${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`, ) <= datePeriodEnd, ).length > 0 - ? true - : false, + ? false + : true, isSuspension: item.current_holder.dateRetire == null ? false : true, isAbsent: item.current_holder.profileDisciplines.length > 0 ? true : false, isLeave: item.current_holder.profileLeaves.length > 0 ? true : false, From 4ba71ff83036bb03264a6abb6edc5c8f3e730e03 Mon Sep 17 00:00:00 2001 From: harid Date: Wed, 26 Nov 2025 16:20:11 +0700 Subject: [PATCH 07/10] =?UTF-8?q?=E0=B9=80=E0=B8=89=E0=B8=9E=E0=B8=B2?= =?UTF-8?q?=E0=B8=B0=E0=B8=84=E0=B8=B3=E0=B8=AA=E0=B8=B1=E0=B9=88=E0=B8=87?= =?UTF-8?q?=20C-PM-10=20=E0=B9=83=E0=B8=AB=E0=B9=89=E0=B8=95=E0=B8=B1?= =?UTF-8?q?=E0=B8=94=20receiverUserId=20=E0=B8=97=E0=B8=B5=E0=B9=88?= =?UTF-8?q?=E0=B8=AA=E0=B9=88=E0=B8=87=20noti=20=E0=B8=84=E0=B8=A3?= =?UTF-8?q?=E0=B8=B1=E0=B9=89=E0=B8=87=E0=B9=81=E0=B8=A3=E0=B8=81=E0=B8=AD?= =?UTF-8?q?=E0=B8=AD=E0=B8=81=20#1995?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/services/rabbitmq.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/services/rabbitmq.ts b/src/services/rabbitmq.ts index dd57d886..74df4dc0 100644 --- a/src/services/rabbitmq.ts +++ b/src/services/rabbitmq.ts @@ -445,7 +445,11 @@ async function handler_command_noti(msg: amqp.ConsumeMessage): Promise isSendNotification: true, })) : []; - + /*เฉพาะคำสั่ง C-PM-10 ให้ตัด receiverUserId ที่ส่ง noti ครั้งแรกออก*/ + if (command && command.commandType && ["C-PM-10"].includes(command.commandType.code)) { + const firstNotiIds = profiles.map((p:any) => p.receiverUserId); + profilesSend = profilesSend.filter((x:any) => !firstNotiIds.includes(x.receiverUserId)); + } const payloadStr = await PayloadSendNoti(command.id); const profilesSendRequest = new CallAPI() .PostData( From 4bdf1ad7b49f3fa10469e789f323049ecc0212fc Mon Sep 17 00:00:00 2001 From: harid Date: Wed, 26 Nov 2025 16:48:35 +0700 Subject: [PATCH 08/10] =?UTF-8?q?=E0=B9=80=E0=B8=89=E0=B8=9E=E0=B8=B2?= =?UTF-8?q?=E0=B8=B0=E0=B8=84=E0=B8=B3=E0=B8=AA=E0=B8=B1=E0=B9=88=E0=B8=87?= =?UTF-8?q?=20C-PM-10=20=E0=B9=83=E0=B8=AB=E0=B9=89=E0=B8=95=E0=B8=B1?= =?UTF-8?q?=E0=B8=94=20profilesNotiRequest=20=E0=B8=97=E0=B8=B5=E0=B9=88?= =?UTF-8?q?=E0=B8=AA=E0=B9=88=E0=B8=87=20noti=20=E0=B8=84=E0=B8=A3?= =?UTF-8?q?=E0=B8=B1=E0=B9=89=E0=B8=87=E0=B9=81=E0=B8=A3=E0=B8=81=E0=B8=AD?= =?UTF-8?q?=E0=B8=AD=E0=B8=81=20=E0=B9=80=E0=B8=9E=E0=B8=A3=E0=B8=B2?= =?UTF-8?q?=E0=B8=B0=20UI=20=E0=B8=9B=E0=B8=B4=E0=B8=94=20Tab=20=E0=B8=99?= =?UTF-8?q?=E0=B8=B5=E0=B9=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/services/rabbitmq.ts | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/services/rabbitmq.ts b/src/services/rabbitmq.ts index 74df4dc0..0c18117c 100644 --- a/src/services/rabbitmq.ts +++ b/src/services/rabbitmq.ts @@ -445,11 +445,6 @@ async function handler_command_noti(msg: amqp.ConsumeMessage): Promise isSendNotification: true, })) : []; - /*เฉพาะคำสั่ง C-PM-10 ให้ตัด receiverUserId ที่ส่ง noti ครั้งแรกออก*/ - if (command && command.commandType && ["C-PM-10"].includes(command.commandType.code)) { - const firstNotiIds = profiles.map((p:any) => p.receiverUserId); - profilesSend = profilesSend.filter((x:any) => !firstNotiIds.includes(x.receiverUserId)); - } const payloadStr = await PayloadSendNoti(command.id); const profilesSendRequest = new CallAPI() .PostData( @@ -479,7 +474,14 @@ async function handler_command_noti(msg: amqp.ConsumeMessage): Promise console.error("Full error object:", error); }); - await Promise.all([profilesNotiRequest, profilesSendRequest]); + /*เฉพาะคำสั่ง C-PM-10 ให้ตัด profilesNotiRequest ที่ส่ง noti ครั้งแรกออก*/ + if (command && command.commandType && ["C-PM-10"].includes(command.commandType.code)) { + await Promise.all([profilesSendRequest]); + } + else { + await Promise.all([profilesNotiRequest, profilesSendRequest]); + } + console.log("[AMQ] Send Notification Success"); return true; From 072d9a6880d2b49f746412e7a347b48449ba7187 Mon Sep 17 00:00:00 2001 From: harid Date: Thu, 27 Nov 2025 19:28:38 +0700 Subject: [PATCH 09/10] migrate #2043 --- src/controllers/EducationLevelController.ts | 4 ++++ src/entities/EducationLevel.ts | 21 +++++++++++++++++++ ...-update_table_educationLeave_add_fields.ts | 16 ++++++++++++++ 3 files changed, 41 insertions(+) create mode 100644 src/migration/1764244579743-update_table_educationLeave_add_fields.ts diff --git a/src/controllers/EducationLevelController.ts b/src/controllers/EducationLevelController.ts index eecdbda0..f99214a9 100644 --- a/src/controllers/EducationLevelController.ts +++ b/src/controllers/EducationLevelController.ts @@ -132,6 +132,8 @@ export class EducationLevelController extends Controller { "id", "name", "rank", + "educationLevel", + "isHigh", "createdAt", "lastUpdatedAt", "createdFullName", @@ -157,6 +159,8 @@ export class EducationLevelController extends Controller { "id", "name", "rank", + "educationLevel", + "isHigh", "createdAt", "lastUpdatedAt", "createdFullName", diff --git a/src/entities/EducationLevel.ts b/src/entities/EducationLevel.ts index 631c5a9d..cc291e90 100644 --- a/src/entities/EducationLevel.ts +++ b/src/entities/EducationLevel.ts @@ -17,6 +17,21 @@ export class EducationLevel extends EntityBase { default: null, }) rank: number; + + @Column({ + nullable: true, + comment: "ขีดจำกัดวุฒิการศึกษา", + length: 50, + default: null, + }) + educationLevel?: string; + + @Column({ + nullable: true, + comment: "วุฒิการศึกษาสูงสุด", + default: null, + }) + isHigh?: boolean; } export class CreateEducationLevel { @@ -25,6 +40,12 @@ export class CreateEducationLevel { @Column() rank: number; + + @Column() + educationLevel?: string; + + @Column() + isHigh?: boolean; } export type UpdateEducationLevel = Partial; diff --git a/src/migration/1764244579743-update_table_educationLeave_add_fields.ts b/src/migration/1764244579743-update_table_educationLeave_add_fields.ts new file mode 100644 index 00000000..0453ff63 --- /dev/null +++ b/src/migration/1764244579743-update_table_educationLeave_add_fields.ts @@ -0,0 +1,16 @@ +import { MigrationInterface, QueryRunner } from "typeorm"; + +export class UpdateTableEducationLeaveAddFields1764244579743 implements MigrationInterface { + name = 'UpdateTableEducationLeaveAddFields1764244579743' + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`educationLevel\` ADD \`educationLevel\` varchar(50) NULL COMMENT 'ขีดจำกัดวุฒิการศึกษา'`); + await queryRunner.query(`ALTER TABLE \`educationLevel\` ADD \`isHigh\` tinyint NULL COMMENT 'วุฒิการศึกษาสูงสุด'`); + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`educationLevel\` DROP COLUMN \`isHigh\``); + await queryRunner.query(`ALTER TABLE \`educationLevel\` DROP COLUMN \`educationLevel\``); + } + +} From bd9c270cd7de29fad9f41fe0a104d4303eac83a3 Mon Sep 17 00:00:00 2001 From: mamoss <> Date: Sat, 29 Nov 2025 14:56:58 +0700 Subject: [PATCH 10/10] add role parent --- src/controllers/CommandController.ts | 107 ++++++++-------- .../DevelopmentRequestController.ts | 35 +++--- .../OrganizationDotnetController.ts | 10 ++ src/controllers/ProfileController.ts | 73 ++++++----- src/controllers/ProfileEditController.ts | 39 +++--- .../ProfileEditEmployeeController.ts | 30 ++--- src/controllers/ProfileEmployeeController.ts | 58 +++++---- .../ProfileSalaryTempController.ts | 118 +++++++----------- src/interfaces/permission.ts | 2 +- 9 files changed, 231 insertions(+), 241 deletions(-) diff --git a/src/controllers/CommandController.ts b/src/controllers/CommandController.ts index b6b5fc7d..cad8dc18 100644 --- a/src/controllers/CommandController.ts +++ b/src/controllers/CommandController.ts @@ -215,7 +215,7 @@ export class CommandController extends Controller { _data.child1 != undefined && _data.child1 != null ? _data.child1[0] != null ? `current_holders.orgChild1Id IN (:...child1)` - : `current_holders.orgChild1Id is null` + : `current_holders.orgChild1Id is ${_data.privilege == "PARENT" ? "not null" : "null"}` : "1=1", { child1: _data.child1, @@ -1477,7 +1477,7 @@ export class CommandController extends Controller { } // @Get("XXX") async cronjobUpdateRetirementStatus(/*@Request() request: RequestWithUser*/) { - const adminToken = await getToken() ?? ""; + const adminToken = (await getToken()) ?? ""; const today = new Date(); today.setUTCHours(0, 0, 0, 0); let type: string = "OFFICER"; @@ -1672,7 +1672,7 @@ export class CommandController extends Controller { positionIsSelected: false, lastUpdateFullName: "System Administrator", lastUpdatedAt: _Date, - } + }, ); _posMaster.isSit = false; _posMaster.current_holderId = null; @@ -1702,7 +1702,7 @@ export class CommandController extends Controller { positionIsSelected: false, lastUpdateFullName: "System Administrator", lastUpdatedAt: _Date, - } + }, ); _posMaster.isSit = false; _posMaster.next_holderId = null; @@ -1730,7 +1730,7 @@ export class CommandController extends Controller { positionIsSelected: false, lastUpdateFullName: "System Administrator", lastUpdatedAt: _Date, - } + }, ); _posMaster.isSit = false; _posMaster.current_holderId = null; @@ -1977,62 +1977,68 @@ export class CommandController extends Controller { if (commandCode == "C-PM-21") { profileTemp.position = profile?.positionTemp ?? "-"; profileTemp.posLevel = profile?.posLevelNameTemp ?? "-"; - profileTemp.org = (profile?.child4Temp == null ? "" : profile?.child4Temp + "\n") + + profileTemp.org = + (profile?.child4Temp == null ? "" : profile?.child4Temp + "\n") + (profile?.child3Temp == null ? "" : profile?.child3Temp + "\n") + (profile?.child2Temp == null ? "" : profile?.child2Temp + "\n") + (profile?.child1Temp == null ? "" : profile?.child1Temp + "\n") + - (profile?.rootTemp == null ? "" : profile?.rootTemp) + (profile?.rootTemp == null ? "" : profile?.rootTemp); if (profile?.nodeTemp) { switch (profile?.nodeTemp) { case "4": profileTemp.posNo = `${profile.child4ShortNameTemp} ${profile?.posMasterNoTemp}`; - break + break; case "3": - profileTemp.posNo = `${profile.child3ShortNameTemp} ${profile?.posMasterNoTemp}`; - break + profileTemp.posNo = `${profile.child3ShortNameTemp} ${profile?.posMasterNoTemp}`; + break; case "2": profileTemp.posNo = `${profile.child2ShortNameTemp} ${profile?.posMasterNoTemp}`; - break + break; case "1": - profileTemp.posNo = `${profile.child1ShortNameTemp} ${profile?.posMasterNoTemp}`; - break + profileTemp.posNo = `${profile.child1ShortNameTemp} ${profile?.posMasterNoTemp}`; + break; case "0": - profileTemp.posNo = `${profile.rootShortNameTemp} ${profile?.posMasterNoTemp}`; - break - default: break; + profileTemp.posNo = `${profile.rootShortNameTemp} ${profile?.posMasterNoTemp}`; + break; + default: + break; } } } return { no: Extension.ToThaiNumber((idx + 1).toString()), - org: commandCode != "C-PM-21" - ? profile?.isLeave == false - ? (_child4 == null ? "" : _child4 + "\n") + - (_child3 == null ? "" : _child3 + "\n") + - (_child2 == null ? "" : _child2 + "\n") + - (_child1 == null ? "" : _child1 + "\n") + - (_root == null ? "" : _root) - : orgLeave - : profileTemp.org, + org: + commandCode != "C-PM-21" + ? profile?.isLeave == false + ? (_child4 == null ? "" : _child4 + "\n") + + (_child3 == null ? "" : _child3 + "\n") + + (_child2 == null ? "" : _child2 + "\n") + + (_child1 == null ? "" : _child1 + "\n") + + (_root == null ? "" : _root) + : orgLeave + : profileTemp.org, fullName: `${x.prefix}${x.firstName} ${x.lastName}`, citizenId: Extension.ToThaiNumber(x.citizenId), - position: commandCode != "C-PM-21" - ? profile?.position - ? profile?.position - : "-" - : profileTemp.position, - posLevel: commandCode != "C-PM-21" - ? profile?.posType && profile?.posLevel - ? Extension.ToThaiNumber( - `${profile?.posType.posTypeShortName} ${profile?.posLevel.posLevelName}`, - ) - : "-" - : Extension.ToThaiNumber(profileTemp.posLevel), - posNo: commandCode != "C-PM-21" - ? shortName - ? Extension.ToThaiNumber(shortName) - : "-" - : Extension.ToThaiNumber(profileTemp.posNo), + position: + commandCode != "C-PM-21" + ? profile?.position + ? profile?.position + : "-" + : profileTemp.position, + posLevel: + commandCode != "C-PM-21" + ? profile?.posType && profile?.posLevel + ? Extension.ToThaiNumber( + `${profile?.posType.posTypeShortName} ${profile?.posLevel.posLevelName}`, + ) + : "-" + : Extension.ToThaiNumber(profileTemp.posLevel), + posNo: + commandCode != "C-PM-21" + ? shortName + ? Extension.ToThaiNumber(shortName) + : "-" + : Extension.ToThaiNumber(profileTemp.posNo), amount: x.amount ? Extension.ToThaiNumber(x.amount.toLocaleString()) : "-", dateRetire: profile?.dateRetire ? Extension.ToThaiNumber(Extension.ToThaiShortDate_monthYear(profile?.dateRetire)) @@ -4272,18 +4278,17 @@ export class CommandController extends Controller { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลทะเบียนประวัตินี้"); } const posMaster: any = await this.posMasterRepository.findOne({ - where: { + where: { current_holderId: item.profileId, - orgRevision:{ + orgRevision: { orgRevisionIsCurrent: true, orgRevisionIsDraft: false, - } + }, }, - relations:['orgRevision'] + relations: ["orgRevision"], }); - - - const orgRevisionRef = posMaster?posMaster.id: null; + + const orgRevisionRef = posMaster ? posMaster.id : null; //ลบตำแหน่งที่รักษาการแทน const code = _command?.commandType?.code; @@ -4784,7 +4789,7 @@ export class CommandController extends Controller { _profile.leaveDate = item.commandDateAffect ?? _null; _profile.leaveType = exceptClear.LeaveType ?? _null; } else { - if(orgRevisionRef){ + if (orgRevisionRef) { await CreatePosMasterHistoryOfficer(orgRevisionRef.id, req, "DELETE"); } await removeProfileInOrganize(_profile.id, "OFFICER"); @@ -5718,7 +5723,7 @@ export class CommandController extends Controller { posNumCodeSit: _posNumCodeSit, posNumCodeSitAbb: _posNumCodeSitAbb, }); - if(orgRevisionRef){ + if (orgRevisionRef) { await CreatePosMasterHistoryOfficer(orgRevisionRef.id, req, "DELETE"); } await removeProfileInOrganize(profile.id, "OFFICER"); diff --git a/src/controllers/DevelopmentRequestController.ts b/src/controllers/DevelopmentRequestController.ts index 7c646230..16288640 100644 --- a/src/controllers/DevelopmentRequestController.ts +++ b/src/controllers/DevelopmentRequestController.ts @@ -52,7 +52,7 @@ export class DevelopmentRequestController extends Controller { if (!profile) { throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); } - + let query = await AppDataSource.getRepository(DevelopmentRequest) .createQueryBuilder("developmentRequest") .andWhere( @@ -104,16 +104,13 @@ export class DevelopmentRequestController extends Controller { ); }), ) - .orderBy("developmentRequest.createdAt", "DESC") + .orderBy("developmentRequest.createdAt", "DESC"); - if (sortBy) { - query = query.orderBy( - `developmentRequest.${sortBy}`, - descending ? "DESC" : "ASC" - ); - } + if (sortBy) { + query = query.orderBy(`developmentRequest.${sortBy}`, descending ? "DESC" : "ASC"); + } - const [lists, total] = await query + const [lists, total] = await query .skip((page - 1) * pageSize) .take(pageSize) .getManyAndCount(); @@ -166,7 +163,7 @@ export class DevelopmentRequestController extends Controller { data.child1 != undefined && data.child1 != null ? data.child1[0] != null ? `current_holders.orgChild1Id IN (:...child1)` - : `current_holders.orgChild1Id is null` + : `current_holders.orgChild1Id is ${data.privilege == "PARENT" ? "not null" : "null"}` : "1=1", { child1: data.child1, @@ -250,21 +247,17 @@ export class DevelopmentRequestController extends Controller { ); }), ) - .orderBy("developmentRequest.createdAt", "DESC") - + .orderBy("developmentRequest.createdAt", "DESC"); if (sortBy) { - query = query.orderBy( - `developmentRequest.${sortBy}`, - descending ? "DESC" : "ASC" - ); + query = query.orderBy(`developmentRequest.${sortBy}`, descending ? "DESC" : "ASC"); } - const [lists, total] = await query - .skip((page - 1) * pageSize) - .take(pageSize) - .getManyAndCount(); - + const [lists, total] = await query + .skip((page - 1) * pageSize) + .take(pageSize) + .getManyAndCount(); + const _data = lists.map((item) => ({ ...item, profile: null })); return new HttpSuccess({ data: _data, total }); } diff --git a/src/controllers/OrganizationDotnetController.ts b/src/controllers/OrganizationDotnetController.ts index 52acf7f0..52fbd5cd 100644 --- a/src/controllers/OrganizationDotnetController.ts +++ b/src/controllers/OrganizationDotnetController.ts @@ -1211,6 +1211,7 @@ export class OrganizationDotnetController extends Controller { let pos = await this.posMasterRepository.findOne({ relations: ["current_holder"], where: { + current_holder: Not(IsNull()), orgRevision: { orgRevisionIsCurrent: true, orgRevisionIsDraft: false, @@ -1234,6 +1235,7 @@ export class OrganizationDotnetController extends Controller { let pos = await this.posMasterRepository.findOne({ relations: ["current_holder"], where: { + current_holder: Not(IsNull()), orgRevision: { orgRevisionIsCurrent: true, orgRevisionIsDraft: false, @@ -1256,6 +1258,7 @@ export class OrganizationDotnetController extends Controller { let pos = await this.posMasterRepository.findOne({ relations: ["current_holder"], where: { + current_holder: Not(IsNull()), orgRevision: { orgRevisionIsCurrent: true, orgRevisionIsDraft: false, @@ -1278,6 +1281,7 @@ export class OrganizationDotnetController extends Controller { let pos = await this.posMasterRepository.findOne({ relations: ["current_holder"], where: { + current_holder: Not(IsNull()), orgRevision: { orgRevisionIsCurrent: true, orgRevisionIsDraft: false, @@ -1300,6 +1304,7 @@ export class OrganizationDotnetController extends Controller { let pos = await this.posMasterRepository.findOne({ relations: ["current_holder"], where: { + current_holder: Not(IsNull()), orgRevision: { orgRevisionIsCurrent: true, orgRevisionIsDraft: false, @@ -1511,6 +1516,7 @@ export class OrganizationDotnetController extends Controller { let pos = await this.posMasterRepository.findOne({ relations: ["current_holder"], where: { + current_holder: Not(IsNull()), orgRevision: { orgRevisionIsCurrent: true, orgRevisionIsDraft: false, @@ -1534,6 +1540,7 @@ export class OrganizationDotnetController extends Controller { let pos = await this.posMasterRepository.findOne({ relations: ["current_holder"], where: { + current_holder: Not(IsNull()), orgRevision: { orgRevisionIsCurrent: true, orgRevisionIsDraft: false, @@ -1556,6 +1563,7 @@ export class OrganizationDotnetController extends Controller { let pos = await this.posMasterRepository.findOne({ relations: ["current_holder"], where: { + current_holder: Not(IsNull()), orgRevision: { orgRevisionIsCurrent: true, orgRevisionIsDraft: false, @@ -1578,6 +1586,7 @@ export class OrganizationDotnetController extends Controller { let pos = await this.posMasterRepository.findOne({ relations: ["current_holder"], where: { + current_holder: Not(IsNull()), orgRevision: { orgRevisionIsCurrent: true, orgRevisionIsDraft: false, @@ -1600,6 +1609,7 @@ export class OrganizationDotnetController extends Controller { let pos = await this.posMasterRepository.findOne({ relations: ["current_holder"], where: { + current_holder: Not(IsNull()), orgRevision: { orgRevisionIsCurrent: true, orgRevisionIsDraft: false, diff --git a/src/controllers/ProfileController.ts b/src/controllers/ProfileController.ts index 6558f0ee..ac19ffdf 100644 --- a/src/controllers/ProfileController.ts +++ b/src/controllers/ProfileController.ts @@ -2219,7 +2219,7 @@ export class ProfileController extends Controller { _data.child1 != undefined && _data.child1 != null ? _data.child1[0] != null ? `current_holders.orgChild1Id IN (:...child1)` - : `current_holders.orgChild1Id is null` + : `current_holders.orgChild1Id is ${_data.privilege == "PARENT" ? "not null" : "null"}` : "1=1", { child1: _data.child1, @@ -6137,7 +6137,7 @@ export class ProfileController extends Controller { _data.child1 != undefined && _data.child1 != null ? _data.child1[0] != null ? `current_holders.orgChild1Id IN (:...child1)` - : `current_holders.orgChild1Id is null` + : `current_holders.orgChild1Id is ${_data.privilege == "PARENT" ? "not null" : "null"}` : "1=1", { child1: _data.child1 }, ) @@ -6524,7 +6524,7 @@ export class ProfileController extends Controller { _data.child1 != undefined && _data.child1 != null ? _data.child1[0] != null ? `current_holders.orgChild1Id IN (:...child1)` - : `current_holders.orgChild1Id is null` + : `current_holders.orgChild1Id is ${_data.privilege == "PARENT" ? "not null" : "null"}` : "1=1", { child1: _data.child1 }, ) @@ -6632,6 +6632,7 @@ export class ProfileController extends Controller { position: _data.position, posNo: shortName ?? null, rootId: holder?.orgRoot?.id ?? null, + child1Id: holder?.orgChild1Id ?? null, root: holder?.orgRoot?.orgRootName ?? null, rootDnaId: holder?.orgRoot == null ? null : holder?.orgRoot?.ancestorDNA, orgRootShortName: holder?.orgRoot?.orgRootShortName ?? null, @@ -7352,10 +7353,10 @@ export class ProfileController extends Controller { nodeDnaId: null, type: profile.employeeClass, salary: profile.amount, - posNo: null - // root?.orgRootShortName && posMaster?.posMasterNo - // ? `${root?.orgRootShortName} ${posMaster?.posMasterNo}` - // : "", + posNo: null, + // root?.orgRootShortName && posMaster?.posMasterNo + // ? `${root?.orgRootShortName} ${posMaster?.posMasterNo}` + // : "", }; if (_profile.child4Id != null) { _profile.node = 4; @@ -7521,10 +7522,10 @@ export class ProfileController extends Controller { nodeDnaId: null, salary: profile ? profile.amount : null, amountSpecial: profile ? profile.amountSpecial : null, - posNo: null - // root?.orgRootShortName && posMaster?.posMasterNo - // ? `${root?.orgRootShortName} ${posMaster?.posMasterNo}` - // : "", + posNo: null, + // root?.orgRootShortName && posMaster?.posMasterNo + // ? `${root?.orgRootShortName} ${posMaster?.posMasterNo}` + // : "", }; if (_profile.child4Id != null) { @@ -8867,7 +8868,7 @@ export class ProfileController extends Controller { _data.child1 != undefined && _data.child1 != null ? _data.child1[0] != null ? `current_holders.orgChild1Id IN (:...child1)` - : `current_holders.orgChild1Id is null` + : `current_holders.orgChild1Id is ${_data.privilege == "PARENT" ? "not null" : "null"}` : "1=1", { child1: _data.child1 }, ) @@ -9390,7 +9391,7 @@ export class ProfileController extends Controller { _data.child1 != undefined && _data.child1 != null ? _data.child1[0] != null ? `current_holders.orgChild1Id IN (:...child1)` - : `current_holders.orgChild1Id is null` + : `current_holders.orgChild1Id is ${_data.privilege == "PARENT" ? "not null" : "null"}` : "1=1", { child1: _data.child1, @@ -9781,21 +9782,26 @@ export class ProfileController extends Controller { .leftJoinAndSelect("current_holders.positions", "positions") .leftJoinAndSelect("positions.posExecutive", "posExecutive") .andWhere( - new Brackets(qb => { + new Brackets((qb) => { qb.where("profile.position LIKE :keyword", { keyword: `%${body.keyword}%` }) .orWhere("posLevel.posLevelName LIKE :keyword", { keyword: `%${body.keyword}%` }) .orWhere("posType.posTypeName LIKE :keyword", { keyword: `%${body.keyword}%` }) - .orWhere("CONCAT(profile.prefix, profile.firstName, ' ', profile.lastName) LIKE :keyword", { keyword: `%${body.keyword}%` }); - }) + .orWhere( + "CONCAT(profile.prefix, profile.firstName, ' ', profile.lastName) LIKE :keyword", + { keyword: `%${body.keyword}%` }, + ); + }), ) .andWhere("profile.isLeave = false") - .andWhere("current_holders.orgRevisionId = :orgRevisionId", { orgRevisionId: orgRevisionActive.id }); + .andWhere("current_holders.orgRevisionId = :orgRevisionId", { + orgRevisionId: orgRevisionActive.id, + }); - const [findProfile, total] = await query - .orderBy("profile.citizenId", "ASC") - .skip((body.page - 1) * body.pageSize) - .take(body.pageSize) - .getManyAndCount(); + const [findProfile, total] = await query + .orderBy("profile.citizenId", "ASC") + .skip((body.page - 1) * body.pageSize) + .take(body.pageSize) + .getManyAndCount(); const mapDataProfile = await Promise.all( findProfile.map(async (item: Profile) => { @@ -9807,9 +9813,10 @@ export class ProfileController extends Controller { : item.current_holders.find((x) => x.orgRevisionId == orgRevisionActive.id); const position = posMaster == null || - item.current_holders.find((x) => x.orgRevisionId == orgRevisionActive.id)?.positions == null || - item.current_holders?.find((x) => x.orgRevisionId == orgRevisionActive.id)?.positions.length == - 0 || + item.current_holders.find((x) => x.orgRevisionId == orgRevisionActive.id)?.positions == + null || + item.current_holders?.find((x) => x.orgRevisionId == orgRevisionActive.id)?.positions + .length == 0 || item.current_holders .find((x) => x.orgRevisionId == orgRevisionActive.id) ?.positions?.find((position) => position.positionIsSelected == true) == null @@ -9837,18 +9844,20 @@ export class ProfileController extends Controller { item.current_holders.length == 0 ? null : item.current_holders.find((x) => x.orgRevisionId == orgRevisionActive.id) != null && - item.current_holders.find((x) => x.orgRevisionId == orgRevisionActive.id)?.orgChild4 != - null + item.current_holders.find((x) => x.orgRevisionId == orgRevisionActive.id) + ?.orgChild4 != null ? `${item.current_holders.find((x) => x.orgRevisionId == orgRevisionActive.id)?.orgChild4.orgChild4ShortName} ${item.current_holders.find((x) => x.orgRevisionId == orgRevisionActive.id)?.posMasterNo}` : item.current_holders.find((x) => x.orgRevisionId == orgRevisionActive.id) != null && - item.current_holders.find((x) => x.orgRevisionId == orgRevisionActive.id)?.orgChild3 != - null + item.current_holders.find((x) => x.orgRevisionId == orgRevisionActive.id) + ?.orgChild3 != null ? `${item.current_holders.find((x) => x.orgRevisionId == orgRevisionActive.id)?.orgChild3.orgChild3ShortName} ${item.current_holders.find((x) => x.orgRevisionId == orgRevisionActive.id)?.posMasterNo}` - : item.current_holders.find((x) => x.orgRevisionId == orgRevisionActive.id) != null && + : item.current_holders.find((x) => x.orgRevisionId == orgRevisionActive.id) != + null && item.current_holders.find((x) => x.orgRevisionId == orgRevisionActive.id) ?.orgChild2 != null ? `${item.current_holders.find((x) => x.orgRevisionId == orgRevisionActive.id)?.orgChild2.orgChild2ShortName} ${item.current_holders.find((x) => x.orgRevisionId == orgRevisionActive.id)?.posMasterNo}` - : item.current_holders.find((x) => x.orgRevisionId == orgRevisionActive.id) != null && + : item.current_holders.find((x) => x.orgRevisionId == orgRevisionActive.id) != + null && item.current_holders.find((x) => x.orgRevisionId == orgRevisionActive.id) ?.orgChild1 != null ? `${item.current_holders.find((x) => x.orgRevisionId == orgRevisionActive.id)?.orgChild1.orgChild1ShortName} ${item.current_holders.find((x) => x.orgRevisionId == orgRevisionActive.id)?.posMasterNo}` @@ -10775,7 +10784,7 @@ export class ProfileController extends Controller { await this.profileRepo.save(profile, { data: request }); setLogDataDiff(request, { before, after: profile }); if (requestBody.isLeave == true) { - if(orgRevisionRef){ + if (orgRevisionRef) { await CreatePosMasterHistoryOfficer(orgRevisionRef.id, request, "DELETE"); } await removeProfileInOrganize(profile.id, "OFFICER"); diff --git a/src/controllers/ProfileEditController.ts b/src/controllers/ProfileEditController.ts index c7d66ee0..4c4fc6b8 100644 --- a/src/controllers/ProfileEditController.ts +++ b/src/controllers/ProfileEditController.ts @@ -75,19 +75,16 @@ export class ProfileEditController extends Controller { ); }), ) - .orderBy("ProfileEdit.createdAt", "DESC") + .orderBy("ProfileEdit.createdAt", "DESC"); if (sortBy) { - query = query.orderBy( - `ProfileEdit.${sortBy}`, - descending ? "DESC" : "ASC" - ); + query = query.orderBy(`ProfileEdit.${sortBy}`, descending ? "DESC" : "ASC"); } const [getProfileEdit, total] = await query - .skip((page - 1) * pageSize) - .take(pageSize) - .getManyAndCount(); + .skip((page - 1) * pageSize) + .take(pageSize) + .getManyAndCount(); const _data = getProfileEdit.map((item) => ({ id: item.id, @@ -153,7 +150,7 @@ export class ProfileEditController extends Controller { data.child1 != undefined && data.child1 != null ? data.child1[0] != null ? `current_holders.orgChild1Id IN (:...child1)` - : `current_holders.orgChild1Id is null` + : `current_holders.orgChild1Id is ${data.privilege == "PARENT" ? "not null" : "null"}` : "1=1", { child1: data.child1, @@ -216,26 +213,20 @@ export class ProfileEditController extends Controller { ); }), ) - .orderBy("ProfileEdit.createdAt", "DESC") - + .orderBy("ProfileEdit.createdAt", "DESC"); + if (sortBy) { - if(sortBy == "fullname"){ - query = query.orderBy( - `profile.firstName`, - descending ? "DESC" : "ASC" - ); - }else{ - query = query.orderBy( - `ProfileEdit.${sortBy}`, - descending ? "DESC" : "ASC" - ); + if (sortBy == "fullname") { + query = query.orderBy(`profile.firstName`, descending ? "DESC" : "ASC"); + } else { + query = query.orderBy(`ProfileEdit.${sortBy}`, descending ? "DESC" : "ASC"); } } const [getProfileEdit, total] = await query - .skip((page - 1) * pageSize) - .take(pageSize) - .getManyAndCount(); + .skip((page - 1) * pageSize) + .take(pageSize) + .getManyAndCount(); const _data = getProfileEdit.map((item) => ({ id: item.id, diff --git a/src/controllers/ProfileEditEmployeeController.ts b/src/controllers/ProfileEditEmployeeController.ts index 75fa1672..8abc6d8b 100644 --- a/src/controllers/ProfileEditEmployeeController.ts +++ b/src/controllers/ProfileEditEmployeeController.ts @@ -119,7 +119,7 @@ export class ProfileEditEmployeeController extends Controller { .where("orgRevision.orgRevisionIsDraft = false") .andWhere("orgRevision.orgRevisionIsCurrent = true") .getOne(); - + let query = await AppDataSource.getRepository(ProfileEdit) .createQueryBuilder("ProfileEdit") .leftJoinAndSelect("ProfileEdit.profileEmployee", "profileEmployee") @@ -148,7 +148,7 @@ export class ProfileEditEmployeeController extends Controller { data.child1 != undefined && data.child1 != null ? data.child1[0] != null ? `current_holders.orgChild1Id IN (:...child1)` - : `current_holders.orgChild1Id is null` + : `current_holders.orgChild1Id is ${data.privilege == "PARENT" ? "not null" : "null"}` : "1=1", { child1: data.child1, @@ -211,26 +211,20 @@ export class ProfileEditEmployeeController extends Controller { ); }), ) - .orderBy("ProfileEdit.createdAt", "DESC") - + .orderBy("ProfileEdit.createdAt", "DESC"); + if (sortBy) { - if(sortBy == "fullname"){ - query = query.orderBy( - `profileEmployee.firstName`, - descending ? "DESC" : "ASC" - ); - }else{ - query = query.orderBy( - `ProfileEdit.${sortBy}`, - descending ? "DESC" : "ASC" - ); + if (sortBy == "fullname") { + query = query.orderBy(`profileEmployee.firstName`, descending ? "DESC" : "ASC"); + } else { + query = query.orderBy(`ProfileEdit.${sortBy}`, descending ? "DESC" : "ASC"); } } - + let [getProfileEdit, total] = await query - .skip((page - 1) * pageSize) - .take(pageSize) - .getManyAndCount(); + .skip((page - 1) * pageSize) + .take(pageSize) + .getManyAndCount(); const _data = getProfileEdit.map((item) => ({ id: item.id, diff --git a/src/controllers/ProfileEmployeeController.ts b/src/controllers/ProfileEmployeeController.ts index ac5523bb..f72df407 100644 --- a/src/controllers/ProfileEmployeeController.ts +++ b/src/controllers/ProfileEmployeeController.ts @@ -2034,12 +2034,15 @@ export class ProfileEmployeeController extends Controller { if (!result) { throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); } - try{ + try { await new permission().PermissionOrgUserDelete(request, "SYS_REGISTRY_EMP", result.id); await this.informationHistoryRepository.delete({ profileEmployeeId: id }); await this.profileRepo.remove(result); } catch { - throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่สามารถลบข้อมูลได้ เนื่องจากข้อมูลนี้ถูกใช้งานในระบบอื่น"); + throw new HttpError( + HttpStatusCode.NOT_FOUND, + "ไม่สามารถลบข้อมูลได้ เนื่องจากข้อมูลนี้ถูกใช้งานในระบบอื่น", + ); } return new HttpSuccess(); } @@ -2837,7 +2840,7 @@ export class ProfileEmployeeController extends Controller { _data.child1 != undefined && _data.child1 != null ? _data.child1[0] != null ? `current_holders.orgChild1Id IN (:...child1)` - : `current_holders.orgChild1Id is null` + : `current_holders.orgChild1Id is ${_data.privilege == "PARENT" ? "not null" : "null"}` : "1=1", { child1: _data.child1, @@ -3582,10 +3585,10 @@ export class ProfileEmployeeController extends Controller { nodeDnaId: null, salary: profile ? profile.amount : null, amountSpecial: profile ? profile.amountSpecial : null, - posNo: null - // root?.orgRootShortName && posMaster?.posMasterNo - // ? `${root?.orgRootShortName} ${posMaster?.posMasterNo}` - // : "", + posNo: null, + // root?.orgRootShortName && posMaster?.posMasterNo + // ? `${root?.orgRootShortName} ${posMaster?.posMasterNo}` + // : "", }; if (_profile.child4Id != null) { _profile.node = 4; @@ -3716,7 +3719,7 @@ export class ProfileEmployeeController extends Controller { _data.child1 != undefined && _data.child1 != null ? _data.child1[0] != null ? `current_holders.orgChild1Id IN (:...child1)` - : `current_holders.orgChild1Id is null` + : `current_holders.orgChild1Id is ${_data.privilege == "PARENT" ? "not null" : "null"}` : "1=1", { child1: _data.child1 }, ) @@ -4274,7 +4277,7 @@ export class ProfileEmployeeController extends Controller { _data.child1 != undefined && _data.child1 != null ? _data.child1[0] != null ? `current_holders.orgChild1Id IN (:...child1)` - : `current_holders.orgChild1Id is null` + : `current_holders.orgChild1Id is ${_data.privilege == "PARENT" ? "not null" : "null"}` : "1=1", { child1: _data.child1, @@ -4435,22 +4438,26 @@ export class ProfileEmployeeController extends Controller { .leftJoinAndSelect("current_holders.orgChild4", "orgChild4") .leftJoinAndSelect("current_holders.positions", "positions") .andWhere( - new Brackets(qb => { + new Brackets((qb) => { qb.where("profileEmployee.position LIKE :keyword", { keyword: `%${body.keyword}%` }) .orWhere("posLevel.posLevelName LIKE :keyword", { keyword: `%${body.keyword}%` }) .orWhere("posType.posTypeName LIKE :keyword", { keyword: `%${body.keyword}%` }) - .orWhere("CONCAT(profileEmployee.prefix, profileEmployee.firstName, ' ', profileEmployee.lastName) LIKE :keyword", { keyword: `%${body.keyword}%` }); - }) + .orWhere( + "CONCAT(profileEmployee.prefix, profileEmployee.firstName, ' ', profileEmployee.lastName) LIKE :keyword", + { keyword: `%${body.keyword}%` }, + ); + }), ) .andWhere("profileEmployee.isLeave = false") - .andWhere("current_holders.orgRevisionId = :orgRevisionId", { orgRevisionId: orgRevisionActive.id }); + .andWhere("current_holders.orgRevisionId = :orgRevisionId", { + orgRevisionId: orgRevisionActive.id, + }); if (body.type) { const typeUpper = body.type.trim().toUpperCase(); if (typeUpper === "EMPLOYEE") { query = query.andWhere("profileEmployee.employeeClass = 'PERM'"); - } - else if (typeUpper === "TEMP"){ + } else if (typeUpper === "TEMP") { query = query.andWhere("profileEmployee.employeeClass = 'TEMP'"); } } @@ -4471,9 +4478,10 @@ export class ProfileEmployeeController extends Controller { : item.current_holders.find((x) => x.orgRevisionId == orgRevisionActive.id); const position = posMaster == null || - item.current_holders.find((x) => x.orgRevisionId == orgRevisionActive.id)?.positions == null || - item.current_holders?.find((x) => x.orgRevisionId == orgRevisionActive.id)?.positions.length == - 0 || + item.current_holders.find((x) => x.orgRevisionId == orgRevisionActive.id)?.positions == + null || + item.current_holders?.find((x) => x.orgRevisionId == orgRevisionActive.id)?.positions + .length == 0 || item.current_holders .find((x) => x.orgRevisionId == orgRevisionActive.id) ?.positions?.find((position) => position.positionIsSelected == true) == null @@ -4486,18 +4494,20 @@ export class ProfileEmployeeController extends Controller { item.current_holders.length == 0 ? null : item.current_holders.find((x) => x.orgRevisionId == orgRevisionActive.id) != null && - item.current_holders.find((x) => x.orgRevisionId == orgRevisionActive.id)?.orgChild4 != - null + item.current_holders.find((x) => x.orgRevisionId == orgRevisionActive.id) + ?.orgChild4 != null ? `${item.current_holders.find((x) => x.orgRevisionId == orgRevisionActive.id)?.orgChild4.orgChild4ShortName} ${item.current_holders.find((x) => x.orgRevisionId == orgRevisionActive.id)?.posMasterNo}` : item.current_holders.find((x) => x.orgRevisionId == orgRevisionActive.id) != null && - item.current_holders.find((x) => x.orgRevisionId == orgRevisionActive.id)?.orgChild3 != - null + item.current_holders.find((x) => x.orgRevisionId == orgRevisionActive.id) + ?.orgChild3 != null ? `${item.current_holders.find((x) => x.orgRevisionId == orgRevisionActive.id)?.orgChild3.orgChild3ShortName} ${item.current_holders.find((x) => x.orgRevisionId == orgRevisionActive.id)?.posMasterNo}` - : item.current_holders.find((x) => x.orgRevisionId == orgRevisionActive.id) != null && + : item.current_holders.find((x) => x.orgRevisionId == orgRevisionActive.id) != + null && item.current_holders.find((x) => x.orgRevisionId == orgRevisionActive.id) ?.orgChild2 != null ? `${item.current_holders.find((x) => x.orgRevisionId == orgRevisionActive.id)?.orgChild2.orgChild2ShortName} ${item.current_holders.find((x) => x.orgRevisionId == orgRevisionActive.id)?.posMasterNo}` - : item.current_holders.find((x) => x.orgRevisionId == orgRevisionActive.id) != null && + : item.current_holders.find((x) => x.orgRevisionId == orgRevisionActive.id) != + null && item.current_holders.find((x) => x.orgRevisionId == orgRevisionActive.id) ?.orgChild1 != null ? `${item.current_holders.find((x) => x.orgRevisionId == orgRevisionActive.id)?.orgChild1.orgChild1ShortName} ${item.current_holders.find((x) => x.orgRevisionId == orgRevisionActive.id)?.posMasterNo}` diff --git a/src/controllers/ProfileSalaryTempController.ts b/src/controllers/ProfileSalaryTempController.ts index 5da8860e..8b49622a 100644 --- a/src/controllers/ProfileSalaryTempController.ts +++ b/src/controllers/ProfileSalaryTempController.ts @@ -120,7 +120,7 @@ export class ProfileSalaryTempController extends Controller { _data.child1 != undefined && _data.child1 != null ? _data.child1[0] != null ? `current_holders.orgChild1Id IN (:...child1)` - : `current_holders.orgChild1Id is null` + : `current_holders.orgChild1Id is ${_data.privilege == "PARENT" ? "not null" : "null"}` : "1=1", { child1: _data.child1, @@ -322,52 +322,42 @@ export class ProfileSalaryTempController extends Controller { .andWhere("current_holders.orgRootId = :rootId", { rootId: rootId, }) - .addSelect("CASE WHEN current_holders.posMasterNo IS NULL THEN 1 ELSE 0 END", "sort_order") - // .orderBy(`${sortBy}`, sort) + .addSelect("CASE WHEN current_holders.posMasterNo IS NULL THEN 1 ELSE 0 END", "sort_order"); + // .orderBy(`${sortBy}`, sort) if (sortBy) { - if(sortBy == "posLevel"){ - query = query.orderBy( - `posLevel.posLevelName`, - descending ? "DESC" : "ASC" - ); - }else if(sortBy == "posType"){ - query = query.orderBy( - `posType.posTypeName`, - descending ? "DESC" : "ASC" - ); - }else if(sortBy == "posExecutive"){ - query = query.orderBy( - `posExecutive.posExecutiveName`, - descending ? "DESC" : "ASC" - ); - }else if(sortBy == "posNo"){ - query = query.orderBy("orgChild4.orgChild4ShortName",descending ? "DESC" : "ASC") - .addOrderBy("orgChild3.orgChild3ShortName",descending ? "DESC" : "ASC") - .addOrderBy("orgChild2.orgChild2ShortName",descending ? "DESC" : "ASC") - .addOrderBy("orgChild1.orgChild1ShortName",descending ? "DESC" : "ASC") - .addOrderBy("orgRoot.orgRootShortName",descending ? "DESC" : "ASC") - .addOrderBy("current_holders.posMasterNo",descending ? "DESC" : "ASC") - }else{ - query = query.orderBy( - `profile.${sortBy}`, - descending ? "DESC" : "ASC" - ); + if (sortBy == "posLevel") { + query = query.orderBy(`posLevel.posLevelName`, descending ? "DESC" : "ASC"); + } else if (sortBy == "posType") { + query = query.orderBy(`posType.posTypeName`, descending ? "DESC" : "ASC"); + } else if (sortBy == "posExecutive") { + query = query.orderBy(`posExecutive.posExecutiveName`, descending ? "DESC" : "ASC"); + } else if (sortBy == "posNo") { + query = query + .orderBy("orgChild4.orgChild4ShortName", descending ? "DESC" : "ASC") + .addOrderBy("orgChild3.orgChild3ShortName", descending ? "DESC" : "ASC") + .addOrderBy("orgChild2.orgChild2ShortName", descending ? "DESC" : "ASC") + .addOrderBy("orgChild1.orgChild1ShortName", descending ? "DESC" : "ASC") + .addOrderBy("orgRoot.orgRootShortName", descending ? "DESC" : "ASC") + .addOrderBy("current_holders.posMasterNo", descending ? "DESC" : "ASC"); + } else { + query = query.orderBy(`profile.${sortBy}`, descending ? "DESC" : "ASC"); } - }else{ - query = query.orderBy("sort_order", "ASC") - .addOrderBy("orgRoot.orgRootOrder", "ASC") - .addOrderBy("orgChild1.orgChild1Order", "ASC") - .addOrderBy("orgChild2.orgChild2Order", "ASC") - .addOrderBy("orgChild3.orgChild3Order", "ASC") - .addOrderBy("orgChild4.orgChild4Order", "ASC") - .addOrderBy("current_holders.posMasterNo", "ASC") + } else { + query = query + .orderBy("sort_order", "ASC") + .addOrderBy("orgRoot.orgRootOrder", "ASC") + .addOrderBy("orgChild1.orgChild1Order", "ASC") + .addOrderBy("orgChild2.orgChild2Order", "ASC") + .addOrderBy("orgChild3.orgChild3Order", "ASC") + .addOrderBy("orgChild4.orgChild4Order", "ASC") + .addOrderBy("current_holders.posMasterNo", "ASC"); } const [record, total] = await query - .skip((page - 1) * pageSize) - .take(pageSize) - .getManyAndCount(); + .skip((page - 1) * pageSize) + .take(pageSize) + .getManyAndCount(); const data = await Promise.all( record.map((_data) => { @@ -541,7 +531,7 @@ export class ProfileSalaryTempController extends Controller { _data.child1 != undefined && _data.child1 != null ? _data.child1[0] != null ? `current_holders.orgChild1Id IN (:...child1)` - : `current_holders.orgChild1Id is null` + : `current_holders.orgChild1Id is ${_data.privilege == "PARENT" ? "not null" : "null"}` : "1=1", { child1: _data.child1, @@ -755,36 +745,24 @@ export class ProfileSalaryTempController extends Controller { .andWhere("current_holders.orgRootId = :rootId", { rootId: rootId, }) - .orderBy("current_holders.posMasterNo", "ASC") - // .orderBy(`${sortBy}`, sort) + .orderBy("current_holders.posMasterNo", "ASC"); + // .orderBy(`${sortBy}`, sort) - if (sortBy) { - if(sortBy == "posLevel"){ - query = query.orderBy( - `posLevel.posLevelName`, - descending ? "DESC" : "ASC" - ); - }else if(sortBy == "posType"){ - query = query.orderBy( - `posType.posTypeName`, - descending ? "DESC" : "ASC" - ); - }else if(sortBy == "posNo"){ - query = query.orderBy( - `orgRoot.orgRootShortName`, - descending ? "DESC" : "ASC" - ); - }else{ - query = query.orderBy( - `profileEmployee.${sortBy}`, - descending ? "DESC" : "ASC" - ); + if (sortBy) { + if (sortBy == "posLevel") { + query = query.orderBy(`posLevel.posLevelName`, descending ? "DESC" : "ASC"); + } else if (sortBy == "posType") { + query = query.orderBy(`posType.posTypeName`, descending ? "DESC" : "ASC"); + } else if (sortBy == "posNo") { + query = query.orderBy(`orgRoot.orgRootShortName`, descending ? "DESC" : "ASC"); + } else { + query = query.orderBy(`profileEmployee.${sortBy}`, descending ? "DESC" : "ASC"); } } const [record, total] = await query - .skip((page - 1) * pageSize) - .take(pageSize) - .getManyAndCount(); + .skip((page - 1) * pageSize) + .take(pageSize) + .getManyAndCount(); const data = await Promise.all( record.map((_data) => { @@ -1192,7 +1170,7 @@ export class ProfileSalaryTempController extends Controller { order: { order: "DESC" }, }); if (salary) { - dest_item = salary.order+1; + dest_item = salary.order + 1; } // const profile = await this.profileRepo.findOneBy({ id: body.profileId }); // if (!profile) { @@ -1210,7 +1188,7 @@ export class ProfileSalaryTempController extends Controller { order: { order: "DESC" }, }); if (salary) { - dest_item = salary.order+1; + dest_item = salary.order + 1; } // const profile = await this.profileEmployeeRepo.findOneBy({ id: body.profileId }); // if (!profile) { diff --git a/src/interfaces/permission.ts b/src/interfaces/permission.ts index 1819b647..b48478dc 100644 --- a/src/interfaces/permission.ts +++ b/src/interfaces/permission.ts @@ -97,7 +97,7 @@ class CheckAuth { } else if (privilege == "PARENT") { data = { root: [x.orgRootId], - child1: null, + child1: [null], child2: null, child3: null, child4: null,