diff --git a/src/controllers/EmployeePositionController.ts b/src/controllers/EmployeePositionController.ts index ecf11619..5809841c 100644 --- a/src/controllers/EmployeePositionController.ts +++ b/src/controllers/EmployeePositionController.ts @@ -39,8 +39,7 @@ import { RequestWithUser } from "../middlewares/user"; import permission from "../interfaces/permission"; import { setLogDataDiff } from "../interfaces/utils"; import { - CreatePosMasterHistoryEmployee, - CreatePosMasterHistoryOfficer, + CreatePosMasterHistoryEmployee } from "../services/PositionService"; import { PosMasterEmployeeHistory } from "../entities/PosMasterEmployeeHistory"; import { KeycloakAttributeService } from "../services/KeycloakAttributeService"; @@ -2377,26 +2376,47 @@ export class EmployeePositionController extends Controller { dataMaster.positions.forEach(async (position) => { if (position.id === requestBody.position) { position.positionIsSelected = true; - const profile = await this.profileRepository.findOne({ - where: { id: requestBody.profileId }, - }); - if (profile != null) { - const _null: any = null; - profile.posLevelId = position?.posLevelId ?? _null; - profile.posTypeId = position?.posTypeId ?? _null; - profile.position = position?.positionName ?? _null; - await this.profileRepository.save(profile); - } } else { position.positionIsSelected = false; } await this.employeePositionRepository.save(position); }); - + const _null: any = null; + const before = null; dataMaster.isSit = requestBody.isSit; - dataMaster.current_holderId = requestBody.profileId; dataMaster.lastUpdatedAt = new Date(); - // dataMaster.next_holderId = requestBody.profileId; + + //เช็คถ้า 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.employeePositionRepository.findOne({ + where: { id: requestBody.position, posMasterId: requestBody.posMaster }, + }); + if (_position) { + + // ถ้าไม่ใช่ตำแหน่งนั่งทับ (isSit = false) ถึงจะอัพเดทตำแหน่งในทะเบียนประวัติ + if (!dataMaster.isSit) { + _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.employeePosMasterRepository.save(dataMaster); await CreatePosMasterHistoryEmployee(dataMaster.id, request); diff --git a/src/entities/ProfileEmployee.ts b/src/entities/ProfileEmployee.ts index 11c2159b..45f5e159 100644 --- a/src/entities/ProfileEmployee.ts +++ b/src/entities/ProfileEmployee.ts @@ -1014,7 +1014,7 @@ export class UpdateInformationProfileEmployee { } export type UpdateProfileEmployee = { - prefix: string; + prefix?: string | null; rank?: string | null; firstName: string; lastName: string;