fixed remove PostRetireToExprofile ย้ายไปรันใน cronjob ที่เดียว

This commit is contained in:
Warunee Tamkoo 2026-05-08 14:37:40 +07:00
parent 09fd606b86
commit 0e8808e371
5 changed files with 178 additions and 254 deletions

View file

@ -100,7 +100,6 @@ import {
CreatePosMasterHistoryEmployeeTemp,
CreatePosMasterHistoryOfficer,
} from "../services/PositionService";
import { PostRetireToExprofile } from "./ExRetirementController";
import { LeaveType } from "../entities/LeaveType";
import { KeycloakAttributeService } from "../services/KeycloakAttributeService";
import { reOrderCommandRecivesAndDelete } from "../services/CommandService";
@ -227,7 +226,7 @@ export class CommandController extends Controller {
? _data.child1[0] != null
? `current_holders.orgChild1Id IN (:...child1)`
: // : `current_holders.orgChild1Id is ${_data.privilege == "PARENT" ? "not null" : "null"}`
`current_holders.orgChild1Id is null`
`current_holders.orgChild1Id is null`
: "1=1",
{
child1: _data.child1,
@ -305,7 +304,7 @@ export class CommandController extends Controller {
status == null || status == undefined || status == ""
? null
: status.trim().toLocaleUpperCase() == "NEW" ||
status.trim().toLocaleUpperCase() == "DRAFT"
status.trim().toLocaleUpperCase() == "DRAFT"
? ["NEW", "DRAFT"]
: [status.trim().toLocaleUpperCase()],
},
@ -806,8 +805,8 @@ export class CommandController extends Controller {
.PostData(request, path + "/delete", {
refIds: [commandRecive.refId],
})
.then(async (res) => { })
.catch(() => { });
.then(async (res) => {})
.catch(() => {});
const commandId = commandRecive.commandId;
await this.commandReciveRepository.delete(commandRecive.id);
@ -850,8 +849,8 @@ export class CommandController extends Controller {
.PostData(request, path + "/delete", {
refIds: [commandRecive.refId],
})
.then(async (res) => { })
.catch(() => { });
.then(async (res) => {})
.catch(() => {});
const commandId = commandRecive.commandId;
await this.commandReciveRepository.delete(commandRecive.id);
@ -894,8 +893,8 @@ export class CommandController extends Controller {
.PostData(request, path + "/delete", {
refIds: [commandRecive.refId],
})
.then(async (res) => { })
.catch(() => { });
.then(async (res) => {})
.catch(() => {});
const commandId = commandRecive.commandId;
await this.commandReciveRepository.delete(commandRecive.id);
@ -1179,8 +1178,8 @@ export class CommandController extends Controller {
.PostData(request, path + "/delete", {
refIds: command.commandRecives.map((x) => x.refId),
})
.then(async (res) => { })
.catch(() => { });
.then(async (res) => {})
.catch(() => {});
await this.commandReciveRepository.delete({ commandId: command.id });
command.status = "CANCEL";
@ -1245,8 +1244,8 @@ export class CommandController extends Controller {
.PostData(request, path + "/delete", {
refIds: command.commandRecives.map((x) => x.refId),
})
.then(async (res) => { })
.catch(() => { });
.then(async (res) => {})
.catch(() => {});
await this.commandSendCCRepository.delete({ commandSendId: In(commandSend.map((x) => x.id)) });
await this.commandReciveRepository.delete({ commandId: command.id });
@ -1399,11 +1398,11 @@ export class CommandController extends Controller {
let profiles =
command && command.commandRecives.length > 0
? command.commandRecives
.filter((x) => x.profileId != null)
.map((x) => ({
receiverUserId: x.profileId,
notiLink: "",
}))
.filter((x) => x.profileId != null)
.map((x) => ({
receiverUserId: x.profileId,
notiLink: "",
}))
: [];
const msgNoti = {
@ -1435,8 +1434,8 @@ export class CommandController extends Controller {
refIds: command.commandRecives.filter((x) => x.refId != null).map((x) => x.refId),
status: "WAITING",
})
.then(async (res) => { })
.catch(() => { });
.then(async (res) => {})
.catch(() => {});
await this.commandRepository.save(command);
} else {
const path = commandTypePath(command.commandType.code);
@ -1573,7 +1572,7 @@ export class CommandController extends Controller {
);
await this.profileRepository.save(profiles);
}
} catch { }
} catch {}
type = "EMPLOYEE";
try {
@ -1605,7 +1604,7 @@ export class CommandController extends Controller {
);
await this.profileEmployeeRepository.save(profiles);
}
} catch { }
} catch {}
return new HttpSuccess();
}
@ -1654,7 +1653,11 @@ export class CommandController extends Controller {
_profile.leaveDate = _Date;
_profile.dateLeave = _Date;
_profile.lastUpdatedAt = _Date;
if (_profile.keycloak != null && _profile.keycloak != "" && _profile.isDelete === false) {
if (
_profile.keycloak != null &&
_profile.keycloak != "" &&
_profile.isDelete === false
) {
// console.log("4. disable keycloak/authen")
const delUserKeycloak = await deleteUser(_profile.keycloak, adminToken);
if (delUserKeycloak) {
@ -1670,7 +1673,7 @@ export class CommandController extends Controller {
}),
);
}
} catch { }
} catch {}
type = "EMPLOYEE";
try {
@ -1712,7 +1715,11 @@ export class CommandController extends Controller {
_profileEmp.leaveDate = _Date;
_profileEmp.dateLeave = _Date;
_profileEmp.lastUpdatedAt = _Date;
if (_profileEmp.keycloak != null && _profileEmp.keycloak != "" && _profileEmp.isDelete === false) {
if (
_profileEmp.keycloak != null &&
_profileEmp.keycloak != "" &&
_profileEmp.isDelete === false
) {
// disable keycloak/authen
const delUserKeycloak = await deleteUser(_profileEmp.keycloak, adminToken);
if (delUserKeycloak) {
@ -1727,7 +1734,7 @@ export class CommandController extends Controller {
}),
);
}
} catch { }
} catch {}
return new HttpSuccess();
}
@ -1955,7 +1962,7 @@ export class CommandController extends Controller {
.then((x) => {
res = x;
})
.catch((x) => { });
.catch((x) => {});
}
let _command;
@ -2033,76 +2040,76 @@ export class CommandController extends Controller {
profile?.current_holders.length == 0
? null
: profile?.current_holders.find((x) => x.orgRevisionId == orgRevisionActive?.id) !=
null &&
profile?.current_holders.find((x) => x.orgRevisionId == orgRevisionActive?.id)
?.orgChild4 != null
null &&
profile?.current_holders.find((x) => x.orgRevisionId == orgRevisionActive?.id)
?.orgChild4 != null
? `${profile?.current_holders.find((x) => x.orgRevisionId == orgRevisionActive?.id)?.orgChild4.orgChild4ShortName} ${profile?.current_holders.find((x) => x.orgRevisionId == orgRevisionActive?.id)?.posMasterNo}`
: profile?.current_holders.find((x) => x.orgRevisionId == orgRevisionActive?.id) !=
null &&
profile?.current_holders.find((x) => x.orgRevisionId == orgRevisionActive?.id)
?.orgChild3 != null
null &&
profile?.current_holders.find((x) => x.orgRevisionId == orgRevisionActive?.id)
?.orgChild3 != null
? `${profile?.current_holders.find((x) => x.orgRevisionId == orgRevisionActive?.id)?.orgChild3.orgChild3ShortName} ${profile?.current_holders.find((x) => x.orgRevisionId == orgRevisionActive?.id)?.posMasterNo}`
: profile?.current_holders.find(
(x) => x.orgRevisionId == orgRevisionActive?.id,
) != null &&
profile?.current_holders.find((x) => x.orgRevisionId == orgRevisionActive?.id)
?.orgChild2 != null
? `${profile?.current_holders.find((x) => x.orgRevisionId == orgRevisionActive?.id)?.orgChild2.orgChild2ShortName} ${profile?.current_holders.find((x) => x.orgRevisionId == orgRevisionActive?.id)?.posMasterNo}`
: profile?.current_holders.find(
(x) => x.orgRevisionId == orgRevisionActive?.id,
) != null &&
profile?.current_holders.find(
(x) => x.orgRevisionId == orgRevisionActive?.id,
)?.orgChild1 != null
? `${profile?.current_holders.find((x) => x.orgRevisionId == orgRevisionActive?.id)?.orgChild1.orgChild1ShortName} ${profile?.current_holders.find((x) => x.orgRevisionId == orgRevisionActive?.id)?.posMasterNo}`
: profile?.current_holders.find(
(x) => x.orgRevisionId == orgRevisionActive?.id,
) != null &&
profile?.current_holders.find((x) => x.orgRevisionId == orgRevisionActive?.id)
?.orgChild2 != null
? `${profile?.current_holders.find((x) => x.orgRevisionId == orgRevisionActive?.id)?.orgChild2.orgChild2ShortName} ${profile?.current_holders.find((x) => x.orgRevisionId == orgRevisionActive?.id)?.posMasterNo}`
: profile?.current_holders.find(
(x) => x.orgRevisionId == orgRevisionActive?.id,
) != null &&
profile?.current_holders.find(
(x) => x.orgRevisionId == orgRevisionActive?.id,
)?.orgRoot != null
)?.orgChild1 != null
? `${profile?.current_holders.find((x) => x.orgRevisionId == orgRevisionActive?.id)?.orgChild1.orgChild1ShortName} ${profile?.current_holders.find((x) => x.orgRevisionId == orgRevisionActive?.id)?.posMasterNo}`
: profile?.current_holders.find(
(x) => x.orgRevisionId == orgRevisionActive?.id,
) != null &&
profile?.current_holders.find(
(x) => x.orgRevisionId == orgRevisionActive?.id,
)?.orgRoot != null
? `${profile?.current_holders.find((x) => x.orgRevisionId == orgRevisionActive?.id)?.orgRoot.orgRootShortName} ${profile?.current_holders.find((x) => x.orgRevisionId == orgRevisionActive?.id)?.posMasterNo}`
: null;
const root =
profile?.current_holders == null ||
profile?.current_holders.length == 0 ||
profile?.current_holders.find((x) => x.orgRevisionId == orgRevisionActive.id) == null
profile?.current_holders.length == 0 ||
profile?.current_holders.find((x) => x.orgRevisionId == orgRevisionActive.id) == null
? null
: profile?.current_holders.find((x) => x.orgRevisionId == orgRevisionActive.id)
?.orgRoot;
?.orgRoot;
const child1 =
profile?.current_holders == null ||
profile?.current_holders.length == 0 ||
profile?.current_holders.find((x) => x.orgRevisionId == orgRevisionActive.id) == null
profile?.current_holders.length == 0 ||
profile?.current_holders.find((x) => x.orgRevisionId == orgRevisionActive.id) == null
? null
: profile?.current_holders.find((x) => x.orgRevisionId == orgRevisionActive.id)
?.orgChild1;
?.orgChild1;
const child2 =
profile?.current_holders == null ||
profile?.current_holders.length == 0 ||
profile?.current_holders.find((x) => x.orgRevisionId == orgRevisionActive.id) == null
profile?.current_holders.length == 0 ||
profile?.current_holders.find((x) => x.orgRevisionId == orgRevisionActive.id) == null
? null
: profile?.current_holders.find((x) => x.orgRevisionId == orgRevisionActive.id)
?.orgChild2;
?.orgChild2;
const child3 =
profile?.current_holders == null ||
profile?.current_holders.length == 0 ||
profile?.current_holders.find((x) => x.orgRevisionId == orgRevisionActive.id) == null
profile?.current_holders.length == 0 ||
profile?.current_holders.find((x) => x.orgRevisionId == orgRevisionActive.id) == null
? null
: profile?.current_holders.find((x) => x.orgRevisionId == orgRevisionActive.id)
?.orgChild3;
?.orgChild3;
const child4 =
profile?.current_holders == null ||
profile?.current_holders.length == 0 ||
profile?.current_holders.find((x) => x.orgRevisionId == orgRevisionActive.id) == null
profile?.current_holders.length == 0 ||
profile?.current_holders.find((x) => x.orgRevisionId == orgRevisionActive.id) == null
? null
: profile?.current_holders.find((x) => x.orgRevisionId == orgRevisionActive.id)
?.orgChild4;
?.orgChild4;
let _root = root?.orgRootName;
let _child1 = child1?.orgChild1Name;
@ -2163,10 +2170,10 @@ export class CommandController extends Controller {
commandCode != "C-PM-21"
? profile?.isLeave == false
? (_child4 == null ? "" : _child4 + "\n") +
(_child3 == null ? "" : _child3 + "\n") +
(_child2 == null ? "" : _child2 + "\n") +
(_child1 == null ? "" : _child1 + "\n") +
(_root == null ? "" : _root)
(_child3 == null ? "" : _child3 + "\n") +
(_child2 == null ? "" : _child2 + "\n") +
(_child1 == null ? "" : _child1 + "\n") +
(_root == null ? "" : _root)
: orgLeave
: profileTemp.org,
fullName: `${x.prefix}${x.firstName} ${x.lastName}`,
@ -2181,8 +2188,8 @@ export class CommandController extends Controller {
commandCode != "C-PM-21"
? profile?.posType && profile?.posLevel
? Extension.ToThaiNumber(
`${profile?.posType.posTypeShortName} ${profile?.posLevel.posLevelName}`,
)
`${profile?.posType.posTypeShortName} ${profile?.posLevel.posLevelName}`,
)
: "-"
: Extension.ToThaiNumber(profileTemp.posLevel),
posNo:
@ -2196,19 +2203,19 @@ export class CommandController extends Controller {
? Extension.ToThaiNumber(Extension.ToThaiShortDate_monthYear(profile?.dateRetire))
: profile?.birthDate && commandCode == "C-PM-21"
? Extension.ToThaiNumber(
Extension.ToThaiShortDate_monthYear(
new Date(
profile.birthDate.getFullYear() + 60,
profile.birthDate.getMonth(),
profile.birthDate.getDate(),
Extension.ToThaiShortDate_monthYear(
new Date(
profile.birthDate.getFullYear() + 60,
profile.birthDate.getMonth(),
profile.birthDate.getDate(),
),
),
),
)
)
: "-",
dateExecute: command.commandExcecuteDate
? Extension.ToThaiNumber(
Extension.ToThaiShortDate_monthYear(command.commandExcecuteDate),
)
Extension.ToThaiShortDate_monthYear(command.commandExcecuteDate),
)
: "-",
remark: x.remarkVertical ? x.remarkVertical : "-",
};
@ -2309,7 +2316,7 @@ export class CommandController extends Controller {
.then(async (res) => {
_command = res;
})
.catch(() => { });
.catch(() => {});
let issue =
command.isBangkok == "OFFICE"
@ -2367,15 +2374,15 @@ export class CommandController extends Controller {
operators:
operators.length > 0
? operators.map((x) => ({
fullName: `${x.prefix ?? ""}${x.firstName ?? ""} ${x.lastName ?? ""}`,
roleName: x.roleName,
}))
fullName: `${x.prefix ?? ""}${x.firstName ?? ""} ${x.lastName ?? ""}`,
roleName: x.roleName,
}))
: [
{
fullName: "",
roleName: "เจ้าหน้าที่ดำเนินการ",
},
],
{
fullName: "",
roleName: "เจ้าหน้าที่ดำเนินการ",
},
],
},
});
}
@ -2715,10 +2722,9 @@ export class CommandController extends Controller {
refIds: requestBody.persons.filter((x) => x.refId != null).map((x) => x.refId),
status: "REPORT",
})
.then(async (res) => { })
.catch(() => { });
}
else {
.then(async (res) => {})
.catch(() => {});
} else {
await new CallAPI()
.PostData(request, path, {
refIds: requestBody.persons.filter((x) => x.refId != null).map((x) => x.refId),
@ -2726,8 +2732,8 @@ export class CommandController extends Controller {
commandTypeId: requestBody.commandTypeId,
commandCode: commandCode,
})
.then(async (res) => { })
.catch(() => { });
.then(async (res) => {})
.catch(() => {});
}
let order =
command.commandRecives == null || command.commandRecives.length <= 0
@ -3501,27 +3507,27 @@ export class CommandController extends Controller {
? x.orgChild1.orgChild1Name + "\n" + x.orgRoot.orgRootName
: x.orgChild3 == null
? x.orgChild2.orgChild2Name +
"\n" +
x.orgChild1.orgChild1Name +
"\n" +
x.orgRoot.orgRootName
: x.orgChild4 == null
? x.orgChild3.orgChild3Name +
"\n" +
x.orgChild2.orgChild2Name +
"\n" +
x.orgChild1.orgChild1Name +
"\n" +
x.orgRoot.orgRootName
: x.orgChild4 == null
? x.orgChild3.orgChild3Name +
"\n" +
x.orgChild2.orgChild2Name +
"\n" +
x.orgChild1.orgChild1Name +
"\n" +
x.orgRoot.orgRootName
: x.orgChild4.orgChild4Name +
"\n" +
x.orgChild3.orgChild3Name +
"\n" +
x.orgChild2.orgChild2Name +
"\n" +
x.orgChild1.orgChild1Name +
"\n" +
x.orgRoot.orgRootName,
"\n" +
x.orgChild3.orgChild3Name +
"\n" +
x.orgChild2.orgChild2Name +
"\n" +
x.orgChild1.orgChild1Name +
"\n" +
x.orgRoot.orgRootName,
positionName: x?.current_holder.position ?? _null,
profileId: x?.current_holder.id ?? _null,
});
@ -4362,20 +4368,6 @@ export class CommandController extends Controller {
organizeName = names.join(" ");
}
PostRetireToExprofile(
req,
profile.citizenId ?? "",
profile.prefix ?? "",
profile.firstName ?? "",
profile.lastName ?? "",
item.commandDateAffect?.getFullYear().toString() ?? "",
profile.position,
profile.posType?.posTypeName ?? "",
profile.posLevel?.posLevelName ?? "",
item.commandDateAffect ?? new Date(),
organizeName,
clearProfile.retireTypeName ?? "",
);
}
}),
);
@ -4619,20 +4611,6 @@ export class CommandController extends Controller {
].filter(Boolean);
organizeName = names.join(" ");
}
PostRetireToExprofile(
req,
profile.citizenId ?? "",
profile.prefix ?? "",
profile.firstName ?? "",
profile.lastName ?? "",
item.commandDateAffect?.getFullYear().toString() ?? "",
profile.position,
profile.posType?.posTypeName ?? "",
`${profile.posType?.posTypeShortName} ${profile.posLevel?.posLevelName}`,
item.commandDateAffect ?? new Date(),
organizeName,
clearProfile.retireTypeName ?? "",
);
}
}),
);
@ -4892,20 +4870,6 @@ export class CommandController extends Controller {
].filter(Boolean);
organizeName = names.join(" ");
}
PostRetireToExprofile(
req,
profile.citizenId ?? "",
profile.prefix ?? "",
profile.firstName ?? "",
profile.lastName ?? "",
item.commandDateAffect?.getFullYear().toString() ?? "",
profile.position,
profile.posType?.posTypeName ?? "",
profile.posLevel?.posLevelName ?? "",
item.commandDateAffect ?? new Date(),
organizeName,
clearProfile.retireTypeName ?? "",
);
}
}
}),
@ -5297,7 +5261,11 @@ export class CommandController extends Controller {
const clearProfile = await checkCommandType(String(item.commandId));
if (clearProfile.status) {
retireTypeName = clearProfile.retireTypeName ?? "";
if (_profile.keycloak != null && _profile.keycloak != "" && _profile.isDelete === false) {
if (
_profile.keycloak != null &&
_profile.keycloak != "" &&
_profile.isDelete === false
) {
const delUserKeycloak = await deleteUser(_profile.keycloak);
if (delUserKeycloak) {
// Task #228
@ -5482,7 +5450,11 @@ export class CommandController extends Controller {
const clearProfile = await checkCommandType(String(item.commandId));
if (clearProfile.status) {
retireTypeName = clearProfile.retireTypeName ?? "";
if (_profile.keycloak != null && _profile.keycloak != "" && _profile.isDelete === false) {
if (
_profile.keycloak != null &&
_profile.keycloak != "" &&
_profile.isDelete === false
) {
const delUserKeycloak = await deleteUser(_profile.keycloak);
if (delUserKeycloak) {
// Task #228
@ -5527,21 +5499,6 @@ export class CommandController extends Controller {
let _posLevelName: string = !isEmployee
? `${profile.posLevel?.posLevelName}`
: `${profile.posType?.posTypeName} ${profile.posLevel?.posLevelName}`;
PostRetireToExprofile(
req,
profile.citizenId ?? "",
profile.prefix ?? "",
profile.firstName ?? "",
profile.lastName ?? "",
item.commandDateAffect?.getFullYear().toString() ?? "",
profile.position,
profile.posType?.posTypeName ?? "",
_posLevelName,
item.commandDateAffect ?? new Date(),
organizeName,
retireTypeName,
);
}
}),
);
@ -5822,7 +5779,11 @@ export class CommandController extends Controller {
}
const clearProfile = await checkCommandType(String(item.commandId));
if (clearProfile.status) {
if (_profile.keycloak != null && _profile.keycloak != "" && _profile.isDelete === false) {
if (
_profile.keycloak != null &&
_profile.keycloak != "" &&
_profile.isDelete === false
) {
const delUserKeycloak = await deleteUser(_profile.keycloak);
if (delUserKeycloak) {
// Task #228
@ -6184,26 +6145,26 @@ export class CommandController extends Controller {
!profile.current_holders || profile.current_holders.length == 0
? null
: profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id) != null &&
profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)
?.orgChild4 != null
profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)
?.orgChild4 != null
? `${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.orgChild4.orgChild4ShortName}`
: profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id) != null &&
profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)
?.orgChild3 != null
profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)
?.orgChild3 != null
? `${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.orgChild3.orgChild3ShortName}`
: profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id) != null &&
profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)
?.orgChild2 != null
profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)
?.orgChild2 != null
? `${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.orgChild2.orgChild2ShortName}`
: profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id) !=
null &&
profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)
?.orgChild1 != null
null &&
profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)
?.orgChild1 != null
? `${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.orgChild1.orgChild1ShortName}`
: profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id) !=
null &&
profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)
?.orgRoot != null
null &&
profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)
?.orgRoot != null
? `${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.orgRoot.orgRootShortName}`
: null;
const posNo = `${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.posMasterNo}`;
@ -6309,20 +6270,6 @@ export class CommandController extends Controller {
].filter(Boolean);
organizeName = names.join(" ");
}
PostRetireToExprofile(
req,
profile.citizenId ?? "",
profile.prefix ?? "",
profile.firstName ?? "",
profile.lastName ?? "",
item.commandDateAffect?.getFullYear().toString() ?? "",
profile.position,
profile.posType?.posTypeName ?? "",
profile.posLevel?.posLevelName ?? "",
item.commandDateAffect ?? new Date(),
organizeName,
clearProfile.retireTypeName ?? "",
);
}),
);
return new HttpSuccess();
@ -6924,11 +6871,19 @@ export class CommandController extends Controller {
where: {
id: item.bodyPosition.posmasterId,
},
relations: { orgRevision: true, orgRoot: true, orgChild1: true, orgChild2: true, orgChild3: true, orgChild4: true }
relations: {
orgRevision: true,
orgRoot: true,
orgChild1: true,
orgChild2: true,
orgChild3: true,
orgChild4: true,
},
});
// เช็คว่า posMaster ที่หามาอยู่ในโครงสร้างปัจจุบันหรือไม่
const isCurrent = posMaster?.orgRevision?.orgRevisionIsCurrent === true &&
const isCurrent =
posMaster?.orgRevision?.orgRevisionIsCurrent === true &&
posMaster?.orgRevision?.orgRevisionIsDraft === false;
// ถ้าไม่อยู่ในโครงสร้างปัจจุบัน ให้หาตัวใหม่จาก ancestorDNA
@ -6938,10 +6893,17 @@ export class CommandController extends Controller {
ancestorDNA: posMaster.ancestorDNA,
orgRevision: {
orgRevisionIsCurrent: true,
orgRevisionIsDraft: false
}
orgRevisionIsDraft: false,
},
},
relations: {
orgRevision: true,
orgRoot: true,
orgChild1: true,
orgChild2: true,
orgChild3: true,
orgChild4: true,
},
relations: { orgRevision: true, orgRoot: true, orgChild1: true, orgChild2: true, orgChild3: true, orgChild4: true }
});
}
@ -7057,7 +7019,7 @@ export class CommandController extends Controller {
}
// await CreatePosMasterHistoryOfficer(posMaster.id, req);
await CreatePosMasterHistoryOfficer(posMaster.id, req, null, {
positionId: positionNew?.id
positionId: positionNew?.id,
});
}
// Insignia
@ -7133,8 +7095,8 @@ export class CommandController extends Controller {
prefix: avatar,
fileName: fileName,
})
.then(() => { })
.catch(() => { });
.then(() => {})
.catch(() => {});
}
}
}),
@ -8245,7 +8207,7 @@ export class CommandController extends Controller {
.then(async (res) => {
_command = res;
})
.catch(() => { });
.catch(() => {});
let issue =
command.isBangkok == "OFFICE"

View file

@ -91,7 +91,7 @@ import { CommandCode } from "../entities/CommandCode";
import { EmployeePosMaster } from "../entities/EmployeePosMaster";
import { CreatePosMasterHistoryOfficer, getTopDegrees } from "../services/PositionService";
import { ProfileLeaveService } from "../services/ProfileLeaveService";
import { PostRetireToExprofile } from "./ExRetirementController";
// import { PostRetireToExprofile } from "./ExRetirementController";
import { getPosNumCodeSit } from "../services/CommandService";
@Route("api/v1/org/profile")
@Tags("Profile")
@ -11380,20 +11380,6 @@ export class ProfileController extends Controller {
].filter(Boolean);
organizeName = names.join(" ");
}
PostRetireToExprofile(
request,
profile.citizenId ?? "",
profile.prefix ?? "",
profile.firstName ?? "",
profile.lastName ?? "",
requestBody.dateLeave?.getFullYear().toString() ?? "",
profile.position,
profile.posType?.posTypeName ?? "",
profile.posLevel?.posLevelName ?? "",
requestBody.dateLeave ?? new Date(),
organizeName,
"ถึงแก่กรรม",
);
return new HttpSuccess();
}

View file

@ -83,7 +83,6 @@ import { ProfileChildren } from "../entities/ProfileChildren";
import { ProfileDuty } from "../entities/ProfileDuty";
import { getTopDegrees } from "../services/PositionService";
import { ProfileLeaveService } from "../services/ProfileLeaveService";
import { PostRetireToExprofile } from "./ExRetirementController";
import { CommandCode } from "../entities/CommandCode";
@Route("api/v1/org/profile-employee")
@Tags("ProfileEmployee")
@ -1961,11 +1960,17 @@ export class ProfileEmployeeController extends Controller {
});
// มีคำสั่งพ้นราชการหรือไม่
if (salaries.length > 0 && salaries.some((s) => s.commandCode &&
retireCommandCodes.includes(s.commandCode))) {
if (
salaries.length > 0 &&
salaries.some((s) => s.commandCode && retireCommandCodes.includes(s.commandCode))
) {
// กรองข้อมูลซ้ำตาม commandDateAffect
const uniqueSalaries = salaries.filter((item, index, self) =>
index === self.findIndex((t) => t.commandDateAffect?.getTime() === item.commandDateAffect?.getTime())
const uniqueSalaries = salaries.filter(
(item, index, self) =>
index ===
self.findIndex(
(t) => t.commandDateAffect?.getTime() === item.commandDateAffect?.getTime(),
),
);
// วนลูปหาคู่ของ "ออกราชการ" และ "กลับเข้าราชการ"
@ -2017,7 +2022,7 @@ export class ProfileEmployeeController extends Controller {
retires.push({
date: `${startDateStr} - ${endDateStr}`,
detail: detail || "-",
day: daysCount > 0 ? Extension.ToThaiNumber(daysCount.toLocaleString()) : "-"
day: daysCount > 0 ? Extension.ToThaiNumber(daysCount.toLocaleString()) : "-",
});
}
}
@ -5791,20 +5796,6 @@ export class ProfileEmployeeController extends Controller {
].filter(Boolean);
organizeName = names.join(" ");
}
PostRetireToExprofile(
request,
profile.citizenId ?? "",
profile.prefix ?? "",
profile.firstName ?? "",
profile.lastName ?? "",
requestBody.dateLeave?.getFullYear().toString() ?? "",
profile.position,
profile.posType?.posTypeName ?? "",
`${profile.posType?.posTypeShortName} ${profile.posLevel?.posLevelName}`,
requestBody.dateLeave ?? new Date(),
organizeName,
"ถึงแก่กรรม",
);
return new HttpSuccess();
}

View file

@ -70,7 +70,6 @@ import { deleteUser } from "../keycloak";
import { ProfileSalaryHistory } from "../entities/ProfileSalaryHistory";
import { getTopDegrees } from "../services/PositionService";
import HttpStatusCode from "../interfaces/http-status";
import { PostRetireToExprofile } from "./ExRetirementController";
@Route("api/v1/org/profile-temp")
@Tags("ProfileEmployee")
@Security("bearerAuth")
@ -3608,20 +3607,6 @@ export class ProfileEmployeeTempController extends Controller {
].filter(Boolean);
organizeName = names.join(" ");
}
PostRetireToExprofile(
request,
profile.citizenId ?? "",
profile.prefix ?? "",
profile.firstName ?? "",
profile.lastName ?? "",
requestBody.dateLeave?.getFullYear().toString() ?? "",
profile.position,
profile.posType?.posTypeName ?? "",
`${profile.posType?.posTypeShortName} ${profile.posLevel?.posLevelName}`,
requestBody.dateLeave ?? new Date(),
organizeName,
"ถึงแก่กรรม",
);
return new HttpSuccess();
}

View file

@ -115,7 +115,7 @@ export class RetirementService {
const retireDate = new Date(profile.leaveDate);
// ส่งไปยัง Exprofile
PostRetireToExprofile(
await PostRetireToExprofile(
null,
profile.citizenId,
profile.prefix || "",