Merge branch 'develop' into adiDev

This commit is contained in:
adisak 2025-08-26 16:10:15 +07:00
commit 6936846a41
10 changed files with 628 additions and 16 deletions

View file

@ -59,7 +59,6 @@ import {
createUser,
getRoles,
deleteUser,
enableStatus,
getUserByUsername,
getRoleMappings,
removeUserRoles,
@ -92,6 +91,10 @@ import { ProfileInsignia, CreateProfileInsignia } from "../entities/ProfileInsig
import { ProfileInsigniaHistory } from "../entities/ProfileInsigniaHistory";
import { Gender } from "../entities/Gender";
import { ProfileAvatar } from "../entities/ProfileAvatar";
import {
CreatePosMasterHistoryEmployee,
CreatePosMasterHistoryOfficer,
} from "../services/PositionService";
@Route("api/v1/org/command")
@Tags("Command")
@Security("bearerAuth")
@ -3154,8 +3157,12 @@ export class CommandController extends Controller {
posMaster.lastUpdatedAt = new Date();
posMaster.conditionReason = _null;
posMaster.isCondition = false;
if (posMasterOld != null) await this.posMasterRepository.save(posMasterOld);
if (posMasterOld != null) {
await this.posMasterRepository.save(posMasterOld);
await CreatePosMasterHistoryOfficer(posMasterOld.id, req);
}
await this.posMasterRepository.save(posMaster);
await CreatePosMasterHistoryOfficer(posMaster.id, req);
const positionNew = await this.positionRepository.findOne({
where: {
@ -3342,8 +3349,12 @@ export class CommandController extends Controller {
posMaster.current_holderId = item.profileId;
posMaster.lastUpdatedAt = new Date();
posMaster.next_holderId = null;
if (posMasterOld != null) await this.employeePosMasterRepository.save(posMasterOld);
if (posMasterOld != null) {
await this.employeePosMasterRepository.save(posMasterOld);
await CreatePosMasterHistoryEmployee(posMasterOld.id, req);
}
await this.employeePosMasterRepository.save(posMaster);
await CreatePosMasterHistoryEmployee(posMaster.id, req);
const positionNew = await this.employeePositionRepository.findOne({
where: {
@ -3573,6 +3584,7 @@ export class CommandController extends Controller {
posMaster.conditionReason = _null;
posMaster.isCondition = false;
await this.posMasterRepository.save(posMaster);
await CreatePosMasterHistoryOfficer(posMaster.id, req);
const positionNew = await this.positionRepository.findOne({
where: {
posMasterId: posMaster.id,
@ -6030,8 +6042,12 @@ export class CommandController extends Controller {
posMaster.lastUpdatedAt = new Date();
posMaster.conditionReason = _null;
posMaster.isCondition = false;
if (posMasterOld != null) await this.posMasterRepository.save(posMasterOld);
if (posMasterOld != null) {
await this.posMasterRepository.save(posMasterOld);
await CreatePosMasterHistoryOfficer(posMasterOld.id, req);
}
await this.posMasterRepository.save(posMaster);
await CreatePosMasterHistoryOfficer(posMaster.id, req);
const positionNew = await this.positionRepository.findOne({
where: {
@ -6411,8 +6427,12 @@ export class CommandController extends Controller {
posMaster.current_holderId = profile.id;
posMaster.lastUpdatedAt = new Date();
posMaster.next_holderId = null;
if (posMasterOld != null) await this.employeePosMasterRepository.save(posMasterOld);
if (posMasterOld != null) {
await this.employeePosMasterRepository.save(posMasterOld);
await CreatePosMasterHistoryEmployee(posMasterOld.id, req);
}
await this.employeePosMasterRepository.save(posMaster);
await CreatePosMasterHistoryEmployee(posMaster.id, req);
const clsTempPosmaster = await this.employeeTempPosMasterRepository.find({
where: {

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,20 @@ 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 },
order: { createdAt: "DESC" },
});
return new HttpSuccess(posMasterHistory);
}
}

View file

@ -41,6 +41,8 @@ import { AuthRole } from "../entities/AuthRole";
import { RequestWithUser } from "../middlewares/user";
import permission from "../interfaces/permission";
import { setLogDataDiff } from "../interfaces/utils";
import { CreatePosMasterHistoryEmployeeTemp } from "../services/PositionService";
import { PosMasterEmployeeTempHistory } from "../entities/PosMasterEmployeeTempHistory";
@Route("api/v1/org/employee-temp/pos")
@Tags("Employee")
@Security("bearerAuth")
@ -53,6 +55,7 @@ export class EmployeeTempPositionController extends Controller {
private employeePosTypeRepository = AppDataSource.getRepository(EmployeePosType);
private employeePosLevelRepository = AppDataSource.getRepository(EmployeePosLevel);
private employeeTempPosMasterRepository = AppDataSource.getRepository(EmployeeTempPosMaster);
private posMasterHistoryRepository = AppDataSource.getRepository(PosMasterEmployeeTempHistory);
private employeePositionRepository = AppDataSource.getRepository(EmployeePosition);
private profileRepository = AppDataSource.getRepository(ProfileEmployee);
private orgRevisionRepository = AppDataSource.getRepository(OrgRevision);
@ -2004,6 +2007,7 @@ export class EmployeeTempPositionController extends Controller {
dataMaster.lastUpdatedAt = new Date();
// dataMaster.next_holderId = requestBody.profileId;
await this.employeeTempPosMasterRepository.save(dataMaster);
await CreatePosMasterHistoryEmployeeTemp(dataMaster.id, request);
return new HttpSuccess();
}
@ -2178,8 +2182,12 @@ export class EmployeeTempPositionController extends Controller {
posMaster.current_holderId = body.profileId;
posMaster.lastUpdatedAt = new Date();
// posMaster.next_holderId = body.profileId;
if (posMasterOld != null) await this.employeeTempPosMasterRepository.save(posMasterOld);
if (posMasterOld != null) {
await this.employeeTempPosMasterRepository.save(posMasterOld);
await CreatePosMasterHistoryEmployeeTemp(posMasterOld.id, request);
}
await this.employeeTempPosMasterRepository.save(posMaster);
await CreatePosMasterHistoryEmployeeTemp(posMaster.id, request);
const positionNew = await this.employeePositionRepository.findOne({
where: {
@ -2202,4 +2210,20 @@ export class EmployeeTempPositionController 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 },
order: { createdAt: "DESC" },
});
return new HttpSuccess(posMasterHistory);
}
}

View file

@ -42,6 +42,8 @@ import { setLogDataDiff } from "../interfaces/utils";
import { PosMasterAssign } from "../entities/PosMasterAssign";
import { Assign } from "../entities/Assign";
import { ProfileEmployee } from "../entities/ProfileEmployee";
import { PosMasterHistory } from "../entities/PosMasterHistory";
import { CreatePosMasterHistoryOfficer } from "../services/PositionService";
@Route("api/v1/org/pos")
@Tags("Position")
@Security("bearerAuth")
@ -57,6 +59,7 @@ export class PositionController extends Controller {
private posLevelEmployeeRepository = AppDataSource.getRepository(EmployeePosLevel);
private posDictRepository = AppDataSource.getRepository(PosDict);
private posMasterRepository = AppDataSource.getRepository(PosMaster);
private posMasterHistoryRepository = AppDataSource.getRepository(PosMasterHistory);
private employeePosMasterRepository = AppDataSource.getRepository(EmployeePosMaster);
private positionRepository = AppDataSource.getRepository(Position);
private profileRepository = AppDataSource.getRepository(Profile);
@ -1541,7 +1544,7 @@ export class PositionController extends Controller {
// posLevelRank: "ASC",
// },
orderNo: "ASC",
createdAt: "ASC"
createdAt: "ASC",
},
});
const formattedData = {
@ -2381,7 +2384,7 @@ export class PositionController extends Controller {
// posType: { posTypeRank: "ASC" },
// posLevel: { posLevelRank: "ASC" },
orderNo: "ASC",
createdAt: "ASC"
createdAt: "ASC",
},
});
@ -3654,6 +3657,7 @@ export class PositionController extends Controller {
dataMaster.current_holderId = _null;
}
await this.posMasterRepository.save(dataMaster, { data: request });
await CreatePosMasterHistoryOfficer(dataMaster.id, request);
setLogDataDiff(request, { before, after: dataMaster });
return new HttpSuccess();
@ -4826,6 +4830,7 @@ export class PositionController extends Controller {
positionId: string;
profileId: string;
},
@Request() request: RequestWithUser,
) {
const posMaster = await this.posMasterRepository.findOne({
where: { id: body.posmasterId },
@ -4879,8 +4884,12 @@ export class PositionController extends Controller {
const _null: any = null;
posMaster.conditionReason = _null;
posMaster.isCondition = false;
if (posMasterOld != null) await this.posMasterRepository.save(posMasterOld);
if (posMasterOld != null) {
await this.posMasterRepository.save(posMasterOld);
await CreatePosMasterHistoryOfficer(posMasterOld.id, request);
}
await this.posMasterRepository.save(posMaster);
await CreatePosMasterHistoryOfficer(posMaster.id, request);
const positionNew = await this.positionRepository.findOne({
where: {
@ -5432,7 +5441,6 @@ export class PositionController extends Controller {
posMaster.lastUpdatedAt = new Date();
posMaster.lastUpdateUserId = request.user.sub;
posMaster.lastUpdateFullName = request.user.name;
posMaster.lastUpdatedAt = new Date();
await this.posMasterRepository.save(posMaster);
return new HttpSuccess();
}
@ -5617,4 +5625,20 @@ export class PositionController 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 },
order: { createdAt: "DESC" },
});
return new HttpSuccess(posMasterHistory);
}
}