api ดึง Profile (ใช้สำหรับใบลา)
This commit is contained in:
parent
0f45c75d62
commit
1f207783d1
1 changed files with 265 additions and 1 deletions
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue