fix ยศไม่แสดงในระบบทะเบียน #2469 + Error Log api check-keycloak
All checks were successful
Build & Deploy on Dev / build (push) Successful in 1m8s

This commit is contained in:
harid 2026-05-18 15:02:38 +07:00
parent 173378d87c
commit 15830ef2ba
2 changed files with 81 additions and 76 deletions

View file

@ -6594,9 +6594,9 @@ export class CommandController extends Controller {
profile.amountSpecial = item.bodyProfile.amountSpecial ?? null;
profile.isProbation = item.bodyProfile.isProbation;
//เพิ่มใหม่จากรับโอน
profile.rank = item.bodyProfile.rank ?? null;
profile.prefix = item.bodyProfile.prefix ?? null;
profile.prefixMain = item.bodyProfile.prefix ?? null;
profile.rank = item?.bodyProfile?.rank ?? null;
profile.prefix = item?.bodyProfile?.rank ?? item?.bodyProfile?.prefix ?? null;
profile.prefixMain = item?.bodyProfile?.prefix ?? null;
profile.firstName = item.bodyProfile.firstName ?? null;
profile.lastName = item.bodyProfile.lastName ?? null;
profile.birthDate = item.bodyProfile.birthDate ?? null;
@ -6658,9 +6658,9 @@ export class CommandController extends Controller {
profile.amount = item.bodyProfile.amount ?? null;
profile.amountSpecial = item.bodyProfile.amountSpecial ?? null;
profile.isProbation = item.bodyProfile.isProbation;
profile.rank = item.bodyProfile.rank ?? null;
profile.prefix = item.bodyProfile.prefix ?? null;
profile.prefixMain = item.bodyProfile.prefix ?? null;
profile.rank = item?.bodyProfile?.rank ?? null;
profile.prefix = item?.bodyProfile?.rank ?? item?.bodyProfile?.prefix ?? null;
profile.prefixMain = item?.bodyProfile?.prefix ?? null;
profile.firstName = item.bodyProfile.firstName ?? null;
profile.lastName = item.bodyProfile.lastName ?? null;
profile.birthDate = item.bodyProfile.birthDate ?? null;
@ -6717,12 +6717,9 @@ export class CommandController extends Controller {
profile.lastUpdateFullName = req.user.name;
profile.lastUpdatedAt = new Date();
//เพิ่มใหม่จากรับโอน
profile.rank = item.bodyProfile.rank ?? null;
profile.prefix =
item.bodyProfile.prefix && item.bodyProfile.prefix != ""
? item.bodyProfile.prefix
: profile.prefix;
profile.prefixMain = item.bodyProfile.prefix ?? null;
profile.rank = item?.bodyProfile?.rank ?? null;
profile.prefix = item?.bodyProfile?.rank ?? item?.bodyProfile?.prefix ?? null;
profile.prefixMain = item?.bodyProfile?.prefix ?? null;
profile.firstName =
item.bodyProfile.firstName && item.bodyProfile.firstName != ""
? item.bodyProfile.firstName

View file

@ -2357,26 +2357,11 @@ export class OrganizationDotnetController extends Controller {
*/
@Get("check-keycloak/{keycloakId}")
async GetProfileForProcessCheckInAsync(@Path() keycloakId: string) {
/* =========================
* 1. Load profile (Officer)
* ========================= */
const profile = await this.profileRepo.findOne({
where: { keycloak: keycloakId },
relations: {
current_holders: {
orgRevision: true,
orgRoot: true,
orgChild1: true,
orgChild2: true,
orgChild3: true,
orgChild4: true,
},
},
});
// Employee
if (!profile) {
const profile = await this.profileEmpRepo.findOne({
try {
/* =========================
* 1. Load profile (Officer)
* ========================= */
const profile = await this.profileRepo.findOne({
where: { keycloak: keycloakId },
relations: {
current_holders: {
@ -2389,15 +2374,72 @@ export class OrganizationDotnetController extends Controller {
},
},
});
if (!profile) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
// Employee
if (!profile) {
const empProfile = await this.profileEmpRepo.findOne({
where: { keycloak: keycloakId },
relations: {
current_holders: {
orgRevision: true,
orgRoot: true,
orgChild1: true,
orgChild2: true,
orgChild3: true,
orgChild4: true,
},
},
});
if (!empProfile) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
const currentHolder = empProfile.current_holders?.find(
(x) =>
x.orgRevision?.orgRevisionIsDraft === false &&
x.orgRevision?.orgRevisionIsCurrent === true,
);
const mapProfile = {
profileType: "EMPLOYEE",
id: empProfile.id,
keycloak: empProfile.keycloak,
prefix: empProfile.prefix,
firstName: empProfile.firstName,
lastName: empProfile.lastName,
citizenId: empProfile.citizenId,
gender: empProfile.gender,
root: currentHolder?.orgRoot?.orgRootName ?? null,
rootId: currentHolder?.orgRootId ?? null,
rootDnaId: currentHolder?.orgRoot?.ancestorDNA ?? null,
child1: currentHolder?.orgChild1?.orgChild1Name ?? null,
child1Id: currentHolder?.orgChild1Id ?? null,
child1DnaId: currentHolder?.orgChild1?.ancestorDNA ?? null,
child2: currentHolder?.orgChild2?.orgChild2Name ?? null,
child2Id: currentHolder?.orgChild2Id ?? null,
child2DnaId: currentHolder?.orgChild2?.ancestorDNA ?? null,
child3: currentHolder?.orgChild3?.orgChild3Name ?? null,
child3Id: currentHolder?.orgChild3Id ?? null,
child3DnaId: currentHolder?.orgChild3?.ancestorDNA ?? null,
child4: currentHolder?.orgChild4?.orgChild4Name ?? null,
child4Id: currentHolder?.orgChild4Id ?? null,
child4DnaId: currentHolder?.orgChild4?.ancestorDNA ?? null,
};
return new HttpSuccess(mapProfile);
}
/* =========================================
* 2. current holder (Officer)
* ========================================= */
const currentHolder = profile.current_holders?.find(
(x) =>
x.orgRevision?.orgRevisionIsDraft === false &&
x.orgRevision?.orgRevisionIsCurrent === true,
x.orgRevision?.orgRevisionIsDraft === false && x.orgRevision?.orgRevisionIsCurrent === true,
);
/* =========================================
* 3. map response
* ========================================= */
const mapProfile = {
profileType: "EMPLOYEE",
profileType: "OFFICER",
id: profile.id,
keycloak: profile.keycloak,
prefix: profile.prefix,
@ -2424,47 +2466,13 @@ export class OrganizationDotnetController extends Controller {
};
return new HttpSuccess(mapProfile);
} catch (error: any) {
// Log เฉพาะ unexpected errors (ไม่ใช่ HttpError)
if (!(error instanceof HttpError)) {
console.error(`[check-keycloak] Unexpected error: keycloakId=${keycloakId}`, error);
}
throw error;
}
/* =========================================
* 2. current holder (Officer)
* ========================================= */
const currentHolder = profile.current_holders?.find(
(x) =>
x.orgRevision?.orgRevisionIsDraft === false && x.orgRevision?.orgRevisionIsCurrent === true,
);
/* =========================================
* 6. map response
* ========================================= */
const mapProfile = {
profileType: "OFFICER",
id: profile.id,
keycloak: profile.keycloak,
prefix: profile.prefix,
firstName: profile.firstName,
lastName: profile.lastName,
citizenId: profile.citizenId,
gender: profile.gender,
root: currentHolder?.orgRoot?.orgRootName ?? null,
rootId: currentHolder?.orgRootId ?? null,
rootDnaId: currentHolder?.orgRoot?.ancestorDNA ?? null,
child1: currentHolder?.orgChild1?.orgChild1Name ?? null,
child1Id: currentHolder?.orgChild1Id ?? null,
child1DnaId: currentHolder?.orgChild1?.ancestorDNA ?? null,
child2: currentHolder?.orgChild2?.orgChild2Name ?? null,
child2Id: currentHolder?.orgChild2Id ?? null,
child2DnaId: currentHolder?.orgChild2?.ancestorDNA ?? null,
child3: currentHolder?.orgChild3?.orgChild3Name ?? null,
child3Id: currentHolder?.orgChild3Id ?? null,
child3DnaId: currentHolder?.orgChild3?.ancestorDNA ?? null,
child4: currentHolder?.orgChild4?.orgChild4Name ?? null,
child4Id: currentHolder?.orgChild4Id ?? null,
child4DnaId: currentHolder?.orgChild4?.ancestorDNA ?? null,
};
return new HttpSuccess(mapProfile);
}
/**