This commit is contained in:
parent
f1c8ecf699
commit
5e52206987
2 changed files with 34 additions and 7 deletions
|
|
@ -66,7 +66,7 @@ import {
|
|||
import { orgStructureCache } from "../utils/OrgStructureCache";
|
||||
import { OrgIdMapping, AllOrgMappings, SavePosMasterHistory } from "../interfaces/OrgMapping";
|
||||
import { OrgPermissionData, NodeLevel } from "../interfaces/OrgTypes";
|
||||
import { formatPosMaster, generateLabelName, filterPosMasters } from "../utils/org-formatting";
|
||||
import { formatPosMaster, generateLabelName, filterPosMasters, getPosMasterNo, getOrgFullName } from "../utils/org-formatting";
|
||||
|
||||
@Route("api/v1/org")
|
||||
@Tags("Organization")
|
||||
|
|
@ -8933,13 +8933,25 @@ export class OrganizationController extends Controller {
|
|||
const draftPosMaster = draftPosMasterMap.get(draftPosMasterId) as any;
|
||||
|
||||
// Collect profile update for the selected position
|
||||
// อัพเดท org และ posMasterNo ตลอดไม่ต้องดัก isSit
|
||||
if (nextHolderId != null && draftPos.positionIsSelected) {
|
||||
const _null: any = null;
|
||||
profileUpdates.set(nextHolderId, {
|
||||
posMasterNo: draftPosMaster ? (getPosMasterNo(draftPosMaster as PosMaster) ?? _null) : _null,
|
||||
org: draftPosMaster ? (getOrgFullName(draftPosMaster as PosMaster) ?? _null) : _null,
|
||||
});
|
||||
}
|
||||
// ถ้าไม่ใช่ตำแหน่งนั่งทับ (isSit = false) ถึงจะอัพเดทตำแหน่งในทะเบียนประวัติ
|
||||
if (nextHolderId != null && draftPos.positionIsSelected && !draftPosMaster?.isSit) {
|
||||
profileUpdates.set(nextHolderId, {
|
||||
position: draftPos.positionName,
|
||||
posTypeId: draftPos.posTypeId,
|
||||
posLevelId: draftPos.posLevelId,
|
||||
});
|
||||
const existing = profileUpdates.get(nextHolderId) || {};
|
||||
existing.position = draftPos.positionName;
|
||||
existing.posTypeId = draftPos.posTypeId;
|
||||
existing.posLevelId = draftPos.posLevelId;
|
||||
existing.positionField = draftPos.positionField ?? null;
|
||||
existing.posExecutive = (draftPos as any).posExecutive?.posExecutiveName ?? null;
|
||||
existing.positionArea = draftPos.positionArea ?? null;
|
||||
existing.positionExecutiveField = draftPos.positionExecutiveField ?? null;
|
||||
profileUpdates.set(nextHolderId, existing);
|
||||
if (draftPosMaster && draftPosMaster.ancestorDNA) {
|
||||
// Find the selected position from draft positions
|
||||
const selectedPos =
|
||||
|
|
|
|||
|
|
@ -1257,7 +1257,7 @@ export class PositionController extends Controller {
|
|||
) {
|
||||
await new permission().PermissionUpdate(request, "SYS_ORG");
|
||||
const posMaster = await this.posMasterRepository.findOne({
|
||||
relations: ["positions", "orgRevision"],
|
||||
relations: ["positions", "orgRevision", "orgRoot", "orgChild1", "orgChild2", "orgChild3", "orgChild4"],
|
||||
where: { id: id },
|
||||
});
|
||||
if (!posMaster) {
|
||||
|
|
@ -1452,6 +1452,17 @@ export class PositionController extends Controller {
|
|||
}),
|
||||
);
|
||||
|
||||
// อัพเดท org และ posMasterNo ตลอดไม่ต้องดัก isSit
|
||||
if (posMaster.orgRevision?.orgRevisionIsCurrent == true && posMaster.current_holderId) {
|
||||
const _profile = await this.profileRepository.findOne({
|
||||
where: { id: posMaster.current_holderId },
|
||||
});
|
||||
if (_profile) {
|
||||
_profile.posMasterNo = getPosMasterNo(posMaster);
|
||||
_profile.org = getOrgFullName(posMaster);
|
||||
await this.profileRepository.save(_profile);
|
||||
}
|
||||
}
|
||||
// ถ้าไม่ใช่ตำแหน่งนั่งทับ (isSit = false) ถึงจะอัพเดทตำแหน่งในทะเบียนประวัติ
|
||||
if (posMaster.orgRevision?.orgRevisionIsCurrent == true && !posMaster.isSit) {
|
||||
const _position = requestBody.positions.find((p) => p.positionIsSelected == true);
|
||||
|
|
@ -1464,6 +1475,10 @@ export class PositionController extends Controller {
|
|||
_profile.position = _position.posDictName ?? _null;
|
||||
_profile.posTypeId = _position.posTypeId;
|
||||
_profile.posLevelId = _position.posLevelId;
|
||||
_profile.positionField = _position.posDictField ?? _null;
|
||||
_profile.posExecutive = _position.posExecutiveId ?? _null;
|
||||
_profile.positionArea = _position.posDictArea ?? _null;
|
||||
_profile.positionExecutiveField = _position.posDictExecutiveField ?? _null;
|
||||
await this.profileRepository.save(_profile);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue