diff --git a/src/controllers/EmployeePositionController.ts b/src/controllers/EmployeePositionController.ts index 420eb12d..6011a253 100644 --- a/src/controllers/EmployeePositionController.ts +++ b/src/controllers/EmployeePositionController.ts @@ -2200,6 +2200,31 @@ export class EmployeePositionController extends Controller { if (posMasterOld != null) posMasterOld.current_holderId = null; if (posMasterOld != null) posMasterOld.next_holderId = null; + const positionOld = await this.employeePositionRepository.findOne({ + where: { + posMasterId: posMasterOld?.id, + positionIsSelected: true + } + }) + if (positionOld != null) { + positionOld.positionIsSelected = false + await this.employeePositionRepository.save(positionOld); + } + + const checkPosition = await this.employeePositionRepository.find({ + where: { + posMasterId: body.posmasterId, + positionIsSelected: true + } + }) + if (checkPosition.length > 0) { + const clearPosition = checkPosition.map(positions => ({ + ...positions, + positionIsSelected: false + })); + await this.employeePositionRepository.save(clearPosition); + } + const profile = await this.profileRepository.findOne({ where: { id: body.profileId }, }); @@ -2210,6 +2235,17 @@ export class EmployeePositionController extends Controller { posMaster.next_holderId = body.profileId; if (posMasterOld != null) await this.employeePosMasterRepository.save(posMasterOld); await this.employeePosMasterRepository.save(posMaster); + + const positionNew = await this.employeePositionRepository.findOne({ + where: { + id: body.positionId, + posMasterId: body.posmasterId + } + }) + if(positionNew != null) { + positionNew.positionIsSelected = true + await this.employeePositionRepository.save(positionNew); + } return new HttpSuccess(); } } diff --git a/src/controllers/PositionController.ts b/src/controllers/PositionController.ts index 040c7bd1..c98dd71e 100644 --- a/src/controllers/PositionController.ts +++ b/src/controllers/PositionController.ts @@ -3373,6 +3373,31 @@ export class PositionController extends Controller { }, }); if (posMasterOld != null) posMasterOld.current_holderId = null; + + const positionOld = await this.positionRepository.findOne({ + where: { + posMasterId: posMasterOld?.id, + positionIsSelected: true + } + }) + if (positionOld != null) { + positionOld.positionIsSelected = false + await this.positionRepository.save(positionOld); + } + + const checkPosition = await this.positionRepository.find({ + where: { + posMasterId: body.posmasterId, + positionIsSelected: true + } + }) + if (checkPosition.length > 0) { + const clearPosition = checkPosition.map(positions => ({ + ...positions, + positionIsSelected: false + })); + await this.positionRepository.save(clearPosition); + } const profile = await this.profileRepository.findOne({ where: { id: body.profileId }, @@ -3383,6 +3408,17 @@ export class PositionController extends Controller { posMaster.current_holderId = body.profileId; if (posMasterOld != null) await this.posMasterRepository.save(posMasterOld); await this.posMasterRepository.save(posMaster); + + const positionNew = await this.positionRepository.findOne({ + where: { + id: body.positionId, + posMasterId: body.posmasterId + } + }) + if(positionNew != null) { + positionNew.positionIsSelected = true + await this.positionRepository.save(positionNew); + } return new HttpSuccess(); } }