From fb4196cfa23b3a79fe26e03c119cbbc934dc5b7b Mon Sep 17 00:00:00 2001 From: waruneeauy Date: Thu, 2 Apr 2026 16:32:29 +0700 Subject: [PATCH] fix keycloak user & update isDelete --- src/controllers/CommandController.ts | 27 +- src/controllers/OrganizationController.ts | 10 +- .../ProfileChangeNameController.ts | 4 +- .../ProfileChangeNameEmployeeController.ts | 2 +- ...ProfileChangeNameEmployeeTempController.ts | 2 +- src/controllers/ProfileController.ts | 378 ++++++++++-------- src/controllers/ProfileEmployeeController.ts | 367 +++++++++-------- .../ProfileEmployeeTempController.ts | 3 +- src/controllers/UserController.ts | 6 +- 9 files changed, 445 insertions(+), 354 deletions(-) diff --git a/src/controllers/CommandController.ts b/src/controllers/CommandController.ts index 63cc937b..4fe95e78 100644 --- a/src/controllers/CommandController.ts +++ b/src/controllers/CommandController.ts @@ -1653,12 +1653,13 @@ export class CommandController extends Controller { _profile.leaveDate = _Date; _profile.dateLeave = _Date; _profile.lastUpdatedAt = _Date; - if (_profile.keycloak != null && _profile.keycloak != "") { + if (_profile.keycloak != null && _profile.keycloak != "" && _profile.isDelete === false) { // console.log("4. disable keycloak/authen") const delUserKeycloak = await deleteUser(_profile.keycloak, adminToken); if (delUserKeycloak) { // Task #228 // _profile.keycloak = ""; + _profile.isDelete = true; _profile.roleKeycloaks = []; } } @@ -1710,12 +1711,13 @@ export class CommandController extends Controller { _profileEmp.leaveDate = _Date; _profileEmp.dateLeave = _Date; _profileEmp.lastUpdatedAt = _Date; - if (_profileEmp.keycloak != null && _profileEmp.keycloak != "") { + if (_profileEmp.keycloak != null && _profileEmp.keycloak != "" && _profileEmp.isDelete === false) { // disable keycloak/authen const delUserKeycloak = await deleteUser(_profileEmp.keycloak, adminToken); if (delUserKeycloak) { // Task #228 // _profileEmp.keycloak = ""; + _profileEmp.isDelete = true; _profileEmp.roleKeycloaks = []; } } @@ -4130,13 +4132,14 @@ export class CommandController extends Controller { await removeProfileInOrganize(profile.id, "OFFICER"); } if (clearProfile.status) { - 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; } } profile.leaveCommandId = item.commandId ?? _null; @@ -4535,13 +4538,14 @@ export class CommandController extends Controller { } if (clearProfile.status) { - 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; } } profile.leaveCommandId = item.commandId ?? _null; @@ -4756,13 +4760,14 @@ export class CommandController extends Controller { const clearProfile = await checkCommandType(String(item.commandId)); const _null: any = null; if (clearProfile.status) { - 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; } } profile.isLeave = item.isLeave; @@ -5253,13 +5258,14 @@ export class CommandController extends Controller { const clearProfile = await checkCommandType(String(item.commandId)); if (clearProfile.status) { retireTypeName = clearProfile.retireTypeName ?? ""; - 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; } } _profile.leaveCommandId = item.commandId ?? _null; @@ -5437,13 +5443,14 @@ export class CommandController extends Controller { const clearProfile = await checkCommandType(String(item.commandId)); if (clearProfile.status) { retireTypeName = clearProfile.retireTypeName ?? ""; - 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; } } _profile.leaveCommandId = item.commandId ?? _null; @@ -5776,13 +5783,14 @@ export class CommandController extends Controller { } const clearProfile = await checkCommandType(String(item.commandId)); if (clearProfile.status) { - 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; } } _profile.leaveCommandId = item.commandId ?? _null; @@ -6214,13 +6222,14 @@ export class CommandController extends Controller { const clearProfile = await checkCommandType(String(item.commandId)); const _null: any = null; if (clearProfile.status) { - 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; } } _profile.leaveCommandId = item.commandId ?? _null; diff --git a/src/controllers/OrganizationController.ts b/src/controllers/OrganizationController.ts index e5a39411..39752b7e 100644 --- a/src/controllers/OrganizationController.ts +++ b/src/controllers/OrganizationController.ts @@ -7796,10 +7796,11 @@ export class OrganizationController extends Controller { profile.leaveType = "RETIRE"; profile.isActive = false; - if (profile.keycloak != null && profile.keycloak != "") { + if (profile.keycloak != null && profile.keycloak != "" && profile.isDelete === false) { const delUserKeycloak = await deleteUser(profile.keycloak, token); if (delUserKeycloak) { - profile.keycloak = ""; + // profile.keycloak = ""; + profile.isDelete = true; profile.roleKeycloaks = []; checkOfficer += 1; } else { @@ -7824,10 +7825,11 @@ export class OrganizationController extends Controller { profileEmp.lastUpdatedAt = new Date(); profileEmp.isActive = false; - if (profileEmp.keycloak != null && profileEmp.keycloak != "") { + if (profileEmp.keycloak != null && profileEmp.keycloak != "" && profileEmp.isDelete === false) { const delUserKeycloak = await deleteUser(profileEmp.keycloak, token); if (delUserKeycloak) { - profileEmp.keycloak = ""; + // profileEmp.keycloak = ""; + profileEmp.isDelete = true; profileEmp.roleKeycloaks = []; checkEmployee += 1; } else { diff --git a/src/controllers/ProfileChangeNameController.ts b/src/controllers/ProfileChangeNameController.ts index 77e63aa6..77cff634 100644 --- a/src/controllers/ProfileChangeNameController.ts +++ b/src/controllers/ProfileChangeNameController.ts @@ -115,7 +115,7 @@ export class ProfileChangeNameController extends Controller { await this.profileRepository.save(profile, { data: req }); setLogDataDiff(req, { before, after: profile }); - if (profile != null && profile.keycloak != null) { + if (profile != null && profile.keycloak != null && profile.isDelete === false) { const result = await updateName( profile.keycloak, profile.firstName, @@ -186,7 +186,7 @@ export class ProfileChangeNameController extends Controller { } // ปิดไว้ก่อนเพราะ error ต้องใช้ keycloak ที่มีสิทธิ์ในการ update //update 17/07 - if (profile != null && profile.keycloak != null) { + if (profile != null && profile.keycloak != null && profile.isDelete === false) { const result = await updateName( profile.keycloak, profile.firstName, diff --git a/src/controllers/ProfileChangeNameEmployeeController.ts b/src/controllers/ProfileChangeNameEmployeeController.ts index 76f5da7f..c2df9c8c 100644 --- a/src/controllers/ProfileChangeNameEmployeeController.ts +++ b/src/controllers/ProfileChangeNameEmployeeController.ts @@ -121,7 +121,7 @@ export class ProfileChangeNameEmployeeController extends Controller { await this.profileEmployeeRepo.save(profile, { data: req }); setLogDataDiff(req, { before, after: profile }); - if (profile != null && profile.keycloak != null) { + if (profile != null && profile.keycloak != null && profile.isDelete === false) { const result = await updateName( profile.keycloak, profile.firstName, diff --git a/src/controllers/ProfileChangeNameEmployeeTempController.ts b/src/controllers/ProfileChangeNameEmployeeTempController.ts index 78aaa09d..92e1e2f3 100644 --- a/src/controllers/ProfileChangeNameEmployeeTempController.ts +++ b/src/controllers/ProfileChangeNameEmployeeTempController.ts @@ -113,7 +113,7 @@ export class ProfileChangeNameEmployeeTempController extends Controller { await this.profileEmployeeRepo.save(profile, { data: req }); setLogDataDiff(req, { before, after: profile }); - if (profile != null && profile.keycloak != null) { + if (profile != null && profile.keycloak != null && profile.isDelete === false) { const result = await updateName( profile.keycloak, profile.firstName, diff --git a/src/controllers/ProfileController.ts b/src/controllers/ProfileController.ts index 18e3f96c..9e758e67 100644 --- a/src/controllers/ProfileController.ts +++ b/src/controllers/ProfileController.ts @@ -1037,7 +1037,7 @@ export class ProfileController extends Controller { profiles.current_holders.find((x) => x.orgRevisionId == orgRevision?.id) == null ? null : profiles.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.id; - + const root = profiles.current_holders == null || profiles.current_holders.length == 0 || @@ -1098,7 +1098,9 @@ export class ProfileController 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( @@ -1130,7 +1132,9 @@ export class ProfileController 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)}`, + ), })) : [ { @@ -1138,7 +1142,7 @@ export class ProfileController extends Controller { degree: "", place: "", duration: "", - date: "" + date: "", }, ]; @@ -1181,14 +1185,14 @@ export class ProfileController 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({ @@ -1308,7 +1312,9 @@ export class ProfileController extends Controller { section: item.section ? Extension.ToThaiNumber(item.section) : "", page: item.page ? Extension.ToThaiNumber(item.page) : "", refCommandDate: item.refCommandDate - ? Extension.ToThaiNumber(`ราชกิจจานุเบกษา เล่มที่ ${item.volume ?? "-"} ตอนที่ ${item.section ?? "-"} ลว. ${Extension.ToThaiFullDate2(item.refCommandDate)}`) + ? Extension.ToThaiNumber( + `ราชกิจจานุเบกษา เล่มที่ ${item.volume ?? "-"} ตอนที่ ${item.section ?? "-"} ลว. ${Extension.ToThaiFullDate2(item.refCommandDate)}`, + ) : "-", note: item.note ? Extension.ToThaiNumber(item.note) : "", })) @@ -1325,7 +1331,7 @@ export class ProfileController extends Controller { section: "", page: "", refCommandDate: "", - note: "" + note: "", }, ]; @@ -1405,9 +1411,7 @@ export class ProfileController 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); @@ -1441,7 +1445,7 @@ export class ProfileController extends Controller { // }); if (leaves.length === 0) { - leaves.push({year:""}); + leaves.push({ year: "" }); } const leave2_raw = await this.profileLeaveRepository @@ -1473,12 +1477,12 @@ export class ProfileController 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: @@ -1570,79 +1574,93 @@ export class ProfileController extends Controller { ]; const position_raw = await this.salaryRepo.find({ - where: [{ - profileId: id, - commandCode: In(["0","1","2","3","4","8","9","10","11","12","13","14","15","16","20"]), - // isEntry: false, - }, - { profileId: id, commandCode: IsNull() }], + where: [ + { + profileId: id, + commandCode: In([ + "0", + "1", + "2", + "3", + "4", + "8", + "9", + "10", + "11", + "12", + "13", + "14", + "15", + "16", + "20", + ]), + // isEntry: false, + }, + { profileId: 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: "", @@ -1654,7 +1672,7 @@ export class ProfileController extends Controller { posLevel: "", amount: "", positionSalaryAmount: "", - refDoc: "" + refDoc: "", }, ]; @@ -1672,7 +1690,7 @@ export class ProfileController extends Controller { // if (retire_raw) { // const startDate = retire_raw.commandDateAffect; - + // // คำนวณจำนวนวันจากวันพ้นสภาพถึงปัจจุบัน // let daysCount = 0; // if (startDate) { @@ -1701,56 +1719,53 @@ export class ProfileController extends Controller { select: ["dateStart", "profileId", "dateEnd", "position", "commandId", "isDeleted"], where: { profileId: id, status: true, isDeleted: false }, order: { createdAt: "ASC" }, - }); + }); let _actpositions = []; - if (actposition_raw.length > 0){ + if (actposition_raw.length > 0) { for (const item of actposition_raw) { let _commandTypename: string = "รักษาการในตำแหน่ง"; let _document: string = "-"; let _org: string = "-"; if (item.commandId) { - const { - posNumCodeSitAbb, - commandTypeName, - commandNo, - commandYear, - commandExcecuteDate, - } = await getPosNumCodeSit(item.commandId, "REPORTED"); + const { posNumCodeSitAbb, commandTypeName, commandNo, commandYear, commandExcecuteDate } = + await getPosNumCodeSit(item.commandId, "REPORTED"); - _document = Extension.ToThaiNumber(`คำสั่ง ${posNumCodeSitAbb ?? "-"} ที่ ${commandNo}/${commandYear>2500?commandYear:commandYear+543} ลว. ${(Extension.ToThaiFullDate2(commandExcecuteDate))}`) + _document = Extension.ToThaiNumber( + `คำสั่ง ${posNumCodeSitAbb ?? "-"} ที่ ${commandNo}/${commandYear > 2500 ? commandYear : commandYear + 543} ลว. ${Extension.ToThaiFullDate2(commandExcecuteDate)}`, + ); _commandTypename = commandTypeName; } // ค้นหาหน่วยงานที่รักษาการ const _posmasterAct = await this.posMasterActRepository.findOne({ where: { posMasterChildId: posMasterId ?? "", - statusReport: "DONE" - } + statusReport: "DONE", + }, }); if (_posmasterAct) { const _posMater = await this.posMasterRepo.findOne({ where: { - id: _posmasterAct.posMasterId + id: _posmasterAct.posMasterId, }, - relations:{ + relations: { orgRoot: true, orgChild1: true, orgChild2: true, orgChild3: true, orgChild4: true, - } + }, }); - let child4 = _posMater?.orgChild4?.orgChild4Name ?? "" - let child3 = _posMater?.orgChild3?.orgChild3Name ?? "" - let child2 = _posMater?.orgChild2?.orgChild2Name ?? "" - let child1 = _posMater?.orgChild1?.orgChild1Name ?? "" - let root = _posMater?.orgRoot?.orgRootName ?? "" + let child4 = _posMater?.orgChild4?.orgChild4Name ?? ""; + let child3 = _posMater?.orgChild3?.orgChild3Name ?? ""; + let child2 = _posMater?.orgChild2?.orgChild2Name ?? ""; + let child1 = _posMater?.orgChild1?.orgChild1Name ?? ""; + let root = _posMater?.orgRoot?.orgRootName ?? ""; _org = `${child4} ${child3} ${child2} ${child1} ${root}`.trim(); } _actpositions.push({ - date: + date: item.dateStart && item.dateEnd ? Extension.ToThaiNumber( `${Extension.ToThaiFullDate2(item.dateStart)} - ${Extension.ToThaiFullDate2(item.dateEnd)}`, @@ -1763,14 +1778,14 @@ export class ProfileController extends Controller { position: item.position ? Extension.ToThaiNumber(item.position) : "", commandName: _commandTypename, agency: _org, - note: _posmasterAct && _posmasterAct?.posMasterOrder - ? Extension.ToThaiNumber(_posmasterAct?.posMasterOrder.toString()) - : "-", + note: + _posmasterAct && _posmasterAct?.posMasterOrder + ? Extension.ToThaiNumber(_posmasterAct?.posMasterOrder.toString()) + : "-", document: _document, }); } - } - else { + } else { _actpositions.push({ date: "", position: "", @@ -1786,7 +1801,7 @@ export class ProfileController extends Controller { where: { profileId: id, /*status: "PENDING",*/ isDeleted: false }, order: { createdAt: "ASC" }, }); - let _assistances = [] + let _assistances = []; if (assistance_raw.length > 0) { for (const item of assistance_raw) { let _commandTypename: string = item.commandName ?? "ให้ช่วยราชการ"; @@ -1794,19 +1809,16 @@ export class ProfileController extends Controller { let _org: string = item.agency ? Extension.ToThaiNumber(item.agency) : "-"; if (item.commandId) { - const { - posNumCodeSitAbb, - commandTypeName, - commandNo, - commandYear, - commandExcecuteDate, - } = await getPosNumCodeSit(item.commandId); + const { posNumCodeSitAbb, commandTypeName, commandNo, commandYear, commandExcecuteDate } = + await getPosNumCodeSit(item.commandId); - _document = Extension.ToThaiNumber(`คำสั่ง ${posNumCodeSitAbb ?? "-"} ที่ ${commandNo}/${commandYear>2500?commandYear:commandYear+543} ลว. ${(Extension.ToThaiFullDate2(commandExcecuteDate))}`) + _document = Extension.ToThaiNumber( + `คำสั่ง ${posNumCodeSitAbb ?? "-"} ที่ ${commandNo}/${commandYear > 2500 ? commandYear : commandYear + 543} ลว. ${Extension.ToThaiFullDate2(commandExcecuteDate)}`, + ); _commandTypename = commandTypeName; } _assistances.push({ - date: + date: item.dateStart && item.dateEnd ? Extension.ToThaiNumber( `${Extension.ToThaiFullDate2(item.dateStart)} - ${Extension.ToThaiFullDate2(item.dateEnd)}`, @@ -1847,10 +1859,12 @@ export class ProfileController extends Controller { type: "-", detail: Extension.ToThaiNumber(item.detail), agency: "-", - refCommandNo: item.refCommandNo + refCommandNo: item.refCommandNo ? item.refCommandDate - ? Extension.ToThaiNumber(`${item.refCommandNo} ลว. ${Extension.ToThaiFullDate2(item.refCommandDate)}`) - : Extension.ToThaiNumber(item.refCommandNo) + ? Extension.ToThaiNumber( + `${item.refCommandNo} ลว. ${Extension.ToThaiFullDate2(item.refCommandDate)}`, + ) + : Extension.ToThaiNumber(item.refCommandNo) : "-", })) : [ @@ -1870,9 +1884,14 @@ export class ProfileController 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()) @@ -1881,8 +1900,8 @@ export class ProfileController 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: @@ -1935,33 +1954,41 @@ export class ProfileController 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: "", @@ -1971,7 +1998,7 @@ export class ProfileController extends Controller { position: "", posLevel: "", amount: "", - refDoc: "" + refDoc: "", }, ]; @@ -2018,7 +2045,7 @@ export class ProfileController extends Controller { ) : ""; - let portfolios:any[] = []; + let portfolios: any[] = []; await new CallAPI() .GetData(req, `/development/portfolio/kk1/${profiles?.keycloak}`) .then((x) => { @@ -2031,7 +2058,7 @@ export class ProfileController extends Controller { portfolios = portfolios.map((x: any) => ({ name: x.name ? Extension.ToThaiNumber(x.name) : "-", year: x.year ? Extension.ToThaiNumber(x.year.toString()) : "-", - position: `${x.position ?? "-"}` + position: `${x.position ?? "-"}`, })); } const org = @@ -2039,19 +2066,21 @@ export class ProfileController extends Controller { (_child3 == null ? "" : _child3 + " ") + (_child2 == null ? "" : _child2 + " ") + (_child1 == null ? "" : _child1 + " ") + - (_root == null ? "" : _root).trim() - const _position = profiles?.position != null ? - profiles?.posLevel != null - ? `${profiles.position}${profiles.posLevel.posLevelName}` - : profiles.position - : "" + (_root == null ? "" : _root).trim(); + const _position = + profiles?.position != null + ? profiles?.posLevel != null + ? `${profiles.position}${profiles.posLevel.posLevelName}` + : profiles.position + : ""; const ocAssistance = await this.profileAssistanceRepository.findOne({ select: ["agency", "profileId", "commandName", "status", "isDeleted"], - where: { + where: { profileId: id, commandName: "ให้ช่วยราชการ", status: "PENDING", - isDeleted: false, }, + isDeleted: false, + }, order: { createdAt: "ASC" }, }); const data = { @@ -2080,7 +2109,8 @@ export class ProfileController 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(), @@ -2212,7 +2242,7 @@ export class ProfileController extends Controller { profileAbility, otherIncome, portfolios, - retires + retires, }; return new HttpSuccess({ @@ -5391,7 +5421,7 @@ export class ProfileController extends Controller { await this.profileRepo.save(record); // setLogDataDiff(request, { before, after: record }); - if (record != null && record.keycloak != null) { + if (record != null && record.keycloak != null && record.isDelete === false) { const result = await updateName( record.keycloak, record.firstName, @@ -5710,7 +5740,7 @@ export class ProfileController extends Controller { await this.profileRepo.save(record, { data: request }); setLogDataDiff(request, { before, after: record }); - if (record != null && record.keycloak != null) { + if (record != null && record.keycloak != null && record.isDelete === false) { const result = await updateName( record.keycloak, record.firstName, @@ -11260,13 +11290,14 @@ export class ProfileController 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, { data: request }); @@ -11372,7 +11403,10 @@ export class ProfileController 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}%` }); diff --git a/src/controllers/ProfileEmployeeController.ts b/src/controllers/ProfileEmployeeController.ts index ffdb2085..2a7fba38 100644 --- a/src/controllers/ProfileEmployeeController.ts +++ b/src/controllers/ProfileEmployeeController.ts @@ -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}%` }); diff --git a/src/controllers/ProfileEmployeeTempController.ts b/src/controllers/ProfileEmployeeTempController.ts index a864710d..f5182deb 100644 --- a/src/controllers/ProfileEmployeeTempController.ts +++ b/src/controllers/ProfileEmployeeTempController.ts @@ -3583,13 +3583,14 @@ export class ProfileEmployeeTempController 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); diff --git a/src/controllers/UserController.ts b/src/controllers/UserController.ts index 52b97622..0b4629da 100644 --- a/src/controllers/UserController.ts +++ b/src/controllers/UserController.ts @@ -277,6 +277,7 @@ export class KeycloakController extends Controller { // Task #228 // const _null: any = null; // profileEmp.keycloak = _null; + profileEmp.isDelete = true; profileEmp.roleKeycloaks = []; await this.profileEmpRepo.save(profileEmp); } @@ -284,6 +285,7 @@ export class KeycloakController extends Controller { // Task #228 // const _null: any = null; // profile.keycloak = _null; + profile.isDelete = true; profile.roleKeycloaks = []; await this.profileRepo.save(profile); return new HttpSuccess(); @@ -569,7 +571,7 @@ export class KeycloakController extends Controller { .leftJoinAndSelect("current_holders.orgChild3", "orgChild3") .leftJoinAndSelect("current_holders.orgChild4", "orgChild4") // .where("profile.keycloak IS NOT NULL AND profile.keycloak != ''") - .where("profile.isActive = :isActive", { isActive: true }) + .where("profile.isDelete = :isDelete", { isDelete: false }) .andWhere(checkChildFromRole) .andWhere(conditions) .andWhere( @@ -613,7 +615,7 @@ export class KeycloakController extends Controller { .leftJoinAndSelect("current_holders.orgChild3", "orgChild3") .leftJoinAndSelect("current_holders.orgChild4", "orgChild4") // .where("profileEmployee.keycloak IS NOT NULL AND profileEmployee.keycloak != ''") - .where("profileEmployee.isActive = :isActive", { isActive: true }) + .where("profileEmployee.isDelete = :isDelete", { isDelete: false }) .andWhere(checkChildFromRole) .andWhere(conditions) .andWhere({ employeeClass: "PERM" })