From f30748470799a5cbf91b584e8483a36d46220c3a Mon Sep 17 00:00:00 2001 From: Bright Date: Wed, 25 Jun 2025 11:18:02 +0700 Subject: [PATCH] Fix Bug Issue #131 --- .../ProfileEmployeeTempController.ts | 84 +++++++++++++++++-- 1 file changed, 76 insertions(+), 8 deletions(-) diff --git a/src/controllers/ProfileEmployeeTempController.ts b/src/controllers/ProfileEmployeeTempController.ts index 5deed3d7..a2e735b2 100644 --- a/src/controllers/ProfileEmployeeTempController.ts +++ b/src/controllers/ProfileEmployeeTempController.ts @@ -1050,18 +1050,20 @@ export class ProfileEmployeeTempController extends Controller { } /** - * API รายการทะเบียนประวัติลูกจ้างชั่วคราว + * API ส่งรายชื่อไปออกคำสั่ง รายการทะเบียนประวัติลูกจ้างชั่วคราว * - * @summary รายการทะเบียนประวัติลูกจ้างชั่วคราว (ADMIN) + * @summary ส่งรายชื่อไปออกคำสั่ง รายการทะเบียนประวัติลูกจ้างชั่วคราว (ADMIN) * */ @Get("temp") - async listProfileEmp() { + async listProfileEmp(@Request() request: RequestWithUser) { + let _dataOrg = await new permission().PermissionOrgList(request, "SYS_REGISTRY_TEMP"); const [record, total] = await this.profileRepo .createQueryBuilder("profileEmployee") .leftJoinAndSelect("profileEmployee.posLevel", "posLevel") .leftJoinAndSelect("profileEmployee.posType", "posType") .leftJoinAndSelect("profileEmployee.current_holders", "current_holders") + .leftJoinAndSelect("profileEmployee.current_holderTemps", "current_holderTemps") .leftJoinAndSelect("profileEmployee.profileEmployeeEmployment", "profileEmployeeEmployment") .leftJoinAndSelect("current_holders.positions", "positions") .leftJoinAndSelect("current_holders.orgRoot", "orgRoot") @@ -1069,8 +1071,63 @@ export class ProfileEmployeeTempController extends Controller { .leftJoinAndSelect("current_holders.orgChild2", "orgChild2") .leftJoinAndSelect("current_holders.orgChild3", "orgChild3") .leftJoinAndSelect("current_holders.orgChild4", "orgChild4") + .leftJoinAndSelect("current_holderTemps.orgRoot", "orgRootTemp") + .leftJoinAndSelect("current_holderTemps.orgChild1", "orgChild1Temp") + .leftJoinAndSelect("current_holderTemps.orgChild2", "orgChild2Temp") + .leftJoinAndSelect("current_holderTemps.orgChild3", "orgChild3Temp") + .leftJoinAndSelect("current_holderTemps.orgChild4", "orgChild4Temp") .andWhere("profileEmployee.employeeClass = :employeeClass", { employeeClass: "TEMP" }) .andWhere("profileEmployee.statusTemp = :statusTemp", { statusTemp: "PENDING" }) + .andWhere( + _dataOrg.root != undefined && _dataOrg.root != null + ? _dataOrg.root[0] != null + ? `current_holderTemps.orgRootId IN (:...root)` + : `current_holderTemps.orgRootId is null` + : "1=1", + { + root: _dataOrg.root, + }, + ) + .andWhere( + _dataOrg.child1 != undefined && _dataOrg.child1 != null + ? _dataOrg.child1[0] != null + ? `current_holderTemps.orgChild1Id IN (:...child1)` + : `current_holderTemps.orgChild1Id is null` + : "1=1", + { + child1: _dataOrg.child1, + }, + ) + .andWhere( + _dataOrg.child2 != undefined && _dataOrg.child2 != null + ? _dataOrg.child2[0] != null + ? `current_holderTemps.orgChild2Id IN (:...child2)` + : `current_holderTemps.orgChild2Id is null` + : "1=1", + { + child2: _dataOrg.child2, + }, + ) + .andWhere( + _dataOrg.child3 != undefined && _dataOrg.child3 != null + ? _dataOrg.child3[0] != null + ? `current_holderTemps.orgChild3Id IN (:...child3)` + : `current_holderTemps.orgChild3Id is null` + : "1=1", + { + child3: _dataOrg.child3, + }, + ) + .andWhere( + _dataOrg.child4 != undefined && _dataOrg.child4 != null + ? _dataOrg.child4[0] != null + ? `current_holderTemps.orgChild4Id IN (:...child4)` + : `current_holderTemps.orgChild4Id is null` + : "1=1", + { + child4: _dataOrg.child4, + }, + ) .getManyAndCount(); const data = await Promise.all( record.map((_data) => { @@ -1409,9 +1466,9 @@ export class ProfileEmployeeTempController extends Controller { } /** - * API รายการทะเบียนประวัติ + * API รายการทะเบียนประวัติลูกจ้างชั่วคราว * - * @summary ORG_065 - รายการทะเบียนประวัติ (ADMIN) #70 + * @summary ORG_065 - รายการทะเบียนประวัติลูกจ้างชั่วคราว (ADMIN) #70 * */ @Get() @@ -1540,9 +1597,20 @@ export class ProfileEmployeeTempController extends Controller { // : `profileEmployee.dateRetire IS NOT NULL` // : "1=1", // ) - .andWhere("profileEmployee.employeeClass = :type", { - type: "TEMP", - }) + .andWhere( + "profileEmployee.employeeClass = :type", { + type: type ? type.trim().toLocaleUpperCase() : "TEMP" + } + ) + .orWhere( + `current_holderTemps.orgRootId is null AND current_holderTemps.orgChild1Id is null AND + current_holderTemps.orgChild2Id is null AND current_holderTemps.orgChild3Id is null AND + current_holderTemps.orgChild4Id is null AND profileEmployee.createdUserId = :keycloak AND + profileEmployee.employeeClass = :type`, { + keycloak: request.user.sub, + type: type ? type.trim().toLocaleUpperCase() : "TEMP", + } + ) .skip((page - 1) * pageSize) .take(pageSize) .getManyAndCount();