diff --git a/src/controllers/CommandController.ts b/src/controllers/CommandController.ts index d5a05800..ca2352c5 100644 --- a/src/controllers/CommandController.ts +++ b/src/controllers/CommandController.ts @@ -93,6 +93,7 @@ import { Gender } from "../entities/Gender"; import { ProfileAvatar } from "../entities/ProfileAvatar"; import { CreatePosMasterHistoryEmployee, + CreatePosMasterHistoryEmployeeTemp, CreatePosMasterHistoryOfficer, } from "../services/PositionService"; @Route("api/v1/org/command") @@ -2175,8 +2176,7 @@ export class CommandController extends Controller { command.isDraft = true; command.isSign = true; command.status = "PENDING"; - } - else { + } else { command.status = "NEW"; } command.issue = commandType.name; @@ -3171,6 +3171,7 @@ export class CommandController extends Controller { await CreatePosMasterHistoryOfficer(posMasterOld.id, req); } await this.posMasterRepository.save(posMaster); + await CreatePosMasterHistoryOfficer(posMaster.id, req); const positionNew = await this.positionRepository.findOne({ where: { @@ -3188,7 +3189,6 @@ export class CommandController extends Controller { await this.profileRepository.save(profile); await this.positionRepository.save(positionNew); } - await CreatePosMasterHistoryOfficer(posMaster.id, req); }), ); @@ -3363,6 +3363,7 @@ export class CommandController extends Controller { await CreatePosMasterHistoryEmployee(posMasterOld.id, req); } await this.employeePosMasterRepository.save(posMaster); + await CreatePosMasterHistoryEmployee(posMaster.id, req); const positionNew = await this.employeePositionRepository.findOne({ where: { id: item.positionId, @@ -3381,7 +3382,6 @@ export class CommandController extends Controller { await this.profileEmployeeRepository.save(profile); await this.employeePositionRepository.save(positionNew); } - await CreatePosMasterHistoryEmployee(posMaster.id, req); }), ); @@ -6055,7 +6055,8 @@ export class CommandController extends Controller { await CreatePosMasterHistoryOfficer(posMasterOld.id, req); } await this.posMasterRepository.save(posMaster); - + await CreatePosMasterHistoryOfficer(posMaster.id, req); + const positionNew = await this.positionRepository.findOne({ where: { id: item.bodyPosition.positionId, @@ -6072,7 +6073,6 @@ export class CommandController extends Controller { setLogDataDiff(req, { before, after: profile }); await this.positionRepository.save(positionNew, { data: req }); } - await CreatePosMasterHistoryOfficer(posMaster.id, req); } // Insignia if (_oldInsigniaIds.length > 0) { @@ -6440,6 +6440,7 @@ export class CommandController extends Controller { await CreatePosMasterHistoryEmployee(posMasterOld.id, req); } await this.employeePosMasterRepository.save(posMaster); + await CreatePosMasterHistoryEmployee(posMaster.id, req); const clsTempPosmaster = await this.employeeTempPosMasterRepository.find({ where: { @@ -6568,7 +6569,6 @@ export class CommandController extends Controller { }); await this.profileEmployeeRepository.save(profile); await this.employeePositionRepository.save(positionNew); - await CreatePosMasterHistoryEmployee(posMaster.id, req); //ลบออกคนออกจากโครงสร้างลูกจ้างชั่วคราว const posMasterTemp = await this.employeeTempPosMasterRepository.findOne({ where: { @@ -6580,6 +6580,7 @@ export class CommandController extends Controller { await this.employeeTempPosMasterRepository.update(posMasterTemp.id, { current_holderId: _null, }); + await CreatePosMasterHistoryEmployeeTemp(posMasterTemp.id, req); } } }), diff --git a/src/controllers/EmployeePositionController.ts b/src/controllers/EmployeePositionController.ts index cd6be34f..632261e0 100644 --- a/src/controllers/EmployeePositionController.ts +++ b/src/controllers/EmployeePositionController.ts @@ -2451,6 +2451,7 @@ export class EmployeePositionController extends Controller { await CreatePosMasterHistoryEmployee(posMasterOld.id, request); } await this.employeePosMasterRepository.save(posMaster); + await CreatePosMasterHistoryEmployee(posMaster.id, request); const positionNew = await this.employeePositionRepository.findOne({ where: { @@ -2471,7 +2472,6 @@ export class EmployeePositionController extends Controller { await this.profileRepository.save(profile); await this.employeePositionRepository.save(positionNew); } - await CreatePosMasterHistoryEmployee(posMaster.id, request); return new HttpSuccess(); } diff --git a/src/controllers/EmployeeTempPositionController.ts b/src/controllers/EmployeeTempPositionController.ts index 4242af81..5d304de0 100644 --- a/src/controllers/EmployeeTempPositionController.ts +++ b/src/controllers/EmployeeTempPositionController.ts @@ -2187,6 +2187,7 @@ export class EmployeeTempPositionController extends Controller { await CreatePosMasterHistoryEmployeeTemp(posMasterOld.id, request); } await this.employeeTempPosMasterRepository.save(posMaster); + await CreatePosMasterHistoryEmployeeTemp(posMaster.id, request); const positionNew = await this.employeePositionRepository.findOne({ where: { @@ -2207,7 +2208,6 @@ export class EmployeeTempPositionController extends Controller { await this.profileRepository.save(profile); await this.employeePositionRepository.save(positionNew); } - await CreatePosMasterHistoryEmployeeTemp(posMaster.id, request); return new HttpSuccess(); } diff --git a/src/controllers/PositionController.ts b/src/controllers/PositionController.ts index 9bafbbe7..875f838e 100644 --- a/src/controllers/PositionController.ts +++ b/src/controllers/PositionController.ts @@ -4087,17 +4087,17 @@ export class PositionController extends Controller { }); posLevel = await this.posLevelRepository.find({ where: { - posTypeId: In(posType.map((x: any) => x.id)), - posLevelName: In(["ทรงคุณวุฒิ", "สูง"]) - }, + posTypeId: In(posType.map((x: any) => x.id)), + posLevelName: In(["ทรงคุณวุฒิ", "สูง"]), + }, }); - conditionA = "positions.posTypeId IN (:...posTypeIds) AND positions.posLevelId IN (:...posLevelIds)"; + conditionA = + "positions.posTypeId IN (:...posTypeIds) AND positions.posLevelId IN (:...posLevelIds)"; params = { posTypeIds: posType.map((x: any) => x.id), posLevelIds: posLevel.map((x: any) => x.id), }; - } - else { + } else { posType = await this.posTypeRepository.findOne({ where: { id: String(body.posType) }, }); @@ -4195,13 +4195,13 @@ export class PositionController extends Controller { .andWhere( new Brackets((qb) => { qb.andWhere(typeCondition) - // .andWhere(conditionA == null ? "1=1" : conditionA, { - // posType: posType == null ? `%%` : `${posType.id}`, - // posLevel: posLevel == null ? `%%` : `${posLevel.id}`, - // posTypeRank: posType == null ? 0 : posType.posTypeRank, - // posLevelRank: posLevel == null ? 0 : posLevel.posLevelRank, - // }); - .andWhere(conditionA, params); + // .andWhere(conditionA == null ? "1=1" : conditionA, { + // posType: posType == null ? `%%` : `${posType.id}`, + // posLevel: posLevel == null ? `%%` : `${posLevel.id}`, + // posTypeRank: posType == null ? 0 : posType.posTypeRank, + // posLevelRank: posLevel == null ? 0 : posLevel.posLevelRank, + // }); + .andWhere(conditionA, params); }), ) .orderBy("orgRoot.orgRootOrder", "ASC") @@ -4924,7 +4924,8 @@ export class PositionController extends Controller { await CreatePosMasterHistoryOfficer(posMasterOld.id, request); } await this.posMasterRepository.save(posMaster); - + await CreatePosMasterHistoryOfficer(posMaster.id, request); + const positionNew = await this.positionRepository.findOne({ where: { id: body.positionId, @@ -4939,7 +4940,6 @@ export class PositionController extends Controller { await this.profileRepository.save(profile); await this.positionRepository.save(positionNew); } - await CreatePosMasterHistoryOfficer(posMaster.id, request); return new HttpSuccess(); }