api getKeycloak ทำไว้ใช้สำหรับระบบลงเวลา
All checks were successful
Build & Deploy on Dev / build (push) Successful in 1m1s
All checks were successful
Build & Deploy on Dev / build (push) Successful in 1m1s
This commit is contained in:
parent
0203a9105f
commit
38e2ec6586
1 changed files with 235 additions and 0 deletions
|
|
@ -1639,6 +1639,241 @@ export class OrganizationDotnetController extends Controller {
|
|||
|
||||
return new HttpSuccess(mapProfile);
|
||||
}
|
||||
|
||||
@Get("by-keycloak/{keycloakId}")
|
||||
async NewGetProfileByKeycloakIdAsync(@Path() keycloakId: string) {
|
||||
/* =========================
|
||||
* 1. Load profile
|
||||
* ========================= */
|
||||
const profile = await this.profileRepo.findOne({
|
||||
where: { keycloak: keycloakId },
|
||||
relations: {
|
||||
posLevel: true,
|
||||
posType: true,
|
||||
current_holders: {
|
||||
orgRevision: true,
|
||||
orgRoot: true,
|
||||
orgChild1: true,
|
||||
orgChild2: true,
|
||||
orgChild3: true,
|
||||
orgChild4: true,
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
// Employee
|
||||
if (!profile) {
|
||||
const profile = await this.profileEmpRepo.findOne({
|
||||
where: { keycloak: keycloakId },
|
||||
relations: {
|
||||
posLevel: true,
|
||||
posType: true,
|
||||
current_holders: {
|
||||
orgRevision: true,
|
||||
orgRoot: true,
|
||||
orgChild1: true,
|
||||
orgChild2: true,
|
||||
orgChild3: true,
|
||||
orgChild4: true,
|
||||
},
|
||||
},
|
||||
});
|
||||
if (!profile) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
const currentHolder = profile.current_holders?.find(
|
||||
x =>
|
||||
x.orgRevision?.orgRevisionIsDraft === false &&
|
||||
x.orgRevision?.orgRevisionIsCurrent === true,
|
||||
);
|
||||
|
||||
let oc = "";
|
||||
if (currentHolder) {
|
||||
if (!currentHolder.orgChild1Id) {
|
||||
oc = currentHolder.orgRoot?.orgRootName;
|
||||
} else if (!currentHolder.orgChild2Id) {
|
||||
oc = `${currentHolder.orgChild1?.orgChild1Name} ${currentHolder.orgRoot?.orgRootName}`;
|
||||
} else if (!currentHolder.orgChild3Id) {
|
||||
oc = `${currentHolder.orgChild2?.orgChild2Name} ${currentHolder.orgChild1?.orgChild1Name} ${currentHolder.orgRoot?.orgRootName}`;
|
||||
} else if (!currentHolder.orgChild4Id) {
|
||||
oc = `${currentHolder.orgChild3?.orgChild3Name} ${currentHolder.orgChild2?.orgChild2Name} ${currentHolder.orgChild1?.orgChild1Name} ${currentHolder.orgRoot?.orgRootName}`;
|
||||
} else {
|
||||
oc = currentHolder.orgChild4?.orgChild4Name;
|
||||
}
|
||||
}
|
||||
|
||||
const mapProfile = {
|
||||
profileType: "EMPLOYEE",
|
||||
id: profile.id,
|
||||
keycloak: profile.keycloak,
|
||||
prefix: profile.prefix,
|
||||
firstName: profile.firstName,
|
||||
lastName: profile.lastName,
|
||||
citizenId: profile.citizenId,
|
||||
position: profile.position,
|
||||
email: profile.email,
|
||||
phone: profile.phone,
|
||||
isProbation: profile.isProbation,
|
||||
isLeave: profile.isLeave,
|
||||
dateRetire: profile.dateRetire,
|
||||
dateAppoint: profile.dateAppoint,
|
||||
dateRetireLaw: profile.dateRetireLaw,
|
||||
dateStart: profile.dateStart,
|
||||
govAgeAbsent: profile.govAgeAbsent,
|
||||
govAgePlus: profile.govAgePlus,
|
||||
birthDate: profile.birthDate ?? new Date(),
|
||||
reasonSameDate: profile.reasonSameDate,
|
||||
telephoneNumber: profile.phone,
|
||||
nationality: profile.nationality,
|
||||
gender: profile.gender,
|
||||
relationship: profile.relationship,
|
||||
religion: profile.religion,
|
||||
bloodGroup: profile.bloodGroup,
|
||||
dutyTimeId: profile.dutyTimeId,
|
||||
dutyTimeEffectiveDate: profile.dutyTimeEffectiveDate,
|
||||
amount: profile.amount,
|
||||
positionSalaryAmount: profile.positionSalaryAmount,
|
||||
mouthSalaryAmount: profile.mouthSalaryAmount,
|
||||
|
||||
posType: profile.posType?.posTypeName ?? null,
|
||||
posLevel: profile.posType?.posTypeShortName == null && profile.posLevel?.posLevelName == null
|
||||
? null
|
||||
: `${profile.posType?.posTypeShortName} ${profile.posLevel?.posLevelName}`,
|
||||
oc,
|
||||
|
||||
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
|
||||
* ========================================= */
|
||||
const currentHolder = profile.current_holders?.find(
|
||||
x =>
|
||||
x.orgRevision?.orgRevisionIsDraft === false &&
|
||||
x.orgRevision?.orgRevisionIsCurrent === true,
|
||||
);
|
||||
|
||||
/* =========================================
|
||||
* 5. position executive
|
||||
* ========================================= */
|
||||
const position = await this.positionRepository.findOne({
|
||||
where: {
|
||||
positionIsSelected: true,
|
||||
posMaster: {
|
||||
orgRevisionId: currentHolder?.orgRevisionId,
|
||||
current_holderId: profile.id,
|
||||
},
|
||||
},
|
||||
order: { createdAt: "DESC" },
|
||||
relations: { posExecutive: true },
|
||||
});
|
||||
|
||||
/* =========================================
|
||||
* 6. OC name
|
||||
* ========================================= */
|
||||
let oc = "";
|
||||
if (currentHolder) {
|
||||
if (!currentHolder.orgChild1Id) {
|
||||
oc = currentHolder.orgRoot?.orgRootName;
|
||||
} else if (!currentHolder.orgChild2Id) {
|
||||
oc = `${currentHolder.orgChild1?.orgChild1Name} ${currentHolder.orgRoot?.orgRootName}`;
|
||||
} else if (!currentHolder.orgChild3Id) {
|
||||
oc = `${currentHolder.orgChild2?.orgChild2Name} ${currentHolder.orgChild1?.orgChild1Name} ${currentHolder.orgRoot?.orgRootName}`;
|
||||
} else if (!currentHolder.orgChild4Id) {
|
||||
oc = `${currentHolder.orgChild3?.orgChild3Name} ${currentHolder.orgChild2?.orgChild2Name} ${currentHolder.orgChild1?.orgChild1Name} ${currentHolder.orgRoot?.orgRootName}`;
|
||||
} else {
|
||||
oc = currentHolder.orgChild4?.orgChild4Name;
|
||||
}
|
||||
}
|
||||
|
||||
/* =========================================
|
||||
* 7. position level name
|
||||
* ========================================= */
|
||||
const positionLeaveName =
|
||||
profile.posType &&
|
||||
profile.posLevel &&
|
||||
(profile.posType.posTypeName === "บริหาร" ||
|
||||
profile.posType.posTypeName === "อำนวยการ")
|
||||
? `${profile.posType.posTypeName}${profile.posLevel.posLevelName}`
|
||||
: profile.posLevel?.posLevelName ?? null;
|
||||
|
||||
/* =========================================
|
||||
* 8. map response
|
||||
* ========================================= */
|
||||
const mapProfile = {
|
||||
profileType: "OFFICER",
|
||||
id: profile.id,
|
||||
keycloak: profile.keycloak,
|
||||
prefix: profile.prefix,
|
||||
firstName: profile.firstName,
|
||||
lastName: profile.lastName,
|
||||
citizenId: profile.citizenId,
|
||||
position: profile.position,
|
||||
email: profile.email,
|
||||
phone: profile.phone,
|
||||
isProbation: profile.isProbation,
|
||||
isLeave: profile.isLeave,
|
||||
dateRetire: profile.dateRetire,
|
||||
dateAppoint: profile.dateAppoint,
|
||||
dateRetireLaw: profile.dateRetireLaw,
|
||||
dateStart: profile.dateStart,
|
||||
govAgeAbsent: profile.govAgeAbsent,
|
||||
govAgePlus: profile.govAgePlus,
|
||||
birthDate: profile.birthDate ?? new Date(),
|
||||
reasonSameDate: profile.reasonSameDate,
|
||||
telephoneNumber: profile.phone,
|
||||
nationality: profile.nationality,
|
||||
gender: profile.gender,
|
||||
relationship: profile.relationship,
|
||||
religion: profile.religion,
|
||||
bloodGroup: profile.bloodGroup,
|
||||
dutyTimeId: profile.dutyTimeId,
|
||||
dutyTimeEffectiveDate: profile.dutyTimeEffectiveDate,
|
||||
amount: profile.amount,
|
||||
positionSalaryAmount: profile.positionSalaryAmount,
|
||||
mouthSalaryAmount: profile.mouthSalaryAmount,
|
||||
|
||||
posLevel: profile.posLevel?.posLevelName ?? null,
|
||||
posType: profile.posType?.posTypeName ?? null,
|
||||
posExecutiveName: position?.posExecutive?.posExecutiveName ?? null,
|
||||
positionLeaveName,
|
||||
oc,
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
* 3. API Get Profile จาก profile id
|
||||
*
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue