update issue #1436 (fix report kk1)

This commit is contained in:
Bright 2025-04-26 14:03:52 +07:00
parent 921e23f81a
commit 1eadad89da

View file

@ -924,6 +924,12 @@ export class ProfileController extends Controller {
"registrationDistrict", "registrationDistrict",
"registrationProvince", "registrationProvince",
"profileAvatars", "profileAvatars",
"current_holders",
"current_holders.orgRoot",
"current_holders.orgChild1",
"current_holders.orgChild2",
"current_holders.orgChild3",
"current_holders.orgChild4",
], ],
order: { order: {
profileAvatars: { createdAt: "ASC" }, profileAvatars: { createdAt: "ASC" },
@ -934,13 +940,6 @@ export class ProfileController extends Controller {
let ImgUrl: any = null; let ImgUrl: any = null;
let _ImgUrl: any = []; let _ImgUrl: any = [];
if (profiles?.avatar != null && profiles?.avatarName != null) { if (profiles?.avatar != null && profiles?.avatarName != null) {
// await new CallAPI()
// .GetData(req, `/salary/file/${profiles?.avatar}/${profiles?.avatarName}`)
// .then(async (x) => {
// ImgUrl = x.downloadUrl;
// })
// .catch();
let req_: any = req; let req_: any = req;
const token_ = "Bearer " + req_.headers.authorization.replace("Bearer ", ""); const token_ = "Bearer " + req_.headers.authorization.replace("Bearer ", "");
@ -975,18 +974,7 @@ export class ProfileController extends Controller {
ImgUrl = response_.data.downloadUrl; ImgUrl = response_.data.downloadUrl;
} catch {} } catch {}
} }
const profileOc = await this.profileRepo.findOne({
relations: [
"current_holders",
"current_holders.orgRoot",
"current_holders.orgChild1",
"current_holders.orgChild2",
"current_holders.orgChild3",
"current_holders.orgChild4",
],
where: { id: id },
});
if (!profileOc) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
const orgRevision = await this.orgRevisionRepo.findOne({ const orgRevision = await this.orgRevisionRepo.findOne({
where: { orgRevisionIsCurrent: true }, where: { orgRevisionIsCurrent: true },
}); });
@ -1010,39 +998,39 @@ export class ProfileController extends Controller {
}); });
const root = const root =
profileOc.current_holders == null || profiles.current_holders == null ||
profileOc.current_holders.length == 0 || profiles.current_holders.length == 0 ||
profileOc.current_holders.find((x) => x.orgRevisionId == orgRevision?.id) == null profiles.current_holders.find((x) => x.orgRevisionId == orgRevision?.id) == null
? null ? null
: profileOc.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.orgRoot; : profiles.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.orgRoot;
const child1 = const child1 =
profileOc.current_holders == null || profiles.current_holders == null ||
profileOc.current_holders.length == 0 || profiles.current_holders.length == 0 ||
profileOc.current_holders.find((x) => x.orgRevisionId == orgRevision?.id) == null profiles.current_holders.find((x) => x.orgRevisionId == orgRevision?.id) == null
? null ? null
: profileOc.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.orgChild1; : profiles.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.orgChild1;
const child2 = const child2 =
profileOc.current_holders == null || profiles.current_holders == null ||
profileOc.current_holders.length == 0 || profiles.current_holders.length == 0 ||
profileOc.current_holders.find((x) => x.orgRevisionId == orgRevision?.id) == null profiles.current_holders.find((x) => x.orgRevisionId == orgRevision?.id) == null
? null ? null
: profileOc.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.orgChild2; : profiles.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.orgChild2;
const child3 = const child3 =
profileOc.current_holders == null || profiles.current_holders == null ||
profileOc.current_holders.length == 0 || profiles.current_holders.length == 0 ||
profileOc.current_holders.find((x) => x.orgRevisionId == orgRevision?.id) == null profiles.current_holders.find((x) => x.orgRevisionId == orgRevision?.id) == null
? null ? null
: profileOc.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.orgChild3; : profiles.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.orgChild3;
const child4 = const child4 =
profileOc.current_holders == null || profiles.current_holders == null ||
profileOc.current_holders.length == 0 || profiles.current_holders.length == 0 ||
profileOc.current_holders.find((x) => x.orgRevisionId == orgRevision?.id) == null profiles.current_holders.find((x) => x.orgRevisionId == orgRevision?.id) == null
? null ? null
: profileOc.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.orgChild4; : profiles.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.orgChild4;
// Construct org path // Construct org path
let _root = root?.orgRootName; let _root = root?.orgRootName;
@ -1058,7 +1046,7 @@ export class ProfileController extends Controller {
}); });
const certs = const certs =
cert_raw.length > 0 cert_raw.length > 0
? cert_raw.slice(-2).map((item) => ({ ? cert_raw.map((item) => ({
certificateType: item.certificateType ?? null, certificateType: item.certificateType ?? null,
issuer: item.issuer ?? null, issuer: item.issuer ?? null,
certificateNo: item.certificateNo ? Extension.ToThaiNumber(item.certificateNo) : null, certificateNo: item.certificateNo ? Extension.ToThaiNumber(item.certificateNo) : null,
@ -1091,7 +1079,7 @@ export class ProfileController extends Controller {
}); });
const trainings = const trainings =
training_raw.length > 0 training_raw.length > 0
? training_raw.slice(-2).map((item) => ({ ? training_raw.map((item) => ({
institute: item.department ?? "", institute: item.department ?? "",
start: start:
item.startDate == null item.startDate == null
@ -1128,7 +1116,7 @@ export class ProfileController extends Controller {
}); });
const disciplines = const disciplines =
discipline_raw.length > 0 discipline_raw.length > 0
? discipline_raw.slice(-2).map((item) => ({ ? discipline_raw.map((item) => ({
disciplineYear: item.refCommandDate disciplineYear: item.refCommandDate
? Extension.ToThaiNumber(new Date(item.refCommandDate).getFullYear().toString()) ? Extension.ToThaiNumber(new Date(item.refCommandDate).getFullYear().toString())
: null, : null,
@ -1143,47 +1131,38 @@ export class ProfileController extends Controller {
}, },
]; ];
const education_raw = await this.profileEducationRepo.find({ const education_raw = await this.profileEducationRepo
select: ["startDate", "endDate", "educationLevel", "degree", "field", "institute"], .createQueryBuilder("education")
where: { profileId: id }, .where("education.profileId = :profileId", { profileId: id })
// order: { lastUpdatedAt: "DESC" }, .orderBy("CASE WHEN education.isEducation = true THEN 1 ELSE 2 END", "ASC")
order: { level: "ASC" }, .addOrderBy("education.level", "ASC")
}); .getMany();
const educations = const educations =
education_raw.length > 0 education_raw.length > 0
? education_raw.slice(-2).map((item) => ({ ? education_raw.map((item) => ({
institute: item.institute, institute: item.institute,
start:
item.startDate == null
? ""
: Extension.ToThaiNumber(new Date(item.startDate).getFullYear().toString()),
end:
item.endDate == null
? ""
: Extension.ToThaiNumber(new Date(item.endDate).getFullYear().toString()),
date: date:
item.startDate && item.endDate item.isDate
? `${Extension.ToThaiNumber(Extension.ToThaiFullDate2(item.startDate))} - ${Extension.ToThaiNumber(Extension.ToThaiFullDate2(item.endDate))}` ? item.startDate && item.endDate
: "", ? `${Extension.ToThaiNumber(Extension.ToThaiFullDate2(item.startDate))} - ${Extension.ToThaiNumber(Extension.ToThaiFullDate2(item.endDate))}`
level: item.educationLevel ?? "", : ""
: item.startDate && item.endDate
? `${Extension.ToThaiNumber(new Date(item.startDate).getFullYear().toString())} - ${Extension.ToThaiNumber(new Date(item.endDate).getFullYear().toString())}`
: "",
degree: item.degree ? `${item.degree} ${item.field ? item.field : ""}` : "", degree: item.degree ? `${item.degree} ${item.field ? item.field : ""}` : "",
field: item.field ?? "-",
})) }))
: [ : [
{ {
institute: "-", institute: "-",
start: "-",
end: "-",
date: "-", date: "-",
level: "-",
degree: "-", degree: "-",
field: "-",
}, },
]; ];
const salary_raw = await this.salaryRepo.find({ const salary_raw = await this.salaryRepo.find({
select: [ select: [
"commandDateAffect", "commandDateAffect",
"positionName", "positionName",
"posNoAbb",
"posNo", "posNo",
"positionType", "positionType",
"positionLevel", "positionLevel",
@ -1207,7 +1186,9 @@ export class ProfileController extends Controller {
? Extension.ToThaiNumber(Extension.ToThaiFullDate2(item.commandDateAffect)) ? Extension.ToThaiNumber(Extension.ToThaiFullDate2(item.commandDateAffect))
: null, : null,
position: item.positionName != null ? Extension.ToThaiNumber(item.positionName) : null, position: item.positionName != null ? Extension.ToThaiNumber(item.positionName) : null,
posNo: item.posNo != null ? Extension.ToThaiNumber(item.posNo) : null, posNo: item.posNoAbb && item.posNo
? Extension.ToThaiNumber(`${item.posNoAbb}${item.posNo}`)
: null,
salary: salary:
item.amount != null ? Extension.ToThaiNumber(item.amount.toLocaleString()) : null, item.amount != null ? Extension.ToThaiNumber(item.amount.toLocaleString()) : null,
rank: item.positionLevel != null ? Extension.ToThaiNumber(item.positionLevel) : null, rank: item.positionLevel != null ? Extension.ToThaiNumber(item.positionLevel) : null,
@ -1447,10 +1428,8 @@ export class ProfileController extends Controller {
commandDateSign: item.commandDateSign commandDateSign: item.commandDateSign
? Extension.ToThaiNumber(Extension.ToThaiFullDate2(item.commandDateSign)) ? Extension.ToThaiNumber(Extension.ToThaiFullDate2(item.commandDateSign))
: "", : "",
posNo: item.posNoAbb posNo: item.posNoAbb && item.posNo
? Extension.ToThaiNumber(item.posNoAbb) ? Extension.ToThaiNumber(`${item.posNoAbb}${item.posNo}`)
: "" + item.posNo
? Extension.ToThaiNumber(item.posNo)
: "", : "",
position: item.positionName, position: item.positionName,
posType: item.positionType, posType: item.positionType,
@ -1676,6 +1655,9 @@ export class ProfileController extends Controller {
appointDate: profiles?.dateAppoint appointDate: profiles?.dateAppoint
? Extension.ToThaiNumber(Extension.ToThaiFullDate2(profiles.dateAppoint)) ? Extension.ToThaiNumber(Extension.ToThaiFullDate2(profiles.dateAppoint))
: "", : "",
positionDate: positionList.length > 0
? positionList[positionList.length-1].commandDateAffect
: "",
citizenId: citizenId:
profiles.citizenId != null ? Extension.ToThaiNumber(profiles.citizenId.toString()) : "", profiles.citizenId != null ? Extension.ToThaiNumber(profiles.citizenId.toString()) : "",
fatherFullName: fatherFullName: