From 2fdf5e58543ce41020288b3964e7b4e4bcd62e5c Mon Sep 17 00:00:00 2001 From: harid Date: Fri, 20 Mar 2026 16:55:27 +0700 Subject: [PATCH] =?UTF-8?q?=E0=B9=81=E0=B8=81=E0=B9=89=E0=B9=84=E0=B8=82?= =?UTF-8?q?=20middleware=20log=20=E0=B9=83=E0=B8=AB=E0=B9=89=E0=B9=83?= =?UTF-8?q?=E0=B8=8A=E0=B9=89=E0=B8=88=E0=B8=B2=E0=B8=81=20token=20#223?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/ProfileController.ts | 216 +++++++++---------- src/controllers/ProfileEmployeeController.ts | 212 +++++++++--------- src/middlewares/logs.ts | 17 +- 3 files changed, 224 insertions(+), 221 deletions(-) diff --git a/src/controllers/ProfileController.ts b/src/controllers/ProfileController.ts index e4685a53..3e0d6fe1 100644 --- a/src/controllers/ProfileController.ts +++ b/src/controllers/ProfileController.ts @@ -1107,11 +1107,11 @@ export class ProfileController extends Controller { })) : [ { - certificateType: "-", - issuer: "-", - certificateNo: "-", - detail: "-", - issueToExpireDate: "-", + certificateType: "", + issuer: "", + certificateNo: "", + detail: "", + issueToExpireDate: "", }, ]; const training_raw = await this.trainingRepository.find({ @@ -1130,11 +1130,11 @@ export class ProfileController extends Controller { })) : [ { - institute: "-", - degree: "-", - place: "-", - duration: "-", - date: "-" + institute: "", + degree: "", + place: "", + duration: "", + date: "" }, ]; @@ -1155,10 +1155,10 @@ export class ProfileController extends Controller { })) : [ { - disciplineYear: "-", - disciplineDetail: "-", - refNo: "-", - level: "-", + disciplineYear: "", + disciplineDetail: "", + refNo: "", + level: "", }, ]; @@ -1181,10 +1181,10 @@ export class ProfileController extends Controller { })) : [ { - institute: "-", - date: "-", - degree: "-", - level: "-" + institute: "", + date: "", + degree: "", + level: "" }, ]; const salary_raw = await this.salaryRepo.find({ @@ -1251,19 +1251,19 @@ export class ProfileController extends Controller { })) : [ { - commandName: "-", - salaryDate: "-", - position: "-", - posNo: "-", - salary: "-", - special: "-", - rank: "-", - refAll: "-", - positionLevel: "-", - positionType: "-", - positionAmount: "-", - fullName: "-", - ocFullPath: "-", + commandName: "", + salaryDate: "", + position: "", + posNo: "", + salary: "", + special: "", + rank: "", + refAll: "", + positionLevel: "", + positionType: "", + positionAmount: "", + fullName: "", + ocFullPath: "", }, ]; @@ -1310,18 +1310,18 @@ export class ProfileController extends Controller { })) : [ { - receiveDate: "-", - insigniaName: "-", - insigniaShortName: "-", - insigniaTypeName: "-", - no: "-", - issue: "-", - volumeNo: "-", - volume: "-", - section: "-", - page: "-", - refCommandDate: "-", - note: "-" + receiveDate: "", + insigniaName: "", + insigniaShortName: "", + insigniaTypeName: "", + no: "", + issue: "", + volumeNo: "", + volume: "", + section: "", + page: "", + refCommandDate: "", + note: "" }, ]; @@ -1417,10 +1417,10 @@ export class ProfileController extends Controller { })) : [ { - date: "-", - type: "-", - leaveDays: "-", - reason: "-", + date: "", + type: "", + leaveDays: "", + reason: "", }, ]; const children_raw = await this.profileChildrenRepository.find({ @@ -1439,11 +1439,11 @@ export class ProfileController extends Controller { : [ { no: "", - childrenPrefix: "-", - childrenFirstName: "-", - childrenLastName: "-", - childrenFullName: "-", - childrenLive: "-", + childrenPrefix: "", + childrenFirstName: "", + childrenLastName: "", + childrenFullName: "", + childrenLive: "", }, ]; const changeName_raw = await this.changeNameRepository.find({ @@ -1463,11 +1463,11 @@ export class ProfileController extends Controller { })) : [ { - createdAt: "-", - status: "-", - prefix: "-", - firstName: "-", - lastName: "-", + createdAt: "", + status: "", + prefix: "", + firstName: "", + lastName: "", }, ]; @@ -1487,8 +1487,8 @@ export class ProfileController extends Controller { })) : [ { - birthDateOld: "-", - birthDate: "-", + birthDateOld: "", + birthDate: "", }, ]; @@ -1529,16 +1529,16 @@ export class ProfileController extends Controller { })) : [ { - commandName: "-", - commandDateAffect: "-", - commandDateSign: "-", - posNo: "-", - position: "-", - posType: "-", - posLevel: "-", - amount: "-", - positionSalaryAmount: "-", - refDoc: "-" + commandName: "", + commandDateAffect: "", + commandDateSign: "", + posNo: "", + position: "", + posType: "", + posLevel: "", + amount: "", + positionSalaryAmount: "", + refDoc: "" }, ]; @@ -1591,7 +1591,7 @@ export class ProfileController extends Controller { // กรณีไม่มีข้อมูล if (retires.length === 0) { - retires.push({ date: "-", detail: "-", day: "-" }); + retires.push({ date: "", detail: "", day: "" }); } // รักษาการ @@ -1674,12 +1674,12 @@ export class ProfileController extends Controller { } else { _actpositions.push({ - date: "-", - position: "-", - commandName: "-", - agency: "-", - note: "-", - document: "-", + date: "", + position: "", + commandName: "", + agency: "", + note: "", + document: "", }); } // ช่วยราชการ @@ -1732,12 +1732,12 @@ export class ProfileController extends Controller { } else { _assistances.push({ - date: "-", - position: "-", - commandName: "-", - agency: "-", - note: "-", - document: "-", + date: "", + position: "", + commandName: "", + agency: "", + note: "", + document: "", }); } // Merge รักษาการ และ ช่วยราชาร @@ -1771,11 +1771,11 @@ export class ProfileController extends Controller { })) : [ { - date: "-", - type: "-", - detail: "-", - agency: "-", - refCommandNo: "-", + date: "", + type: "", + detail: "", + agency: "", + refCommandNo: "", }, ]; const assessments_raw = await this.profileAssessmentsRepository.find({ @@ -1814,13 +1814,13 @@ export class ProfileController extends Controller { })) : [ { - year: "-", - period: "-", - point1: "-", - point2: "-", - pointSum: "-", - pointSumTh: "-", - level: "-", + year: "", + period: "", + point1: "", + point2: "", + pointSum: "", + pointSumTh: "", + level: "", }, ]; const profileAbility_raw = await this.profileAbilityRepo.find({ @@ -1835,8 +1835,8 @@ export class ProfileController extends Controller { })) : [ { - field: "-", - detail: "-", + field: "", + detail: "", }, ]; @@ -1870,14 +1870,14 @@ export class ProfileController extends Controller { })) : [ { - commandName: "-", - commandDateAffect: "-", - commandDateSign: "-", - commandNo: "-", - position: "-", - posLevel: "-", - amount: "-", - refDoc: "-" + commandName: "", + commandDateAffect: "", + commandDateSign: "", + commandNo: "", + position: "", + posLevel: "", + amount: "", + refDoc: "" }, ]; @@ -1924,15 +1924,15 @@ export class ProfileController extends Controller { ) : ""; - let portfolios: any; + let portfolios:any[] = []; await new CallAPI() .GetData(req, `/development/portfolio/kk1/${profiles?.keycloak}`) .then((x) => { - portfolios = x; + portfolios = Array.isArray(x) ? x : []; }) .catch(() => {}); - if (!portfolios) { - portfolios = [{ name: "-", year: "-", position: "-" }]; + if (portfolios.length == 0) { + portfolios = [{ name: "", year: "", position: "" }]; } else { portfolios = portfolios.map((x: any) => ({ name: x.name ? Extension.ToThaiNumber(x.name) : "-", diff --git a/src/controllers/ProfileEmployeeController.ts b/src/controllers/ProfileEmployeeController.ts index c87f61f9..559e5b70 100644 --- a/src/controllers/ProfileEmployeeController.ts +++ b/src/controllers/ProfileEmployeeController.ts @@ -1022,12 +1022,12 @@ export class ProfileEmployeeController extends Controller { order: { lastUpdatedAt: "DESC" }, }); - const posMasterId = - profiles.current_holders == null || - profiles.current_holders.length == 0 || - profiles.current_holders.find((x) => x.orgRevisionId == orgRevision?.id) == null - ? null - : profiles.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.id; + // const posMasterId = + // profiles.current_holders == null || + // profiles.current_holders.length == 0 || + // 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 || @@ -1102,11 +1102,11 @@ export class ProfileEmployeeController extends Controller { })) : [ { - certificateType: "-", - issuer: "-", - certificateNo: "-", - detail: "-", - issueToExpireDate: "-", + certificateType: "", + issuer: "", + certificateNo: "", + detail: "", + issueToExpireDate: "", }, ]; const training_raw = await this.trainingRepository.find({ @@ -1125,11 +1125,11 @@ export class ProfileEmployeeController extends Controller { })) : [ { - institute: "-", - degree: "-", - place: "-", - duration: "-", - date: "-" + institute: "", + degree: "", + place: "", + duration: "", + date: "" }, ]; @@ -1150,10 +1150,10 @@ export class ProfileEmployeeController extends Controller { })) : [ { - disciplineYear: "-", - disciplineDetail: "-", - refNo: "-", - level: "-", + disciplineYear: "", + disciplineDetail: "", + refNo: "", + level: "", }, ]; @@ -1176,10 +1176,10 @@ export class ProfileEmployeeController extends Controller { })) : [ { - institute: "-", - date: "-", - degree: "-", - level: "-" + institute: "", + date: "", + degree: "", + level: "" }, ]; const salary_raw = await this.salaryRepo.find({ @@ -1246,19 +1246,19 @@ export class ProfileEmployeeController extends Controller { })) : [ { - commandName: "-", - salaryDate: "-", - position: "-", - posNo: "-", - salary: "-", - special: "-", - rank: "-", - refAll: "-", - positionLevel: "-", - positionType: "-", - positionAmount: "-", - fullName: "-", - ocFullPath: "-", + commandName: "", + salaryDate: "", + position: "", + posNo: "", + salary: "", + special: "", + rank: "", + refAll: "", + positionLevel: "", + positionType: "", + positionAmount: "", + fullName: "", + ocFullPath: "", }, ]; @@ -1305,17 +1305,17 @@ export class ProfileEmployeeController extends Controller { })) : [ { - receiveDate: "-", - insigniaName: "-", - insigniaShortName: "-", - insigniaTypeName: "-", - no: "-", - issue: "-", - volumeNo: "-", - volume: "-", - section: "-", - page: "-", - refCommandDate: "-", + receiveDate: "", + insigniaName: "", + insigniaShortName: "", + insigniaTypeName: "", + no: "", + issue: "", + volumeNo: "", + volume: "", + section: "", + page: "", + refCommandDate: "", }, ]; @@ -1411,10 +1411,10 @@ export class ProfileEmployeeController extends Controller { })) : [ { - date: "-", - type: "-", - leaveDays: "-", - reason: "-", + date: "", + type: "", + leaveDays: "", + reason: "", }, ]; const children_raw = await this.profileChildrenRepository.find({ @@ -1433,11 +1433,11 @@ export class ProfileEmployeeController extends Controller { : [ { no: "", - childrenPrefix: "-", - childrenFirstName: "-", - childrenLastName: "-", - childrenFullName: "-", - childrenLive: "-", + childrenPrefix: "", + childrenFirstName: "", + childrenLastName: "", + childrenFullName: "", + childrenLive: "", }, ]; const changeName_raw = await this.changeNameRepository.find({ @@ -1457,11 +1457,11 @@ export class ProfileEmployeeController extends Controller { })) : [ { - createdAt: "-", - status: "-", - prefix: "-", - firstName: "-", - lastName: "-", + createdAt: "", + status: "", + prefix: "", + firstName: "", + lastName: "", }, ]; @@ -1481,8 +1481,8 @@ export class ProfileEmployeeController extends Controller { })) : [ { - birthDateOld: "-", - birthDate: "-", + birthDateOld: "", + birthDate: "", }, ]; @@ -1523,16 +1523,16 @@ export class ProfileEmployeeController extends Controller { })) : [ { - commandName: "-", - commandDateAffect: "-", - commandDateSign: "-", - posNo: "-", - position: "-", - posType: "-", - posLevel: "-", - amount: "-", - positionSalaryAmount: "-", - refDoc: "-" + commandName: "", + commandDateAffect: "", + commandDateSign: "", + posNo: "", + position: "", + posType: "", + posLevel: "", + amount: "", + positionSalaryAmount: "", + refDoc: "" }, ]; // ลูกจ้างยังไม่มีรักษาการและช่วยราชการ @@ -1567,11 +1567,11 @@ export class ProfileEmployeeController extends Controller { })) : [ { - date: "-", - position: "-", - commandName: "-", - agency: "-", - document: "-", + date: "", + position: "", + commandName: "", + agency: "", + document: "", }, ]; const _assistance = @@ -1594,11 +1594,11 @@ export class ProfileEmployeeController extends Controller { })) : [ { - date: "-", - position: "-", - commandName: "-", - agency: "-", - document: "-", + date: "", + position: "", + commandName: "", + agency: "", + document: "", }, ]; const actposition = [..._actposition, ..._assistance]; @@ -1630,11 +1630,11 @@ export class ProfileEmployeeController extends Controller { })) : [ { - date: "-", - type: "-", - detail: "-", - agency: "-", - refCommandNo: "-", + date: "", + type: "", + detail: "", + agency: "", + refCommandNo: "", }, ]; const assessments_raw = await this.profileAssessmentsRepository.find({ @@ -1673,12 +1673,12 @@ export class ProfileEmployeeController extends Controller { })) : [ { - year: "-", - period: "-", - point1: "-", - point2: "-", - pointSum: "-", - pointSumTh: "-", + year: "", + period: "", + point1: "", + point2: "", + pointSum: "", + pointSumTh: "", }, ]; const profileAbility_raw = await this.profileAbilityRepo.find({ @@ -1693,8 +1693,8 @@ export class ProfileEmployeeController extends Controller { })) : [ { - field: "-", - detail: "-", + field: "", + detail: "", }, ]; @@ -1728,14 +1728,14 @@ export class ProfileEmployeeController extends Controller { })) : [ { - commandName: "-", - commandDateAffect: "-", - commandDateSign: "-", - commandNo: "-", - position: "-", - posLevel: "-", - amount: "-", - refDoc: "-" + commandName: "", + commandDateAffect: "", + commandDateSign: "", + commandNo: "", + position: "", + posLevel: "", + amount: "", + refDoc: "" }, ]; @@ -1788,7 +1788,7 @@ export class ProfileEmployeeController extends Controller { // กรณีไม่มีข้อมูล if (retires.length === 0) { - retires.push({ date: "-", detail: "-", day: "-" }); + retires.push({ date: "", detail: "", day: "" }); } const org = diff --git a/src/middlewares/logs.ts b/src/middlewares/logs.ts index 1bff2060..3f1a5963 100644 --- a/src/middlewares/logs.ts +++ b/src/middlewares/logs.ts @@ -67,14 +67,17 @@ async function logMiddleware(req: Request, res: Response, next: NextFunction) { const level = LOG_LEVEL_MAP[process.env.LOG_LEVEL ?? "debug"] || 4; - // Get profile from cache - const profileByKeycloak = await logMemoryStore.getProfileByKeycloak( - req.app.locals.logData.userId, - ); + // // Get profile from cache + // const profileByKeycloak = await logMemoryStore.getProfileByKeycloak( + // req.app.locals.logData.userId, + // ); - // Get rootId from cache - const rootId = await logMemoryStore.getRootIdByProfileId(profileByKeycloak?.id); - // console.log("ancestorDNA:", rootId); + // // Get rootId from cache + // const rootId = await logMemoryStore.getRootIdByProfileId(profileByKeycloak?.id); + // // console.log("ancestorDNA:", rootId); + + // Get rootId from token + const rootId = req.app.locals.logData?.orgRootDnaId; if (level === 1 && res.statusCode < 500) return; if (level === 2 && res.statusCode < 400) return;