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(); }