fix ระบบไม่ปั๊มประวัติข้อมูลเดิมให้ row แรก #2535
All checks were successful
Build & Deploy on Dev / build (push) Successful in 1m2s
All checks were successful
Build & Deploy on Dev / build (push) Successful in 1m2s
This commit is contained in:
parent
774a58bc22
commit
ad9a7dcbb6
4 changed files with 78 additions and 0 deletions
|
|
@ -2385,6 +2385,24 @@ export class ProfileEmployeeController extends Controller {
|
|||
Extension.CheckCitizen(body.citizenId);
|
||||
}
|
||||
const record = await this.profileRepo.findOneBy({ id });
|
||||
const before = structuredClone(record);
|
||||
// เช็คว่ามี profileHistory ของ profile นี้หรือไม่
|
||||
const historyCount = await this.profileHistoryRepo.count({
|
||||
where: { profileEmployeeId: id },
|
||||
});
|
||||
|
||||
// ถ้าไม่มีเลย ให้บันทึกข้อมูลเริ่มต้น (ก่อน update) ลงไปก่อน
|
||||
if (historyCount === 0) {
|
||||
await this.profileHistoryRepo.save(
|
||||
Object.assign(new ProfileEmployeeHistory(), {
|
||||
...before,
|
||||
birthDateOld: before?.birthDate,
|
||||
profileEmployeeId: id,
|
||||
id: undefined,
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลโปรไฟล์นี้");
|
||||
|
||||
if (body.employeeClass == null || body.employeeClass == undefined || body.employeeClass == "") {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue