From 02f19d66ad75a20b073be74f2a54bc48adc2c380 Mon Sep 17 00:00:00 2001 From: Bright Date: Mon, 22 Sep 2025 12:05:45 +0700 Subject: [PATCH 01/17] =?UTF-8?q?=E0=B8=9A=E0=B8=B1=E0=B8=8D=E0=B8=8A?= =?UTF-8?q?=E0=B8=B5=202=20=E0=B9=81=E0=B8=9A=E0=B8=9A=E0=B8=A3=E0=B9=88?= =?UTF-8?q?=E0=B8=B2=E0=B8=87=20=E0=B8=82=E0=B9=89=E0=B8=AD=E0=B8=A1?= =?UTF-8?q?=E0=B8=B9=E0=B8=A5=E0=B9=81=E0=B8=AA=E0=B8=94=E0=B8=87=E0=B9=84?= =?UTF-8?q?=E0=B8=A1=E0=B9=88=E0=B8=84=E0=B8=A3=E0=B8=9A=20#164?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/ReportController.ts | 109 ++++++++++++++++++++-------- 1 file changed, 80 insertions(+), 29 deletions(-) diff --git a/src/controllers/ReportController.ts b/src/controllers/ReportController.ts index 811a2c8b..ac0b0cbb 100644 --- a/src/controllers/ReportController.ts +++ b/src/controllers/ReportController.ts @@ -4592,11 +4592,11 @@ export class ReportController extends Controller { (x: any) => x.orgRevisionId == orgRevisionActive.id && x.ancestorDNA == posMaster.ancestorDNA, ); - if (positionMasterOld && positionMasterOld.positions) { - profilePositionName = [ - ...new Set(positionMasterOld.positions.map((x: any) => x.positionName)), - ]; - } + // if (positionMasterOld && positionMasterOld.positions) { + // profilePositionName = [ + // ...new Set(positionMasterOld.positions.map((x: any) => x.positionName)), + // ]; + // } if (positionMasterOld && positionMasterOld.positions) { profilePositionName = [ ...new Set(positionMasterOld.positions.map((x: any) => x.positionName)), @@ -4684,6 +4684,11 @@ export class ReportController extends Controller { } } } + if (positionMasterProfileOld == null && posMaster.next_holder != null + && posMaster.next_holder.current_holders == null + ) { + positionMasterProfileOld = positionMasterOld + } let node = { posMasterOrder: posMaster.posMasterOrder, // isSit: posMaster.isSit, // @@ -4783,17 +4788,23 @@ export class ReportController extends Controller { ? positionMasterOld == null ? posType.join(" หรือ ") : profilePosType.join(" หรือ ") - : posMaster.next_holder.posType == null + : positionMasterProfileOld == null ? "-" - : posMaster.next_holder.posType.posTypeName, + // : posMaster.next_holder.posType.posTypeName, + : positionMasterProfileOld.positions.find( + (x: any) => x.positionIsSelected == true, + )?.posType?.posTypeName, profilePosLevel: posMaster.next_holder == null ? positionMasterOld == null ? posLevel.join(" หรือ ") : profilePosLevel.join(" หรือ ") - : posMaster.next_holder.posLevel == null + : positionMasterProfileOld == null ? "-" - : posMaster.next_holder.posLevel.posLevelName, + // : posMaster.next_holder.posLevel.posLevelName, + : positionMasterProfileOld.positions.find( + (x: any) => x.positionIsSelected == true, + )?.posLevel?.posLevelName, profilePosExecutive: posMaster.next_holder == null ? positionMasterOld == null @@ -5087,7 +5098,11 @@ export class ReportController extends Controller { } } } - + if (positionMasterProfileOld == null && posMaster.next_holder != null + && posMaster.next_holder.current_holders == null + ) { + positionMasterProfileOld = positionMasterOld + } let node = { posMasterOrder: posMaster.posMasterOrder, // isSit: posMaster.isSit, // @@ -5188,17 +5203,23 @@ export class ReportController extends Controller { ? positionMasterOld == null ? posType.join(" หรือ ") : profilePosType.join(" หรือ ") - : posMaster.next_holder.posType == null + : positionMasterProfileOld == null ? "-" - : posMaster.next_holder.posType.posTypeName, + // : posMaster.next_holder.posType.posTypeName, + : positionMasterProfileOld.positions.find( + (x: any) => x.positionIsSelected == true, + )?.posType?.posTypeName, profilePosLevel: posMaster.next_holder == null ? positionMasterOld == null ? posLevel.join(" หรือ ") : profilePosLevel.join(" หรือ ") - : posMaster.next_holder.posLevel == null + : positionMasterProfileOld == null ? "-" - : posMaster.next_holder.posLevel.posLevelName, + // : posMaster.next_holder.posLevel.posLevelName, + : positionMasterProfileOld.positions.find( + (x: any) => x.positionIsSelected == true, + )?.posLevel?.posLevelName, profilePosExecutive: posMaster.next_holder == null ? positionMasterOld == null @@ -5499,7 +5520,11 @@ export class ReportController extends Controller { } } } - + if (positionMasterProfileOld == null && posMaster.next_holder != null + && posMaster.next_holder.current_holders == null + ) { + positionMasterProfileOld = positionMasterOld + } let node = { posMasterOrder: posMaster.posMasterOrder, // isSit: posMaster.isSit, // @@ -5600,17 +5625,23 @@ export class ReportController extends Controller { ? positionMasterOld == null ? posType.join(" หรือ ") : profilePosType.join(" หรือ ") - : posMaster.next_holder.posType == null + : positionMasterProfileOld == null ? "-" - : posMaster.next_holder.posType.posTypeName, + // : posMaster.next_holder.posType.posTypeName, + : positionMasterProfileOld.positions.find( + (x: any) => x.positionIsSelected == true, + )?.posType?.posTypeName, profilePosLevel: posMaster.next_holder == null ? positionMasterOld == null ? posLevel.join(" หรือ ") : profilePosLevel.join(" หรือ ") - : posMaster.next_holder.posLevel == null + : positionMasterProfileOld == null ? "-" - : posMaster.next_holder.posLevel.posLevelName, + // : posMaster.next_holder.posLevel.posLevelName, + : positionMasterProfileOld.positions.find( + (x: any) => x.positionIsSelected == true, + )?.posLevel?.posLevelName, profilePosExecutive: posMaster.next_holder == null ? positionMasterOld == null @@ -5912,7 +5943,11 @@ export class ReportController extends Controller { } } } - + if (positionMasterProfileOld == null && posMaster.next_holder != null + && posMaster.next_holder.current_holders == null + ) { + positionMasterProfileOld = positionMasterOld + } let node = { posMasterOrder: posMaster.posMasterOrder, // isSit: posMaster.isSit, // @@ -6013,17 +6048,23 @@ export class ReportController extends Controller { ? positionMasterOld == null ? posType.join(" หรือ ") : profilePosType.join(" หรือ ") - : posMaster.next_holder.posType == null + : positionMasterProfileOld == null ? "-" - : posMaster.next_holder.posType.posTypeName, + // : posMaster.next_holder.posType.posTypeName, + : positionMasterProfileOld.positions.find( + (x: any) => x.positionIsSelected == true, + )?.posType?.posTypeName, profilePosLevel: posMaster.next_holder == null ? positionMasterOld == null ? posLevel.join(" หรือ ") : profilePosLevel.join(" หรือ ") - : posMaster.next_holder.posLevel == null + : positionMasterProfileOld == null ? "-" - : posMaster.next_holder.posLevel.posLevelName, + // : posMaster.next_holder.posLevel.posLevelName, + : positionMasterProfileOld.positions.find( + (x: any) => x.positionIsSelected == true, + )?.posLevel?.posLevelName, profilePosExecutive: posMaster.next_holder == null ? positionMasterOld == null @@ -6332,7 +6373,11 @@ export class ReportController extends Controller { } } } - + if (positionMasterProfileOld == null && posMaster.next_holder != null + && posMaster.next_holder.current_holders == null + ) { + positionMasterProfileOld = positionMasterOld + } let node = { posMasterOrder: posMaster.posMasterOrder, // isSit: posMaster.isSit, // @@ -6433,17 +6478,23 @@ export class ReportController extends Controller { ? positionMasterOld == null ? posType.join(" หรือ ") : profilePosType.join(" หรือ ") - : posMaster.next_holder.posType == null + : positionMasterProfileOld == null ? "-" - : posMaster.next_holder.posType.posTypeName, + // : posMaster.next_holder.posType.posTypeName, + : positionMasterProfileOld.positions.find( + (x: any) => x.positionIsSelected == true, + )?.posType?.posTypeName, profilePosLevel: posMaster.next_holder == null ? positionMasterOld == null ? posLevel.join(" หรือ ") : profilePosLevel.join(" หรือ ") - : posMaster.next_holder.posLevel == null + : positionMasterProfileOld == null ? "-" - : posMaster.next_holder.posLevel.posLevelName, + // : posMaster.next_holder.posLevel.posLevelName, + : positionMasterProfileOld.positions.find( + (x: any) => x.positionIsSelected == true, + )?.posLevel?.posLevelName, profilePosExecutive: posMaster.next_holder == null ? positionMasterOld == null From 57c9a84c40a1a0c6c5e90c85da89ff409a03a08f Mon Sep 17 00:00:00 2001 From: Bright Date: Mon, 22 Sep 2025 15:59:21 +0700 Subject: [PATCH 02/17] no message --- src/controllers/ReportController.ts | 55 +++++++++++++++++++++-------- 1 file changed, 40 insertions(+), 15 deletions(-) diff --git a/src/controllers/ReportController.ts b/src/controllers/ReportController.ts index ac0b0cbb..d98800b0 100644 --- a/src/controllers/ReportController.ts +++ b/src/controllers/ReportController.ts @@ -4592,11 +4592,6 @@ export class ReportController extends Controller { (x: any) => x.orgRevisionId == orgRevisionActive.id && x.ancestorDNA == posMaster.ancestorDNA, ); - // if (positionMasterOld && positionMasterOld.positions) { - // profilePositionName = [ - // ...new Set(positionMasterOld.positions.map((x: any) => x.positionName)), - // ]; - // } if (positionMasterOld && positionMasterOld.positions) { profilePositionName = [ ...new Set(positionMasterOld.positions.map((x: any) => x.positionName)), @@ -4822,12 +4817,18 @@ export class ReportController extends Controller { if (_node == null) { const head = { posMasterNo: Extension.ToThaiNumber(node.orgTreeShortName.toString()), - profileFullname: Extension.ToThaiNumber(node.profileOrgName.toString()), + profileFullname: + posMaster.next_holder == null + ? Extension.ToThaiNumber(node.profileOrgName.toString()) + : Extension.ToThaiNumber(node.orgTreeName.toString()), posExecutive: Extension.ToThaiNumber(node.orgTreeName.toString()), positionName: "", posType: "", posLevel: "", - profilePosMasterNo: Extension.ToThaiNumber(node.profileOrgShortName.toString()), + profilePosMasterNo: + posMaster.next_holder == null + ? Extension.ToThaiNumber(node.profileOrgShortName.toString()) + : Extension.ToThaiNumber(node.orgTreeShortName.toString()), profilePosExecutive: "", profilePositionName: "", profilePosType: "", @@ -5237,12 +5238,18 @@ export class ReportController extends Controller { if (_node == null) { const head = { posMasterNo: Extension.ToThaiNumber(node.orgTreeShortName.toString()), - profileFullname: Extension.ToThaiNumber(node.profileOrgName.toString()), + profileFullname: + posMaster.next_holder == null + ? Extension.ToThaiNumber(node.profileOrgName.toString()) + : Extension.ToThaiNumber(node.orgTreeName.toString()), posExecutive: Extension.ToThaiNumber(node.orgTreeName.toString()), positionName: "", posType: "", posLevel: "", - profilePosMasterNo: Extension.ToThaiNumber(node.profileOrgShortName.toString()), + profilePosMasterNo: + posMaster.next_holder == null + ? Extension.ToThaiNumber(node.profileOrgShortName.toString()) + : Extension.ToThaiNumber(node.orgTreeShortName.toString()), profilePosExecutive: "", profilePositionName: "", profilePosType: "", @@ -5659,12 +5666,18 @@ export class ReportController extends Controller { if (_node == null) { const head = { posMasterNo: Extension.ToThaiNumber(node.orgTreeShortName.toString()), - profileFullname: Extension.ToThaiNumber(node.profileOrgName.toString()), + profileFullname: + posMaster.next_holder == null + ? Extension.ToThaiNumber(node.profileOrgName.toString()) + : Extension.ToThaiNumber(node.orgTreeName.toString()), posExecutive: Extension.ToThaiNumber(node.orgTreeName.toString()), positionName: "", posType: "", posLevel: "", - profilePosMasterNo: Extension.ToThaiNumber(node.profileOrgShortName.toString()), + profilePosMasterNo: + posMaster.next_holder == null + ? Extension.ToThaiNumber(node.profileOrgShortName.toString()) + : Extension.ToThaiNumber(node.orgTreeShortName.toString()), profilePosExecutive: "", profilePositionName: "", profilePosType: "", @@ -6082,12 +6095,18 @@ export class ReportController extends Controller { if (_node == null) { const head = { posMasterNo: Extension.ToThaiNumber(node.orgTreeShortName.toString()), - profileFullname: Extension.ToThaiNumber(node.profileOrgName.toString()), + profileFullname: + posMaster.next_holder == null + ? Extension.ToThaiNumber(node.profileOrgName.toString()) + : Extension.ToThaiNumber(node.orgTreeName.toString()), posExecutive: Extension.ToThaiNumber(node.orgTreeName.toString()), positionName: "", posType: "", posLevel: "", - profilePosMasterNo: Extension.ToThaiNumber(node.profileOrgShortName.toString()), + profilePosMasterNo: + posMaster.next_holder == null + ? Extension.ToThaiNumber(node.profileOrgShortName.toString()) + : Extension.ToThaiNumber(node.orgTreeShortName.toString()), profilePosExecutive: "", profilePositionName: "", profilePosType: "", @@ -6512,12 +6531,18 @@ export class ReportController extends Controller { if (_node == null) { const head = { posMasterNo: Extension.ToThaiNumber(node.orgTreeShortName.toString()), - profileFullname: Extension.ToThaiNumber(node.profileOrgName.toString()), + profileFullname: + posMaster.next_holder == null + ? Extension.ToThaiNumber(node.profileOrgName.toString()) + : Extension.ToThaiNumber(node.orgTreeName.toString()), posExecutive: Extension.ToThaiNumber(node.orgTreeName.toString()), positionName: "", posType: "", posLevel: "", - profilePosMasterNo: Extension.ToThaiNumber(node.profileOrgShortName.toString()), + profilePosMasterNo: + posMaster.next_holder == null + ? Extension.ToThaiNumber(node.profileOrgShortName.toString()) + : Extension.ToThaiNumber(node.orgTreeShortName.toString()), profilePosExecutive: "", profilePositionName: "", profilePosType: "", From d999241536a7f3dda5033d965a3bc482f6826294 Mon Sep 17 00:00:00 2001 From: adisak Date: Tue, 23 Sep 2025 11:54:17 +0700 Subject: [PATCH 03/17] sort admin --- .../DevelopmentRequestController.ts | 21 +++++++++++--- .../ProfileDevelopmentController.ts | 14 ++++++++- src/controllers/ProfileEditController.ts | 29 +++++++++++++++---- 3 files changed, 54 insertions(+), 10 deletions(-) diff --git a/src/controllers/DevelopmentRequestController.ts b/src/controllers/DevelopmentRequestController.ts index 752ae293..7c646230 100644 --- a/src/controllers/DevelopmentRequestController.ts +++ b/src/controllers/DevelopmentRequestController.ts @@ -127,6 +127,8 @@ export class DevelopmentRequestController extends Controller { @Query("keyword") keyword: string = "", @Query("page") page: number = 1, @Query("pageSize") pageSize: number = 10, + @Query("sortBy") sortBy?: string, + @Query("descending") descending?: boolean, ) { let data = await new permission().PermissionOrgList(request, "SYS_REGISTRY_OFFICER"); const orgRevisionPublish = await this.orgRevisionRepository @@ -134,7 +136,7 @@ export class DevelopmentRequestController extends Controller { .where("orgRevision.orgRevisionIsDraft = false") .andWhere("orgRevision.orgRevisionIsCurrent = true") .getOne(); - const [lists, total] = await AppDataSource.getRepository(DevelopmentRequest) + let query = await AppDataSource.getRepository(DevelopmentRequest) .createQueryBuilder("developmentRequest") .leftJoinAndSelect("developmentRequest.profile", "profile") .leftJoinAndSelect("profile.current_holders", "current_holders") @@ -249,9 +251,20 @@ export class DevelopmentRequestController extends Controller { }), ) .orderBy("developmentRequest.createdAt", "DESC") - .skip((page - 1) * pageSize) - .take(pageSize) - .getManyAndCount(); + + + if (sortBy) { + query = query.orderBy( + `developmentRequest.${sortBy}`, + descending ? "DESC" : "ASC" + ); + } + + 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/ProfileDevelopmentController.ts b/src/controllers/ProfileDevelopmentController.ts index 7982fe7d..3a615a5a 100644 --- a/src/controllers/ProfileDevelopmentController.ts +++ b/src/controllers/ProfileDevelopmentController.ts @@ -58,11 +58,13 @@ export class ProfileDevelopmentController extends Controller { @Query("page") page: number = 1, @Query("pageSize") pageSize: number = 10, @Query() searchKeyword: string = "", + @Query("sortBy") sortBy?: string, + @Query("descending") descending?: boolean, ) { let _workflow = await new permission().Workflow(req, profileId, "SYS_REGISTRY_OFFICER"); if (_workflow == false) await new permission().PermissionOrgUserGet(req, "SYS_REGISTRY_OFFICER", profileId); - const [profileDevelopment, total] = await AppDataSource.getRepository(ProfileDevelopment) + let query = await AppDataSource.getRepository(ProfileDevelopment) .createQueryBuilder("profileDevelopment") .where({ profileId: profileId }) .andWhere( @@ -102,9 +104,19 @@ export class ProfileDevelopmentController extends Controller { }), ) .orderBy("profileDevelopment.createdAt", "ASC") + + if (sortBy) { + query = query.orderBy( + `profileDevelopment.${sortBy}`, + descending ? "DESC" : "ASC" + ); + } + + const [profileDevelopment, total] = await query .skip((page - 1) * pageSize) .take(pageSize) .getManyAndCount(); + return new HttpSuccess({ data: profileDevelopment, total }); } diff --git a/src/controllers/ProfileEditController.ts b/src/controllers/ProfileEditController.ts index 9e90d294..c7d66ee0 100644 --- a/src/controllers/ProfileEditController.ts +++ b/src/controllers/ProfileEditController.ts @@ -116,6 +116,8 @@ export class ProfileEditController extends Controller { @Query("pageSize") pageSize: number = 10, @Query("keyword") keyword: string = "", @Query("status") status: string = "", + @Query("sortBy") sortBy?: string, + @Query("descending") descending?: boolean, ) { let data = await new permission().PermissionOrgList(request, "SYS_REGISTRY_OFFICER"); const orgRevisionPublish = await this.orgRevisionRepository @@ -123,7 +125,7 @@ export class ProfileEditController extends Controller { .where("orgRevision.orgRevisionIsDraft = false") .andWhere("orgRevision.orgRevisionIsCurrent = true") .getOne(); - let [getProfileEdit, total] = await AppDataSource.getRepository(ProfileEdit) + let query = await AppDataSource.getRepository(ProfileEdit) .createQueryBuilder("ProfileEdit") .leftJoinAndSelect("ProfileEdit.profile", "profile") .leftJoinAndSelect("profile.current_holders", "current_holders") @@ -214,10 +216,27 @@ export class ProfileEditController extends Controller { ); }), ) - .orderBy("ProfileEdit.createdAt", "DESC") - .skip((page - 1) * pageSize) - .take(pageSize) - .getManyAndCount(); + .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" + ); + } + } + + const [getProfileEdit, total] = await query + .skip((page - 1) * pageSize) + .take(pageSize) + .getManyAndCount(); + const _data = getProfileEdit.map((item) => ({ id: item.id, idcard: item.profile.citizenId, From 8b40eb0ad55b75f47a1cd5b3ff18417722a3a425 Mon Sep 17 00:00:00 2001 From: adisak Date: Tue, 23 Sep 2025 14:56:38 +0700 Subject: [PATCH 04/17] sort admin --- .../ProfileDevelopmentEmployeeController.ts | 15 ++++++++- .../ProfileEditEmployeeController.ts | 27 ++++++++++++--- .../ProfileEmployeeTempController.ts | 33 ++++++++++++++++--- 3 files changed, 66 insertions(+), 9 deletions(-) diff --git a/src/controllers/ProfileDevelopmentEmployeeController.ts b/src/controllers/ProfileDevelopmentEmployeeController.ts index c7099378..76260a1b 100644 --- a/src/controllers/ProfileDevelopmentEmployeeController.ts +++ b/src/controllers/ProfileDevelopmentEmployeeController.ts @@ -56,11 +56,14 @@ export class ProfileDevelopmentEmployeeController extends Controller { @Query("page") page: number = 1, @Query("pageSize") pageSize: number = 10, @Query() searchKeyword: string = "", + @Query("sortBy") sortBy?: string, + @Query("descending") descending?: boolean, ) { let _workflow = await new permission().Workflow(req, profileId, "SYS_REGISTRY_EMP"); if (_workflow == false) await new permission().PermissionOrgUserGet(req, "SYS_REGISTRY_EMP", profileId); - const [profileDevelopment, total] = await AppDataSource.getRepository(ProfileDevelopment) + + let query = await AppDataSource.getRepository(ProfileDevelopment) .createQueryBuilder("profileDevelopment") .where({ profileEmployeeId: profileId }) .andWhere( @@ -100,9 +103,19 @@ export class ProfileDevelopmentEmployeeController extends Controller { }), ) .orderBy("profileDevelopment.createdAt", "ASC") + + if (sortBy) { + query = query.orderBy( + `profileDevelopment.${sortBy}`, + descending ? "DESC" : "ASC" + ); + } + + const [profileDevelopment, total] = await query .skip((page - 1) * pageSize) .take(pageSize) .getManyAndCount(); + return new HttpSuccess({ data: profileDevelopment, total }); } diff --git a/src/controllers/ProfileEditEmployeeController.ts b/src/controllers/ProfileEditEmployeeController.ts index 03e56021..75fa1672 100644 --- a/src/controllers/ProfileEditEmployeeController.ts +++ b/src/controllers/ProfileEditEmployeeController.ts @@ -110,6 +110,8 @@ export class ProfileEditEmployeeController extends Controller { @Query("pageSize") pageSize: number = 10, @Query("keyword") keyword: string = "", @Query("status") status: string = "", + @Query("sortBy") sortBy?: string, + @Query("descending") descending?: boolean, ) { let data = await new permission().PermissionOrgList(request, "SYS_REGISTRY_EMP"); const orgRevisionPublish = await this.orgRevisionRepository @@ -117,7 +119,8 @@ export class ProfileEditEmployeeController extends Controller { .where("orgRevision.orgRevisionIsDraft = false") .andWhere("orgRevision.orgRevisionIsCurrent = true") .getOne(); - let [getProfileEdit, total] = await AppDataSource.getRepository(ProfileEdit) + + let query = await AppDataSource.getRepository(ProfileEdit) .createQueryBuilder("ProfileEdit") .leftJoinAndSelect("ProfileEdit.profileEmployee", "profileEmployee") .leftJoinAndSelect("profileEmployee.current_holders", "current_holders") @@ -209,9 +212,25 @@ export class ProfileEditEmployeeController extends Controller { }), ) .orderBy("ProfileEdit.createdAt", "DESC") - .skip((page - 1) * pageSize) - .take(pageSize) - .getManyAndCount(); + + if (sortBy) { + 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(); const _data = getProfileEdit.map((item) => ({ id: item.id, diff --git a/src/controllers/ProfileEmployeeTempController.ts b/src/controllers/ProfileEmployeeTempController.ts index b00197a5..e900a99f 100644 --- a/src/controllers/ProfileEmployeeTempController.ts +++ b/src/controllers/ProfileEmployeeTempController.ts @@ -1504,6 +1504,8 @@ export class ProfileEmployeeTempController extends Controller { @Query() isProbation?: boolean, @Query() isRetire?: boolean, @Query() type?: string, + @Query("sortBy") sortBy?: string, + @Query("descending") descending?: boolean, ) { let _data = await new permission().PermissionOrgList(request, "SYS_REGISTRY_TEMP"); let queryLike = @@ -1525,7 +1527,8 @@ export class ProfileEmployeeTempController extends Controller { if (!findRevision) { throw new HttpError(HttpStatus.NOT_FOUND, "not found. OrgRevision"); } - const [record, total] = await this.profileRepo + + let query = await this.profileRepo .createQueryBuilder("profileEmployee") .leftJoinAndSelect("profileEmployee.posLevel", "posLevel") .leftJoinAndSelect("profileEmployee.posType", "posType") @@ -1638,9 +1641,31 @@ export class ProfileEmployeeTempController extends Controller { } }), ) - .skip((page - 1) * pageSize) - .take(pageSize) - .getManyAndCount(); + + 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{ + query = query.orderBy( + `profileEmployee.${sortBy}`, + descending ? "DESC" : "ASC" + ); + } + } + + const [record, total] = await query + .skip((page - 1) * pageSize) + .take(pageSize) + .getManyAndCount(); + const data = await Promise.all( record.map((_data) => { const shortName = From f8ba8004b3c32948e0e0d84d66b9c13eb14e9acc Mon Sep 17 00:00:00 2001 From: adisak Date: Tue, 23 Sep 2025 16:22:13 +0700 Subject: [PATCH 05/17] fix --- src/controllers/ProfileEmployeeTempController.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/controllers/ProfileEmployeeTempController.ts b/src/controllers/ProfileEmployeeTempController.ts index e900a99f..e5d03e4a 100644 --- a/src/controllers/ProfileEmployeeTempController.ts +++ b/src/controllers/ProfileEmployeeTempController.ts @@ -1643,7 +1643,7 @@ export class ProfileEmployeeTempController extends Controller { ) if (sortBy) { - if(sortBy == "posLevel"){ + if(sortBy == "posLevel"){ query = query.orderBy( `posLevel.posLevelName`, descending ? "DESC" : "ASC" @@ -1653,6 +1653,11 @@ export class ProfileEmployeeTempController extends Controller { `posType.posTypeName`, descending ? "DESC" : "ASC" ); + }else if(sortBy == "govAge"){ + query = query.orderBy( + `profileEmployee.dateAppoint`, + descending ? "DESC" : "ASC" + ); }else{ query = query.orderBy( `profileEmployee.${sortBy}`, From 191ca586c587a796f5a93468a4a7090ce9e71f56 Mon Sep 17 00:00:00 2001 From: Bright Date: Thu, 25 Sep 2025 18:07:18 +0700 Subject: [PATCH 06/17] =?UTF-8?q?API=20=E0=B8=AD=E0=B8=B1=E0=B8=9E?= =?UTF-8?q?=E0=B9=80=E0=B8=94=E0=B8=97=E0=B8=AA=E0=B8=96=E0=B8=B2=E0=B8=99?= =?UTF-8?q?=E0=B8=B0=20CANCEL=20=E0=B8=84=E0=B8=B3=E0=B8=AA=E0=B8=B1?= =?UTF-8?q?=E0=B9=88=E0=B8=87=E0=B8=A2=E0=B8=81=E0=B9=80=E0=B8=A5=E0=B8=B4?= =?UTF-8?q?=E0=B8=81=E0=B8=81=E0=B8=B2=E0=B8=A3=E0=B8=A5=E0=B8=B2=E0=B8=AD?= =?UTF-8?q?=E0=B8=AD=E0=B8=81,=20=E0=B8=84=E0=B8=B3=E0=B8=AA=E0=B8=B1?= =?UTF-8?q?=E0=B9=88=E0=B8=87=E0=B8=A2=E0=B8=81=E0=B9=80=E0=B8=A5=E0=B8=B4?= =?UTF-8?q?=E0=B8=81=E0=B8=81=E0=B8=B2=E0=B8=A3=E0=B8=A5=E0=B8=B2=E0=B8=AD?= =?UTF-8?q?=E0=B8=AD=E0=B8=81=E0=B8=A5=E0=B8=B9=E0=B8=81=E0=B8=88=E0=B9=89?= =?UTF-8?q?=E0=B8=B2=E0=B8=87=20#1409?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/CommandController.ts | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/controllers/CommandController.ts b/src/controllers/CommandController.ts index 8046056a..04de1aef 100644 --- a/src/controllers/CommandController.ts +++ b/src/controllers/CommandController.ts @@ -3012,6 +3012,29 @@ export class CommandController extends Controller { return new HttpSuccess(_data); } + /** + * API อัพเดทสถานะ CANCEL คำสั่งยกเลิกการลาออก, คำสั่งยกเลิกการลาออกลูกจ้าง + * + * @summary API อัพเดทสถานะ CANCEL คำสั่งยกเลิกการลาออก, คำสั่งยกเลิกการลาออกลูกจ้าง + * + */ + @Post("cancel-resign") + public async command41Excecute( + @Request() req: RequestWithUser, + @Body() + body: { + commandId: string[]; + }, + ) { + const commands = await this.commandRepository.find({ where: { id: In(body.commandId) } }); + const data = commands.map((_data) => ({ + ..._data, + status: "CANCEL", + })); + await this.commandRepository.save(data); + return new HttpSuccess(); + } + @Post("excexute/salary-current") public async newSalaryAndUpdateCurrent( @Request() req: RequestWithUser, From 91281ba995b4719b2dda57225fa29a90e939da34 Mon Sep 17 00:00:00 2001 From: mamoss <> Date: Fri, 26 Sep 2025 23:42:26 +0700 Subject: [PATCH 07/17] add-role-staff/user --- src/controllers/UserController.ts | 105 +++++++++++++++++++++++++++--- 1 file changed, 97 insertions(+), 8 deletions(-) diff --git a/src/controllers/UserController.ts b/src/controllers/UserController.ts index e808a2be..8d77b1ec 100644 --- a/src/controllers/UserController.ts +++ b/src/controllers/UserController.ts @@ -852,10 +852,15 @@ export class KeycloakController extends Controller { // _item.birthDate.toISOString().slice(5, 7) + // gregorianYear; // password = formattedDate; - const _date = new Date(_item.birthDate.toDateString()).getDate().toString().padStart(2, "0"); - const _month = (new Date(_item.birthDate.toDateString()).getMonth()+1).toString().padStart(2, "0"); - const _year = (new Date(_item.birthDate.toDateString()).getFullYear()+543); - password = `${_date}${_month}${_year}` + const _date = new Date(_item.birthDate.toDateString()) + .getDate() + .toString() + .padStart(2, "0"); + const _month = (new Date(_item.birthDate.toDateString()).getMonth() + 1) + .toString() + .padStart(2, "0"); + const _year = new Date(_item.birthDate.toDateString()).getFullYear() + 543; + password = `${_date}${_month}${_year}`; } const checkUser = await getUserByUsername(_item.citizenId); let userId: any = ""; @@ -918,10 +923,15 @@ export class KeycloakController extends Controller { // _item.birthDate.toISOString().slice(5, 7) + // gregorianYear; // password = formattedDate; - const _date = new Date(_item.birthDate.toDateString()).getDate().toString().padStart(2, "0"); - const _month = (new Date(_item.birthDate.toDateString()).getMonth()+1).toString().padStart(2, "0"); - const _year = (new Date(_item.birthDate.toDateString()).getFullYear()+543); - password = `${_date}${_month}${_year}` + const _date = new Date(_item.birthDate.toDateString()) + .getDate() + .toString() + .padStart(2, "0"); + const _month = (new Date(_item.birthDate.toDateString()).getMonth() + 1) + .toString() + .padStart(2, "0"); + const _year = new Date(_item.birthDate.toDateString()).getFullYear() + 543; + password = `${_date}${_month}${_year}`; } const checkUser = await getUserByUsername(_item.citizenId); let userId: any = ""; @@ -990,4 +1000,83 @@ export class KeycloakController extends Controller { } return; } + + @Post("add-role-staff/user/{child1Id}") + @Security("bearerAuth", ["system", "admin"]) + async addroleStaffToUser( + @Path() child1Id: string, + @Request() request: { user: { sub: string; preferred_username: string } }, + ) { + const profiles = await this.profileRepo.find({ + where: { + keycloak: Not(IsNull()), + current_holders: { + orgChild1Id: child1Id, + }, + }, + relations: ["roleKeycloaks"], + }); + // return profiles.length; + + for await (const _item of profiles) { + let password = _item.citizenId; + if (_item.birthDate != null) { + const _date = new Date(_item.birthDate.toDateString()) + .getDate() + .toString() + .padStart(2, "0"); + const _month = (new Date(_item.birthDate.toDateString()).getMonth() + 1) + .toString() + .padStart(2, "0"); + const _year = new Date(_item.birthDate.toDateString()).getFullYear() + 543; + password = `${_date}${_month}${_year}`; + } + const checkUser = await getUserByUsername(_item.citizenId); + let userId: any = ""; + if (checkUser.length == 0) { + userId = await createUser(_item.citizenId, password, { + firstName: _item.firstName, + lastName: _item.lastName, + }); + if (typeof userId !== "string") { + throw new Error(userId.errorMessage); + } + } else { + userId = checkUser[0].id; + } + + const list = await getRoles(); + if (!Array.isArray(list)) throw new Error("Failed. Cannot get role(s) data from the server."); + const resultUser = await addUserRoles( + userId, + list.filter((v) => v.id == "8a1a0dc9-304c-4e5b-a90a-65f841048212"), + ); + const resultStaff = await addUserRoles( + userId, + list.filter((v) => v.id == "f1fff8db-0795-47c1-9952-f3c18d5b6172"), + ); + + // if (!resultUser) { + // throw new Error("Failed. Cannot set user's role."); + // } + + // if (!resultStaff) { + // throw new Error("Failed. Cannot set staff's role."); + // } + if (typeof userId === "string") { + _item.keycloak = userId; + } + const roleKeycloakUser = await this.roleKeycloakRepo.find({ + where: { id: "8a1a0dc9-304c-4e5b-a90a-65f841048212" }, + }); + const roleKeycloakStaff = await this.roleKeycloakRepo.find({ + where: { id: "f1fff8db-0795-47c1-9952-f3c18d5b6172" }, + }); + if (_item) { + _item.roleKeycloaks = Array.from(new Set([...roleKeycloakUser, ...roleKeycloakStaff])); + this.profileRepo.save(_item); + } + } + return ""; + } } From c5b54d55dee13afb6e2e5aaa931bb1131918f0f6 Mon Sep 17 00:00:00 2001 From: mamoss <> Date: Sun, 28 Sep 2025 14:24:46 +0700 Subject: [PATCH 08/17] api add permission org --- src/controllers/OrganizationController.ts | 46 +++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/src/controllers/OrganizationController.ts b/src/controllers/OrganizationController.ts index 20511811..5ad7c11c 100644 --- a/src/controllers/OrganizationController.ts +++ b/src/controllers/OrganizationController.ts @@ -30,6 +30,7 @@ import { checkQueueInProgress, setLogDataDiff } from "../interfaces/utils"; import { sendToQueueOrg, sendToQueueOrgDraft } from "../services/rabbitmq"; import { PosType } from "../entities/PosType"; import { PosLevel } from "../entities/PosLevel"; +import { PermissionOrg } from "../entities/PermissionOrg"; @Route("api/v1/org") @Tags("Organization") @@ -49,6 +50,7 @@ export class OrganizationController extends Controller { private profileRepo = AppDataSource.getRepository(Profile); private posTypeRepository = AppDataSource.getRepository(PosType); private posLevelRepository = AppDataSource.getRepository(PosLevel); + private permissionOrgRepository = AppDataSource.getRepository(PermissionOrg); /** * API ล้างข้อมูล @@ -7869,4 +7871,48 @@ export class OrganizationController extends Controller { posLevelNameOrder: posLevel.map((x) => x.posLevelName), }); } + + /** + * API เพิ่มสิทธิ์โครงสร้าง + * + * @summary - เพิ่มสิทธิ์โครงสร้าง (ADMIN) + * + */ + @Get("root/add/permission/{child1Id}") + async addRootPermission(@Path() child1Id: string, @Request() request: RequestWithUser) { + const profiles = await this.profileRepo.find({ + where: { + keycloak: Not(IsNull()), + current_holders: { + orgChild1Id: child1Id, + }, + }, + }); + const orgRoots = await this.orgRootRepository.find({ + where: { + orgRevision: { + orgRevisionIsDraft: true, + orgRevisionIsCurrent: false, + }, + }, + }); + + for await (const root of orgRoots) { + const _permissionOrg = profiles.map((profile) => { + const permission = new PermissionOrg(); + permission.orgRootId = root.id; + permission.profileId = profile.id; + permission.createdUserId = request.user.sub; + permission.createdFullName = request.user.name; + permission.lastUpdateUserId = request.user.sub; + permission.lastUpdateFullName = request.user.name; + permission.createdAt = new Date(); + permission.lastUpdatedAt = new Date(); + return permission; + }); + await this.permissionOrgRepository.save(_permissionOrg); + } + + return new HttpSuccess(); + } } From 3961488b917ca77c7e9bad16b62a15e631df7d15 Mon Sep 17 00:00:00 2001 From: Bright Date: Mon, 29 Sep 2025 11:46:19 +0700 Subject: [PATCH 09/17] =?UTF-8?q?#1409=20=E0=B9=81=E0=B8=81=E0=B9=89?= =?UTF-8?q?=E0=B9=80=E0=B8=9B=E0=B9=87=E0=B8=99=E0=B8=AA=E0=B9=88=E0=B8=87?= =?UTF-8?q?=20refId=20=E0=B8=82=E0=B8=AD=E0=B8=87=E0=B8=84=E0=B8=B3?= =?UTF-8?q?=E0=B8=AA=E0=B8=B1=E0=B9=88=E0=B8=87=E0=B8=82=E0=B8=AD=E0=B8=A5?= =?UTF-8?q?=E0=B8=B2=E0=B8=AD=E0=B8=AD=E0=B8=81=E0=B9=84=E0=B8=9B=E0=B8=84?= =?UTF-8?q?=E0=B9=89=E0=B8=99=E0=B8=97=E0=B8=B5=E0=B9=88=20command=20?= =?UTF-8?q?=E0=B8=81=E0=B9=88=E0=B8=AD=E0=B8=99=E0=B8=AD=E0=B8=B1=E0=B8=9E?= =?UTF-8?q?=20status=20=3D=20CANCEL?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/CommandController.ts | 29 ++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/src/controllers/CommandController.ts b/src/controllers/CommandController.ts index 04de1aef..a9feeeb0 100644 --- a/src/controllers/CommandController.ts +++ b/src/controllers/CommandController.ts @@ -3466,6 +3466,7 @@ export class CommandController extends Controller { orgChild2New?: string | null; orgChild3New?: string | null; orgChild4New?: string | null; + resignId?: string | null; }[]; }, ) { @@ -3530,6 +3531,19 @@ export class CommandController extends Controller { if (code && ["C-PM-08", "C-PM-17", "C-PM-18"].includes(code)) { removePostMasterAct(profile.id); } + //ออกคำสั่งยกเลิกลาออกต้องอัพเดทสถานะคำสั่งลาออกเป็น CANCEL + else if (item.resignId && code && ["C-PM-41"].includes(code)) { + const commandRecive = await this.commandReciveRepository.findOne({ + select: ["commandId"], + where: { refId: item.resignId }, + }); + if (commandRecive && commandRecive.commandId) { + await this.commandRepository.update( + { id: commandRecive?.commandId }, + { status: "CANCEL" } + ); + } + } let _commandYear = item.commandYear; if (item.commandYear) { _commandYear = item.commandYear > 2500 ? item.commandYear : item.commandYear + 543; @@ -3796,6 +3810,7 @@ export class CommandController extends Controller { commandCode?: string | null; commandName?: string | null; remark: string | null; + resignId: string | null; }[]; }, ) { @@ -3851,6 +3866,20 @@ export class CommandController extends Controller { if (!profile) { throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); } + const code = _command?.commandType?.code; + //ออกคำสั่งยกเลิกลาออกต้องอัพเดทสถานะคำสั่งลาออกเป็น CANCEL + if (item.resignId && code && ["C-PM-42"].includes(code)) { + const commandRecive = await this.commandReciveRepository.findOne({ + select: ["commandId"], + where: { refId: item.resignId }, + }); + if (commandRecive && commandRecive.commandId) { + await this.commandRepository.update( + { id: commandRecive?.commandId }, + { status: "CANCEL" } + ); + } + } let _commandYear = item.commandYear; if (item.commandYear) { _commandYear = item.commandYear > 2500 ? item.commandYear : item.commandYear + 543; From f2ea301d443e0866b53aa1fda54f59bdb71cad02 Mon Sep 17 00:00:00 2001 From: Adisak Date: Mon, 29 Sep 2025 13:59:02 +0700 Subject: [PATCH 10/17] =?UTF-8?q?sort=20=E0=B9=81=E0=B8=81=E0=B9=89?= =?UTF-8?q?=E0=B9=84=E0=B8=82=E0=B8=97=E0=B8=B0=E0=B9=80=E0=B8=9A=E0=B8=B5?= =?UTF-8?q?=E0=B8=A2=E0=B8=99=E0=B8=9B=E0=B8=A3=E0=B8=B0=E0=B8=A7=E0=B8=B1?= =?UTF-8?q?=E0=B8=95=E0=B8=B4=20=E0=B8=95=E0=B8=B3=E0=B9=81=E0=B8=AB?= =?UTF-8?q?=E0=B8=99=E0=B9=88=E0=B8=87/=E0=B9=80=E0=B8=87=E0=B8=B4?= =?UTF-8?q?=E0=B8=99=E0=B9=80=E0=B8=94=E0=B8=B7=E0=B8=AD=E0=B8=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit @Get: api/v1/org/profile/salaryTemp --- .../ProfileSalaryTempController.ts | 80 ++++++++++++++++--- 1 file changed, 70 insertions(+), 10 deletions(-) diff --git a/src/controllers/ProfileSalaryTempController.ts b/src/controllers/ProfileSalaryTempController.ts index 81cc1751..3583d09b 100644 --- a/src/controllers/ProfileSalaryTempController.ts +++ b/src/controllers/ProfileSalaryTempController.ts @@ -64,6 +64,8 @@ export class ProfileSalaryTempController extends Controller { @Query() searchKeyword: string = "", @Query() statusCheckEdit?: string | null, @Query() rootId?: string, + @Query("sortBy") sortBy?: string, + @Query("descending") descending?: boolean, ) { if (type.trim().toUpperCase() == "OFFICER") { let _data = await new permission().PermissionOrgList(request, "SYS_REGISTRY_OFFICER"); @@ -78,7 +80,7 @@ export class ProfileSalaryTempController extends Controller { if (!findRevision) { throw new HttpError(HttpStatus.NOT_FOUND, "not found. OrgRevision"); } - const [record, total] = await this.profileRepo + let query = await this.profileRepo .createQueryBuilder("profile") .leftJoinAndSelect("profile.posLevel", "posLevel") .leftJoinAndSelect("profile.posType", "posType") @@ -321,17 +323,49 @@ export class ProfileSalaryTempController extends Controller { rootId: rootId, }) .addSelect("CASE WHEN current_holders.posMasterNo IS NULL THEN 1 ELSE 0 END", "sort_order") - .orderBy("sort_order", "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 == "posExecutive"){ + query = query.orderBy( + `posExecutive.posExecutiveName`, + descending ? "DESC" : "ASC" + ); + }else if(sortBy == "posNo"){ + query = query.orderBy( + `orgRoot.orgRootShortName`, + 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") - // .orderBy(`${sortBy}`, sort) - .skip((page - 1) * pageSize) - .take(pageSize) - .getManyAndCount(); + } + + const [record, total] = await query + .skip((page - 1) * pageSize) + .take(pageSize) + .getManyAndCount(); const data = await Promise.all( record.map((_data) => { @@ -465,7 +499,7 @@ export class ProfileSalaryTempController extends Controller { if (!findRevision) { throw new HttpError(HttpStatus.NOT_FOUND, "not found. OrgRevision"); } - const [record, total] = await this.profileEmployeeRepo + let query = await this.profileEmployeeRepo .createQueryBuilder("profileEmployee") .leftJoinAndSelect("profileEmployee.posLevel", "posLevel") .leftJoinAndSelect("profileEmployee.posType", "posType") @@ -721,9 +755,35 @@ export class ProfileSalaryTempController extends Controller { }) .orderBy("current_holders.posMasterNo", "ASC") // .orderBy(`${sortBy}`, sort) - .skip((page - 1) * pageSize) - .take(pageSize) - .getManyAndCount(); + + 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(); + const data = await Promise.all( record.map((_data) => { const shortName = From a7ada567454c3097345b44555008cc70d7990051 Mon Sep 17 00:00:00 2001 From: Adisak Date: Mon, 29 Sep 2025 14:15:49 +0700 Subject: [PATCH 11/17] fix --- src/controllers/ProfileSalaryTempController.ts | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/controllers/ProfileSalaryTempController.ts b/src/controllers/ProfileSalaryTempController.ts index 3583d09b..b160f98d 100644 --- a/src/controllers/ProfileSalaryTempController.ts +++ b/src/controllers/ProfileSalaryTempController.ts @@ -342,10 +342,12 @@ export class ProfileSalaryTempController extends Controller { descending ? "DESC" : "ASC" ); }else if(sortBy == "posNo"){ - query = query.orderBy( - `orgRoot.orgRootShortName`, - descending ? "DESC" : "ASC" - ); + 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}`, From e63799eb00e09fbfcc4e895996866726c12c6737 Mon Sep 17 00:00:00 2001 From: Bright Date: Mon, 29 Sep 2025 15:01:01 +0700 Subject: [PATCH 12/17] no message --- src/controllers/CommandController.ts | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/src/controllers/CommandController.ts b/src/controllers/CommandController.ts index a9feeeb0..6a4a2e3f 100644 --- a/src/controllers/CommandController.ts +++ b/src/controllers/CommandController.ts @@ -3023,15 +3023,24 @@ export class CommandController extends Controller { @Request() req: RequestWithUser, @Body() body: { - commandId: string[]; + resignId: string[]; }, ) { - const commands = await this.commandRepository.find({ where: { id: In(body.commandId) } }); - const data = commands.map((_data) => ({ - ..._data, - status: "CANCEL", - })); - await this.commandRepository.save(data); + const _refId = Array.from(new Set(body.resignId)); + // 1. ดึง commandRecive ที่ refId ตรงกับ resignId + const commandRecives = await this.commandReciveRepository.find({ + select: ["commandId"], + where: { refId: In(_refId) }, + }); + // 2. ดึง commandId ที่ไม่ซ้ำ + const commandIds = Array.from(new Set(commandRecives.map(x => x.commandId).filter(Boolean))); + // 3. อัปเดต status ของ command + if (commandIds.length > 0) { + await this.commandRepository.update( + { id: In(commandIds) }, + { status: "CANCEL" } + ); + } return new HttpSuccess(); } From 5be36351986530443db647c9fc6879afe22b69a7 Mon Sep 17 00:00:00 2001 From: Bright Date: Mon, 29 Sep 2025 17:33:22 +0700 Subject: [PATCH 13/17] no message --- src/controllers/CommandController.ts | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/src/controllers/CommandController.ts b/src/controllers/CommandController.ts index 6a4a2e3f..4e5f898e 100644 --- a/src/controllers/CommandController.ts +++ b/src/controllers/CommandController.ts @@ -160,6 +160,8 @@ export class CommandController extends Controller { @Get("list") async GetResult( @Request() request: RequestWithUser, + @Query("sortBy") sortBy?: string, + @Query("descending") descending?: boolean, @Query("page") page: number = 1, @Query("pageSize") pageSize: number = 10, @Query() keyword: string = "", @@ -262,14 +264,9 @@ export class CommandController extends Controller { yearKeyword = match[1].trim(); } let yearInBC = yearKeyword ? parseInt(yearKeyword) - 543 : null; - // - - // console.log("k>>",keyword); - // console.log("bk>>",baseKeyword); - // console.log("yk>>",yearKeyword); - // console.log("yi>>",yearInBC); - - const [commands, total] = await this.commandRepository + + // const [commands, total] = await this.commandRepository + let query = await this.commandRepository .createQueryBuilder("command") .leftJoinAndSelect("command.commandType", "commandType") .andWhere( @@ -339,6 +336,15 @@ export class CommandController extends Controller { }), ) .orderBy("command.createdAt", "DESC") + + if (sortBy) { + query = query.orderBy( + `command.${sortBy}`, + descending ? "DESC" : "ASC" + ); + } + + let [commands, total] = await query .skip((page - 1) * pageSize) .take(pageSize) .getManyAndCount(); From 8af006bae3538d88b99867ee1d34282f235abb9e Mon Sep 17 00:00:00 2001 From: Adisak Date: Tue, 30 Sep 2025 12:02:44 +0700 Subject: [PATCH 14/17] sort probation --- src/controllers/ProfileController.ts | 33 ++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/src/controllers/ProfileController.ts b/src/controllers/ProfileController.ts index 81781adf..800dc72d 100644 --- a/src/controllers/ProfileController.ts +++ b/src/controllers/ProfileController.ts @@ -9103,6 +9103,8 @@ export class ProfileController extends Controller { page: number; pageSize: number; keyword?: string; + sortBy?: string; + descending?: boolean; }, ) { let _data: any = { @@ -9116,7 +9118,7 @@ export class ProfileController extends Controller { if (!request.user.role.includes("SUPER_ADMIN")) { _data = await new permission().PermissionOrgCreate(request, "SYS_PROBATION"); } - const [findProfile, total] = await AppDataSource.getRepository(Profile) + let query = await AppDataSource.getRepository(Profile) .createQueryBuilder("profile") .leftJoinAndSelect("profile.profileSalary", "profileSalary") .leftJoinAndSelect("profile.posLevel", "posLevel") @@ -9230,7 +9232,34 @@ export class ProfileController extends Controller { ); }), ) - .orderBy("profile.citizenId", "ASC") + + if (body.sortBy) { + if(body.sortBy === "posLevelName"){ + query = query.orderBy( + `posLevel.posLevelName`, + body.descending ? "DESC" : "ASC" + ); + }else if(body.sortBy === "posTypeName"){ + query = query.orderBy( + `posType.posTypeName`, + body.descending ? "DESC" : "ASC" + ); + }else if(body.sortBy === "commandNo"){ + query = query.orderBy( + `profileSalary.commandNo`, + body.descending ? "DESC" : "ASC" + ); + }else{ + query = query.orderBy( + `profile.${body.sortBy}`, + body.descending ? "DESC" : "ASC" + ); + } + }else{ + query = query.orderBy("profile.citizenId", "ASC") + } + + const [findProfile, total] = await query .skip((body.page - 1) * body.pageSize) .take(body.pageSize) .getManyAndCount(); From 77b455ea8f4b1b56c153f5ca11885c9923684cf1 Mon Sep 17 00:00:00 2001 From: Adisak Date: Tue, 30 Sep 2025 12:16:48 +0700 Subject: [PATCH 15/17] fix --- src/controllers/ProfileController.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/controllers/ProfileController.ts b/src/controllers/ProfileController.ts index 800dc72d..e9ead8e5 100644 --- a/src/controllers/ProfileController.ts +++ b/src/controllers/ProfileController.ts @@ -9249,6 +9249,11 @@ export class ProfileController extends Controller { `profileSalary.commandNo`, body.descending ? "DESC" : "ASC" ); + }else if(body.sortBy === "orgRootName"){ + query = query.orderBy( + `orgRoot.orgRootName`, + body.descending ? "DESC" : "ASC" + ); }else{ query = query.orderBy( `profile.${body.sortBy}`, From 58e44de196abaed7b3a63e69870032c497805449 Mon Sep 17 00:00:00 2001 From: Adisak Date: Tue, 30 Sep 2025 13:52:48 +0700 Subject: [PATCH 16/17] sort org command --- src/controllers/ProfileController.ts | 32 +++++++++++++++++++++++----- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/src/controllers/ProfileController.ts b/src/controllers/ProfileController.ts index e9ead8e5..c8a0e3c3 100644 --- a/src/controllers/ProfileController.ts +++ b/src/controllers/ProfileController.ts @@ -2585,6 +2585,8 @@ export class ProfileController extends Controller { keyword: string; page: number; pageSize: number; + sortBy?: string; + descending?: boolean; }, ) { let posMaster = await this.posMasterRepo.findOne({ @@ -2672,7 +2674,7 @@ export class ProfileController extends Controller { // condition.isDirector = true; // // conditionNow.isDirector = true; // } - const [lists, total] = await AppDataSource.getRepository(viewDirectorActing) + let query = await AppDataSource.getRepository(viewDirectorActing) .createQueryBuilder("viewDirectorActing") // .andWhere(condition) .andWhere( @@ -2724,9 +2726,19 @@ export class ProfileController extends Controller { ); }), ) - .skip((body.page - 1) * body.pageSize) - .take(body.pageSize) - .getManyAndCount(); + + if (body.sortBy) { + query = query.orderBy( + `viewDirectorActing.${body.sortBy}`, + body.descending ? "DESC" : "ASC" + ); + } + + const [lists, total] = await query + .skip((body.page - 1) * body.pageSize) + .take(body.pageSize) + .getManyAndCount(); + return new HttpSuccess({ data: lists, total }); } else { // const posMaster = await this.posMasterRepo.findOne({ @@ -2764,7 +2776,7 @@ export class ProfileController extends Controller { // condition.isDirector = true; // // conditionNow.isDirector = true; // } - const [lists, total] = await AppDataSource.getRepository(viewDirector) + let query = await AppDataSource.getRepository(viewDirector) .createQueryBuilder("viewDirector") // .andWhere(condition) .andWhere( @@ -2816,9 +2828,19 @@ export class ProfileController extends Controller { ); }), ) + + if (body.sortBy) { + query = query.orderBy( + `viewDirector.${body.sortBy}`, + body.descending ? "DESC" : "ASC" + ); + } + + const [lists, total] = await query .skip((body.page - 1) * body.pageSize) .take(body.pageSize) .getManyAndCount(); + return new HttpSuccess({ data: lists, total }); } } From 2a9f69f736b95a084a0aaaf4518a395970033d19 Mon Sep 17 00:00:00 2001 From: Adisak Date: Tue, 30 Sep 2025 15:15:57 +0700 Subject: [PATCH 17/17] sort --- src/controllers/ProfileController.ts | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/src/controllers/ProfileController.ts b/src/controllers/ProfileController.ts index c8a0e3c3..33d33227 100644 --- a/src/controllers/ProfileController.ts +++ b/src/controllers/ProfileController.ts @@ -8567,6 +8567,8 @@ export class ProfileController extends Controller { keyword?: string; system?: string; }, + @Query("sortBy") sortBy?: string, + @Query("descending") descending?: boolean ) { // ค้นหารายชื่อถ้าไม่ส่ง system มาให้ default ตามทะเบียนประวัติ let _system: string = "SYS_REGISTRY_OFFICER"; @@ -8638,7 +8640,7 @@ export class ProfileController extends Controller { break; } - const [findProfile, total] = await this.profileRepo + let query = await this.profileRepo .createQueryBuilder("profile") .leftJoinAndSelect("profile.posType", "posType") .leftJoinAndSelect("profile.posLevel", "posLevel") @@ -8694,6 +8696,27 @@ export class ProfileController extends Controller { qb.orWhere(body.keyword ? queryLike : "1=1", { keyword: `%${body.keyword}%` }); }), ) + + if (sortBy) { + if(sortBy === "name"){ + query = query + .orderBy(`profile.prefix`,descending ? "DESC" : "ASC") + .addOrderBy(`profile.firstName`,descending ? "DESC" : "ASC") + .addOrderBy(`profile.lastName`,descending ? "DESC" : "ASC") + }else if(sortBy === "organization"){ + query = query.orderBy( + `orgRoot.orgRootName`, + descending ? "DESC" : "ASC" + ); + }else{ + query = query.orderBy( + `profile.${sortBy}`, + descending ? "DESC" : "ASC" + ); + } + } + + const [findProfile, total] = await query .skip((page - 1) * pageSize) .take(pageSize) .getManyAndCount();