API Get Profile For Logs
All checks were successful
Build & Deploy on Dev / build (push) Successful in 1m0s

@Get("user-logs/{keycloakId}")
This commit is contained in:
Adisak 2026-01-28 12:04:49 +07:00
parent ecd002456e
commit b64a8bb26d

View file

@ -1201,8 +1201,8 @@ export class OrganizationDotnetController extends Controller {
profileType: "OFFICER",
positionLeaveName: positionLeaveName,
posExecutiveName: position == null || position.posExecutive == null
? null
: position.posExecutive.posExecutiveName,
? null
: position.posExecutive.posExecutiveName,
oc: oc,
};
@ -1345,9 +1345,9 @@ export class OrganizationDotnetController extends Controller {
const positionLeaveName =
profile.posType &&
profile.posLevel &&
(profile.posType.posTypeName === "บริหาร" ||
profile.posType.posTypeName === "อำนวยการ")
profile.posLevel &&
(profile.posType.posTypeName === "บริหาร" ||
profile.posType.posTypeName === "อำนวยการ")
? `${profile.posType.posTypeName}${profile.posLevel.posLevelName}`
: profile.posLevel?.posLevelName ?? null;
@ -1549,9 +1549,9 @@ export class OrganizationDotnetController extends Controller {
* ========================================= */
const positionLeaveName =
profile.posType &&
profile.posLevel &&
(profile.posType.posTypeName === "บริหาร" ||
profile.posType.posTypeName === "อำนวยการ")
profile.posLevel &&
(profile.posType.posTypeName === "บริหาร" ||
profile.posType.posTypeName === "อำนวยการ")
? `${profile.posType.posTypeName}${profile.posLevel.posLevelName}`
: profile.posLevel?.posLevelName ?? null;
@ -1808,9 +1808,9 @@ export class OrganizationDotnetController extends Controller {
* ========================================= */
const positionLeaveName =
profile.posType &&
profile.posLevel &&
(profile.posType.posTypeName === "บริหาร" ||
profile.posType.posTypeName === "อำนวยการ")
profile.posLevel &&
(profile.posType.posTypeName === "บริหาร" ||
profile.posType.posTypeName === "อำนวยการ")
? `${profile.posType.posTypeName}${profile.posLevel.posLevelName}`
: profile.posLevel?.posLevelName ?? null;
@ -1876,6 +1876,86 @@ export class OrganizationDotnetController extends Controller {
return new HttpSuccess(mapProfile);
}
/**
* API Get Profile For Logs
*
* @summary API Get Profile For Logs
*
* @param {string} keycloakId keycloakId profile
*/
@Get("user-logs/{keycloakId}")
async UserLogs(@Path() keycloakId: string) {
/* =========================
* 1. Load profile
* ========================= */
const profile = await this.profileRepo.findOne({
where: { keycloak: keycloakId },
relations: {
current_holders: {
orgRevision: true,
orgRoot: true,
},
},
});
// Employee
if (!profile) {
const profile = await this.profileEmpRepo.findOne({
where: { keycloak: keycloakId },
relations: {
current_holders: {
orgRevision: true,
orgRoot: true,
},
},
});
if (!profile) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
const currentHolder = profile.current_holders?.find(
x =>
x.orgRevision?.orgRevisionIsDraft === false &&
x.orgRevision?.orgRevisionIsCurrent === true,
);
const mapProfile = {
profileId: profile.id,
keycloak: profile.keycloak,
prefix: profile.prefix,
firstName: profile.firstName,
lastName: profile.lastName,
citizenId: profile.citizenId,
rootId: currentHolder?.orgRootId ?? null,
rootDnaId: currentHolder?.orgRoot?.ancestorDNA ?? null,
};
return new HttpSuccess(mapProfile);
}
/* =========================================
* 2. current holder
* ========================================= */
const currentHolder = profile.current_holders?.find(
x =>
x.orgRevision?.orgRevisionIsDraft === false &&
x.orgRevision?.orgRevisionIsCurrent === true,
);
/* =========================================
* 8. map response
* ========================================= */
const mapProfile = {
profileId: profile.id,
keycloak: profile.keycloak,
prefix: profile.prefix,
firstName: profile.firstName,
lastName: profile.lastName,
citizenId: profile.citizenId,
rootId: currentHolder?.orgRootId ?? null,
rootDnaId: currentHolder?.orgRoot?.ancestorDNA ?? null,
};
return new HttpSuccess(mapProfile);
}
/**
* 3. API Get Profile profile id
*
@ -4132,7 +4212,7 @@ export class OrganizationDotnetController extends Controller {
// "current_holders.orgChild3",
// "current_holders.orgChild4",
// ],
relations:{
relations: {
posType: true,
posLevel: true,
current_holders: {
@ -7078,9 +7158,9 @@ export class OrganizationDotnetController extends Controller {
* ========================================= */
const positionLeaveName =
profile.posType &&
profile.posLevel &&
(profile.posType.posTypeName === "บริหาร" ||
profile.posType.posTypeName === "อำนวยการ")
profile.posLevel &&
(profile.posType.posTypeName === "บริหาร" ||
profile.posType.posTypeName === "อำนวยการ")
? `${profile.posType.posTypeName}${profile.posLevel.posLevelName}`
: profile.posLevel?.posLevelName ?? null;