history update position

This commit is contained in:
mamoss 2025-08-26 13:47:43 +07:00
parent 0df264e900
commit 910e568973
10 changed files with 625 additions and 16 deletions

View file

@ -38,6 +38,11 @@ import { AuthRole } from "../entities/AuthRole";
import { RequestWithUser } from "../middlewares/user";
import permission from "../interfaces/permission";
import { setLogDataDiff } from "../interfaces/utils";
import {
CreatePosMasterHistoryOfficer,
CreatePosMasterHistoryEmployee,
} from "../services/PositionService";
import { PosMasterEmployeeHistory } from "../entities/PosMasterEmployeeHistory";
@Route("api/v1/org/employee/pos")
@Tags("Employee")
@Security("bearerAuth")
@ -50,6 +55,7 @@ export class EmployeePositionController extends Controller {
private employeePosTypeRepository = AppDataSource.getRepository(EmployeePosType);
private employeePosLevelRepository = AppDataSource.getRepository(EmployeePosLevel);
private employeePosMasterRepository = AppDataSource.getRepository(EmployeePosMaster);
private posMasterHistoryRepository = AppDataSource.getRepository(PosMasterEmployeeHistory);
private employeePositionRepository = AppDataSource.getRepository(EmployeePosition);
private profileRepository = AppDataSource.getRepository(ProfileEmployee);
private orgRevisionRepository = AppDataSource.getRepository(OrgRevision);
@ -2265,6 +2271,7 @@ export class EmployeePositionController extends Controller {
dataMaster.lastUpdatedAt = new Date();
// dataMaster.next_holderId = requestBody.profileId;
await this.employeePosMasterRepository.save(dataMaster);
await CreatePosMasterHistoryEmployee(dataMaster.id, request);
return new HttpSuccess();
}
@ -2439,8 +2446,12 @@ export class EmployeePositionController extends Controller {
posMaster.current_holderId = body.profileId;
posMaster.lastUpdatedAt = new Date();
// posMaster.next_holderId = body.profileId;
if (posMasterOld != null) await this.employeePosMasterRepository.save(posMasterOld);
if (posMasterOld != null) {
await this.employeePosMasterRepository.save(posMasterOld);
await CreatePosMasterHistoryEmployee(posMasterOld.id, request);
}
await this.employeePosMasterRepository.save(posMaster);
await CreatePosMasterHistoryEmployee(posMaster.id, request);
const positionNew = await this.employeePositionRepository.findOne({
where: {
@ -2463,4 +2474,19 @@ export class EmployeePositionController extends Controller {
}
return new HttpSuccess();
}
/**
* API
*
* @summary (ADMIN)
*
*/
@Get("history-update/{id}")
async listPosMasterHistory(@Path() id: string, @Request() request: RequestWithUser) {
const posMasterHistory = await this.posMasterHistoryRepository.find({
where: { ancestorDNA: id },
});
return new HttpSuccess(posMasterHistory);
}
}