Merge branch 'develop'

This commit is contained in:
Warunee Tamkoo 2025-09-07 08:21:54 +07:00
commit 7d5872a5a4
8 changed files with 130 additions and 40 deletions

View file

@ -93,6 +93,7 @@ import { Gender } from "../entities/Gender";
import { ProfileAvatar } from "../entities/ProfileAvatar"; import { ProfileAvatar } from "../entities/ProfileAvatar";
import { import {
CreatePosMasterHistoryEmployee, CreatePosMasterHistoryEmployee,
CreatePosMasterHistoryEmployeeTemp,
CreatePosMasterHistoryOfficer, CreatePosMasterHistoryOfficer,
} from "../services/PositionService"; } from "../services/PositionService";
@Route("api/v1/org/command") @Route("api/v1/org/command")
@ -2175,8 +2176,7 @@ export class CommandController extends Controller {
command.isDraft = true; command.isDraft = true;
command.isSign = true; command.isSign = true;
command.status = "PENDING"; command.status = "PENDING";
} } else {
else {
command.status = "NEW"; command.status = "NEW";
} }
command.issue = commandType.name; command.issue = commandType.name;
@ -3171,7 +3171,6 @@ export class CommandController extends Controller {
await CreatePosMasterHistoryOfficer(posMasterOld.id, req); await CreatePosMasterHistoryOfficer(posMasterOld.id, req);
} }
await this.posMasterRepository.save(posMaster); await this.posMasterRepository.save(posMaster);
await CreatePosMasterHistoryOfficer(posMaster.id, req);
const positionNew = await this.positionRepository.findOne({ const positionNew = await this.positionRepository.findOne({
where: { where: {
@ -3189,6 +3188,7 @@ export class CommandController extends Controller {
await this.profileRepository.save(profile); await this.profileRepository.save(profile);
await this.positionRepository.save(positionNew); await this.positionRepository.save(positionNew);
} }
await CreatePosMasterHistoryOfficer(posMaster.id, req);
}), }),
); );
@ -3363,8 +3363,6 @@ export class CommandController extends Controller {
await CreatePosMasterHistoryEmployee(posMasterOld.id, req); await CreatePosMasterHistoryEmployee(posMasterOld.id, req);
} }
await this.employeePosMasterRepository.save(posMaster); await this.employeePosMasterRepository.save(posMaster);
await CreatePosMasterHistoryEmployee(posMaster.id, req);
const positionNew = await this.employeePositionRepository.findOne({ const positionNew = await this.employeePositionRepository.findOne({
where: { where: {
id: item.positionId, id: item.positionId,
@ -3383,6 +3381,7 @@ export class CommandController extends Controller {
await this.profileEmployeeRepository.save(profile); await this.profileEmployeeRepository.save(profile);
await this.employeePositionRepository.save(positionNew); await this.employeePositionRepository.save(positionNew);
} }
await CreatePosMasterHistoryEmployee(posMaster.id, req);
}), }),
); );
@ -3541,10 +3540,29 @@ export class CommandController extends Controller {
profile.lastUpdateUserId = req.user.sub; profile.lastUpdateUserId = req.user.sub;
profile.lastUpdateFullName = req.user.name; profile.lastUpdateFullName = req.user.name;
profile.lastUpdatedAt = new Date(); profile.lastUpdatedAt = new Date();
const clearProfile = await checkCommandType(String(item.commandId));
//ปั๊มประวัติก่อนลบตำแหน่ง
const curRevision = await this.orgRevisionRepo.findOne({
where: { orgRevisionIsCurrent: true, orgRevisionIsDraft: false }
})
if(curRevision){
const curPosMaster = await this.posMasterRepository.findOne({
where:{
current_holderId: profile.id,
orgRevisionId: curRevision.id
}
})
if (curPosMaster && clearProfile.LeaveType != "RETIRE_OUT_EMP") {
await CreatePosMasterHistoryOfficer(curPosMaster.id, req);
}
}
//ลบตำแหน่ง
if (item.isLeave == true) { if (item.isLeave == true) {
await removeProfileInOrganize(profile.id, "OFFICER"); await removeProfileInOrganize(profile.id, "OFFICER");
} }
const clearProfile = await checkCommandType(String(item.commandId));
if (clearProfile.status) { if (clearProfile.status) {
if (profile.keycloak != null) { if (profile.keycloak != null) {
const delUserKeycloak = await deleteUser(profile.keycloak); const delUserKeycloak = await deleteUser(profile.keycloak);
@ -3593,7 +3611,6 @@ export class CommandController extends Controller {
posMaster.conditionReason = _null; posMaster.conditionReason = _null;
posMaster.isCondition = false; posMaster.isCondition = false;
await this.posMasterRepository.save(posMaster); await this.posMasterRepository.save(posMaster);
await CreatePosMasterHistoryOfficer(posMaster.id, req);
const positionNew = await this.positionRepository.findOne({ const positionNew = await this.positionRepository.findOne({
where: { where: {
posMasterId: posMaster.id, posMasterId: posMaster.id,
@ -3603,6 +3620,7 @@ export class CommandController extends Controller {
positionNew.positionIsSelected = true; positionNew.positionIsSelected = true;
await this.positionRepository.save(positionNew, { data: req }); await this.positionRepository.save(positionNew, { data: req });
} }
await CreatePosMasterHistoryOfficer(posMaster.id, req);
} }
const newMapProfileSalary = { const newMapProfileSalary = {
profileId: profile.id, profileId: profile.id,
@ -6056,7 +6074,6 @@ export class CommandController extends Controller {
await CreatePosMasterHistoryOfficer(posMasterOld.id, req); await CreatePosMasterHistoryOfficer(posMasterOld.id, req);
} }
await this.posMasterRepository.save(posMaster); await this.posMasterRepository.save(posMaster);
await CreatePosMasterHistoryOfficer(posMaster.id, req);
const positionNew = await this.positionRepository.findOne({ const positionNew = await this.positionRepository.findOne({
where: { where: {
@ -6074,6 +6091,7 @@ export class CommandController extends Controller {
setLogDataDiff(req, { before, after: profile }); setLogDataDiff(req, { before, after: profile });
await this.positionRepository.save(positionNew, { data: req }); await this.positionRepository.save(positionNew, { data: req });
} }
await CreatePosMasterHistoryOfficer(posMaster.id, req);
} }
// Insignia // Insignia
if (_oldInsigniaIds.length > 0) { if (_oldInsigniaIds.length > 0) {
@ -6471,6 +6489,12 @@ export class CommandController extends Controller {
})); }));
await this.employeePositionRepository.save(clearTempPosition); await this.employeePositionRepository.save(clearTempPosition);
} }
await Promise.all(
clsTempPosmaster.map(
async (posMasterTemp) =>
await CreatePosMasterHistoryEmployeeTemp(posMasterTemp.id, req),
),
);
} }
const positionNew = await this.employeePositionRepository.findOne({ const positionNew = await this.employeePositionRepository.findOne({
@ -6570,6 +6594,7 @@ export class CommandController extends Controller {
}); });
await this.profileEmployeeRepository.save(profile); await this.profileEmployeeRepository.save(profile);
await this.employeePositionRepository.save(positionNew); await this.employeePositionRepository.save(positionNew);
await CreatePosMasterHistoryEmployee(posMaster.id, req);
//ลบออกคนออกจากโครงสร้างลูกจ้างชั่วคราว //ลบออกคนออกจากโครงสร้างลูกจ้างชั่วคราว
const posMasterTemp = await this.employeeTempPosMasterRepository.findOne({ const posMasterTemp = await this.employeeTempPosMasterRepository.findOne({
where: { where: {
@ -6581,6 +6606,7 @@ export class CommandController extends Controller {
await this.employeeTempPosMasterRepository.update(posMasterTemp.id, { await this.employeeTempPosMasterRepository.update(posMasterTemp.id, {
current_holderId: _null, current_holderId: _null,
}); });
await CreatePosMasterHistoryEmployeeTemp(posMasterTemp.id, req);
} }
} }
}), }),

View file

@ -45,13 +45,15 @@ export class DevelopmentRequestController extends Controller {
@Query("page") page: number = 1, @Query("page") page: number = 1,
@Query("pageSize") pageSize: number = 10, @Query("pageSize") pageSize: number = 10,
@Query("status") status?: string, @Query("status") status?: string,
@Query("sortBy") sortBy?: string,
@Query("descending") descending?: boolean,
) { ) {
const profile = await this.profileRepository.findOneBy({ keycloak: req.user.sub }); const profile = await this.profileRepository.findOneBy({ keycloak: req.user.sub });
if (!profile) { if (!profile) {
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
} }
const [lists, total] = await AppDataSource.getRepository(DevelopmentRequest) let query = await AppDataSource.getRepository(DevelopmentRequest)
.createQueryBuilder("developmentRequest") .createQueryBuilder("developmentRequest")
.andWhere( .andWhere(
status == undefined || status.trim().toUpperCase() == "ALL" || status == "" status == undefined || status.trim().toUpperCase() == "ALL" || status == ""
@ -103,6 +105,15 @@ export class DevelopmentRequestController extends Controller {
}), }),
) )
.orderBy("developmentRequest.createdAt", "DESC") .orderBy("developmentRequest.createdAt", "DESC")
if (sortBy) {
query = query.orderBy(
`developmentRequest.${sortBy}`,
descending ? "DESC" : "ASC"
);
}
const [lists, total] = await query
.skip((page - 1) * pageSize) .skip((page - 1) * pageSize)
.take(pageSize) .take(pageSize)
.getManyAndCount(); .getManyAndCount();

View file

@ -39,8 +39,8 @@ import { RequestWithUser } from "../middlewares/user";
import permission from "../interfaces/permission"; import permission from "../interfaces/permission";
import { setLogDataDiff } from "../interfaces/utils"; import { setLogDataDiff } from "../interfaces/utils";
import { import {
CreatePosMasterHistoryOfficer,
CreatePosMasterHistoryEmployee, CreatePosMasterHistoryEmployee,
CreatePosMasterHistoryOfficer,
} from "../services/PositionService"; } from "../services/PositionService";
import { PosMasterEmployeeHistory } from "../entities/PosMasterEmployeeHistory"; import { PosMasterEmployeeHistory } from "../entities/PosMasterEmployeeHistory";
@Route("api/v1/org/employee/pos") @Route("api/v1/org/employee/pos")
@ -2288,7 +2288,7 @@ export class EmployeePositionController extends Controller {
await new permission().PermissionDelete(request, "SYS_ORG_EMP"); await new permission().PermissionDelete(request, "SYS_ORG_EMP");
const dataMaster = await this.employeePosMasterRepository.findOne({ const dataMaster = await this.employeePosMasterRepository.findOne({
where: { id: id }, where: { id: id },
relations: ["positions"], relations: ["positions", "orgRevision"],
}); });
if (!dataMaster) { if (!dataMaster) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลตำแหน่งนี้"); throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลตำแหน่งนี้");
@ -2321,7 +2321,9 @@ export class EmployeePositionController extends Controller {
positionIsSelected: false, positionIsSelected: false,
}); });
}); });
if (dataMaster.orgRevision.orgRevisionIsCurrent) {
await CreatePosMasterHistoryEmployee(dataMaster.id, request);
}
return new HttpSuccess(); return new HttpSuccess();
} }
@ -2451,7 +2453,6 @@ export class EmployeePositionController extends Controller {
await CreatePosMasterHistoryEmployee(posMasterOld.id, request); await CreatePosMasterHistoryEmployee(posMasterOld.id, request);
} }
await this.employeePosMasterRepository.save(posMaster); await this.employeePosMasterRepository.save(posMaster);
await CreatePosMasterHistoryEmployee(posMaster.id, request);
const positionNew = await this.employeePositionRepository.findOne({ const positionNew = await this.employeePositionRepository.findOne({
where: { where: {
@ -2472,6 +2473,7 @@ export class EmployeePositionController extends Controller {
await this.profileRepository.save(profile); await this.profileRepository.save(profile);
await this.employeePositionRepository.save(positionNew); await this.employeePositionRepository.save(positionNew);
} }
await CreatePosMasterHistoryEmployee(posMaster.id, request);
return new HttpSuccess(); return new HttpSuccess();
} }

View file

@ -2024,7 +2024,7 @@ export class EmployeeTempPositionController extends Controller {
await new permission().PermissionDelete(request, "SYS_ORG_TEMP"); await new permission().PermissionDelete(request, "SYS_ORG_TEMP");
const dataMaster = await this.employeeTempPosMasterRepository.findOne({ const dataMaster = await this.employeeTempPosMasterRepository.findOne({
where: { id: id }, where: { id: id },
relations: ["positions"], relations: ["positions", "orgRevision"],
}); });
if (!dataMaster) { if (!dataMaster) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลตำแหน่งนี้"); throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลตำแหน่งนี้");
@ -2057,6 +2057,9 @@ export class EmployeeTempPositionController extends Controller {
positionIsSelected: false, positionIsSelected: false,
}); });
}); });
if (dataMaster.orgRevision.orgRevisionIsCurrent) {
await CreatePosMasterHistoryEmployeeTemp(dataMaster.id, request);
}
return new HttpSuccess(); return new HttpSuccess();
} }
@ -2187,7 +2190,6 @@ export class EmployeeTempPositionController extends Controller {
await CreatePosMasterHistoryEmployeeTemp(posMasterOld.id, request); await CreatePosMasterHistoryEmployeeTemp(posMasterOld.id, request);
} }
await this.employeeTempPosMasterRepository.save(posMaster); await this.employeeTempPosMasterRepository.save(posMaster);
await CreatePosMasterHistoryEmployeeTemp(posMaster.id, request);
const positionNew = await this.employeePositionRepository.findOne({ const positionNew = await this.employeePositionRepository.findOne({
where: { where: {
@ -2208,6 +2210,7 @@ export class EmployeeTempPositionController extends Controller {
await this.profileRepository.save(profile); await this.profileRepository.save(profile);
await this.employeePositionRepository.save(positionNew); await this.employeePositionRepository.save(positionNew);
} }
await CreatePosMasterHistoryEmployeeTemp(posMaster.id, request);
return new HttpSuccess(); return new HttpSuccess();
} }

View file

@ -4724,6 +4724,8 @@ export class OrganizationDotnetController extends Controller {
firstName: item.firstName, firstName: item.firstName,
lastName: item.lastName, lastName: item.lastName,
citizenId: item.citizenId, citizenId: item.citizenId,
dateStart: item.dateStart,
dateAppoint: item.dateAppoint,
keycloak: item.keycloak, keycloak: item.keycloak,
posNo: shortName, posNo: shortName,
position: item.position, position: item.position,
@ -5284,6 +5286,8 @@ export class OrganizationDotnetController extends Controller {
firstName: item.firstName, firstName: item.firstName,
lastName: item.lastName, lastName: item.lastName,
citizenId: item.citizenId, citizenId: item.citizenId,
dateStart: item.dateStart,
dateAppoint: item.dateAppoint,
keycloak: item.keycloak, keycloak: item.keycloak,
posNo: shortName, posNo: shortName,
position: item.position, position: item.position,

View file

@ -961,37 +961,42 @@ export class PositionController extends Controller {
if (!posMaster) { if (!posMaster) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล"); throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
} }
let orgRoot: any = null; let orgRoot: any = null;
let SName: any = null; let SName: any = null;
let revisionId:any = null;
if (requestBody.orgRootId != null) if (requestBody.orgRootId != null)
orgRoot = await this.orgRootRepository.findOne({ orgRoot = await this.orgRootRepository.findOne({
where: { id: requestBody.orgRootId }, where: { id: requestBody.orgRootId },
}); });
revisionId = orgRoot?.orgRevisionId;
if (!orgRoot) { if (!orgRoot) {
let orgChild1: any = null; let orgChild1: any = null;
if (requestBody.orgChild1Id != null) if (requestBody.orgChild1Id != null)
orgChild1 = await this.child1Repository.findOne({ orgChild1 = await this.child1Repository.findOne({
where: { id: requestBody.orgChild1Id }, where: { id: requestBody.orgChild1Id },
}); });
revisionId = orgChild1?.orgRevisionId;
if (!orgChild1) { if (!orgChild1) {
let orgChild2: any = null; let orgChild2: any = null;
if (requestBody.orgChild2Id != null) if (requestBody.orgChild2Id != null)
orgChild2 = await this.child2Repository.findOne({ orgChild2 = await this.child2Repository.findOne({
where: { id: requestBody.orgChild2Id }, where: { id: requestBody.orgChild2Id },
}); });
revisionId = orgChild2?.orgRevisionId;
if (!orgChild2) { if (!orgChild2) {
let orgChild3: any = null; let orgChild3: any = null;
if (requestBody.orgChild3Id != null) if (requestBody.orgChild3Id != null)
orgChild3 = await this.child3Repository.findOne({ orgChild3 = await this.child3Repository.findOne({
where: { id: requestBody.orgChild3Id }, where: { id: requestBody.orgChild3Id },
}); });
revisionId = orgChild3?.orgRevisionId;
if (!orgChild3) { if (!orgChild3) {
let orgChild4: any = null; let orgChild4: any = null;
if (requestBody.orgChild4Id != null) if (requestBody.orgChild4Id != null)
orgChild4 = await this.child4Repository.findOne({ orgChild4 = await this.child4Repository.findOne({
where: { id: requestBody.orgChild4Id }, where: { id: requestBody.orgChild4Id },
}); });
revisionId = orgChild4?.orgRevisionId;
if (!orgChild4) { if (!orgChild4) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงสร้าง"); throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงสร้าง");
} else { } else {
@ -1089,7 +1094,6 @@ export class PositionController extends Controller {
posMaster.orgRevisionId = orgRoot.orgRevisionId; posMaster.orgRevisionId = orgRoot.orgRevisionId;
SName = orgRoot.orgRootShortName; SName = orgRoot.orgRootShortName;
} }
const chk_SName0 = await this.posMasterRepository.findOne({ const chk_SName0 = await this.posMasterRepository.findOne({
where: { where: {
orgRevisionId: posMaster.orgRevisionId, orgRevisionId: posMaster.orgRevisionId,
@ -1105,7 +1109,6 @@ export class PositionController extends Controller {
"ไม่สามารถใส่เลขที่ตำแหน่งซ้ำกันได้", "ไม่สามารถใส่เลขที่ตำแหน่งซ้ำกันได้",
); );
} }
const chk_SName1 = await this.posMasterRepository.findOne({ const chk_SName1 = await this.posMasterRepository.findOne({
where: { where: {
orgRevisionId: posMaster.orgRevisionId, orgRevisionId: posMaster.orgRevisionId,
@ -1121,7 +1124,6 @@ export class PositionController extends Controller {
"ไม่สามารถใส่เลขที่ตำแหน่งซ้ำกันได้", "ไม่สามารถใส่เลขที่ตำแหน่งซ้ำกันได้",
); );
} }
const chk_SName2 = await this.posMasterRepository.findOne({ const chk_SName2 = await this.posMasterRepository.findOne({
where: { where: {
orgRevisionId: posMaster.orgRevisionId, orgRevisionId: posMaster.orgRevisionId,
@ -1137,7 +1139,6 @@ export class PositionController extends Controller {
"ไม่สามารถใส่เลขที่ตำแหน่งซ้ำกันได้", "ไม่สามารถใส่เลขที่ตำแหน่งซ้ำกันได้",
); );
} }
const chk_SName3 = await this.posMasterRepository.findOne({ const chk_SName3 = await this.posMasterRepository.findOne({
where: { where: {
orgRevisionId: posMaster.orgRevisionId, orgRevisionId: posMaster.orgRevisionId,
@ -1153,7 +1154,6 @@ export class PositionController extends Controller {
"ไม่สามารถใส่เลขที่ตำแหน่งซ้ำกันได้", "ไม่สามารถใส่เลขที่ตำแหน่งซ้ำกันได้",
); );
} }
const chk_SName4 = await this.posMasterRepository.findOne({ const chk_SName4 = await this.posMasterRepository.findOne({
where: { where: {
orgRevisionId: posMaster.orgRevisionId, orgRevisionId: posMaster.orgRevisionId,
@ -1169,13 +1169,26 @@ export class PositionController extends Controller {
); );
} }
const before = null; const before = null;
let chkRevision:any = null;
if(revisionId){
chkRevision = await this.orgRevisionRepository.findOne({
where: { id: revisionId },
});
}
posMaster.createdUserId = request.user.sub; posMaster.createdUserId = request.user.sub;
posMaster.createdFullName = request.user.name; posMaster.createdFullName = request.user.name;
posMaster.lastUpdateUserId = request.user.sub; posMaster.lastUpdateUserId = request.user.sub;
posMaster.lastUpdateFullName = request.user.name; posMaster.lastUpdateFullName = request.user.name;
posMaster.createdAt = new Date(); posMaster.createdAt = new Date();
posMaster.lastUpdatedAt = new Date(); posMaster.lastUpdatedAt = new Date();
await this.posMasterRepository.save(posMaster, { data: request }); const saved = await this.posMasterRepository.save(posMaster, { data: request });
// รอบสอง set ancestorDNA = id ที่เพิ่งได้มา
if (chkRevision?.orgRevisionIsCurrent) {
saved.ancestorDNA = saved.id; //โครงสร้างปัจจุบันเอาตัวเองเป็น dna
await this.posMasterRepository.save(saved, { data: request });
}
setLogDataDiff(request, { before, after: posMaster }); setLogDataDiff(request, { before, after: posMaster });
await Promise.all( await Promise.all(
requestBody.positions.map(async (x: any) => { requestBody.positions.map(async (x: any) => {
@ -3676,11 +3689,16 @@ export class PositionController extends Controller {
await new permission().PermissionDelete(request, "SYS_ORG"); await new permission().PermissionDelete(request, "SYS_ORG");
const dataMaster = await this.posMasterRepository.findOne({ const dataMaster = await this.posMasterRepository.findOne({
where: { id: id }, where: { id: id },
relations: ["positions"], relations: ["positions", "orgRevision"],
}); });
if (!dataMaster) { if (!dataMaster) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลตำแหน่งนี้"); throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลตำแหน่งนี้");
} }
if (dataMaster.orgRevision.orgRevisionIsCurrent) {
await CreatePosMasterHistoryOfficer(dataMaster.id, request);
}
let _profileId: string = ""; let _profileId: string = "";
if (dataMaster?.current_holderId) { if (dataMaster?.current_holderId) {
_profileId = dataMaster?.current_holderId; _profileId = dataMaster?.current_holderId;
@ -4088,16 +4106,16 @@ export class PositionController extends Controller {
posLevel = await this.posLevelRepository.find({ posLevel = await this.posLevelRepository.find({
where: { where: {
posTypeId: In(posType.map((x: any) => x.id)), posTypeId: In(posType.map((x: any) => x.id)),
posLevelName: In(["ทรงคุณวุฒิ", "สูง"]) posLevelName: In(["ทรงคุณวุฒิ", "สูง"]),
}, },
}); });
conditionA = "positions.posTypeId IN (:...posTypeIds) AND positions.posLevelId IN (:...posLevelIds)"; conditionA =
"positions.posTypeId IN (:...posTypeIds) AND positions.posLevelId IN (:...posLevelIds)";
params = { params = {
posTypeIds: posType.map((x: any) => x.id), posTypeIds: posType.map((x: any) => x.id),
posLevelIds: posLevel.map((x: any) => x.id), posLevelIds: posLevel.map((x: any) => x.id),
}; };
} } else {
else {
posType = await this.posTypeRepository.findOne({ posType = await this.posTypeRepository.findOne({
where: { id: String(body.posType) }, where: { id: String(body.posType) },
}); });
@ -4195,13 +4213,13 @@ export class PositionController extends Controller {
.andWhere( .andWhere(
new Brackets((qb) => { new Brackets((qb) => {
qb.andWhere(typeCondition) qb.andWhere(typeCondition)
// .andWhere(conditionA == null ? "1=1" : conditionA, { // .andWhere(conditionA == null ? "1=1" : conditionA, {
// posType: posType == null ? `%%` : `${posType.id}`, // posType: posType == null ? `%%` : `${posType.id}`,
// posLevel: posLevel == null ? `%%` : `${posLevel.id}`, // posLevel: posLevel == null ? `%%` : `${posLevel.id}`,
// posTypeRank: posType == null ? 0 : posType.posTypeRank, // posTypeRank: posType == null ? 0 : posType.posTypeRank,
// posLevelRank: posLevel == null ? 0 : posLevel.posLevelRank, // posLevelRank: posLevel == null ? 0 : posLevel.posLevelRank,
// }); // });
.andWhere(conditionA, params); .andWhere(conditionA, params);
}), }),
) )
.orderBy("orgRoot.orgRootOrder", "ASC") .orderBy("orgRoot.orgRootOrder", "ASC")
@ -4924,7 +4942,6 @@ export class PositionController extends Controller {
await CreatePosMasterHistoryOfficer(posMasterOld.id, request); await CreatePosMasterHistoryOfficer(posMasterOld.id, request);
} }
await this.posMasterRepository.save(posMaster); await this.posMasterRepository.save(posMaster);
await CreatePosMasterHistoryOfficer(posMaster.id, request);
const positionNew = await this.positionRepository.findOne({ const positionNew = await this.positionRepository.findOne({
where: { where: {
@ -4940,6 +4957,8 @@ export class PositionController extends Controller {
await this.profileRepository.save(profile); await this.profileRepository.save(profile);
await this.positionRepository.save(positionNew); await this.positionRepository.save(positionNew);
} }
await CreatePosMasterHistoryOfficer(posMaster.id, request);
return new HttpSuccess(); return new HttpSuccess();
} }

View file

@ -0,0 +1,25 @@
import { Body, Controller, Post, Route } from "tsoa";
import { sendWebSocket } from "../services/webSocket";
@Route("/api/v1/org/through-socket")
export class SocketController extends Controller {
@Post("notify")
async notify(
@Body()
payload: {
message: string;
userId?: string | string[];
roles?: string | string[];
error?: boolean;
},
) {
sendWebSocket(
"socket-notification",
{ success: !payload.error, message: payload.message },
{
roles: payload.roles || [],
userId: payload.userId || [],
},
);
}
}

View file

@ -40,7 +40,7 @@ export async function CreatePosMasterHistoryOfficer(
pm.positions.length > 0 pm.positions.length > 0
? pm.positions.find((p) => p.positionIsSelected === true) ?? null ? pm.positions.find((p) => p.positionIsSelected === true) ?? null
: null; : null;
h.ancestorDNA = pm.ancestorDNA; h.ancestorDNA = pm.ancestorDNA? pm.ancestorDNA : _null;
h.prefix = pm.current_holder?.prefix || _null; h.prefix = pm.current_holder?.prefix || _null;
h.firstName = pm.current_holder?.firstName || _null; h.firstName = pm.current_holder?.firstName || _null;
h.lastName = pm.current_holder?.lastName || _null; h.lastName = pm.current_holder?.lastName || _null;