ปั๊มประวัติคนครองกรณีมีแก้ไขชื่อและนามสกุล #244
All checks were successful
Build & Deploy on Dev / build (push) Successful in 58s

This commit is contained in:
harid 2026-05-27 16:41:56 +07:00
parent a678f95075
commit 7d463806a9
3 changed files with 66 additions and 0 deletions

View file

@ -25,6 +25,7 @@ import {
} from "../entities/ProfileChangeName";
import { updateName } from "../keycloak";
import permission from "../interfaces/permission";
import { updateHolderProfileHistory } from "../services/PositionService";
import { setLogDataDiff } from "../interfaces/utils";
@Route("api/v1/org/profile/changeName")
@Tags("ProfileChangeName")
@ -127,6 +128,9 @@ export class ProfileChangeNameController extends Controller {
}
}
// บันทึกประวัติคนครองตำแหน่ง (ถ้า profile นี้ครองตำแหน่งอยู่)
await updateHolderProfileHistory(profile.id, req);
return new HttpSuccess(data.id);
}

View file

@ -24,6 +24,7 @@ import {
} from "../entities/ProfileChangeName";
import { ProfileEmployee } from "../entities/ProfileEmployee";
import permission from "../interfaces/permission";
import { updateHolderProfileHistory } from "../services/PositionService";
import { updateName } from "../keycloak";
import { setLogDataDiff } from "../interfaces/utils";
@Route("api/v1/org/profile-employee/changeName")
@ -133,6 +134,9 @@ export class ProfileChangeNameEmployeeController extends Controller {
}
}
// บันทึกประวัติคนครองตำแหน่ง (ถ้า profile นี้ครองตำแหน่งอยู่)
await updateHolderProfileHistory(profile.id, req, "EMPLOYEE");
return new HttpSuccess(data.id);
}

View file

@ -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;
}
}