#2453
All checks were successful
Build & Deploy on Dev / build (push) Successful in 1m16s

This commit is contained in:
Adisak 2026-05-01 12:08:41 +07:00
parent ef279df452
commit cba5991097

View file

@ -3352,6 +3352,41 @@ export class PositionController extends Controller {
posMaster.lastUpdatedAt = new Date();
await this.posMasterRepository.save(posMaster, { data: request });
setLogDataDiff(request, { before, after: posMaster });
// อัพเดท org และ posMasterNo ใน profile ตลอดไม่ต้องดัก isSit
if (posMaster.current_holderId) {
const orgRevision = await this.orgRevisionRepository.findOne({
where: { id: posMaster.orgRevisionId },
});
if (orgRevision?.orgRevisionIsCurrent) {
const pmWithOrg = await this.posMasterRepository.findOne({
where: { id: posMaster.id },
relations: ["orgRoot", "orgChild1", "orgChild2", "orgChild3", "orgChild4", "positions", "positions.posExecutive"],
});
const _profile = await this.profileRepository.findOne({
where: { id: posMaster.current_holderId },
});
if (_profile && pmWithOrg) {
const _null: any = null;
_profile.posMasterNo = getPosMasterNo(pmWithOrg) ?? _null;
_profile.org = getOrgFullName(pmWithOrg) ?? _null;
// ถ้าไม่ใช่ตำแหน่งนั่งทับ (isSit = false) ถึงจะอัพเดทตำแหน่งในทะเบียนประวัติ
if (!pmWithOrg.isSit) {
const selectedPos = (pmWithOrg as any).positions?.find((p: any) => p.positionIsSelected === true);
if (selectedPos) {
_profile.position = selectedPos.positionName ?? _null;
_profile.posTypeId = selectedPos.posTypeId ?? _null;
_profile.posLevelId = selectedPos.posLevelId ?? _null;
_profile.positionField = selectedPos.positionField ?? _null;
_profile.posExecutive = (selectedPos as any).posExecutive?.posExecutiveName ?? _null;
_profile.positionArea = selectedPos.positionArea ?? _null;
_profile.positionExecutiveField = selectedPos.positionExecutiveField ?? _null;
}
}
await this.profileRepository.save(_profile);
}
}
}
}
}),
);