API Get Profile For Logs
All checks were successful
Build & Deploy on Dev / build (push) Successful in 1m0s
All checks were successful
Build & Deploy on Dev / build (push) Successful in 1m0s
@Get("user-logs/{keycloakId}")
This commit is contained in:
parent
ecd002456e
commit
b64a8bb26d
1 changed files with 112 additions and 32 deletions
|
|
@ -1876,6 +1876,86 @@ export class OrganizationDotnetController extends Controller {
|
||||||
return new HttpSuccess(mapProfile);
|
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
|
* 3. API Get Profile จาก profile id
|
||||||
*
|
*
|
||||||
|
|
@ -4132,7 +4212,7 @@ export class OrganizationDotnetController extends Controller {
|
||||||
// "current_holders.orgChild3",
|
// "current_holders.orgChild3",
|
||||||
// "current_holders.orgChild4",
|
// "current_holders.orgChild4",
|
||||||
// ],
|
// ],
|
||||||
relations:{
|
relations: {
|
||||||
posType: true,
|
posType: true,
|
||||||
posLevel: true,
|
posLevel: true,
|
||||||
current_holders: {
|
current_holders: {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue