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

View file

@ -91,7 +91,7 @@ import { CommandCode } from "../entities/CommandCode";
import { EmployeePosMaster } from "../entities/EmployeePosMaster"; import { EmployeePosMaster } from "../entities/EmployeePosMaster";
import { CreatePosMasterHistoryOfficer, getTopDegrees } from "../services/PositionService"; import { CreatePosMasterHistoryOfficer, getTopDegrees } from "../services/PositionService";
import { ProfileLeaveService } from "../services/ProfileLeaveService"; import { ProfileLeaveService } from "../services/ProfileLeaveService";
import { PostRetireToExprofile } from "./ExRetirementController"; // import { PostRetireToExprofile } from "./ExRetirementController";
import { getPosNumCodeSit } from "../services/CommandService"; import { getPosNumCodeSit } from "../services/CommandService";
@Route("api/v1/org/profile") @Route("api/v1/org/profile")
@Tags("Profile") @Tags("Profile")
@ -11380,20 +11380,6 @@ export class ProfileController extends Controller {
].filter(Boolean); ].filter(Boolean);
organizeName = names.join(" "); 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(); return new HttpSuccess();
} }

View file

@ -83,7 +83,6 @@ import { ProfileChildren } from "../entities/ProfileChildren";
import { ProfileDuty } from "../entities/ProfileDuty"; import { ProfileDuty } from "../entities/ProfileDuty";
import { getTopDegrees } from "../services/PositionService"; import { getTopDegrees } from "../services/PositionService";
import { ProfileLeaveService } from "../services/ProfileLeaveService"; import { ProfileLeaveService } from "../services/ProfileLeaveService";
import { PostRetireToExprofile } from "./ExRetirementController";
import { CommandCode } from "../entities/CommandCode"; import { CommandCode } from "../entities/CommandCode";
@Route("api/v1/org/profile-employee") @Route("api/v1/org/profile-employee")
@Tags("ProfileEmployee") @Tags("ProfileEmployee")
@ -1961,11 +1960,17 @@ export class ProfileEmployeeController extends Controller {
}); });
// มีคำสั่งพ้นราชการหรือไม่ // มีคำสั่งพ้นราชการหรือไม่
if (salaries.length > 0 && salaries.some((s) => s.commandCode && if (
retireCommandCodes.includes(s.commandCode))) { salaries.length > 0 &&
salaries.some((s) => s.commandCode && retireCommandCodes.includes(s.commandCode))
) {
// กรองข้อมูลซ้ำตาม commandDateAffect // กรองข้อมูลซ้ำตาม commandDateAffect
const uniqueSalaries = salaries.filter((item, index, self) => const uniqueSalaries = salaries.filter(
index === self.findIndex((t) => t.commandDateAffect?.getTime() === item.commandDateAffect?.getTime()) (item, index, self) =>
index ===
self.findIndex(
(t) => t.commandDateAffect?.getTime() === item.commandDateAffect?.getTime(),
),
); );
// วนลูปหาคู่ของ "ออกราชการ" และ "กลับเข้าราชการ" // วนลูปหาคู่ของ "ออกราชการ" และ "กลับเข้าราชการ"
@ -2017,7 +2022,7 @@ export class ProfileEmployeeController extends Controller {
retires.push({ retires.push({
date: `${startDateStr} - ${endDateStr}`, date: `${startDateStr} - ${endDateStr}`,
detail: detail || "-", 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); ].filter(Boolean);
organizeName = names.join(" "); 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(); return new HttpSuccess();
} }

View file

@ -70,7 +70,6 @@ import { deleteUser } from "../keycloak";
import { ProfileSalaryHistory } from "../entities/ProfileSalaryHistory"; import { ProfileSalaryHistory } from "../entities/ProfileSalaryHistory";
import { getTopDegrees } from "../services/PositionService"; import { getTopDegrees } from "../services/PositionService";
import HttpStatusCode from "../interfaces/http-status"; import HttpStatusCode from "../interfaces/http-status";
import { PostRetireToExprofile } from "./ExRetirementController";
@Route("api/v1/org/profile-temp") @Route("api/v1/org/profile-temp")
@Tags("ProfileEmployee") @Tags("ProfileEmployee")
@Security("bearerAuth") @Security("bearerAuth")
@ -3608,20 +3607,6 @@ export class ProfileEmployeeTempController extends Controller {
].filter(Boolean); ].filter(Boolean);
organizeName = names.join(" "); 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(); return new HttpSuccess();
} }

View file

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