From 2629ae87a3e17ee32618e3f7b3452197387c270b Mon Sep 17 00:00:00 2001 From: Bright Date: Thu, 21 Aug 2025 10:11:45 +0700 Subject: [PATCH] =?UTF-8?q?=E0=B9=80=E0=B8=9E=E0=B8=B4=E0=B9=88=E0=B8=A1?= =?UTF-8?q?=E0=B9=81=E0=B8=A5=E0=B8=B0=E0=B8=A5=E0=B8=9A=E0=B8=84=E0=B8=99?= =?UTF-8?q?=E0=B8=84=E0=B8=A3=E0=B8=AD=E0=B8=87=E0=B8=97=E0=B8=B5=E0=B9=88?= =?UTF-8?q?=E0=B9=82=E0=B8=84=E0=B8=A3=E0=B8=87=E0=B8=AA=E0=B8=A3=E0=B9=89?= =?UTF-8?q?=E0=B8=B2=E0=B8=87=E0=B8=9B=E0=B8=B1=E0=B8=88=E0=B8=88=E0=B8=B8?= =?UTF-8?q?=E0=B8=9A=E0=B8=B1=E0=B8=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/PositionController.ts | 52 +++++++++++++++++++++++++-- 1 file changed, 50 insertions(+), 2 deletions(-) diff --git a/src/controllers/PositionController.ts b/src/controllers/PositionController.ts index ee43c5a5..f9a5e298 100644 --- a/src/controllers/PositionController.ts +++ b/src/controllers/PositionController.ts @@ -3589,11 +3589,38 @@ export class PositionController extends Controller { const _null: any = null; const before = null; dataMaster.isSit = requestBody.isSit; - dataMaster.next_holderId = requestBody.profileId; + // dataMaster.next_holderId = requestBody.profileId; dataMaster.lastUpdatedAt = new Date(); //add on dataMaster.conditionReason = _null; dataMaster.isCondition = false; + //เช็คถ้า revision ปัจจุบันให้ปั๊มที่ profile + const chkRevision = await this.orgRevisionRepository.findOne({ + where: { id: dataMaster.orgRevisionId }, + }); + if (chkRevision?.orgRevisionIsCurrent) { + const _profile = await this.profileRepository.findOne({ + where: { id: requestBody.profileId } + }); + if (_profile) { + let _position = await this.positionRepository.findOne({ + where: { id: requestBody.position, posMasterId: requestBody.posMaster } + }); + if (_position) { + _profile.position = _position.positionName + _profile.posTypeId = _position.posTypeId + _profile.posLevelId = _position.posLevelId + await this.profileRepository.save(_profile); + setLogDataDiff(request, { before, after: _profile }); + } + } + dataMaster.current_holderId = requestBody.profileId; + dataMaster.next_holderId = _null; + } + else { + dataMaster.next_holderId = requestBody.profileId; + dataMaster.current_holderId = _null; + } await this.posMasterRepository.save(dataMaster, { data: request }); setLogDataDiff(request, { before, after: dataMaster }); @@ -3617,6 +3644,10 @@ export class PositionController extends Controller { if (!dataMaster) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลตำแหน่งนี้"); } + let _profileId: string = "" + if (dataMaster?.current_holderId) { + _profileId = dataMaster?.current_holderId; + } await this.posMasterRepository.update(id, { isSit: false, next_holderId: null, @@ -3629,7 +3660,24 @@ export class PositionController extends Controller { positionIsSelected: false, }); }); - + //เช็คถ้า revision ปัจจุบันให้ปั๊มที่ profile + const chkRevision = await this.orgRevisionRepository.findOne({ + where: { id: dataMaster.orgRevisionId }, + }); + if (chkRevision?.orgRevisionIsCurrent) { + const _profile = await this.profileRepository.findOne({ + where: { id: _profileId } + }); + if (_profile) { + const _null: any = null; + const before = null; + _profile.position = _null + _profile.posTypeId = _null + _profile.posLevelId = _null + await this.profileRepository.save(_profile); + setLogDataDiff(request, { before, after: _profile }); + } + } return new HttpSuccess(); }