get detail profile

This commit is contained in:
kittapath 2024-11-18 10:45:05 +07:00
parent 5bc6101e12
commit 8001a4b138

View file

@ -800,12 +800,19 @@ export class OrganizationDotnetController extends Controller {
@Get("profile/{profileId}")
async GetProfileByProfileIdAsync(@Path() profileId: string) {
const profile = await this.profileRepo.findOne({
relations: {
posLevel: true,
posType: true,
profileSalary: true,
profileInsignias: true,
},
relations: [
"posLevel",
"posType",
"profileSalary",
"profileInsignias",
"current_holders",
"current_holders.orgRevision",
"current_holders.orgRoot",
"current_holders.orgChild1",
"current_holders.orgChild2",
"current_holders.orgChild3",
"current_holders.orgChild4",
],
where: { id: profileId },
order: {
profileSalary: {
@ -816,7 +823,418 @@ export class OrganizationDotnetController extends Controller {
},
},
});
if (!profile) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
if (!profile) {
const profile = await this.profileEmpRepo.findOne({
relations: [
"posLevel",
"posType",
"profileSalary",
"profileInsignias",
"current_holders",
"current_holders.orgRevision",
"current_holders.orgRoot",
"current_holders.orgChild1",
"current_holders.orgChild2",
"current_holders.orgChild3",
"current_holders.orgChild4",
],
where: { id: profileId },
order: {
profileSalary: {
date: "DESC",
},
profileInsignias: {
receiveDate: "DESC",
},
},
});
if (!profile) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
const org = {
root:
profile?.current_holders?.find(
(x) =>
x.orgRevision?.orgRevisionIsDraft == false &&
x.orgRevision?.orgRevisionIsCurrent == true,
)?.orgRoot?.id ?? null,
child1:
profile?.current_holders?.find(
(x) =>
x.orgRevision?.orgRevisionIsDraft == false &&
x.orgRevision?.orgRevisionIsCurrent == true,
)?.orgChild1?.id ?? null,
child2:
profile?.current_holders?.find(
(x) =>
x.orgRevision?.orgRevisionIsDraft == false &&
x.orgRevision?.orgRevisionIsCurrent == true,
)?.orgChild2?.id ?? null,
child3:
profile?.current_holders?.find(
(x) =>
x.orgRevision?.orgRevisionIsDraft == false &&
x.orgRevision?.orgRevisionIsCurrent == true,
)?.orgChild3?.id ?? null,
child4:
profile?.current_holders?.find(
(x) =>
x.orgRevision?.orgRevisionIsDraft == false &&
x.orgRevision?.orgRevisionIsCurrent == true,
)?.orgChild4?.id ?? null,
};
let fullname = "";
let pos = await this.posMasterRepository.findOne({
relations: ["current_holder"],
where: {
orgRevision: {
orgRevisionIsCurrent: true,
orgRevisionIsDraft: false,
},
isDirector: true,
orgRootId: org?.root ?? "",
orgChild1Id: org?.child1 ?? "",
orgChild2Id: org?.child2 ?? "",
orgChild3Id: org?.child3 ?? "",
orgChild4Id: org?.child4 ?? "",
},
});
if (pos) {
fullname =
pos.current_holder.prefix +
pos.current_holder.firstName +
" " +
pos.current_holder.lastName;
} else {
let pos = await this.posMasterRepository.findOne({
relations: ["current_holder"],
where: {
orgRevision: {
orgRevisionIsCurrent: true,
orgRevisionIsDraft: false,
},
isDirector: true,
orgRootId: org?.root ?? "",
orgChild1Id: org?.child1 ?? "",
orgChild2Id: org?.child2 ?? "",
orgChild3Id: org?.child3 ?? "",
orgChild4Id: IsNull(),
},
});
if (pos) {
fullname =
pos.current_holder.prefix +
pos.current_holder.firstName +
" " +
pos.current_holder.lastName;
} else {
let pos = await this.posMasterRepository.findOne({
relations: ["current_holder"],
where: {
orgRevision: {
orgRevisionIsCurrent: true,
orgRevisionIsDraft: false,
},
isDirector: true,
orgRootId: org?.root ?? "",
orgChild1Id: org?.child1 ?? "",
orgChild2Id: org?.child2 ?? "",
orgChild3Id: IsNull(),
orgChild4Id: IsNull(),
},
});
if (pos) {
fullname =
pos.current_holder.prefix +
pos.current_holder.firstName +
" " +
pos.current_holder.lastName;
} else {
let pos = await this.posMasterRepository.findOne({
relations: ["current_holder"],
where: {
orgRevision: {
orgRevisionIsCurrent: true,
orgRevisionIsDraft: false,
},
isDirector: true,
orgRootId: org?.root ?? "",
orgChild1Id: org?.child1 ?? "",
orgChild2Id: IsNull(),
orgChild3Id: IsNull(),
orgChild4Id: IsNull(),
},
});
if (pos) {
fullname =
pos.current_holder.prefix +
pos.current_holder.firstName +
" " +
pos.current_holder.lastName;
} else {
let pos = await this.posMasterRepository.findOne({
relations: ["current_holder"],
where: {
orgRevision: {
orgRevisionIsCurrent: true,
orgRevisionIsDraft: false,
},
orgRootId: org?.root ?? "",
orgChild1Id: IsNull(),
orgChild2Id: IsNull(),
orgChild3Id: IsNull(),
orgChild4Id: IsNull(),
},
});
if (pos) {
fullname =
pos.current_holder.prefix +
pos.current_holder.firstName +
" " +
pos.current_holder.lastName;
} else {
fullname = "";
}
}
}
}
}
const mapProfile = {
id: profile.id,
avatar: profile.avatar,
avatarName: profile.avatarName,
rank: profile.rank,
prefix: profile.prefix,
firstName: profile.firstName,
lastName: profile.lastName,
citizenId: profile.citizenId,
position: profile.position,
posLevelId: profile.posLevelId,
email: profile.email,
phone: profile.phone,
keycloak: profile.keycloak,
isProbation: profile.isProbation,
isLeave: profile.isLeave,
leaveReason: profile.leaveReason,
dateRetire: profile.dateRetire,
dateAppoint: profile.dateAppoint,
dateRetireLaw: profile.dateRetireLaw,
dateStart: profile.dateStart,
govAgeAbsent: profile.govAgeAbsent,
govAgePlus: profile.govAgePlus,
birthDate: profile.birthDate,
reasonSameDate: profile.reasonSameDate,
telephoneNumber: profile.telephoneNumber,
nationality: profile.nationality,
gender: profile.gender,
relationship: profile.relationship,
religion: profile.religion,
bloodGroup: profile.bloodGroup,
registrationAddress: profile.registrationAddress,
registrationProvinceId: profile.registrationProvinceId,
registrationDistrictId: profile.registrationDistrictId,
registrationSubDistrictId: profile.registrationSubDistrictId,
registrationZipCode: profile.registrationZipCode,
currentAddress: profile.currentAddress,
currentProvinceId: profile.currentProvinceId,
currentSubDistrictId: profile.currentSubDistrictId,
currentZipCode: profile.currentZipCode,
dutyTimeId: profile.dutyTimeId,
dutyTimeEffectiveDate: profile.dutyTimeEffectiveDate,
amountd: profile.amount,
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,
commander: fullname,
posLevel: profile.posLevel ? profile.posLevel : null,
posType: profile.posType ? profile.posType : null,
profileSalary: profile.profileSalary.length > 0 ? profile.profileSalary[0] : null,
profileInsignia: profile.profileInsignias.length > 0 ? profile.profileInsignias[0] : null,
profileType: "EMPLOYEE",
};
return new HttpSuccess(mapProfile);
}
const org = {
root:
profile?.current_holders?.find(
(x) =>
x.orgRevision?.orgRevisionIsDraft == false &&
x.orgRevision?.orgRevisionIsCurrent == true,
)?.orgRoot?.id ?? null,
child1:
profile?.current_holders?.find(
(x) =>
x.orgRevision?.orgRevisionIsDraft == false &&
x.orgRevision?.orgRevisionIsCurrent == true,
)?.orgChild1?.id ?? null,
child2:
profile?.current_holders?.find(
(x) =>
x.orgRevision?.orgRevisionIsDraft == false &&
x.orgRevision?.orgRevisionIsCurrent == true,
)?.orgChild2?.id ?? null,
child3:
profile?.current_holders?.find(
(x) =>
x.orgRevision?.orgRevisionIsDraft == false &&
x.orgRevision?.orgRevisionIsCurrent == true,
)?.orgChild3?.id ?? null,
child4:
profile?.current_holders?.find(
(x) =>
x.orgRevision?.orgRevisionIsDraft == false &&
x.orgRevision?.orgRevisionIsCurrent == true,
)?.orgChild4?.id ?? null,
};
let fullname = "";
let pos = await this.posMasterRepository.findOne({
relations: ["current_holder"],
where: {
orgRevision: {
orgRevisionIsCurrent: true,
orgRevisionIsDraft: false,
},
isDirector: true,
orgRootId: org?.root ?? "",
orgChild1Id: org?.child1 ?? "",
orgChild2Id: org?.child2 ?? "",
orgChild3Id: org?.child3 ?? "",
orgChild4Id: org?.child4 ?? "",
},
});
if (pos) {
fullname =
pos.current_holder.prefix +
pos.current_holder.firstName +
" " +
pos.current_holder.lastName;
} else {
let pos = await this.posMasterRepository.findOne({
relations: ["current_holder"],
where: {
orgRevision: {
orgRevisionIsCurrent: true,
orgRevisionIsDraft: false,
},
isDirector: true,
orgRootId: org?.root ?? "",
orgChild1Id: org?.child1 ?? "",
orgChild2Id: org?.child2 ?? "",
orgChild3Id: org?.child3 ?? "",
orgChild4Id: IsNull(),
},
});
if (pos) {
fullname =
pos.current_holder.prefix +
pos.current_holder.firstName +
" " +
pos.current_holder.lastName;
} else {
let pos = await this.posMasterRepository.findOne({
relations: ["current_holder"],
where: {
orgRevision: {
orgRevisionIsCurrent: true,
orgRevisionIsDraft: false,
},
isDirector: true,
orgRootId: org?.root ?? "",
orgChild1Id: org?.child1 ?? "",
orgChild2Id: org?.child2 ?? "",
orgChild3Id: IsNull(),
orgChild4Id: IsNull(),
},
});
if (pos) {
fullname =
pos.current_holder.prefix +
pos.current_holder.firstName +
" " +
pos.current_holder.lastName;
} else {
let pos = await this.posMasterRepository.findOne({
relations: ["current_holder"],
where: {
orgRevision: {
orgRevisionIsCurrent: true,
orgRevisionIsDraft: false,
},
isDirector: true,
orgRootId: org?.root ?? "",
orgChild1Id: org?.child1 ?? "",
orgChild2Id: IsNull(),
orgChild3Id: IsNull(),
orgChild4Id: IsNull(),
},
});
if (pos) {
fullname =
pos.current_holder.prefix +
pos.current_holder.firstName +
" " +
pos.current_holder.lastName;
} else {
let pos = await this.posMasterRepository.findOne({
relations: ["current_holder"],
where: {
orgRevision: {
orgRevisionIsCurrent: true,
orgRevisionIsDraft: false,
},
orgRootId: org?.root ?? "",
orgChild1Id: IsNull(),
orgChild2Id: IsNull(),
orgChild3Id: IsNull(),
orgChild4Id: IsNull(),
},
});
if (pos) {
fullname =
pos.current_holder.prefix +
pos.current_holder.firstName +
" " +
pos.current_holder.lastName;
} else {
fullname = "";
}
}
}
}
}
const mapProfile = {
id: profile.id,
@ -860,10 +1278,43 @@ export class OrganizationDotnetController extends Controller {
currentZipCode: profile.currentZipCode,
dutyTimeId: profile.dutyTimeId,
dutyTimeEffectiveDate: profile.dutyTimeEffectiveDate,
amountd: profile.amount,
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,
commander: fullname,
posLevel: profile.posLevel ? profile.posLevel : null,
posType: profile.posType ? profile.posType : null,
profileSalary: profile.profileSalary,
profileInsignia: profile.profileInsignias,
profileSalary: profile.profileSalary.length > 0 ? profile.profileSalary[0] : null,
profileInsignia: profile.profileInsignias.length > 0 ? profile.profileInsignias[0] : null,
profileType: "OFFICER",
};
return new HttpSuccess(mapProfile);