ปั๊มประวัติคนครองกรณีมีแก้ไขชื่อและนามสกุล #244
All checks were successful
Build & Deploy on Dev / build (push) Successful in 58s
All checks were successful
Build & Deploy on Dev / build (push) Successful in 58s
This commit is contained in:
parent
a678f95075
commit
7d463806a9
3 changed files with 66 additions and 0 deletions
|
|
@ -501,3 +501,61 @@ export async function BatchSavePosMasterHistoryOfficer(
|
|||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* อัพเดทประวัติคนครองตำแหน่งเมื่อมีการเปลี่ยนแปลงข้อมูล profile
|
||||
* เช่น เปลี่ยนชื่อ - นามสกุล
|
||||
* ใช้สำหรับบันทึกประวัติเมื่อ profile ที่ครองตำแหน่งมีการเปลี่ยนแปลง
|
||||
*
|
||||
* @param profileId ID ของ profile ที่ต้องการตรวจสอบ
|
||||
* @param request RequestWithUser สำหรับบันทึกข้อมูลผู้ดำเนินการ
|
||||
* @param type "OFFICER" สำหรับข้าราชการ | "EMPLOYEE" สำหรับลูกจ้างประจำ (default: "OFFICER")
|
||||
*/
|
||||
export async function updateHolderProfileHistory(
|
||||
profileId: string,
|
||||
request: RequestWithUser,
|
||||
type: "OFFICER" | "EMPLOYEE" = "OFFICER",
|
||||
): Promise<void> {
|
||||
try {
|
||||
if (type === "OFFICER") {
|
||||
const posMasterRepo = AppDataSource.getRepository(PosMaster);
|
||||
const posMaster = await posMasterRepo.findOne({
|
||||
where: {
|
||||
current_holderId: profileId,
|
||||
orgRevision: {
|
||||
orgRevisionIsCurrent: true,
|
||||
orgRevisionIsDraft: false,
|
||||
}
|
||||
},
|
||||
relations: {
|
||||
orgRevision : true
|
||||
}
|
||||
});
|
||||
|
||||
if (posMaster) {
|
||||
await CreatePosMasterHistoryOfficer(posMaster.id, request);
|
||||
}
|
||||
} else if (type === "EMPLOYEE") {
|
||||
const empPosMasterRepo = AppDataSource.getRepository(EmployeePosMaster);
|
||||
const employeePosMaster = await empPosMasterRepo.findOne({
|
||||
where: {
|
||||
current_holderId: profileId,
|
||||
orgRevision: {
|
||||
orgRevisionIsCurrent: true,
|
||||
orgRevisionIsDraft: false,
|
||||
}
|
||||
},
|
||||
relations: {
|
||||
orgRevision : true
|
||||
}
|
||||
});
|
||||
|
||||
if (employeePosMaster) {
|
||||
await CreatePosMasterHistoryEmployee(employeePosMaster.id, request);
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("updateHolderProfileHistory error:", error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue