add api get profile keycloak/position-checkin
All checks were successful
Build & Deploy on Dev / build (push) Successful in 1m26s
All checks were successful
Build & Deploy on Dev / build (push) Successful in 1m26s
This commit is contained in:
parent
8705d1abf5
commit
28319f443f
1 changed files with 97 additions and 5 deletions
|
|
@ -1690,11 +1690,17 @@ export class ProfileController extends Controller {
|
|||
});
|
||||
|
||||
// มีคำสั่งพ้นราชการหรือไม่
|
||||
if (salaries.length > 0 && salaries.some((s) => s.commandCode &&
|
||||
retireCommandCodes.includes(s.commandCode))) {
|
||||
if (
|
||||
salaries.length > 0 &&
|
||||
salaries.some((s) => s.commandCode && retireCommandCodes.includes(s.commandCode))
|
||||
) {
|
||||
// กรองข้อมูลซ้ำตาม commandDateAffect
|
||||
const uniqueSalaries = salaries.filter((item, index, self) =>
|
||||
index === self.findIndex((t) => t.commandDateAffect?.getTime() === item.commandDateAffect?.getTime())
|
||||
const uniqueSalaries = salaries.filter(
|
||||
(item, index, self) =>
|
||||
index ===
|
||||
self.findIndex(
|
||||
(t) => t.commandDateAffect?.getTime() === item.commandDateAffect?.getTime(),
|
||||
),
|
||||
);
|
||||
|
||||
// วนลูปหาคู่ของ "ออกราชการ" และ "กลับเข้าราชการ"
|
||||
|
|
@ -1746,7 +1752,7 @@ export class ProfileController extends Controller {
|
|||
retires.push({
|
||||
date: `${startDateStr} - ${endDateStr}`,
|
||||
detail: detail || "-",
|
||||
day: daysCount > 0 ? Extension.ToThaiNumber(daysCount.toLocaleString()) : "-"
|
||||
day: daysCount > 0 ? Extension.ToThaiNumber(daysCount.toLocaleString()) : "-",
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
@ -12008,4 +12014,90 @@ export class ProfileController extends Controller {
|
|||
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
||||
/**
|
||||
* API ข้อมูลทะเบียนประวัติตาม keycloak สำหรับเช็คอินเข้าใช้งานระบบ
|
||||
*
|
||||
* @summary ข้อมูลทะเบียนประวัติตาม keycloak สำหรับเช็คอินเข้าใช้งานระบบ
|
||||
*
|
||||
*/
|
||||
@Get("keycloak/position-checkin")
|
||||
async getProfileByKeycloakForCheckin(@Request() request: { user: Record<string, any> }) {
|
||||
const userSub = request.user.sub;
|
||||
const relations = [
|
||||
"current_holders",
|
||||
"current_holders.orgRoot",
|
||||
"current_holders.orgChild1",
|
||||
"current_holders.orgChild2",
|
||||
"current_holders.orgChild3",
|
||||
"current_holders.orgChild4",
|
||||
];
|
||||
|
||||
const [officerProfile, orgRevisionPublish] = await Promise.all([
|
||||
this.profileRepo.findOne({
|
||||
where: { keycloak: userSub },
|
||||
relations,
|
||||
}),
|
||||
this.orgRevisionRepo.findOne({
|
||||
where: {
|
||||
orgRevisionIsDraft: false,
|
||||
orgRevisionIsCurrent: true,
|
||||
},
|
||||
}),
|
||||
]);
|
||||
|
||||
if (!orgRevisionPublish) {
|
||||
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบแบบร่างโครงสร้าง");
|
||||
}
|
||||
|
||||
let profile: any = officerProfile;
|
||||
let profileType: "OFFICER" | "EMPLOYEE" = "OFFICER";
|
||||
|
||||
if (!profile) {
|
||||
profile = await this.profileEmpRepo.findOne({
|
||||
where: { keycloak: userSub },
|
||||
relations,
|
||||
});
|
||||
profileType = "EMPLOYEE";
|
||||
}
|
||||
|
||||
if (!profile) {
|
||||
if (request.user.role.includes("SUPER_ADMIN")) {
|
||||
return new HttpSuccess(null);
|
||||
}
|
||||
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลบุคคลนี้ในระบบ");
|
||||
}
|
||||
|
||||
const currentHolder =
|
||||
profile.current_holders?.find((x: any) => x.orgRevisionId == orgRevisionPublish.id) ?? null;
|
||||
const root = currentHolder?.orgRoot ?? null;
|
||||
const child1 = currentHolder?.orgChild1 ?? null;
|
||||
const child2 = currentHolder?.orgChild2 ?? null;
|
||||
const child3 = currentHolder?.orgChild3 ?? null;
|
||||
const child4 = currentHolder?.orgChild4 ?? null;
|
||||
|
||||
const _profile: any = {
|
||||
profileId: profile.id,
|
||||
keycloak: profile.keycloak,
|
||||
prefix: profile.prefix,
|
||||
avatar: profile.avatar,
|
||||
profileType,
|
||||
isProbation: profile.isProbation,
|
||||
avatarName: profile.avatarName,
|
||||
firstName: profile.firstName,
|
||||
lastName: profile.lastName,
|
||||
citizenId: profile.citizenId,
|
||||
root: root?.orgRootName ?? null,
|
||||
child1: child1?.orgChild1Name ?? null,
|
||||
child2: child2?.orgChild2Name ?? null,
|
||||
child3: child3?.orgChild3Name ?? null,
|
||||
child4: child4?.orgChild4Name ?? null,
|
||||
privacyCheckin: profile.privacyCheckin,
|
||||
privacyUser: profile.privacyUser,
|
||||
privacyMgt: profile.privacyMgt,
|
||||
...(profileType !== "OFFICER" ? { type: profile.employeeClass } : {}),
|
||||
};
|
||||
|
||||
return new HttpSuccess(_profile);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue