fix keycloak user & update isDelete
All checks were successful
Build & Deploy on Dev / build (push) Successful in 1m1s

This commit is contained in:
Warunee Tamkoo 2026-04-02 16:32:29 +07:00
parent 212360a764
commit fb4196cfa2
9 changed files with 445 additions and 354 deletions

View file

@ -871,7 +871,7 @@ export class ProfileEmployeeController extends Controller {
});
// กรองเอา object ที่ไม่มี year ออก
const filteredLeaves = leaves.filter(item => item.year && item.year !== "");
const filteredLeaves = leaves.filter((item) => item.year && item.year !== "");
const data = {
fullName: `${profiles?.prefix}${profiles?.firstName} ${profiles?.lastName}`,
@ -1135,7 +1135,9 @@ export class ProfileEmployeeController extends Controller {
certificateType: item.certificateType ?? null,
issuer: item.issuer ?? null,
certificateNo: item.certificateNo ? Extension.ToThaiNumber(item.certificateNo) : null,
detail: Extension.ToThaiNumber(`${item.issuer ?? ""} ${item.certificateNo ?? ""}`.trim()),
detail: Extension.ToThaiNumber(
`${item.issuer ?? ""} ${item.certificateNo ?? ""}`.trim(),
),
issueToExpireDate: item.issueDate
? item.expireDate
? Extension.ToThaiNumber(
@ -1167,7 +1169,9 @@ export class ProfileEmployeeController extends Controller {
degree: item.name ? Extension.ToThaiNumber(item.name) : "",
place: item.place ? Extension.ToThaiNumber(item.place) : "",
duration: item.duration ? Extension.ToThaiNumber(item.duration) : "",
date: Extension.ToThaiNumber(`${Extension.ToThaiFullDate2(item.startDate)} - ${Extension.ToThaiFullDate2(item.endDate)}`)
date: Extension.ToThaiNumber(
`${Extension.ToThaiFullDate2(item.startDate)} - ${Extension.ToThaiFullDate2(item.endDate)}`,
),
}))
: [
{
@ -1175,7 +1179,7 @@ export class ProfileEmployeeController extends Controller {
degree: "",
place: "",
duration: "",
date: ""
date: "",
},
];
@ -1218,14 +1222,14 @@ export class ProfileEmployeeController extends Controller {
? `${item.startDate ? Extension.ToThaiNumber(Extension.ToThaiFullDate2(item.startDate)) : ""} - ${item.endDate ? Extension.ToThaiNumber(Extension.ToThaiFullDate2(item.endDate)) : ""}`
: `${item.startDate ? Extension.ToThaiNumber(Extension.ToThaiShortYear(new Date(item.startDate))) : ""} - ${item.endDate ? Extension.ToThaiNumber(Extension.ToThaiShortYear(new Date(item.endDate))) : ""}`,
degree: `${item.degree ?? ""} ${item.field ?? ""}`.trim(),
level: item.educationLevel
level: item.educationLevel,
}))
: [
{
institute: "",
date: "",
degree: "",
level: ""
level: "",
},
];
const salary_raw = await this.salaryRepo.find({
@ -1441,9 +1445,7 @@ export class ProfileEmployeeController extends Controller {
// Merge มาสาย/ขาดราชการเข้า leaves array
absentLate_raw.forEach((item) => {
const year = item.year
? Extension.ToThaiNumber((item.year + 543).toString())
: "";
const year = item.year ? Extension.ToThaiNumber((item.year + 543).toString()) : "";
let yearData = leaves.find((data) => data.year === year);
@ -1477,7 +1479,7 @@ export class ProfileEmployeeController extends Controller {
// });
if (leaves.length === 0) {
leaves.push({year:""});
leaves.push({ year: "" });
}
const leave2_raw = await this.profileLeaveRepository
@ -1509,12 +1511,12 @@ export class ProfileEmployeeController extends Controller {
const displayType =
leaveTypeCode === "LV-008" && item.leaveSubTypeName
? item.leaveSubTypeName
: (item.name || "-");
: item.name || "-";
// ข้อที่ 2: แสดง reason ก่อนเสมอ ถ้ามี coupleDayLevelCountry ค่อยแสดงประเทศ
const displayReason = item.coupleDayLevelCountry
? `${item.reason || ""} ลาไปประเทศ ${item.coupleDayLevelCountry}`.trim()
: (item.reason || "-");
: item.reason || "-";
return {
date:
@ -1606,79 +1608,93 @@ export class ProfileEmployeeController extends Controller {
];
const position_raw = await this.salaryRepo.find({
where: [{
profileEmployeeId: id,
commandCode: In(["0","1","2","3","4","8","9","10","11","12","13","14","15","16","20"]),
// isEntry: false,
},
{ profileEmployeeId: id, commandCode: IsNull() }],
where: [
{
profileEmployeeId: id,
commandCode: In([
"0",
"1",
"2",
"3",
"4",
"8",
"9",
"10",
"11",
"12",
"13",
"14",
"15",
"16",
"20",
]),
// isEntry: false,
},
{ profileEmployeeId: id, commandCode: IsNull() },
],
order: { order: "ASC" },
});
let _commandName:any = "";
let _commandDateAffect:any = ""
let _commandName: any = "";
let _commandDateAffect: any = "";
const positionList =
position_raw.length > 0
? await Promise.all(position_raw.map(async(item, idx, arr) => {
const isLast = idx === arr.length - 1;
if (isLast) {
_commandDateAffect = item.commandDateAffect
? Extension.ToThaiNumber(Extension.ToThaiFullDate2(item.commandDateAffect))
: "";
}
const _code = item.commandCode ? Number(item.commandCode) : null;
if (_code != null) {
_commandName = await this.commandCodeRepository.findOne({
select: { name: true, code: true },
where: { code: _code }
});
}
const codeSitAbb = item.posNumCodeSitAbb ?? "-"
const commandNo = item.commandNo && item.commandYear
? item.commandNo+"/"+(item.commandYear > 2500 ? item.commandYear : item.commandYear + 543)
: "-"
const dateAffect = item.commandDateAffect
? `${Extension.ToThaiFullDate2(item.commandDateAffect)}`
: "-"
return {
commandName: _commandName && _commandName.name
? _commandName.name
: item.commandName,
commandDateAffect: item.commandDateAffect
? Extension.ToThaiNumber(
Extension.ToThaiFullDate2(item.commandDateAffect)
)
: "",
commandDateSign: item.commandDateSign
? Extension.ToThaiNumber(
Extension.ToThaiFullDate2(item.commandDateSign)
)
: "",
posNo:
item.posNoAbb && item.posNo
? Extension.ToThaiNumber(`${item.posNoAbb} ${item.posNo}`)
? await Promise.all(
position_raw.map(async (item, idx, arr) => {
const isLast = idx === arr.length - 1;
if (isLast) {
_commandDateAffect = item.commandDateAffect
? Extension.ToThaiNumber(Extension.ToThaiFullDate2(item.commandDateAffect))
: "";
}
const _code = item.commandCode ? Number(item.commandCode) : null;
if (_code != null) {
_commandName = await this.commandCodeRepository.findOne({
select: { name: true, code: true },
where: { code: _code },
});
}
const codeSitAbb = item.posNumCodeSitAbb ?? "-";
const commandNo =
item.commandNo && item.commandYear
? item.commandNo +
"/" +
(item.commandYear > 2500 ? item.commandYear : item.commandYear + 543)
: "-";
const dateAffect = item.commandDateAffect
? `${Extension.ToThaiFullDate2(item.commandDateAffect)}`
: "-";
return {
commandName:
_commandName && _commandName.name ? _commandName.name : item.commandName,
commandDateAffect: item.commandDateAffect
? Extension.ToThaiNumber(Extension.ToThaiFullDate2(item.commandDateAffect))
: "",
position: item.positionName,
posType: item.positionType,
posLevel: item.positionLevel
? Extension.ToThaiNumber(item.positionLevel)
: item.positionCee
? Extension.ToThaiNumber(item.positionCee)
: null,
amount: item.amount
? Extension.ToThaiNumber(
Number(item.amount).toLocaleString()
)
: "",
positionSalaryAmount: item.positionSalaryAmount
? Extension.ToThaiNumber(
Number(item.positionSalaryAmount).toLocaleString()
)
: "",
refDoc: Extension.ToThaiNumber(
`คำสั่ง ${codeSitAbb} ที่ ${commandNo} ลว. ${dateAffect}`
),
};
}))
commandDateSign: item.commandDateSign
? Extension.ToThaiNumber(Extension.ToThaiFullDate2(item.commandDateSign))
: "",
posNo:
item.posNoAbb && item.posNo
? Extension.ToThaiNumber(`${item.posNoAbb} ${item.posNo}`)
: "",
position: item.positionName,
posType: item.positionType,
posLevel: item.positionLevel
? Extension.ToThaiNumber(item.positionLevel)
: item.positionCee
? Extension.ToThaiNumber(item.positionCee)
: null,
amount: item.amount
? Extension.ToThaiNumber(Number(item.amount).toLocaleString())
: "",
positionSalaryAmount: item.positionSalaryAmount
? Extension.ToThaiNumber(Number(item.positionSalaryAmount).toLocaleString())
: "",
refDoc: Extension.ToThaiNumber(
`คำสั่ง ${codeSitAbb} ที่ ${commandNo} ลว. ${dateAffect}`,
),
};
}),
)
: [
{
commandName: "",
@ -1690,7 +1706,7 @@ export class ProfileEmployeeController extends Controller {
posLevel: "",
amount: "",
positionSalaryAmount: "",
refDoc: ""
refDoc: "",
},
];
@ -1760,48 +1776,52 @@ export class ProfileEmployeeController extends Controller {
// document: "",
// },
// ];
const actposition = [{
date: "",
position: "",
commandName: "",
agency: "",
document: "",
}];
const actposition = [
{
date: "",
position: "",
commandName: "",
agency: "",
document: "",
},
];
const duty_raw = await this.dutyRepository.find({
where: { profileEmployeeId: id, isDeleted: false },
order: { createdAt: "ASC" },
});
const duty =
duty_raw.length > 0
? duty_raw.map((item) => ({
date:
item.dateStart && item.dateEnd
? Extension.ToThaiNumber(
`${Extension.ToThaiFullDate2(item.dateStart)} - ${Extension.ToThaiFullDate2(item.dateEnd)}`,
)
: item.dateStart
? Extension.ToThaiNumber(Extension.ToThaiFullDate2(item.dateStart))
: item.dateEnd
? Extension.ToThaiNumber(Extension.ToThaiFullDate2(item.dateEnd))
: "",
type: "-",
detail: Extension.ToThaiNumber(item.detail),
agency: "-",
refCommandNo: item.refCommandNo
? item.refCommandDate
? Extension.ToThaiNumber(`${item.refCommandNo} ลว. ${Extension.ToThaiFullDate2(item.refCommandDate)}`)
: Extension.ToThaiNumber(item.refCommandNo)
: "-",
}))
: [
{
date: "",
type: "",
detail: "",
agency: "",
refCommandNo: "",
},
];
duty_raw.length > 0
? duty_raw.map((item) => ({
date:
item.dateStart && item.dateEnd
? Extension.ToThaiNumber(
`${Extension.ToThaiFullDate2(item.dateStart)} - ${Extension.ToThaiFullDate2(item.dateEnd)}`,
)
: item.dateStart
? Extension.ToThaiNumber(Extension.ToThaiFullDate2(item.dateStart))
: item.dateEnd
? Extension.ToThaiNumber(Extension.ToThaiFullDate2(item.dateEnd))
: "",
type: "-",
detail: Extension.ToThaiNumber(item.detail),
agency: "-",
refCommandNo: item.refCommandNo
? item.refCommandDate
? Extension.ToThaiNumber(
`${item.refCommandNo} ลว. ${Extension.ToThaiFullDate2(item.refCommandDate)}`,
)
: Extension.ToThaiNumber(item.refCommandNo)
: "-",
}))
: [
{
date: "",
type: "",
detail: "",
agency: "",
refCommandNo: "",
},
];
const assessments_raw = await this.profileAssessmentsRepository.find({
where: { profileEmployeeId: id, isDeleted: false },
order: { createdAt: "ASC" },
@ -1810,9 +1830,14 @@ export class ProfileEmployeeController extends Controller {
assessments_raw.length > 0
? assessments_raw.map((item) => ({
year: item.year ? Extension.ToThaiNumber((parseInt(item.year) + 543).toString()) : "",
period: item.period && item.period == "APR"
? Extension.ToThaiNumber(`1 เม.ย. ${(parseInt(item.year) + 543 - 1).toString()} - 31 มี.ค. ${(parseInt(item.year) + 543).toString()}`)
: Extension.ToThaiNumber(`1 ต.ค. ${(parseInt(item.year) + 543 - 1).toString()} - 30 ก.ย. ${(parseInt(item.year) + 543).toString()}`),
period:
item.period && item.period == "APR"
? Extension.ToThaiNumber(
`1 เม.ย. ${(parseInt(item.year) + 543 - 1).toString()} - 31 มี.ค. ${(parseInt(item.year) + 543).toString()}`,
)
: Extension.ToThaiNumber(
`1 ต.ค. ${(parseInt(item.year) + 543 - 1).toString()} - 30 ก.ย. ${(parseInt(item.year) + 543).toString()}`,
),
point1: item.point1 ? Extension.ToThaiNumber(item.point1.toString()) : "",
point1Total: item.point1Total
? Extension.ToThaiNumber(item.point1Total.toString())
@ -1821,8 +1846,8 @@ export class ProfileEmployeeController extends Controller {
point2Total: item.point2Total
? Extension.ToThaiNumber(item.point2Total.toString())
: "",
pointSum: item.pointSum
? Extension.ToThaiNumber(`ร้อยละ ${item.pointSum.toString()}`)
pointSum: item.pointSum
? Extension.ToThaiNumber(`ร้อยละ ${item.pointSum.toString()}`)
: "",
pointSumTh: item.pointSum ? Extension.textPoint(item.pointSum) : "",
level:
@ -1874,33 +1899,41 @@ export class ProfileEmployeeController extends Controller {
const otherIncome =
otherIncome_raw.length > 0
? await Promise.all(
otherIncome_raw.map(async(item) => {
const codeSitAbb = item.posNumCodeSitAbb ?? "-"
const commandNo = item.commandNo && item.commandYear
? item.commandNo+"/"+(item.commandYear > 2500 ? item.commandYear : item.commandYear + 543)
: "-"
const dateAffect = item.commandDateAffect
? `${Extension.ToThaiFullDate2(item.commandDateAffect)}`
: "-"
return {
commandName: item.commandName ?? "",
commandDateAffect: item.commandDateAffect
? Extension.ToThaiNumber(Extension.ToThaiFullDate2(item.commandDateAffect))
: "",
commandDateSign: item.commandDateSign
? Extension.ToThaiNumber(Extension.ToThaiFullDate2(item.commandDateSign))
: "",
commandNo: item.commandNo ? Extension.ToThaiNumber(item.commandNo) : "",
position: item.positionName,
posLevel: item.positionLevel
? Extension.ToThaiNumber(item.positionLevel)
: item.positionCee
? Extension.ToThaiNumber(item.positionCee)
: null,
amount: item.amount ? Extension.ToThaiNumber(Number(item.amount).toLocaleString()) : "",
refDoc: Extension.ToThaiNumber(`คำสั่ง ${codeSitAbb} ที่ ${commandNo} ลว. ${dateAffect}`)
}
}))
otherIncome_raw.map(async (item) => {
const codeSitAbb = item.posNumCodeSitAbb ?? "-";
const commandNo =
item.commandNo && item.commandYear
? item.commandNo +
"/" +
(item.commandYear > 2500 ? item.commandYear : item.commandYear + 543)
: "-";
const dateAffect = item.commandDateAffect
? `${Extension.ToThaiFullDate2(item.commandDateAffect)}`
: "-";
return {
commandName: item.commandName ?? "",
commandDateAffect: item.commandDateAffect
? Extension.ToThaiNumber(Extension.ToThaiFullDate2(item.commandDateAffect))
: "",
commandDateSign: item.commandDateSign
? Extension.ToThaiNumber(Extension.ToThaiFullDate2(item.commandDateSign))
: "",
commandNo: item.commandNo ? Extension.ToThaiNumber(item.commandNo) : "",
position: item.positionName,
posLevel: item.positionLevel
? Extension.ToThaiNumber(item.positionLevel)
: item.positionCee
? Extension.ToThaiNumber(item.positionCee)
: null,
amount: item.amount
? Extension.ToThaiNumber(Number(item.amount).toLocaleString())
: "",
refDoc: Extension.ToThaiNumber(
`คำสั่ง ${codeSitAbb} ที่ ${commandNo} ลว. ${dateAffect}`,
),
};
}),
)
: [
{
commandName: "",
@ -1910,7 +1943,7 @@ export class ProfileEmployeeController extends Controller {
position: "",
posLevel: "",
amount: "",
refDoc: ""
refDoc: "",
},
];
@ -1957,19 +1990,24 @@ export class ProfileEmployeeController extends Controller {
(_child3 == null ? "" : _child3 + " ") +
(_child2 == null ? "" : _child2 + " ") +
(_child1 == null ? "" : _child1 + " ") +
(_root == null ? "" : _root).trim()
const _position = (profiles?.position != null ?
profiles.posType != null && profiles?.posLevel != null
? Extension.ToThaiNumber(`${profiles.position} ${profiles.posType.posTypeShortName} ${profiles.posLevel.posLevelName}`)
: profiles.position
: "").trim()
(_root == null ? "" : _root).trim();
const _position = (
profiles?.position != null
? profiles.posType != null && profiles?.posLevel != null
? Extension.ToThaiNumber(
`${profiles.position} ${profiles.posType.posTypeShortName} ${profiles.posLevel.posLevelName}`,
)
: profiles.position
: ""
).trim();
const ocAssistance = await this.profileAssistanceRepository.findOne({
select: ["agency", "profileEmployeeId", "commandName", "status", "isDeleted"],
where: {
profileEmployeeId: id,
commandName: "ให้ช่วยราชการ",
status: "PENDING",
isDeleted: false, },
isDeleted: false,
},
order: { createdAt: "ASC" },
});
@ -2041,7 +2079,8 @@ export class ProfileEmployeeController extends Controller {
ocFullPath: org,
ocAssistance: ocAssistance?.agency ?? org,
root: _root == null ? "" : _root,
agency: (_child4 == null ? "" : _child4 + " ") +
agency:
(_child4 == null ? "" : _child4 + " ") +
(_child3 == null ? "" : _child3 + " ") +
(_child2 == null ? "" : _child2 + " ") +
(_child1 == null ? "" : _child1).trim(),
@ -2172,7 +2211,7 @@ export class ProfileEmployeeController extends Controller {
assessments,
profileAbility,
otherIncome,
retires
retires,
};
return new HttpSuccess({
@ -5684,13 +5723,14 @@ export class ProfileEmployeeController extends Controller {
// profile.position = _null;
// profile.posLevelId = _null;
// profile.posTypeId = _null;
if (profile.keycloak != null) {
if (profile.keycloak != null && profile.keycloak != "" && profile.isDelete === false) {
const delUserKeycloak = await deleteUser(profile.keycloak);
if (delUserKeycloak) {
// Task #228
// profile.keycloak = _null;
profile.roleKeycloaks = [];
profile.isActive = false;
profile.isDelete = true;
}
}
await this.profileRepo.save(profile);
@ -6162,7 +6202,10 @@ export class ProfileEmployeeController extends Controller {
.leftJoinAndSelect("current_holders.orgChild2", "orgChild2")
.leftJoinAndSelect("current_holders.orgChild3", "orgChild3")
.leftJoinAndSelect("current_holders.orgChild4", "orgChild4")
.where("profile.isActive = :isActive", { isActive: false })
.where(body.system ? "profile.isActive = :isActive" : "profile.isDelete = :isDelete", {
isActive: false,
isDelete: true,
})
.andWhere(
new Brackets((qb) => {
qb.orWhere(body.keyword ? queryLike : "1=1", { keyword: `%${body.keyword}%` });