diff --git a/src/controllers/EmployeePositionController.ts b/src/controllers/EmployeePositionController.ts index d3d70b0c..4b6ef89f 100644 --- a/src/controllers/EmployeePositionController.ts +++ b/src/controllers/EmployeePositionController.ts @@ -888,6 +888,31 @@ export class EmployeePositionController extends Controller { await this.employeePositionRepository.save(position, { data: request }); }), ); + + if (posMaster.current_holderId != null) { + const profile = await this.profileRepository.findOne({ + where: { + id: posMaster.current_holderId, + }, + }); + if (profile != null) { + const positionNew = await this.employeePositionRepository.findOne({ + where: { + // positionIsSelected: true, + posMasterId: posMaster.id, + }, + }); + if (positionNew != null) { + profile.posLevelId = positionNew.posLevelId; + profile.posTypeId = positionNew.posTypeId; + profile.position = positionNew.positionName; + profile.employeeOc = posMaster?.orgRoot?.orgRootName ?? null; + profile.positionEmployeePositionId = positionNew.positionName; + + await this.profileRepository.save(profile); + } + } + } return new HttpSuccess(posMaster.id); } @@ -2242,6 +2267,23 @@ export class EmployeePositionController extends Controller { if (!dataMaster) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลตำแหน่งนี้"); } + if (dataMaster.current_holderId != null) { + const profile = await this.profileRepository.findOne({ + where: { + id: dataMaster.current_holderId, + }, + }); + const _null: any = null; + if (profile != null) { + profile.posLevelId = _null; + profile.posTypeId = _null; + profile.position = _null; + profile.employeeOc = _null; + profile.positionEmployeePositionId = _null; + await this.profileRepository.save(profile); + } + } + await this.employeePosMasterRepository.update(id, { isSit: false, next_holderId: null, diff --git a/src/controllers/EmployeeTempPositionController.ts b/src/controllers/EmployeeTempPositionController.ts index 46939932..b551fa95 100644 --- a/src/controllers/EmployeeTempPositionController.ts +++ b/src/controllers/EmployeeTempPositionController.ts @@ -689,6 +689,31 @@ export class EmployeeTempPositionController extends Controller { await this.employeePositionRepository.save(position, { data: request }); }), ); + + if (posMaster.current_holderId != null) { + const profile = await this.profileRepository.findOne({ + where: { + id: posMaster.current_holderId, + }, + }); + if (profile != null) { + const positionNew = await this.employeePositionRepository.findOne({ + where: { + // positionIsSelected: true, + posMasterId: posMaster.id, + }, + }); + if (positionNew != null) { + profile.posLevelId = positionNew.posLevelId; + profile.posTypeId = positionNew.posTypeId; + profile.position = positionNew.positionName; + profile.employeeOc = posMaster?.orgRoot?.orgRootName ?? null; + profile.positionEmployeePositionId = positionNew.positionName; + + await this.profileRepository.save(profile); + } + } + } return new HttpSuccess(posMaster.id); } @@ -1966,6 +1991,23 @@ export class EmployeeTempPositionController extends Controller { if (!dataMaster) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลตำแหน่งนี้"); } + if (dataMaster.current_holderId != null) { + const profile = await this.profileRepository.findOne({ + where: { + id: dataMaster.current_holderId, + }, + }); + const _null: any = null; + if (profile != null) { + profile.posLevelId = _null; + profile.posTypeId = _null; + profile.position = _null; + profile.employeeOc = _null; + profile.positionEmployeePositionId = _null; + await this.profileRepository.save(profile); + } + } + await this.employeeTempPosMasterRepository.update(id, { isSit: false, next_holderId: null,