From 8b7de2a0ba5d15a248f96549db4fc3f3bd1e9481 Mon Sep 17 00:00:00 2001 From: mamoss <> Date: Mon, 18 Aug 2025 22:56:04 +0700 Subject: [PATCH] update current --- src/controllers/CommandController.ts | 25 +++++++++-- src/controllers/EmployeePositionController.ts | 35 +++++++++------ .../EmployeeTempPositionController.ts | 7 ++- src/controllers/OrgRootController.ts | 2 +- src/controllers/PositionController.ts | 26 +++++------ src/controllers/ProfileController.ts | 45 ++++++++++--------- 6 files changed, 86 insertions(+), 54 deletions(-) diff --git a/src/controllers/CommandController.ts b/src/controllers/CommandController.ts index 9fbf9199..5dfcf45d 100644 --- a/src/controllers/CommandController.ts +++ b/src/controllers/CommandController.ts @@ -3120,7 +3120,10 @@ export class CommandController extends Controller { orgRevisionId: posMaster.orgRevisionId, }, }); - if (posMasterOld != null) posMasterOld.current_holderId = null; + if (posMasterOld != null) { + posMasterOld.current_holderId = null; + posMasterOld.lastUpdatedAt = new Date(); + } const positionOld = await this.positionRepository.findOne({ where: { @@ -3148,6 +3151,7 @@ export class CommandController extends Controller { } posMaster.current_holderId = item.profileId; + posMaster.lastUpdatedAt = new Date(); posMaster.conditionReason = _null; posMaster.isCondition = false; if (posMasterOld != null) await this.posMasterRepository.save(posMasterOld); @@ -3304,7 +3308,10 @@ export class CommandController extends Controller { orgRevisionId: posMaster.orgRevisionId, }, }); - if (posMasterOld != null) posMasterOld.current_holderId = null; + if (posMasterOld != null) { + posMasterOld.current_holderId = null; + posMasterOld.lastUpdatedAt = new Date(); + } // if (posMasterOld != null) posMasterOld.next_holderId = null; const positionOld = await this.employeePositionRepository.findOne({ @@ -3333,6 +3340,7 @@ export class CommandController extends Controller { } posMaster.current_holderId = item.profileId; + posMaster.lastUpdatedAt = new Date(); posMaster.next_holderId = null; if (posMasterOld != null) await this.employeePosMasterRepository.save(posMasterOld); await this.employeePosMasterRepository.save(posMaster); @@ -3561,6 +3569,7 @@ export class CommandController extends Controller { await this.positionRepository.save(clearPosition); } posMaster.current_holderId = profile.id; + posMaster.lastUpdatedAt = new Date(); posMaster.conditionReason = _null; posMaster.isCondition = false; await this.posMasterRepository.save(posMaster); @@ -5987,7 +5996,10 @@ export class CommandController extends Controller { orgRevisionId: posMaster.orgRevisionId, }, }); - if (posMasterOld != null) posMasterOld.current_holderId = null; + if (posMasterOld != null) { + posMasterOld.current_holderId = null; + posMasterOld.lastUpdatedAt = new Date(); + } const positionOld = await this.positionRepository.findOne({ where: { @@ -6015,6 +6027,7 @@ export class CommandController extends Controller { } posMaster.current_holderId = profile.id; + posMaster.lastUpdatedAt = new Date(); posMaster.conditionReason = _null; posMaster.isCondition = false; if (posMasterOld != null) await this.posMasterRepository.save(posMasterOld); @@ -6364,7 +6377,10 @@ export class CommandController extends Controller { orgRevisionId: posMaster.orgRevisionId, }, }); - if (posMasterOld != null) posMasterOld.current_holderId = null; + if (posMasterOld != null) { + posMasterOld.current_holderId = null; + posMasterOld.lastUpdatedAt = new Date(); + } // if (posMasterOld != null) posMasterOld.next_holderId = null; const positionOld = await this.employeePositionRepository.findOne({ @@ -6393,6 +6409,7 @@ export class CommandController extends Controller { } posMaster.current_holderId = profile.id; + posMaster.lastUpdatedAt = new Date(); posMaster.next_holderId = null; if (posMasterOld != null) await this.employeePosMasterRepository.save(posMasterOld); await this.employeePosMasterRepository.save(posMaster); diff --git a/src/controllers/EmployeePositionController.ts b/src/controllers/EmployeePositionController.ts index 1cb09d65..6ef4ffaa 100644 --- a/src/controllers/EmployeePositionController.ts +++ b/src/controllers/EmployeePositionController.ts @@ -372,18 +372,22 @@ export class EmployeePositionController extends Controller { // }); // } findData = await this.employeePosDictRepository - .createQueryBuilder("posDict") - .leftJoinAndSelect("posDict.posType", "posType") - .leftJoinAndSelect("posDict.posLevel", "posLevel") - .where( keyword - ? "CONCAT(posType.posTypeShortName, ' ', posLevel.posLevelName) LIKE :keyword":"1=1", {keyword: `%${keyword}%`}) - .orderBy("posDict.posDictName", "ASC") - .addOrderBy("posDict.createdAt", "DESC") - .addOrderBy("posType.posTypeRank", "ASC") - .addOrderBy("posType.createdAt", "DESC") - .addOrderBy("posLevel.posLevelName", "ASC") - .addOrderBy("posLevel.createdAt", "DESC") - .getMany(); + .createQueryBuilder("posDict") + .leftJoinAndSelect("posDict.posType", "posType") + .leftJoinAndSelect("posDict.posLevel", "posLevel") + .where( + keyword + ? "CONCAT(posType.posTypeShortName, ' ', posLevel.posLevelName) LIKE :keyword" + : "1=1", + { keyword: `%${keyword}%` }, + ) + .orderBy("posDict.posDictName", "ASC") + .addOrderBy("posDict.createdAt", "DESC") + .addOrderBy("posType.posTypeRank", "ASC") + .addOrderBy("posType.createdAt", "DESC") + .addOrderBy("posLevel.posLevelName", "ASC") + .addOrderBy("posLevel.createdAt", "DESC") + .getMany(); break; default: @@ -2258,6 +2262,7 @@ export class EmployeePositionController extends Controller { dataMaster.isSit = requestBody.isSit; dataMaster.current_holderId = requestBody.profileId; + dataMaster.lastUpdatedAt = new Date(); // dataMaster.next_holderId = requestBody.profileId; await this.employeePosMasterRepository.save(dataMaster); @@ -2394,7 +2399,10 @@ export class EmployeePositionController extends Controller { orgRevisionId: posMaster.orgRevisionId, }, }); - if (posMasterOld != null) posMasterOld.current_holderId = null; + if (posMasterOld != null) { + posMasterOld.current_holderId = null; + posMasterOld.lastUpdatedAt = new Date(); + } // if (posMasterOld != null) posMasterOld.next_holderId = null; const positionOld = await this.employeePositionRepository.findOne({ @@ -2429,6 +2437,7 @@ export class EmployeePositionController extends Controller { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลทะเบียนประวัตินี้"); posMaster.current_holderId = body.profileId; + posMaster.lastUpdatedAt = new Date(); // posMaster.next_holderId = body.profileId; if (posMasterOld != null) await this.employeePosMasterRepository.save(posMasterOld); await this.employeePosMasterRepository.save(posMaster); diff --git a/src/controllers/EmployeeTempPositionController.ts b/src/controllers/EmployeeTempPositionController.ts index a7f875a1..7ad6b9c7 100644 --- a/src/controllers/EmployeeTempPositionController.ts +++ b/src/controllers/EmployeeTempPositionController.ts @@ -2001,6 +2001,7 @@ export class EmployeeTempPositionController extends Controller { dataMaster.isSit = requestBody.isSit; dataMaster.current_holderId = requestBody.profileId; + dataMaster.lastUpdatedAt = new Date(); // dataMaster.next_holderId = requestBody.profileId; await this.employeeTempPosMasterRepository.save(dataMaster); @@ -2137,7 +2138,10 @@ export class EmployeeTempPositionController extends Controller { orgRevisionId: posMaster.orgRevisionId, }, }); - if (posMasterOld != null) posMasterOld.current_holderId = null; + if (posMasterOld != null) { + posMasterOld.current_holderId = null; + posMasterOld.lastUpdatedAt = new Date(); + } // if (posMasterOld != null) posMasterOld.next_holderId = null; const positionOld = await this.employeePositionRepository.findOne({ @@ -2172,6 +2176,7 @@ export class EmployeeTempPositionController extends Controller { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลทะเบียนประวัตินี้"); posMaster.current_holderId = body.profileId; + posMaster.lastUpdatedAt = new Date(); // posMaster.next_holderId = body.profileId; if (posMasterOld != null) await this.employeeTempPosMasterRepository.save(posMasterOld); await this.employeeTempPosMasterRepository.save(posMaster); diff --git a/src/controllers/OrgRootController.ts b/src/controllers/OrgRootController.ts index 9af60c20..9e6e428f 100644 --- a/src/controllers/OrgRootController.ts +++ b/src/controllers/OrgRootController.ts @@ -340,7 +340,7 @@ export class OrgRootController extends Controller { const before = structuredClone(orgRoot); orgRoot.lastUpdateUserId = request.user.sub; orgRoot.lastUpdateFullName = request.user.name; - orgRoot.lastUpdatedAt = new Date(); + // orgRoot.lastUpdatedAt = new Date(); this.orgRootRepository.merge(orgRoot, { ...requestBody, DEPARTMENT_CODE: requestBody.DEPARTMENT_CODE != null ? requestBody.DEPARTMENT_CODE : _null, diff --git a/src/controllers/PositionController.ts b/src/controllers/PositionController.ts index c3cb0930..ee43c5a5 100644 --- a/src/controllers/PositionController.ts +++ b/src/controllers/PositionController.ts @@ -1431,13 +1431,7 @@ export class PositionController extends Controller { @Get("position/{id}") async detailPosition(@Path() id: string) { const posMaster = await this.posMasterRepository.findOne({ - relations: [ - "orgRoot", - "orgChild1", - "orgChild2", - "orgChild3", - "orgChild4", - ], + relations: ["orgRoot", "orgChild1", "orgChild2", "orgChild3", "orgChild4"], where: { id }, }); if (!posMaster) { @@ -1474,7 +1468,7 @@ export class PositionController extends Controller { posMaster.orgChild3Id == null ) { shortName = posMaster.orgRoot.orgRootShortName; - orgId = posMaster.orgRootId; + orgId = posMaster.orgRootId; } else if ( posMaster.orgRootId !== null && posMaster.orgChild1Id !== null && @@ -1482,7 +1476,7 @@ export class PositionController extends Controller { posMaster.orgChild3Id == null ) { shortName = posMaster.orgChild1.orgChild1ShortName; - orgId = posMaster.orgChild1Id; + orgId = posMaster.orgChild1Id; } else if ( posMaster.orgRootId !== null && posMaster.orgChild1Id !== null && @@ -1490,7 +1484,7 @@ export class PositionController extends Controller { posMaster.orgChild3Id == null ) { shortName = posMaster.orgChild2.orgChild2ShortName; - orgId = posMaster.orgChild2Id; + orgId = posMaster.orgChild2Id; } else if ( posMaster.orgRootId !== null && posMaster.orgChild1Id !== null && @@ -1498,7 +1492,7 @@ export class PositionController extends Controller { posMaster.orgChild3Id !== null ) { shortName = posMaster.orgChild3.orgChild3ShortName; - orgId = posMaster.orgChild3Id; + orgId = posMaster.orgChild3Id; } else if ( posMaster.orgRootId !== null && posMaster.orgChild1Id !== null && @@ -1506,7 +1500,7 @@ export class PositionController extends Controller { posMaster.orgChild3Id !== null ) { shortName = posMaster.orgChild4.orgChild4ShortName; - orgId = posMaster.orgChild4Id; + orgId = posMaster.orgChild4Id; } const positions = await this.positionRepository.find({ where: { posMasterId: posMaster.id }, @@ -3596,6 +3590,7 @@ export class PositionController extends Controller { const before = null; dataMaster.isSit = requestBody.isSit; dataMaster.next_holderId = requestBody.profileId; + dataMaster.lastUpdatedAt = new Date(); //add on dataMaster.conditionReason = _null; dataMaster.isCondition = false; @@ -4736,7 +4731,10 @@ export class PositionController extends Controller { orgRevisionId: posMaster.orgRevisionId, }, }); - if (posMasterOld != null) posMasterOld.current_holderId = null; + if (posMasterOld != null) { + posMasterOld.current_holderId = null; + posMasterOld.lastUpdatedAt = new Date(); + } const positionOld = await this.positionRepository.findOne({ where: { @@ -4770,6 +4768,7 @@ export class PositionController extends Controller { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลทะเบียนประวัตินี้"); posMaster.current_holderId = body.profileId; + posMaster.lastUpdatedAt = new Date(); const _null: any = null; posMaster.conditionReason = _null; posMaster.isCondition = false; @@ -5323,6 +5322,7 @@ export class PositionController extends Controller { if (!profile) throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลผู้ใช้งาน"); posMaster.next_holderId = requestBody.profileId; + posMaster.lastUpdatedAt = new Date(); posMaster.lastUpdateUserId = request.user.sub; posMaster.lastUpdateFullName = request.user.name; posMaster.lastUpdatedAt = new Date(); diff --git a/src/controllers/ProfileController.ts b/src/controllers/ProfileController.ts index a8fba726..8a99f81a 100644 --- a/src/controllers/ProfileController.ts +++ b/src/controllers/ProfileController.ts @@ -1321,7 +1321,7 @@ export class ProfileController extends Controller { "profileLeave.dateLeaveEnd AS dateLeaveEnd", "profileLeave.leaveDays AS leaveDays", "profileLeave.reason AS reason", - "leaveType.name as name" + "leaveType.name as name", ]) .where("profileLeave.profileId = :profileId", { profileId: id }) .andWhere("leaveType.code IN (:...codes)", { codes: ["LV-008", "LV-009", "LV-010"] }) @@ -1331,10 +1331,12 @@ export class ProfileController extends Controller { const leaves2 = leave2_raw.length > 0 ? leave2_raw.map((item) => ({ - date: item.dateLeaveStart && item.dateLeaveEnd - ? Extension.ToThaiNumber(Extension.ToThaiFullDate2(item.dateLeaveStart)) + " - " - + Extension.ToThaiNumber(Extension.ToThaiFullDate2(item.dateLeaveEnd)) - : "-", + date: + item.dateLeaveStart && item.dateLeaveEnd + ? Extension.ToThaiNumber(Extension.ToThaiFullDate2(item.dateLeaveStart)) + + " - " + + Extension.ToThaiNumber(Extension.ToThaiFullDate2(item.dateLeaveEnd)) + : "-", type: item.name || "-", leaveDays: item.leaveDays ? Extension.ToThaiNumber(item.leaveDays.toString()) : "-", reason: item.reason || "-", @@ -1684,24 +1686,22 @@ export class ProfileController extends Controller { ) : ""; - let portfolios:any - await new CallAPI() - .GetData(req, `/development/portfolio/kk1/${profiles?.keycloak}`) - .then((x) => { - portfolios = x; - }) - .catch(() => {}); + let portfolios: any; + await new CallAPI() + .GetData(req, `/development/portfolio/kk1/${profiles?.keycloak}`) + .then((x) => { + portfolios = x; + }) + .catch(() => {}); if (!portfolios) { - portfolios = [{ name: "-", year: "-" }] - } - else { - portfolios = portfolios.map((x:any) => ({ + portfolios = [{ name: "-", year: "-" }]; + } else { + portfolios = portfolios.map((x: any) => ({ name: x.name ? Extension.ToThaiNumber(x.name) : "-", - year: x.year ? Extension.ToThaiNumber(x.year.toString()) : "-" - })) + year: x.year ? Extension.ToThaiNumber(x.year.toString()) : "-", + })); } - - + const data = { fullName: `${profiles?.prefix}${profiles?.firstName} ${profiles?.lastName}`, prefix: profiles?.prefix != null ? profiles.prefix : "", @@ -1855,7 +1855,7 @@ export class ProfileController extends Controller { assessments, profileAbility, otherIncome, - portfolios + portfolios, }; return new HttpSuccess({ @@ -2855,7 +2855,8 @@ export class ProfileController extends Controller { }, }); if (!posMaster) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลการครองตำแหน่ง"); - posMaster.current_holderId = ""; + posMaster.current_holderId = null; + posMaster.lastUpdatedAt = new Date(); // return new HttpSuccess({ data: [], total: 0 }); } else if ((posMaster?.current_holder?.posLevel?.posLevelAuthority ?? null) == "GOVERNOR") { return new HttpSuccess({ data: [], total: 0 });