insert profileSalary เดิมเข้ามายัง profile ใหม่ #232
All checks were successful
Build & Deploy on Dev / build (push) Successful in 1m8s

This commit is contained in:
harid 2026-04-28 15:17:16 +07:00
parent d82cd842f6
commit 58afa49fcd

View file

@ -6510,6 +6510,7 @@ export class CommandController extends Controller {
relations: ["roleKeycloaks", "profileInsignias", "profileAvatars"],
});
let _oldInsigniaIds: string[] = [];
let _oldSalaries: any[] = [];
//ลูกจ้างประจำ หรือ บุคคลภายนอก
if (!profile) {
//กรณีลูกจ้างประจำมาสอบเป็นข้าราชการ ต้อง update สถานะโปรไฟล์เดิม
@ -6618,6 +6619,11 @@ export class CommandController extends Controller {
profile.isLeave &&
["PLACEMENT_TRANSFER", "RETIRE_RESIGN"].includes(profile.leaveType)
) {
//ดึง profileSalary เดิม
_oldSalaries = await this.salaryRepo.find({
where: { profileId: profile.id },
order: { order: "ASC" },
});
if (profile.profileInsignias.length > 0) {
_oldInsigniaIds = profile.profileInsignias?.map((x: any) => x.id) ?? [];
}
@ -6856,6 +6862,23 @@ export class CommandController extends Controller {
await this.profileFamilyMotherHistoryRepo.save(motherHistory, { data: req });
}
//Salary
//insert profileSalary อันเก่า กรณีพ้นราชการแล้วกลับมาบรรจุ
if (_oldSalaries.length > 0) {
await Promise.all(
_oldSalaries.map(async (oldSal) => {
const profileSal: any = new ProfileSalary();
Object.assign(profileSal, { ...oldSal, ...meta });
const salaryHistory = new ProfileSalaryHistory();
Object.assign(salaryHistory, { ...profileSal, id: undefined });
profileSal.profileId = profile.id;
await this.salaryRepo.save(profileSal, { data: req });
setLogDataDiff(req, { before, after: profileSal });
salaryHistory.profileSalaryId = profileSal.id;
await this.salaryHistoryRepo.save(salaryHistory, { data: req });
}),
);
}
//insert item.bodySalarys ต่อจากที่ insert เดิมไปแล้ว
if (item.bodySalarys && item.bodySalarys != null) {
const dest_item = await this.salaryRepo.findOne({
where: { profileId: profile.id },