diff --git a/src/controllers/ProfileController.ts b/src/controllers/ProfileController.ts index f556adb4..6cfa91d1 100644 --- a/src/controllers/ProfileController.ts +++ b/src/controllers/ProfileController.ts @@ -437,219 +437,124 @@ export class ProfileController extends Controller { const _child3 = child3 ? `${child3.orgChild3Name}/` : ""; const _child4 = child4 ? `${child4.orgChild4Name}/` : ""; - const Profile = { - CitizenId: - profiles.citizenId != null ? Extension.ToThaiNumber(profiles.citizenId.toString()) : "", - 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 - ? Extension.ToThaiNumber(new Date(profiles.birthDate).getDate().toString()) - : null, - BirthDayText: - profiles.birthDate != null - ? Extension.ToThaiNumber(Extension.ToThaiFullDate2(profiles.birthDate).toString()) - : "", - BirthMonth: profiles?.birthDate - ? Extension.ToThaiNumber(new Date(profiles.birthDate).getMonth() + (1).toString()) - : null, // Months are zero-based - BirthYear: profiles?.birthDate - ? Extension.ToThaiNumber(new Date(profiles.birthDate).getFullYear().toString()) - : null, - BirthYearText: - profiles.birthDate != null - ? Extension.ToThaiNumber(Extension.ToThaiFullDate2(profiles.birthDate).toString()) - : "", - Address: "", - District: "", - Area: "", - Province: "", - Telephone: - profiles.telephoneNumber != null ? Extension.ToThaiNumber(profiles.telephoneNumber) : "", - CoupleLastNameOld: profileFamilyCouple?.coupleLastNameOld ?? null, - CouplePrefix: profileFamilyCouple?.couplePrefix ?? "", - CoupleFullName: - profileFamilyCouple?.couplePrefix || - profileFamilyCouple?.coupleFirstName || - profileFamilyCouple?.coupleLastNameOld - ? `${profileFamilyCouple?.couplePrefix ?? ""}${profileFamilyCouple?.coupleFirstName ?? ""} ${profileFamilyCouple?.coupleLastName ?? ""}`.trim() - : null, - FatherPrefix: profileFamilyFather?.fatherPrefix ?? "", - FatherFullName: - profileFamilyFather?.fatherPrefix || - profileFamilyFather?.fatherFirstName || - profileFamilyFather?.fatherLastName - ? `${profileFamilyFather?.fatherPrefix ?? ""}${profileFamilyFather?.fatherFirstName ?? ""} ${profileFamilyFather?.fatherLastName ?? ""}`.trim() - : null, - MotherPrefix: profileFamilyMother?.motherPrefix ?? "", - 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 - ? Extension.ToThaiNumber(Extension.ToThaiFullDate2(profiles.dateStart)) - : "", - AppointDate: profiles?.dateAppoint - ? Extension.ToThaiNumber(Extension.ToThaiFullDate2(profiles.dateAppoint)) - : "", - BirthDate: profiles?.birthDate - ? Extension.ToThaiNumber(Extension.ToThaiFullDate2(profiles.birthDate)) - : "", - RetireDate: - profiles.dateRetireLaw != null - ? Extension.ToThaiNumber(Extension.ToThaiFullDate2(profiles.dateRetireLaw)) - : "", - CurrentAddress: - profiles.currentAddress != null ? Extension.ToThaiNumber(profiles.currentAddress) : "", - CurrentSubDistrict: - profiles.currentSubDistrict != null - ? Extension.ToThaiNumber(profiles.currentSubDistrict.name) - : "", - CurrentDistrict: - profiles.currentDistrict != null - ? Extension.ToThaiNumber(profiles.currentDistrict.name) - : "", - CurrentProvince: - profiles.currentProvince != null - ? Extension.ToThaiNumber(profiles.currentProvince.name) - : "", - // AvatarId: profiles?.avatar ?? null, - ImgUrl: ImgUrl - ? ImgUrl - : `https://bma-ehr.frappet.synology.me/assets/avatar_user-89f22423.jpg`, - ImgUrl1: _ImgUrl[0] ? _ImgUrl[0] : null, - ImgUrl2: _ImgUrl[1] ? _ImgUrl[1] : null, - ImgUrl3: _ImgUrl[2] ? _ImgUrl[2] : null, - ImgUrl4: _ImgUrl[3] ? _ImgUrl[3] : null, - ImgUrl5: _ImgUrl[4] ? _ImgUrl[4] : null, - ImgUrl6: _ImgUrl[5] ? _ImgUrl[5] : null, - ImgUrl7: _ImgUrl[6] ? _ImgUrl[6] : null, - }; - - const certs = await this.certificateRepository.find({ + const cert_raw = await this.certificateRepository.find({ where: { profileId: id }, select: ["certificateType", "issuer", "certificateNo", "issueDate"], order: { createdAt: "ASC" }, }); - const Cert = - certs.length > 0 - ? certs.slice(-3).map((item) => ({ - CertificateType: item.certificateType ?? null, - Issuer: item.issuer ?? null, - CertificateNo: Extension.ToThaiNumber(item.certificateNo) ?? null, - IssueDate: Extension.ToThaiNumber(Extension.ToThaiFullDate2(item.issueDate)) ?? null, + const certs = + cert_raw.length > 0 + ? cert_raw.slice(-2).map((item) => ({ + certificateType: item.certificateType ?? null, + issuer: item.issuer ?? null, + certificateNo: Extension.ToThaiNumber(item.certificateNo) ?? null, + issueDate: Extension.ToThaiNumber(Extension.ToThaiFullDate2(item.issueDate)) ?? null, })) : [ { - CertificateType: "-", - Issuer: "-", - CertificateNo: "-", - IssueDate: "-", + certificateType: "-", + issuer: "-", + certificateNo: "-", + issueDate: "-", }, ]; - const trainings = await this.trainingRepository.find({ + const training_raw = await this.trainingRepository.find({ select: ["startDate", "endDate", "place", "department", "name"], where: { profileId: id }, order: { createdAt: "ASC" }, }); - const Training = - trainings.length > 0 - ? trainings.slice(-3).map((item) => ({ - Institute: item.department ?? "", - Start: + const trainings = + training_raw.length > 0 + ? training_raw.slice(-2).map((item) => ({ + institute: item.department ?? "", + start: item.startDate == null ? "" : Extension.ToThaiNumber(Extension.ToThaiFullDate2(item.startDate)), - End: + end: item.endDate == null ? "" : Extension.ToThaiNumber(Extension.ToThaiFullDate2(item.endDate)), - Date: + date: item.startDate && item.endDate ? `${Extension.ToThaiNumber(Extension.ToThaiFullDate2(item.startDate))} - ${Extension.ToThaiNumber(Extension.ToThaiFullDate2(item.endDate))}` : "", - Level: "", - Degree: item.name, - Field: "", + level: "", + degree: item.name, + field: "", })) : [ { - Institute: "-", - Start: "-", - End: "-", - Date: "-", - Level: "-", - Degree: "-", - Field: "-", + institute: "-", + start: "-", + end: "-", + date: "-", + level: "-", + degree: "-", + field: "-", }, ]; - const disciplines = await this.disciplineRepository.find({ + const discipline_raw = await this.disciplineRepository.find({ select: ["refCommandDate", "refCommandNo", "detail"], where: { profileId: id }, order: { createdAt: "ASC" }, }); - const Discipline = - disciplines.length > 0 - ? disciplines.slice(-3).map((item) => ({ - DisciplineYear: + const disciplines = + discipline_raw.length > 0 + ? discipline_raw.slice(-2).map((item) => ({ + disciplineYear: Extension.ToThaiNumber(new Date(item.refCommandDate).getFullYear().toString()) ?? null, - DisciplineDetail: item.detail ?? null, - RefNo: Extension.ToThaiNumber(item.refCommandNo) ?? null, + disciplineDetail: item.detail ?? null, + refNo: Extension.ToThaiNumber(item.refCommandNo) ?? null, })) : [ { - DisciplineYear: "-", - DisciplineDetail: "-", - RefNo: "-", + disciplineYear: "-", + disciplineDetail: "-", + refNo: "-", }, ]; - const educations = await this.educationRepository.find({ + const education_raw = await this.educationRepository.find({ select: ["startDate", "endDate", "educationLevel", "degree", "field", "institute"], where: { profileId: id }, // order: { lastUpdatedAt: "DESC" }, order: { createdAt: "ASC" }, }); - const Education = - educations.length > 0 - ? educations.slice(-3).map((item) => ({ - Institute: item.institute, - Start: + const educations = + education_raw.length > 0 + ? education_raw.slice(-2).map((item) => ({ + institute: item.institute, + start: item.startDate == null ? "" : Extension.ToThaiNumber(new Date(item.startDate).getFullYear().toString()), - End: + end: item.endDate == null ? "" : Extension.ToThaiNumber(new Date(item.endDate).getFullYear().toString()), - Date: + date: item.startDate && item.endDate ? `${Extension.ToThaiNumber(Extension.ToThaiFullDate2(item.startDate))} - ${Extension.ToThaiNumber(Extension.ToThaiFullDate2(item.endDate))}` : "", - Level: item.educationLevel ?? "", - Degree: item.degree ? `${item.degree} ${item.field ? item.field : ""}` : "", - Field: item.field ?? "-", + level: item.educationLevel ?? "", + degree: item.degree ? `${item.degree} ${item.field ? item.field : ""}` : "", + field: item.field ?? "-", })) : [ { - Institute: "-", - Start: "-", - End: "-", - Date: "-", - Level: "-", - Degree: "-", - Field: "-", + institute: "-", + start: "-", + end: "-", + date: "-", + level: "-", + degree: "-", + field: "-", }, ]; - const salarys = await this.salaryRepository.find({ + const salary_raw = await this.salaryRepository.find({ select: [ "date", "position", @@ -665,45 +570,45 @@ export class ProfileController extends Controller { order: { order: "ASC" }, }); - const Salary = - salarys.length > 0 - ? salarys.map((item) => ({ - SalaryDate: item.date + const salarys = + salary_raw.length > 0 + ? salary_raw.map((item) => ({ + salaryDate: item.date ? Extension.ToThaiNumber(Extension.ToThaiFullDate2(item.date)) : null, - Position: item.position != null ? Extension.ToThaiNumber(item.position) : null, - PosNo: item.posNo != null ? Extension.ToThaiNumber(item.posNo) : null, - Salary: + position: item.position != null ? Extension.ToThaiNumber(item.position) : null, + posNo: item.posNo != null ? Extension.ToThaiNumber(item.posNo) : null, + salary: item.amount != null ? Extension.ToThaiNumber(item.amount.toLocaleString()) : null, - Rank: item.positionLevel != null ? Extension.ToThaiNumber(item.positionLevel) : null, - RefAll: item.templateDoc ? Extension.ToThaiNumber(item.templateDoc) : null, - PositionLevel: + rank: item.positionLevel != null ? Extension.ToThaiNumber(item.positionLevel) : null, + refAll: item.templateDoc ? Extension.ToThaiNumber(item.templateDoc) : null, + positionLevel: item.positionLevel != null ? Extension.ToThaiNumber(item.positionLevel) : null, - PositionType: item.positionType ?? null, - PositionAmount: + positionType: item.positionType ?? null, + positionAmount: item.positionSalaryAmount == null ? null : Extension.ToThaiNumber(item.positionSalaryAmount.toLocaleString()), - FullName: `${profiles?.prefix}${profiles?.firstName} ${profiles?.lastName}`, - OcFullPath: `${_child4}${_child3}${_child2}${_child1}${_root}`, + fullName: `${profiles?.prefix}${profiles?.firstName} ${profiles?.lastName}`, + ocFullPath: `${_child4}${_child3}${_child2}${_child1}${_root}`, })) : [ { - SalaryDate: "-", - Position: "-", - PosNo: "-", - Salary: "-", - Rank: "-", - RefAll: "-", - PositionLevel: "-", - PositionType: "-", - PositionAmount: "-", - FullName: "-", - OcFullPath: "-", + salaryDate: "-", + position: "-", + posNo: "-", + salary: "-", + rank: "-", + refAll: "-", + positionLevel: "-", + positionType: "-", + positionAmount: "-", + fullName: "-", + ocFullPath: "-", }, ]; - const insignias = await this.profileInsigniaRepo.find({ + const insignia_raw = await this.profileInsigniaRepo.find({ relations: { insignia: { insigniaType: true, @@ -712,82 +617,172 @@ export class ProfileController extends Controller { where: { profileId: id }, order: { receiveDate: "ASC" }, }); - const Insignia = - insignias.length > 0 - ? insignias.map((item) => ({ - ReceiveDate: item.receiveDate + const insignias = + insignia_raw.length > 0 + ? insignia_raw.map((item) => ({ + receiveDate: item.receiveDate ? Extension.ToThaiNumber(Extension.ToThaiFullDate2(item.receiveDate)) : "", - InsigniaName: item.insignia.name, - InsigniaShortName: item.insignia.shortName, - InsigniaTypeName: item.insignia.insigniaType.name, - No: item.no ? Extension.ToThaiNumber(item.no) : "", - Issue: item.issue ? item.issue : "", - VolumeNo: item.volumeNo ? Extension.ToThaiNumber(item.volumeNo) : "", - Volume: item.volume ? Extension.ToThaiNumber(item.volume) : "", - Section: item.section ? Extension.ToThaiNumber(item.section) : "", - Page: item.page ? Extension.ToThaiNumber(item.page) : "", - RefCommandDate: item.refCommandDate + insigniaName: item.insignia.name, + insigniaShortName: item.insignia.shortName, + insigniaTypeName: item.insignia.insigniaType.name, + no: item.no ? Extension.ToThaiNumber(item.no) : "", + issue: item.issue ? item.issue : "", + volumeNo: item.volumeNo ? Extension.ToThaiNumber(item.volumeNo) : "", + volume: item.volume ? Extension.ToThaiNumber(item.volume) : "", + section: item.section ? Extension.ToThaiNumber(item.section) : "", + page: item.page ? Extension.ToThaiNumber(item.page) : "", + refCommandDate: item.refCommandDate ? Extension.ToThaiNumber(Extension.ToThaiFullDate2(item.refCommandDate)) : "", })) : [ { - ReceiveDate: "-", - InsigniaName: "-", - InsigniaShortName: "-", - InsigniaTypeName: "-", - No: "-", - Issue: "-", - VolumeNo: "-", - Volume: "-", - Section: "-", - Page: "-", - RefCommandDate: "-", + receiveDate: "-", + insigniaName: "-", + insigniaShortName: "-", + insigniaTypeName: "-", + no: "-", + issue: "-", + volumeNo: "-", + volume: "-", + section: "-", + page: "-", + refCommandDate: "-", }, ]; - const leaves = await this.profileLeaveRepository.find({ + const leave_raw = await this.profileLeaveRepository.find({ relations: { leaveType: true }, where: { profileId: id }, order: { dateLeaveStart: "ASC" }, }); - const Leave = - leaves.length > 0 - ? leaves.map((item) => ({ - LeaveTypeName: item.leaveType.name, - DateLeaveStart: item.dateLeaveStart + const leaves = + leave_raw.length > 0 + ? leave_raw.map((item) => ({ + leaveTypeName: item.leaveType.name, + dateLeaveStart: item.dateLeaveStart ? Extension.ToThaiNumber(Extension.ToThaiFullDate2(item.dateLeaveStart)) : "", - LeaveDays: item.leaveDays ? Extension.ToThaiNumber(item.leaveDays.toString()) : "", + leaveDays: item.leaveDays ? Extension.ToThaiNumber(item.leaveDays.toString()) : "", })) : [ { - LeaveTypeName: "-", - DateLeaveStart: "-", - LeaveDays: "-", + leaveTypeName: "-", + dateLeaveStart: "-", + leaveDays: "-", }, ]; - // const data = { - // FullName: , - // }; + const data = { + fullName: `${profiles?.prefix}${profiles?.firstName} ${profiles?.lastName}`, + prefix: profiles?.prefix != null ? profiles.prefix : "", + firstName: profiles?.firstName != null ? profiles.firstName : "", + lastName: profiles?.lastName != null ? profiles.lastName : "", + ocFullPath: `${_child4}${_child3}${_child2}${_child1}${_root}`, + birthDate: profiles?.birthDate + ? Extension.ToThaiNumber(Extension.ToThaiFullDate2(profiles.birthDate)) + : "", + retireDate: + profiles.dateRetireLaw != null + ? Extension.ToThaiNumber(Extension.ToThaiFullDate2(profiles.dateRetireLaw)) + : "", + appointDate: profiles?.dateAppoint + ? Extension.ToThaiNumber(Extension.ToThaiFullDate2(profiles.dateAppoint)) + : "", + citizenId: + profiles.citizenId != null ? Extension.ToThaiNumber(profiles.citizenId.toString()) : "", + fatherFullName: + profileFamilyFather?.fatherPrefix || + profileFamilyFather?.fatherFirstName || + profileFamilyFather?.fatherLastName + ? `${profileFamilyFather?.fatherPrefix ?? ""}${profileFamilyFather?.fatherFirstName ?? ""} ${profileFamilyFather?.fatherLastName ?? ""}`.trim() + : null, + motherFullName: + profileFamilyMother?.motherPrefix || + profileFamilyMother?.motherFirstName || + profileFamilyMother?.motherLastName + ? `${profileFamilyMother?.motherPrefix ?? ""}${profileFamilyMother?.motherFirstName ?? ""} ${profileFamilyMother?.motherLastName ?? ""}`.trim() + : null, + coupleFullName: + profileFamilyCouple?.couplePrefix || + profileFamilyCouple?.coupleFirstName || + profileFamilyCouple?.coupleLastNameOld + ? `${profileFamilyCouple?.couplePrefix ?? ""}${profileFamilyCouple?.coupleFirstName ?? ""} ${profileFamilyCouple?.coupleLastName ?? ""}`.trim() + : null, + coupleLastNameOld: profileFamilyCouple?.coupleLastNameOld ?? null, + currentAddress: + profiles.currentAddress != null ? Extension.ToThaiNumber(profiles.currentAddress) : "", + currentSubDistrict: + profiles.currentSubDistrict != null + ? Extension.ToThaiNumber(profiles.currentSubDistrict.name) + : "", + currentDistrict: + profiles.currentDistrict != null + ? Extension.ToThaiNumber(profiles.currentDistrict.name) + : "", + currentProvince: + profiles.currentProvince != null + ? Extension.ToThaiNumber(profiles.currentProvince.name) + : "", + telephone: + profiles.telephoneNumber != null ? Extension.ToThaiNumber(profiles.telephoneNumber) : "", + url: ImgUrl + ? ImgUrl + : `https://bma-ehr.frappet.synology.me/assets/avatar_user-89f22423.jpg`, + url1: _ImgUrl[0] ? _ImgUrl[0] : null, + url2: _ImgUrl[1] ? _ImgUrl[1] : null, + url3: _ImgUrl[2] ? _ImgUrl[2] : null, + url4: _ImgUrl[3] ? _ImgUrl[3] : null, + url5: _ImgUrl[4] ? _ImgUrl[4] : null, + url6: _ImgUrl[5] ? _ImgUrl[5] : null, + url7: _ImgUrl[6] ? _ImgUrl[6] : null, + + // BirthDay: profiles?.birthDate + // ? Extension.ToThaiNumber(new Date(profiles.birthDate).getDate().toString()) + // : null, + // BirthDayText: + // profiles.birthDate != null + // ? Extension.ToThaiNumber(Extension.ToThaiFullDate2(profiles.birthDate).toString()) + // : "", + // BirthMonth: profiles?.birthDate + // ? Extension.ToThaiNumber(new Date(profiles.birthDate).getMonth() + (1).toString()) + // : null, // Months are zero-based + // BirthYear: profiles?.birthDate + // ? Extension.ToThaiNumber(new Date(profiles.birthDate).getFullYear().toString()) + // : null, + // BirthYearText: + // profiles.birthDate != null + // ? Extension.ToThaiNumber(Extension.ToThaiFullDate2(profiles.birthDate).toString()) + // : "", + // Address: "", + // District: "", + // Area: "", + // Province: "", + // CouplePrefix: profileFamilyCouple?.couplePrefix ?? "", + // FatherPrefix: profileFamilyFather?.fatherPrefix ?? "", + // MotherPrefix: profileFamilyMother?.motherPrefix ?? "", + // Division: "", + // Institute: "", + // StartDate: profiles?.dateStart + // ? Extension.ToThaiNumber(Extension.ToThaiFullDate2(profiles.dateStart)) + // : "", + // AvatarId: profiles?.avatar ?? null, + + insignias, + leaves, + certs, + trainings, + disciplines, + educations, + salarys, + }; return new HttpSuccess({ - Profile: [Profile], - Cert, - Training, - Discipline, - Education, - Salary, - Insignia, - Leave, + template: "kk1", + reportName: "docx-report", + data: data, }); - // return new HttpSuccess({ - // template: "kk1", - // reportName: "docx-report", - // data: data, - // }); } /** *