เพิ่ม report kk1

This commit is contained in:
AnandaTon 2024-05-24 13:42:59 +07:00
parent 7b480b1247
commit a242f7bbdd

View file

@ -43,6 +43,14 @@ import { ProfileEmployee } from "../entities/ProfileEmployee";
import { Province } from "../entities/Province";
import { District } from "../entities/District";
import { SubDistrict } from "../entities/SubDistrict";
import { ProfileCertificate } from "../entities/ProfileCertificate";
import { ProfileTraining } from "../entities/ProfileTraining";
import { ProfileDiscipline } from "../entities/ProfileDiscipline";
import { ProfileEducation } from "../entities/ProfileEducation";
import { ProfileSalary } from "../entities/ProfileSalary";
import { ProfileFamilyCouple } from "../entities/ProfileFamilyCouple";
import { ProfileFamilyMother } from "../entities/ProfileFamilyMother";
import { ProfileFamilyFather } from "../entities/ProfileFamilyFather";
import Extension from "../interfaces/extension";
@Route("api/v1/org/profile")
@ -65,6 +73,14 @@ export class ProfileController extends Controller {
private provinceRepository = AppDataSource.getRepository(Province);
private districtRepository = AppDataSource.getRepository(District);
private subDistrict = AppDataSource.getRepository(SubDistrict);
private certificateRepository = AppDataSource.getRepository(ProfileCertificate);
private profileFamilyCoupleRepository = AppDataSource.getRepository(ProfileFamilyCouple);
private profileFamilyMotherRepository = AppDataSource.getRepository(ProfileFamilyMother);
private profileFamilyFatherRepository = AppDataSource.getRepository(ProfileFamilyFather);
private trainingRepository = AppDataSource.getRepository(ProfileTraining);
private disciplineRepository = AppDataSource.getRepository(ProfileDiscipline);
private educationRepository = AppDataSource.getRepository(ProfileEducation);
private salaryRepository = AppDataSource.getRepository(ProfileSalary);
/**
* report
@ -189,6 +205,193 @@ export class ProfileController extends Controller {
return new HttpSuccess(mapData);
}
@Get("kk1/{id}")
public async getKk1(@Path() id: string) {
const profiles = await this.profileRepo.findOne({
select: [
"citizenId",
"prefix",
"firstName",
"lastName",
"birthDate",
"currentAddress",
"currentDistrictId",
"currentProvinceId",
"telephoneNumber",
"avatar",
],
where: { id: id },
});
const province = await this.provinceRepository.findOneBy({
id: profiles?.registrationProvinceId,
});
const district = await this.districtRepository.findOneBy({
id: profiles?.registrationDistrictId,
});
const orgRevision = await this.orgRevisionRepo.findOne({
where: { orgRevisionIsCurrent: true },
});
const profileFamilyCouple = await this.profileFamilyCoupleRepository.findOne({
where: { id },
select: ["couplePrefix", "coupleFirstName", "coupleLastNameOld"],
});
const profileFamilyMother = await this.profileFamilyMotherRepository.findOne({
where: { id },
select: ["motherPrefix", "motherFirstName", "motherLastName"],
});
const profileFamilyFather = await this.profileFamilyFatherRepository.findOne({
where: { id },
select: ["fatherPrefix", "fatherFirstName", "fatherLastName"],
});
// Extract relevant data
const root =
profiles?.current_holders?.find((x) => x.orgRevisionId === orgRevision?.id)?.orgRoot ?? null;
const child1 =
profiles?.current_holders?.find((x) => x.orgRevisionId === orgRevision?.id)?.orgChild1 ??
null;
const child2 =
profiles?.current_holders?.find((x) => x.orgRevisionId === orgRevision?.id)?.orgChild2 ??
null;
const child3 =
profiles?.current_holders?.find((x) => x.orgRevisionId === orgRevision?.id)?.orgChild3 ??
null;
const child4 =
profiles?.current_holders?.find((x) => x.orgRevisionId === orgRevision?.id)?.orgChild4 ??
null;
// Construct org path
const _root = root ? `${root.orgRootName}` : "";
const _child1 = child1 ? `${child1.orgChild1Name}/` : "";
const _child2 = child2 ? `${child2.orgChild2Name}/` : "";
const _child3 = child3 ? `${child3.orgChild3Name}/` : "";
const _child4 = child4 ? `${child4.orgChild4Name}/` : "";
const profile = {
CitizenId: profiles?.citizenId ?? null,
Prefix: profiles?.prefix != null ? profiles.prefix : "",
FirstName: profiles?.firstName != null ? profiles.firstName : "",
LastName: profiles?.lastName != null ? profiles.lastName : "",
FullName: `${profiles?.prefix} ${profiles?.firstName} ${profiles?.lastName}`,
BirthDay: profiles?.birthDate ? new Date(profiles.birthDate).getDate() : null,
BirthDayText: "ห้า",
BirthMonth: profiles?.birthDate ? new Date(profiles.birthDate).getMonth() + 1 : null, // Months are zero-based
BirthYear: profiles?.birthDate ? new Date(profiles.birthDate).getFullYear() : null,
BirthYearText: "สองพันห้าร้อยสามสิบสี่",
Address: profiles?.currentAddress,
District: district?.name ?? null,
Area: "",
Province: province?.name ?? null,
Telephone: profiles?.telephoneNumber ?? null,
CoupleLastNameOld: profileFamilyCouple?.coupleLastNameOld ?? null,
CouplePrefix: profileFamilyCouple?.couplePrefix ?? null,
CoupleFullName:
profileFamilyCouple?.couplePrefix ||
profileFamilyCouple?.coupleFirstName ||
profileFamilyCouple?.coupleLastNameOld
? `${profileFamilyCouple?.couplePrefix ?? ""} ${profileFamilyCouple?.coupleFirstName ?? ""} ${profileFamilyCouple?.coupleLastNameOld ?? ""}`.trim()
: null,
FatherPrefix: profileFamilyFather?.fatherPrefix ?? null,
FatherFullName:
profileFamilyFather?.fatherPrefix ||
profileFamilyFather?.fatherFirstName ||
profileFamilyFather?.fatherLastName
? `${profileFamilyFather?.fatherPrefix ?? ""} ${profileFamilyFather?.fatherFirstName ?? ""} ${profileFamilyFather?.fatherLastName ?? ""}`.trim()
: null,
MotherPrefix: profileFamilyMother?.motherPrefix ?? null,
MotherFullName:
profileFamilyMother?.motherPrefix ||
profileFamilyMother?.motherFirstName ||
profileFamilyMother?.motherLastName
? `${profileFamilyMother?.motherPrefix ?? ""} ${profileFamilyMother?.motherFirstName ?? ""} ${profileFamilyMother?.motherLastName ?? ""}`.trim()
: null,
OcFullPath: `${_child4}${_child3}${_child2}${_child1}${_root}`,
Division: "",
Institute: "",
StartDate: profiles?.dateStart,
AppointDate: profiles?.dateAppoint,
BirthDate: profiles?.birthDate,
RetireDate: profiles?.dateRetireLaw,
AvatarId: profiles?.avatar ?? null,
};
const certs = await this.certificateRepository.find({
where: { profileId: id },
select: ["certificateType", "issuer", "certificateNo", "issueDate"],
});
const cert = certs.map((item) => ({
CertificateType: item.certificateType ?? null,
Issuer: item.issuer ?? null,
CertificateNo: item.certificateNo ?? null,
IssueDate: item.issueDate ?? null,
}));
const trainings = await this.trainingRepository.find({
select: ["startDate", "endDate", "place", "department"],
where: { profileId: id },
});
const training = trainings.map((item) => ({
institute: item.department ?? null,
start: item.startDate ?? null,
end: item.endDate ?? null,
level: "",
degree: "",
field: item.place ?? null,
}));
const disciplines = await this.disciplineRepository.find({
select: ["refCommandDate", "refCommandNo", "detail"],
where: { profileId: id },
});
const discipline = disciplines.map((item) => ({
DisciplineYear: item.refCommandDate ?? null,
DisciplineDetail: item.detail ?? null,
RefNo: item.refCommandNo ?? null,
}));
const educations = await this.educationRepository.find({
select: ["startDate", "endDate", "educationLevel", "degree", "field", "institute"],
where: { profileId: id },
});
const education = educations.map((item) => ({
Institute: item.institute ?? null,
Start: item.startDate ?? null,
End: item.endDate ?? null,
Level: item.educationLevel ?? null,
Degree: item.degree ?? null,
Field: item.field ?? null,
}));
const salarys = await this.salaryRepository.find({
select: [
"date",
"position",
"posNo",
"positionType",
"positionLevel",
"positionSalaryAmount",
"refCommandNo",
],
where: { profileId: id },
});
const salary = salarys.map((item) => ({
SalaryDate: item.date ?? null,
Position: item.position ?? null,
PosNo: item.posNo ?? null,
Salary: "",
RefAll: item.refCommandNo ?? null,
PositionType: item.positionType ?? null,
PositionLevel: item.positionLevel ?? null,
PositionAmount: item.positionSalaryAmount ?? null,
FullName: `${profiles?.prefix} ${profiles?.firstName} ${profiles?.lastName}`,
OcFullPath: `${_child4}${_child3}${_child2}${_child1}${_root}`,
}));
return new HttpSuccess({ profile, cert, training, discipline, education, salary });
}
/**
*
*
@ -573,7 +776,7 @@ export class ProfileController extends Controller {
/**
* API
*
* @summary
* @summary
*
* @param {string} id Id
*/
@ -586,8 +789,8 @@ export class ProfileController extends Controller {
},
where: { keycloak: request.user.sub },
order: {
createdAt:"ASC",
}
createdAt: "ASC",
},
});
if (!historyProfile) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");