From 16622b47686b00afa978e2d8fc1beffb223cf7dd Mon Sep 17 00:00:00 2001 From: mamoss <> Date: Wed, 3 Sep 2025 23:50:45 +0700 Subject: [PATCH] =?UTF-8?q?=E0=B9=80=E0=B8=81=E0=B9=87=E0=B8=9A=E0=B8=9B?= =?UTF-8?q?=E0=B8=A3=E0=B8=B0=E0=B8=A7=E0=B8=B1=E0=B8=95=E0=B8=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/CommandController.ts | 15 +++++++++++---- src/controllers/EmployeePositionController.ts | 10 ++++++---- src/controllers/EmployeeTempPositionController.ts | 7 +++++-- src/controllers/PositionController.ts | 8 ++++++-- 4 files changed, 28 insertions(+), 12 deletions(-) diff --git a/src/controllers/CommandController.ts b/src/controllers/CommandController.ts index ca2352c5..be14db4c 100644 --- a/src/controllers/CommandController.ts +++ b/src/controllers/CommandController.ts @@ -3171,7 +3171,6 @@ export class CommandController extends Controller { await CreatePosMasterHistoryOfficer(posMasterOld.id, req); } await this.posMasterRepository.save(posMaster); - await CreatePosMasterHistoryOfficer(posMaster.id, req); const positionNew = await this.positionRepository.findOne({ where: { @@ -3189,6 +3188,7 @@ export class CommandController extends Controller { await this.profileRepository.save(profile); await this.positionRepository.save(positionNew); } + await CreatePosMasterHistoryOfficer(posMaster.id, req); }), ); @@ -3363,7 +3363,6 @@ export class CommandController extends Controller { await CreatePosMasterHistoryEmployee(posMasterOld.id, req); } await this.employeePosMasterRepository.save(posMaster); - await CreatePosMasterHistoryEmployee(posMaster.id, req); const positionNew = await this.employeePositionRepository.findOne({ where: { id: item.positionId, @@ -3382,6 +3381,7 @@ export class CommandController extends Controller { await this.profileEmployeeRepository.save(profile); await this.employeePositionRepository.save(positionNew); } + await CreatePosMasterHistoryEmployee(posMaster.id, req); }), ); @@ -3592,7 +3592,6 @@ export class CommandController extends Controller { posMaster.conditionReason = _null; posMaster.isCondition = false; await this.posMasterRepository.save(posMaster); - await CreatePosMasterHistoryOfficer(posMaster.id, req); const positionNew = await this.positionRepository.findOne({ where: { posMasterId: posMaster.id, @@ -3602,6 +3601,7 @@ export class CommandController extends Controller { positionNew.positionIsSelected = true; await this.positionRepository.save(positionNew, { data: req }); } + await CreatePosMasterHistoryOfficer(posMaster.id, req); } const newMapProfileSalary = { profileId: profile.id, @@ -6055,7 +6055,6 @@ export class CommandController extends Controller { await CreatePosMasterHistoryOfficer(posMasterOld.id, req); } await this.posMasterRepository.save(posMaster); - await CreatePosMasterHistoryOfficer(posMaster.id, req); const positionNew = await this.positionRepository.findOne({ where: { @@ -6073,6 +6072,7 @@ export class CommandController extends Controller { setLogDataDiff(req, { before, after: profile }); await this.positionRepository.save(positionNew, { data: req }); } + await CreatePosMasterHistoryOfficer(posMaster.id, req); } // Insignia if (_oldInsigniaIds.length > 0) { @@ -6470,6 +6470,12 @@ export class CommandController extends Controller { })); await this.employeePositionRepository.save(clearTempPosition); } + await Promise.all( + clsTempPosmaster.map( + async (posMasterTemp) => + await CreatePosMasterHistoryEmployeeTemp(posMasterTemp.id, req), + ), + ); } const positionNew = await this.employeePositionRepository.findOne({ @@ -6569,6 +6575,7 @@ export class CommandController extends Controller { }); await this.profileEmployeeRepository.save(profile); await this.employeePositionRepository.save(positionNew); + await CreatePosMasterHistoryEmployee(posMaster.id, req); //ลบออกคนออกจากโครงสร้างลูกจ้างชั่วคราว const posMasterTemp = await this.employeeTempPosMasterRepository.findOne({ where: { diff --git a/src/controllers/EmployeePositionController.ts b/src/controllers/EmployeePositionController.ts index 632261e0..b0091494 100644 --- a/src/controllers/EmployeePositionController.ts +++ b/src/controllers/EmployeePositionController.ts @@ -39,8 +39,8 @@ import { RequestWithUser } from "../middlewares/user"; import permission from "../interfaces/permission"; import { setLogDataDiff } from "../interfaces/utils"; import { - CreatePosMasterHistoryOfficer, CreatePosMasterHistoryEmployee, + CreatePosMasterHistoryOfficer, } from "../services/PositionService"; import { PosMasterEmployeeHistory } from "../entities/PosMasterEmployeeHistory"; @Route("api/v1/org/employee/pos") @@ -2288,7 +2288,7 @@ export class EmployeePositionController extends Controller { await new permission().PermissionDelete(request, "SYS_ORG_EMP"); const dataMaster = await this.employeePosMasterRepository.findOne({ where: { id: id }, - relations: ["positions"], + relations: ["positions", "orgRevision"], }); if (!dataMaster) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลตำแหน่งนี้"); @@ -2321,7 +2321,9 @@ export class EmployeePositionController extends Controller { positionIsSelected: false, }); }); - + if (dataMaster.orgRevision.orgRevisionIsCurrent) { + await CreatePosMasterHistoryEmployee(dataMaster.id, request); + } return new HttpSuccess(); } @@ -2451,7 +2453,6 @@ export class EmployeePositionController extends Controller { await CreatePosMasterHistoryEmployee(posMasterOld.id, request); } await this.employeePosMasterRepository.save(posMaster); - await CreatePosMasterHistoryEmployee(posMaster.id, request); const positionNew = await this.employeePositionRepository.findOne({ where: { @@ -2472,6 +2473,7 @@ export class EmployeePositionController extends Controller { await this.profileRepository.save(profile); await this.employeePositionRepository.save(positionNew); } + await CreatePosMasterHistoryEmployee(posMaster.id, request); return new HttpSuccess(); } diff --git a/src/controllers/EmployeeTempPositionController.ts b/src/controllers/EmployeeTempPositionController.ts index 5d304de0..7f526c8d 100644 --- a/src/controllers/EmployeeTempPositionController.ts +++ b/src/controllers/EmployeeTempPositionController.ts @@ -2024,7 +2024,7 @@ export class EmployeeTempPositionController extends Controller { await new permission().PermissionDelete(request, "SYS_ORG_TEMP"); const dataMaster = await this.employeeTempPosMasterRepository.findOne({ where: { id: id }, - relations: ["positions"], + relations: ["positions", "orgRevision"], }); if (!dataMaster) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลตำแหน่งนี้"); @@ -2057,6 +2057,9 @@ export class EmployeeTempPositionController extends Controller { positionIsSelected: false, }); }); + if (dataMaster.orgRevision.orgRevisionIsCurrent) { + await CreatePosMasterHistoryEmployeeTemp(dataMaster.id, request); + } return new HttpSuccess(); } @@ -2187,7 +2190,6 @@ export class EmployeeTempPositionController extends Controller { await CreatePosMasterHistoryEmployeeTemp(posMasterOld.id, request); } await this.employeeTempPosMasterRepository.save(posMaster); - await CreatePosMasterHistoryEmployeeTemp(posMaster.id, request); const positionNew = await this.employeePositionRepository.findOne({ where: { @@ -2208,6 +2210,7 @@ export class EmployeeTempPositionController extends Controller { await this.profileRepository.save(profile); await this.employeePositionRepository.save(positionNew); } + await CreatePosMasterHistoryEmployeeTemp(posMaster.id, request); return new HttpSuccess(); } diff --git a/src/controllers/PositionController.ts b/src/controllers/PositionController.ts index e63e4f64..7ba51726 100644 --- a/src/controllers/PositionController.ts +++ b/src/controllers/PositionController.ts @@ -3676,7 +3676,7 @@ export class PositionController extends Controller { await new permission().PermissionDelete(request, "SYS_ORG"); const dataMaster = await this.posMasterRepository.findOne({ where: { id: id }, - relations: ["positions"], + relations: ["positions", "orgRevision"], }); if (!dataMaster) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลตำแหน่งนี้"); @@ -3697,6 +3697,9 @@ export class PositionController extends Controller { positionIsSelected: false, }); }); + if (dataMaster.orgRevision.orgRevisionIsCurrent) { + await CreatePosMasterHistoryOfficer(dataMaster.id, request); + } // //เช็คถ้า revision ปัจจุบันให้ปั๊มที่ profile // const chkRevision = await this.orgRevisionRepository.findOne({ // where: { id: dataMaster.orgRevisionId }, @@ -4924,7 +4927,6 @@ export class PositionController extends Controller { await CreatePosMasterHistoryOfficer(posMasterOld.id, request); } await this.posMasterRepository.save(posMaster); - await CreatePosMasterHistoryOfficer(posMaster.id, request); const positionNew = await this.positionRepository.findOne({ where: { @@ -4940,6 +4942,8 @@ export class PositionController extends Controller { await this.profileRepository.save(profile); await this.positionRepository.save(positionNew); } + await CreatePosMasterHistoryOfficer(posMaster.id, request); + return new HttpSuccess(); }