From 1f207783d1f25c4ccf7d4e842778560d1342834f Mon Sep 17 00:00:00 2001 From: Bright Date: Fri, 2 May 2025 18:09:22 +0700 Subject: [PATCH] =?UTF-8?q?api=20=E0=B8=94=E0=B8=B6=E0=B8=87=20Profile=20(?= =?UTF-8?q?=E0=B9=83=E0=B8=8A=E0=B9=89=E0=B8=AA=E0=B8=B3=E0=B8=AB=E0=B8=A3?= =?UTF-8?q?=E0=B8=B1=E0=B8=9A=E0=B9=83=E0=B8=9A=E0=B8=A5=E0=B8=B2)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../OrganizationDotnetController.ts | 266 +++++++++++++++++- 1 file changed, 265 insertions(+), 1 deletion(-) diff --git a/src/controllers/OrganizationDotnetController.ts b/src/controllers/OrganizationDotnetController.ts index 4fc045c7..6e5e638b 100644 --- a/src/controllers/OrganizationDotnetController.ts +++ b/src/controllers/OrganizationDotnetController.ts @@ -27,7 +27,10 @@ import { Insignia } from "../entities/Insignia"; import { CreateProfileInsignia, ProfileInsignia } from "../entities/ProfileInsignia"; import { PosMaster } from "../entities/PosMaster"; import { EmployeePosDict } from "../entities/EmployeePosDict"; - +import { + calculateRetireLaw +} from "../interfaces/utils"; +import Extension from "../interfaces/extension"; @Route("api/v1/org/dotnet") @Tags("Dotnet") @Security("bearerAuth") @@ -4126,4 +4129,265 @@ export class OrganizationDotnetController extends Controller { return new HttpSuccess(null); } + + /** + * API Get Profile จาก keycloak id (ใช้สำหรับใบลา) + * + * @summary API Get Profile จาก keycloak id (ใช้สำหรับใบลา) + * + * @param {string} keycloakId Id keycloak + */ + @Get("profile-leave/keycloak/{keycloakId}") + async GetProfileLeaveByKeycloakIdAsync(@Path() keycloakId: string) { + const profile = await this.profileRepo.findOne({ + relations: [ + "posLevel", + "posType", + "current_holders", + "current_holders.orgRevision", + "current_holders.orgRoot", + "current_holders.orgChild1", + "current_holders.orgChild2", + "current_holders.orgChild3", + "current_holders.orgChild4", + "profileEducations", + "currentProvince", + "currentDistrict", + "currentSubDistrict", + ], + where: { + keycloak: keycloakId, + }, + order: { + profileEducations: { + level: "ASC" + } + }, + }); + + if (!profile) { + const profile = await this.profileEmpRepo.findOne({ + relations: [ + "posLevel", + "posType", + "current_holders", + "current_holders.orgRevision", + "current_holders.orgRoot", + "current_holders.orgChild1", + "current_holders.orgChild2", + "current_holders.orgChild3", + "current_holders.orgChild4", + "profileEducations", + "currentProvince", + "currentDistrict", + "currentSubDistrict", + ], + where: { + keycloak: keycloakId, + }, + order: { + profileEducations: { + level: "ASC" + } + }, + }); + if (!profile) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); + + const _profileCurrent = profile?.current_holders?.find( + (x) => + x.orgRevision?.orgRevisionIsDraft === false && + x.orgRevision?.orgRevisionIsCurrent === true, + ); + let oc = ""; + if (_profileCurrent != null) { + if (_profileCurrent.orgChild1Id === null) { + oc = _profileCurrent.orgRoot?.orgRootName; + } else if (_profileCurrent.orgChild2Id === null) { + oc = `${_profileCurrent.orgChild1?.orgChild1Name} ${_profileCurrent.orgRoot?.orgRootName}`; + } else if (_profileCurrent.orgChild3Id === null) { + oc = `${_profileCurrent.orgChild2?.orgChild2Name} ${_profileCurrent.orgChild1?.orgChild1Name} ${_profileCurrent.orgRoot?.orgRootName}`; + } else if (_profileCurrent.orgChild4Id === null) { + oc = `${_profileCurrent.orgChild3?.orgChild3Name} ${_profileCurrent.orgChild2?.orgChild2Name} ${_profileCurrent.orgChild1?.orgChild1Name} ${_profileCurrent.orgRoot?.orgRootName}`; + } else { + oc = `${_profileCurrent.orgChild4?.orgChild4Name}`; + } + } + const position = await AppDataSource.query("CALL GetProfileEmployeeSalaryPosition(?)", [profile.id]); + const _position = position.length > 0 ? position[0] : []; + + const mapEmpProfile = { + birthDate: profile.birthDate ?? null, + retireDate: profile.birthDate ? calculateRetireLaw(profile.birthDate) : null, + govAge: profile.dateAppoint ? `${Extension.CalculateGovAge(profile.dateAppoint, 0, 0)} ปี` : "", + age: profile.birthDate ? Extension.CalculateAgeStrV2(profile.birthDate, 0, 0) : "", + dateAppoint: profile.dateAppoint, + amount: profile.amount, + telephoneNumber: profile.telephoneNumber ?? null, + positionName: profile.position, + posLevel: profile.posType && profile.posLevel + ? `${profile.posType?.posTypeShortName} ${profile.posLevel?.posLevelName}` : null, + posType: profile.posType?.posTypeName ?? null, + currentAddress: profile && profile.currentAddress + ? profile.currentAddress + + (profile.currentSubDistrict && profile.currentSubDistrict.name + ? " ตำบล/แขวง " + profile.currentSubDistrict.name : "") + + (profile.currentDistrict && profile.currentDistrict.name + ? " อำเภอ/เขต " + profile.currentDistrict.name : "") + + (profile.currentProvince && profile.currentProvince.name + ? " จังหวัด " + profile.currentProvince.name : "") + + profile.currentZipCode + : "", + oc: oc, + root: + profile?.current_holders?.find( + (x) => + x.orgRevision?.orgRevisionIsDraft == false && + x.orgRevision?.orgRevisionIsCurrent == true, + )?.orgRoot?.orgRootName ?? null, + child1: + profile?.current_holders?.find( + (x) => + x.orgRevision?.orgRevisionIsDraft == false && + x.orgRevision?.orgRevisionIsCurrent == true, + )?.orgChild1?.orgChild1Name ?? null, + child2: + profile?.current_holders?.find( + (x) => + x.orgRevision?.orgRevisionIsDraft == false && + x.orgRevision?.orgRevisionIsCurrent == true, + )?.orgChild2?.orgChild2Name ?? null, + child3: + profile?.current_holders?.find( + (x) => + x.orgRevision?.orgRevisionIsDraft == false && + x.orgRevision?.orgRevisionIsCurrent == true, + )?.orgChild3?.orgChild3Name ?? null, + child4: + profile?.current_holders?.find( + (x) => + x.orgRevision?.orgRevisionIsDraft == false && + x.orgRevision?.orgRevisionIsCurrent == true, + )?.orgChild4?.orgChild4Name ?? null, + positions: _position && _position.length > 0 + ? _position.map((x:any) => ({ + positionName: x.positionName, + date: x.commandDateAffect, + positionType: x.positionType, + positionLevel: x.positionLevel, + orgRoot: x.orgRoot, + orgChild1: x.orgChild1, + orgChild2: x.orgChild2, + orgChild3: x.orgChild3, + orgChild4: x.orgChild4, + })) + : [], + educations: profile.profileEducations && profile.profileEducations.length > 0 + ? profile.profileEducations.map(x => ({ + educationLevel: x.educationLevel, + institute: x.institute, + country: x.country, + finishDate: x.finishDate, + })) + : [] + }; + return new HttpSuccess(mapEmpProfile); + } + const _profileCurrent = profile?.current_holders?.find( + (x) => + x.orgRevision?.orgRevisionIsDraft === false && + x.orgRevision?.orgRevisionIsCurrent === true, + ); + let oc = ""; + if (_profileCurrent != null) { + if (_profileCurrent.orgChild1Id === null) { + oc = _profileCurrent.orgRoot?.orgRootName; + } else if (_profileCurrent.orgChild2Id === null) { + oc = `${_profileCurrent.orgChild1?.orgChild1Name} ${_profileCurrent.orgRoot?.orgRootName}`; + } else if (_profileCurrent.orgChild3Id === null) { + oc = `${_profileCurrent.orgChild2?.orgChild2Name} ${_profileCurrent.orgChild1?.orgChild1Name} ${_profileCurrent.orgRoot?.orgRootName}`; + } else if (_profileCurrent.orgChild4Id === null) { + oc = `${_profileCurrent.orgChild3?.orgChild3Name} ${_profileCurrent.orgChild2?.orgChild2Name} ${_profileCurrent.orgChild1?.orgChild1Name} ${_profileCurrent.orgRoot?.orgRootName}`; + } else { + oc = `${_profileCurrent.orgChild4?.orgChild4Name}`; + } + } + const position = await AppDataSource.query("CALL GetProfileSalaryPosition(?)", [profile.id]); + const _position = position.length > 0 ? position[0] : []; + + const mapProfile = { + birthDate: profile.birthDate ?? null, + retireDate: profile.birthDate ? calculateRetireLaw(profile.birthDate) : null, + govAge: profile.dateAppoint ? `${Extension.CalculateGovAge(profile.dateAppoint, 0, 0)} ปี` : "", + age: profile.birthDate ? Extension.CalculateAgeStrV2(profile.birthDate, 0, 0) : "", + dateAppoint: profile.dateAppoint, + amount: profile.amount, + telephoneNumber: profile.telephoneNumber ?? null, + positionName: profile.position, + posLevel: profile.posLevel?.posLevelName ?? null, + posType: profile.posType?.posTypeName ?? null, + currentAddress: profile && profile.currentAddress + ? profile.currentAddress + + (profile.currentSubDistrict && profile.currentSubDistrict.name + ? " ตำบล/แขวง " + profile.currentSubDistrict.name : "") + + (profile.currentDistrict && profile.currentDistrict.name + ? " อำเภอ/เขต " + profile.currentDistrict.name : "") + + (profile.currentProvince && profile.currentProvince.name + ? " จังหวัด " + profile.currentProvince.name : "") + + profile.currentZipCode + : "", + oc: oc, + root: + profile?.current_holders?.find( + (x) => + x.orgRevision?.orgRevisionIsDraft == false && + x.orgRevision?.orgRevisionIsCurrent == true, + )?.orgRoot?.orgRootName ?? null, + child1: + profile?.current_holders?.find( + (x) => + x.orgRevision?.orgRevisionIsDraft == false && + x.orgRevision?.orgRevisionIsCurrent == true, + )?.orgChild1?.orgChild1Name ?? null, + child2: + profile?.current_holders?.find( + (x) => + x.orgRevision?.orgRevisionIsDraft == false && + x.orgRevision?.orgRevisionIsCurrent == true, + )?.orgChild2?.orgChild2Name ?? null, + child3: + profile?.current_holders?.find( + (x) => + x.orgRevision?.orgRevisionIsDraft == false && + x.orgRevision?.orgRevisionIsCurrent == true, + )?.orgChild3?.orgChild3Name ?? null, + child4: + profile?.current_holders?.find( + (x) => + x.orgRevision?.orgRevisionIsDraft == false && + x.orgRevision?.orgRevisionIsCurrent == true, + )?.orgChild4?.orgChild4Name ?? null, + positions: _position && _position.length > 0 + ? _position.map((x:any) => ({ + positionName: x.positionName, + date: x.commandDateAffect, + positionType: x.positionType, + positionLevel: x.positionLevel, + orgRoot: x.orgRoot, + orgChild1: x.orgChild1, + orgChild2: x.orgChild2, + orgChild3: x.orgChild3, + orgChild4: x.orgChild4, + })) + : [], + educations: profile.profileEducations && profile.profileEducations.length > 0 + ? profile.profileEducations.map(x => ({ + educationLevel: x.educationLevel, + institute: x.institute, + country: x.country, + finishDate: x.finishDate, + })) + : [] + }; + return new HttpSuccess(mapProfile); + } }