insert position to profile
All checks were successful
Build & Deploy on Dev / build (push) Successful in 1m8s

This commit is contained in:
Adisak 2026-04-20 16:01:38 +07:00
parent 28b5408d5b
commit f1c8ecf699
3 changed files with 35 additions and 28 deletions

View file

@ -3722,6 +3722,9 @@ export class CommandController extends Controller {
// ถ้าไม่ใช่ตำแหน่งนั่งทับ (isSit = false) ถึงจะอัพเดทตำแหน่งในทะเบียนประวัติ
if (positionNew != null) {
positionNew.positionIsSelected = true;
// อัพเดท org และ posMasterNo ตลอดไม่ต้องดัก isSit
profile.posMasterNo = getPosMasterNo(posMaster);
profile.org = getOrgFullName(posMaster);
if(!posMaster.isSit){
profile.posLevelId = positionNew.posLevelId;
profile.posTypeId = positionNew.posTypeId;
@ -3730,8 +3733,6 @@ export class CommandController extends Controller {
profile.posExecutive = positionNew.posExecutive?.posExecutiveName ?? null;
profile.positionArea = positionNew.positionArea ?? null;
profile.positionExecutiveField = positionNew.positionExecutiveField ?? null;
profile.posMasterNo = getPosMasterNo(posMaster);
profile.org = getOrgFullName(posMaster);
}
profile.amount = item.amount ?? null;
profile.amountSpecial = item.amountSpecial ?? null;
@ -6998,6 +6999,9 @@ export class CommandController extends Controller {
// ถ้าไม่ใช่ตำแหน่งนั่งทับ (isSit = false) ถึงจะอัพเดทตำแหน่งในทะเบียนประวัติ
if (positionNew != null) {
positionNew.positionIsSelected = true;
// อัพเดท org และ posMasterNo ตลอดไม่ต้องดัก isSit
profile.posMasterNo = getPosMasterNo(posMaster);
profile.org = getOrgFullName(posMaster);
if(!posMaster.isSit){
profile.posLevelId = positionNew.posLevelId;
profile.posTypeId = positionNew.posTypeId;
@ -7006,12 +7010,10 @@ export class CommandController extends Controller {
profile.posExecutive = positionNew.posExecutive?.posExecutiveName ?? null;
profile.positionArea = positionNew.positionArea ?? null;
profile.positionExecutiveField = positionNew.positionExecutiveField ?? null;
profile.posMasterNo = getPosMasterNo(posMaster);
profile.org = getOrgFullName(posMaster);
// profile.dateStart = new Date();
await this.profileRepository.save(profile, { data: req });
setLogDataDiff(req, { before, after: profile });
}
await this.profileRepository.save(profile, { data: req });
setLogDataDiff(req, { before, after: profile });
await this.positionRepository.save(positionNew, { data: req });
}
// await CreatePosMasterHistoryOfficer(posMaster.id, req);

View file

@ -3829,6 +3829,9 @@ export class PositionController extends Controller {
relations: ["posExecutive"],
});
if (_position) {
// อัพเดท org และ posMasterNo ตลอดไม่ต้องดัก isSit
_profile.posMasterNo = getPosMasterNo(dataMaster);
_profile.org = getOrgFullName(dataMaster);
// ถ้าไม่ใช่ตำแหน่งนั่งทับ (isSit = false) ถึงจะอัพเดทตำแหน่งในทะเบียนประวัติ
if(!dataMaster.isSit){
_profile.position = _position.positionName;
@ -3838,11 +3841,9 @@ export class PositionController extends Controller {
_profile.posExecutive = _position.posExecutive?.posExecutiveName ?? undefined;
_profile.positionArea = _position.positionArea ?? undefined;
_profile.positionExecutiveField = _position.positionExecutiveField ?? undefined;
_profile.posMasterNo = getPosMasterNo(dataMaster);
_profile.org = getOrgFullName(dataMaster);
await this.profileRepository.save(_profile);
setLogDataDiff(request, { before, after: _profile });
}
await this.profileRepository.save(_profile);
setLogDataDiff(request, { before, after: _profile });
}
}
dataMaster.current_holderId = requestBody.profileId;

View file

@ -652,29 +652,33 @@ async function handler_org(msg: amqp.ConsumeMessage): Promise<boolean> {
await posMasterAssignRepository.save(newAssigns);
}
// ถ้าไม่ใช่ตำแหน่งนั่งทับ (isSit = false) ถึงจะอัพเดทตำแหน่งในทะเบียนประวัติ
if (item.next_holderId != null && !item.isSit) {
// อัพเดท org และ posMasterNo ตลอดไม่ต้องดัก isSit
if (item.next_holderId != null) {
const profile = await repoProfile.findOne({
where: { id: item.next_holderId == null ? "" : item.next_holderId },
});
if (profile != null && item.positions.length > 0) {
let position = await item.positions.find((x) => x.positionIsSelected == true);
if (position == null) {
position = await item.positions.find((x) => x.posLevelId == profile?.posLevelId);
if (position == null) {
position = await item.positions.sort((a, b) => a.orderNo - b.orderNo)[0];
}
}
profile.posLevelId = position?.posLevelId ?? _null;
profile.posTypeId = position?.posTypeId ?? _null;
profile.position = position?.positionName ?? _null;
profile.positionField = position?.positionField ?? _null;
profile.posExecutive = position?.posExecutive?.posExecutiveName ?? _null;
profile.positionArea = position?.positionArea ?? _null;
profile.positionExecutiveField = position?.positionExecutiveField ?? _null;
if (profile != null) {
profile.posMasterNo = getPosMasterNo(item) ?? _null;
profile.org = getOrgFullName(item) ?? _null;
// ถ้าไม่ใช่ตำแหน่งนั่งทับ (isSit = false) ถึงจะอัพเดทตำแหน่งในทะเบียนประวัติ
if (!item.isSit && item.positions.length > 0) {
let position = await item.positions.find((x) => x.positionIsSelected == true);
if (position == null) {
position = await item.positions.find((x) => x.posLevelId == profile?.posLevelId);
if (position == null) {
position = await item.positions.sort((a, b) => a.orderNo - b.orderNo)[0];
}
}
profile.posLevelId = position?.posLevelId ?? _null;
profile.posTypeId = position?.posTypeId ?? _null;
profile.position = position?.positionName ?? _null;
profile.positionField = position?.positionField ?? _null;
profile.posExecutive = position?.posExecutive?.posExecutiveName ?? _null;
profile.positionArea = position?.positionArea ?? _null;
profile.positionExecutiveField = position?.positionExecutiveField ?? _null;
}
await repoProfile.save(profile);
}
}