แก้ไข middleware log ให้ใช้จาก token #223
All checks were successful
Build & Deploy on Dev / build (push) Successful in 1m21s

This commit is contained in:
harid 2026-03-20 16:55:27 +07:00
parent 251e87d2b2
commit 2fdf5e5854
3 changed files with 224 additions and 221 deletions

View file

@ -1107,11 +1107,11 @@ export class ProfileController extends Controller {
})) }))
: [ : [
{ {
certificateType: "-", certificateType: "",
issuer: "-", issuer: "",
certificateNo: "-", certificateNo: "",
detail: "-", detail: "",
issueToExpireDate: "-", issueToExpireDate: "",
}, },
]; ];
const training_raw = await this.trainingRepository.find({ const training_raw = await this.trainingRepository.find({
@ -1130,11 +1130,11 @@ export class ProfileController extends Controller {
})) }))
: [ : [
{ {
institute: "-", institute: "",
degree: "-", degree: "",
place: "-", place: "",
duration: "-", duration: "",
date: "-" date: ""
}, },
]; ];
@ -1155,10 +1155,10 @@ export class ProfileController extends Controller {
})) }))
: [ : [
{ {
disciplineYear: "-", disciplineYear: "",
disciplineDetail: "-", disciplineDetail: "",
refNo: "-", refNo: "",
level: "-", level: "",
}, },
]; ];
@ -1181,10 +1181,10 @@ export class ProfileController extends Controller {
})) }))
: [ : [
{ {
institute: "-", institute: "",
date: "-", date: "",
degree: "-", degree: "",
level: "-" level: ""
}, },
]; ];
const salary_raw = await this.salaryRepo.find({ const salary_raw = await this.salaryRepo.find({
@ -1251,19 +1251,19 @@ export class ProfileController extends Controller {
})) }))
: [ : [
{ {
commandName: "-", commandName: "",
salaryDate: "-", salaryDate: "",
position: "-", position: "",
posNo: "-", posNo: "",
salary: "-", salary: "",
special: "-", special: "",
rank: "-", rank: "",
refAll: "-", refAll: "",
positionLevel: "-", positionLevel: "",
positionType: "-", positionType: "",
positionAmount: "-", positionAmount: "",
fullName: "-", fullName: "",
ocFullPath: "-", ocFullPath: "",
}, },
]; ];
@ -1310,18 +1310,18 @@ export class ProfileController extends Controller {
})) }))
: [ : [
{ {
receiveDate: "-", receiveDate: "",
insigniaName: "-", insigniaName: "",
insigniaShortName: "-", insigniaShortName: "",
insigniaTypeName: "-", insigniaTypeName: "",
no: "-", no: "",
issue: "-", issue: "",
volumeNo: "-", volumeNo: "",
volume: "-", volume: "",
section: "-", section: "",
page: "-", page: "",
refCommandDate: "-", refCommandDate: "",
note: "-" note: ""
}, },
]; ];
@ -1417,10 +1417,10 @@ export class ProfileController extends Controller {
})) }))
: [ : [
{ {
date: "-", date: "",
type: "-", type: "",
leaveDays: "-", leaveDays: "",
reason: "-", reason: "",
}, },
]; ];
const children_raw = await this.profileChildrenRepository.find({ const children_raw = await this.profileChildrenRepository.find({
@ -1439,11 +1439,11 @@ export class ProfileController extends Controller {
: [ : [
{ {
no: "", no: "",
childrenPrefix: "-", childrenPrefix: "",
childrenFirstName: "-", childrenFirstName: "",
childrenLastName: "-", childrenLastName: "",
childrenFullName: "-", childrenFullName: "",
childrenLive: "-", childrenLive: "",
}, },
]; ];
const changeName_raw = await this.changeNameRepository.find({ const changeName_raw = await this.changeNameRepository.find({
@ -1463,11 +1463,11 @@ export class ProfileController extends Controller {
})) }))
: [ : [
{ {
createdAt: "-", createdAt: "",
status: "-", status: "",
prefix: "-", prefix: "",
firstName: "-", firstName: "",
lastName: "-", lastName: "",
}, },
]; ];
@ -1487,8 +1487,8 @@ export class ProfileController extends Controller {
})) }))
: [ : [
{ {
birthDateOld: "-", birthDateOld: "",
birthDate: "-", birthDate: "",
}, },
]; ];
@ -1529,16 +1529,16 @@ export class ProfileController extends Controller {
})) }))
: [ : [
{ {
commandName: "-", commandName: "",
commandDateAffect: "-", commandDateAffect: "",
commandDateSign: "-", commandDateSign: "",
posNo: "-", posNo: "",
position: "-", position: "",
posType: "-", posType: "",
posLevel: "-", posLevel: "",
amount: "-", amount: "",
positionSalaryAmount: "-", positionSalaryAmount: "",
refDoc: "-" refDoc: ""
}, },
]; ];
@ -1591,7 +1591,7 @@ export class ProfileController extends Controller {
// กรณีไม่มีข้อมูล // กรณีไม่มีข้อมูล
if (retires.length === 0) { if (retires.length === 0) {
retires.push({ date: "-", detail: "-", day: "-" }); retires.push({ date: "", detail: "", day: "" });
} }
// รักษาการ // รักษาการ
@ -1674,12 +1674,12 @@ export class ProfileController extends Controller {
} }
else { else {
_actpositions.push({ _actpositions.push({
date: "-", date: "",
position: "-", position: "",
commandName: "-", commandName: "",
agency: "-", agency: "",
note: "-", note: "",
document: "-", document: "",
}); });
} }
// ช่วยราชการ // ช่วยราชการ
@ -1732,12 +1732,12 @@ export class ProfileController extends Controller {
} }
else { else {
_assistances.push({ _assistances.push({
date: "-", date: "",
position: "-", position: "",
commandName: "-", commandName: "",
agency: "-", agency: "",
note: "-", note: "",
document: "-", document: "",
}); });
} }
// Merge รักษาการ และ ช่วยราชาร // Merge รักษาการ และ ช่วยราชาร
@ -1771,11 +1771,11 @@ export class ProfileController extends Controller {
})) }))
: [ : [
{ {
date: "-", date: "",
type: "-", type: "",
detail: "-", detail: "",
agency: "-", agency: "",
refCommandNo: "-", refCommandNo: "",
}, },
]; ];
const assessments_raw = await this.profileAssessmentsRepository.find({ const assessments_raw = await this.profileAssessmentsRepository.find({
@ -1814,13 +1814,13 @@ export class ProfileController extends Controller {
})) }))
: [ : [
{ {
year: "-", year: "",
period: "-", period: "",
point1: "-", point1: "",
point2: "-", point2: "",
pointSum: "-", pointSum: "",
pointSumTh: "-", pointSumTh: "",
level: "-", level: "",
}, },
]; ];
const profileAbility_raw = await this.profileAbilityRepo.find({ const profileAbility_raw = await this.profileAbilityRepo.find({
@ -1835,8 +1835,8 @@ export class ProfileController extends Controller {
})) }))
: [ : [
{ {
field: "-", field: "",
detail: "-", detail: "",
}, },
]; ];
@ -1870,14 +1870,14 @@ export class ProfileController extends Controller {
})) }))
: [ : [
{ {
commandName: "-", commandName: "",
commandDateAffect: "-", commandDateAffect: "",
commandDateSign: "-", commandDateSign: "",
commandNo: "-", commandNo: "",
position: "-", position: "",
posLevel: "-", posLevel: "",
amount: "-", amount: "",
refDoc: "-" refDoc: ""
}, },
]; ];
@ -1924,15 +1924,15 @@ export class ProfileController extends Controller {
) )
: ""; : "";
let portfolios: any; let portfolios:any[] = [];
await new CallAPI() await new CallAPI()
.GetData(req, `/development/portfolio/kk1/${profiles?.keycloak}`) .GetData(req, `/development/portfolio/kk1/${profiles?.keycloak}`)
.then((x) => { .then((x) => {
portfolios = x; portfolios = Array.isArray(x) ? x : [];
}) })
.catch(() => {}); .catch(() => {});
if (!portfolios) { if (portfolios.length == 0) {
portfolios = [{ name: "-", year: "-", position: "-" }]; portfolios = [{ name: "", year: "", position: "" }];
} else { } else {
portfolios = portfolios.map((x: any) => ({ portfolios = portfolios.map((x: any) => ({
name: x.name ? Extension.ToThaiNumber(x.name) : "-", name: x.name ? Extension.ToThaiNumber(x.name) : "-",

View file

@ -1022,12 +1022,12 @@ export class ProfileEmployeeController extends Controller {
order: { lastUpdatedAt: "DESC" }, order: { lastUpdatedAt: "DESC" },
}); });
const posMasterId = // const posMasterId =
profiles.current_holders == null || // profiles.current_holders == null ||
profiles.current_holders.length == 0 || // profiles.current_holders.length == 0 ||
profiles.current_holders.find((x) => x.orgRevisionId == orgRevision?.id) == null // profiles.current_holders.find((x) => x.orgRevisionId == orgRevision?.id) == null
? null // ? null
: profiles.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.id; // : profiles.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.id;
const root = const root =
profiles.current_holders == null || profiles.current_holders == null ||
@ -1102,11 +1102,11 @@ export class ProfileEmployeeController extends Controller {
})) }))
: [ : [
{ {
certificateType: "-", certificateType: "",
issuer: "-", issuer: "",
certificateNo: "-", certificateNo: "",
detail: "-", detail: "",
issueToExpireDate: "-", issueToExpireDate: "",
}, },
]; ];
const training_raw = await this.trainingRepository.find({ const training_raw = await this.trainingRepository.find({
@ -1125,11 +1125,11 @@ export class ProfileEmployeeController extends Controller {
})) }))
: [ : [
{ {
institute: "-", institute: "",
degree: "-", degree: "",
place: "-", place: "",
duration: "-", duration: "",
date: "-" date: ""
}, },
]; ];
@ -1150,10 +1150,10 @@ export class ProfileEmployeeController extends Controller {
})) }))
: [ : [
{ {
disciplineYear: "-", disciplineYear: "",
disciplineDetail: "-", disciplineDetail: "",
refNo: "-", refNo: "",
level: "-", level: "",
}, },
]; ];
@ -1176,10 +1176,10 @@ export class ProfileEmployeeController extends Controller {
})) }))
: [ : [
{ {
institute: "-", institute: "",
date: "-", date: "",
degree: "-", degree: "",
level: "-" level: ""
}, },
]; ];
const salary_raw = await this.salaryRepo.find({ const salary_raw = await this.salaryRepo.find({
@ -1246,19 +1246,19 @@ export class ProfileEmployeeController extends Controller {
})) }))
: [ : [
{ {
commandName: "-", commandName: "",
salaryDate: "-", salaryDate: "",
position: "-", position: "",
posNo: "-", posNo: "",
salary: "-", salary: "",
special: "-", special: "",
rank: "-", rank: "",
refAll: "-", refAll: "",
positionLevel: "-", positionLevel: "",
positionType: "-", positionType: "",
positionAmount: "-", positionAmount: "",
fullName: "-", fullName: "",
ocFullPath: "-", ocFullPath: "",
}, },
]; ];
@ -1305,17 +1305,17 @@ export class ProfileEmployeeController extends Controller {
})) }))
: [ : [
{ {
receiveDate: "-", receiveDate: "",
insigniaName: "-", insigniaName: "",
insigniaShortName: "-", insigniaShortName: "",
insigniaTypeName: "-", insigniaTypeName: "",
no: "-", no: "",
issue: "-", issue: "",
volumeNo: "-", volumeNo: "",
volume: "-", volume: "",
section: "-", section: "",
page: "-", page: "",
refCommandDate: "-", refCommandDate: "",
}, },
]; ];
@ -1411,10 +1411,10 @@ export class ProfileEmployeeController extends Controller {
})) }))
: [ : [
{ {
date: "-", date: "",
type: "-", type: "",
leaveDays: "-", leaveDays: "",
reason: "-", reason: "",
}, },
]; ];
const children_raw = await this.profileChildrenRepository.find({ const children_raw = await this.profileChildrenRepository.find({
@ -1433,11 +1433,11 @@ export class ProfileEmployeeController extends Controller {
: [ : [
{ {
no: "", no: "",
childrenPrefix: "-", childrenPrefix: "",
childrenFirstName: "-", childrenFirstName: "",
childrenLastName: "-", childrenLastName: "",
childrenFullName: "-", childrenFullName: "",
childrenLive: "-", childrenLive: "",
}, },
]; ];
const changeName_raw = await this.changeNameRepository.find({ const changeName_raw = await this.changeNameRepository.find({
@ -1457,11 +1457,11 @@ export class ProfileEmployeeController extends Controller {
})) }))
: [ : [
{ {
createdAt: "-", createdAt: "",
status: "-", status: "",
prefix: "-", prefix: "",
firstName: "-", firstName: "",
lastName: "-", lastName: "",
}, },
]; ];
@ -1481,8 +1481,8 @@ export class ProfileEmployeeController extends Controller {
})) }))
: [ : [
{ {
birthDateOld: "-", birthDateOld: "",
birthDate: "-", birthDate: "",
}, },
]; ];
@ -1523,16 +1523,16 @@ export class ProfileEmployeeController extends Controller {
})) }))
: [ : [
{ {
commandName: "-", commandName: "",
commandDateAffect: "-", commandDateAffect: "",
commandDateSign: "-", commandDateSign: "",
posNo: "-", posNo: "",
position: "-", position: "",
posType: "-", posType: "",
posLevel: "-", posLevel: "",
amount: "-", amount: "",
positionSalaryAmount: "-", positionSalaryAmount: "",
refDoc: "-" refDoc: ""
}, },
]; ];
// ลูกจ้างยังไม่มีรักษาการและช่วยราชการ // ลูกจ้างยังไม่มีรักษาการและช่วยราชการ
@ -1567,11 +1567,11 @@ export class ProfileEmployeeController extends Controller {
})) }))
: [ : [
{ {
date: "-", date: "",
position: "-", position: "",
commandName: "-", commandName: "",
agency: "-", agency: "",
document: "-", document: "",
}, },
]; ];
const _assistance = const _assistance =
@ -1594,11 +1594,11 @@ export class ProfileEmployeeController extends Controller {
})) }))
: [ : [
{ {
date: "-", date: "",
position: "-", position: "",
commandName: "-", commandName: "",
agency: "-", agency: "",
document: "-", document: "",
}, },
]; ];
const actposition = [..._actposition, ..._assistance]; const actposition = [..._actposition, ..._assistance];
@ -1630,11 +1630,11 @@ export class ProfileEmployeeController extends Controller {
})) }))
: [ : [
{ {
date: "-", date: "",
type: "-", type: "",
detail: "-", detail: "",
agency: "-", agency: "",
refCommandNo: "-", refCommandNo: "",
}, },
]; ];
const assessments_raw = await this.profileAssessmentsRepository.find({ const assessments_raw = await this.profileAssessmentsRepository.find({
@ -1673,12 +1673,12 @@ export class ProfileEmployeeController extends Controller {
})) }))
: [ : [
{ {
year: "-", year: "",
period: "-", period: "",
point1: "-", point1: "",
point2: "-", point2: "",
pointSum: "-", pointSum: "",
pointSumTh: "-", pointSumTh: "",
}, },
]; ];
const profileAbility_raw = await this.profileAbilityRepo.find({ const profileAbility_raw = await this.profileAbilityRepo.find({
@ -1693,8 +1693,8 @@ export class ProfileEmployeeController extends Controller {
})) }))
: [ : [
{ {
field: "-", field: "",
detail: "-", detail: "",
}, },
]; ];
@ -1728,14 +1728,14 @@ export class ProfileEmployeeController extends Controller {
})) }))
: [ : [
{ {
commandName: "-", commandName: "",
commandDateAffect: "-", commandDateAffect: "",
commandDateSign: "-", commandDateSign: "",
commandNo: "-", commandNo: "",
position: "-", position: "",
posLevel: "-", posLevel: "",
amount: "-", amount: "",
refDoc: "-" refDoc: ""
}, },
]; ];
@ -1788,7 +1788,7 @@ export class ProfileEmployeeController extends Controller {
// กรณีไม่มีข้อมูล // กรณีไม่มีข้อมูล
if (retires.length === 0) { if (retires.length === 0) {
retires.push({ date: "-", detail: "-", day: "-" }); retires.push({ date: "", detail: "", day: "" });
} }
const org = const org =

View file

@ -67,14 +67,17 @@ async function logMiddleware(req: Request, res: Response, next: NextFunction) {
const level = LOG_LEVEL_MAP[process.env.LOG_LEVEL ?? "debug"] || 4; const level = LOG_LEVEL_MAP[process.env.LOG_LEVEL ?? "debug"] || 4;
// Get profile from cache // // Get profile from cache
const profileByKeycloak = await logMemoryStore.getProfileByKeycloak( // const profileByKeycloak = await logMemoryStore.getProfileByKeycloak(
req.app.locals.logData.userId, // req.app.locals.logData.userId,
); // );
// Get rootId from cache // // Get rootId from cache
const rootId = await logMemoryStore.getRootIdByProfileId(profileByKeycloak?.id); // const rootId = await logMemoryStore.getRootIdByProfileId(profileByKeycloak?.id);
// console.log("ancestorDNA:", rootId); // // console.log("ancestorDNA:", rootId);
// Get rootId from token
const rootId = req.app.locals.logData?.orgRootDnaId;
if (level === 1 && res.statusCode < 500) return; if (level === 1 && res.statusCode < 500) return;
if (level === 2 && res.statusCode < 400) return; if (level === 2 && res.statusCode < 400) return;