refactor transaction
This commit is contained in:
parent
869bb093a3
commit
a6d3df9904
2 changed files with 251 additions and 499 deletions
|
|
@ -1,4 +1,4 @@
|
||||||
import { In } from "typeorm";
|
import { EntityManager, In } from "typeorm";
|
||||||
import { SavePosMasterHistory } from "./../interfaces/OrgMapping";
|
import { SavePosMasterHistory } from "./../interfaces/OrgMapping";
|
||||||
import { AppDataSource } from "../database/data-source";
|
import { AppDataSource } from "../database/data-source";
|
||||||
import { EmployeePosMaster } from "../entities/EmployeePosMaster";
|
import { EmployeePosMaster } from "../entities/EmployeePosMaster";
|
||||||
|
|
@ -17,13 +17,13 @@ export async function CreatePosMasterHistoryOfficer(
|
||||||
request: RequestWithUser | null,
|
request: RequestWithUser | null,
|
||||||
type?: string | null,
|
type?: string | null,
|
||||||
positionData?: { positionId?: string } | null,
|
positionData?: { positionId?: string } | null,
|
||||||
|
manager?: EntityManager,
|
||||||
): Promise<boolean> {
|
): Promise<boolean> {
|
||||||
try {
|
const execute = async (transactionManager: EntityManager) => {
|
||||||
await AppDataSource.transaction(async (manager) => {
|
const repoPosmaster = transactionManager.getRepository(PosMaster);
|
||||||
const repoPosmaster = manager.getRepository(PosMaster);
|
const repoHistory = transactionManager.getRepository(PosMasterHistory);
|
||||||
const repoHistory = manager.getRepository(PosMasterHistory);
|
const repoOrgRevision = transactionManager.getRepository(OrgRevision);
|
||||||
const repoOrgRevision = manager.getRepository(OrgRevision);
|
const repoPosition = transactionManager.getRepository(Position);
|
||||||
const repoPosition = manager.getRepository(Position);
|
|
||||||
|
|
||||||
const pm = await repoPosmaster.findOne({
|
const pm = await repoPosmaster.findOne({
|
||||||
where: { id: posMasterId },
|
where: { id: posMasterId },
|
||||||
|
|
@ -42,8 +42,9 @@ export async function CreatePosMasterHistoryOfficer(
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!pm) return false;
|
if (!pm || !pm.ancestorDNA) {
|
||||||
if (!pm.ancestorDNA) return false;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const checkCurrentRevision = await repoOrgRevision.findOne({
|
const checkCurrentRevision = await repoOrgRevision.findOne({
|
||||||
where: {
|
where: {
|
||||||
|
|
@ -112,10 +113,22 @@ export async function CreatePosMasterHistoryOfficer(
|
||||||
h.createdAt = new Date();
|
h.createdAt = new Date();
|
||||||
h.lastUpdatedAt = new Date();
|
h.lastUpdatedAt = new Date();
|
||||||
await repoHistory.save(h);
|
await repoHistory.save(h);
|
||||||
});
|
};
|
||||||
|
|
||||||
|
try {
|
||||||
|
if (manager) {
|
||||||
|
await execute(manager);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
await AppDataSource.transaction(async (transactionManager) => {
|
||||||
|
await execute(transactionManager);
|
||||||
|
});
|
||||||
return true;
|
return true;
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
if (manager) {
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
console.error("CreatePosMasterHistoryOfficer transaction error:", err);
|
console.error("CreatePosMasterHistoryOfficer transaction error:", err);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -818,6 +818,68 @@ async function handler_org(msg: amqp.ConsumeMessage): Promise<boolean> {
|
||||||
);
|
);
|
||||||
|
|
||||||
// ===== BATCH EXECUTION: save ทีละ batch =====
|
// ===== BATCH EXECUTION: save ทีละ batch =====
|
||||||
|
let shouldSkipPublishInTransaction = false;
|
||||||
|
await AppDataSource.transaction(async (manager) => {
|
||||||
|
const repoPosmaster = manager.getRepository(PosMaster);
|
||||||
|
const posMasterAssignRepository = manager.getRepository(PosMasterAssign);
|
||||||
|
const posMasterActRepository = manager.getRepository(PosMasterAct);
|
||||||
|
const permissionProfilesRepository = manager.getRepository(PermissionProfile);
|
||||||
|
const repoEmployeePosmaster = manager.getRepository(EmployeePosMaster);
|
||||||
|
const repoEmployeeTempPosmaster = manager.getRepository(EmployeeTempPosMaster);
|
||||||
|
const repoProfile = manager.getRepository(Profile);
|
||||||
|
const repoProfileEmployee = manager.getRepository(ProfileEmployee);
|
||||||
|
const employeePositionRepository = manager.getRepository(EmployeePosition);
|
||||||
|
const repoOrgRevision = manager.getRepository(OrgRevision);
|
||||||
|
const orgRootRepository = manager.getRepository(OrgRoot);
|
||||||
|
const child1Repository = manager.getRepository(OrgChild1);
|
||||||
|
const child2Repository = manager.getRepository(OrgChild2);
|
||||||
|
const child3Repository = manager.getRepository(OrgChild3);
|
||||||
|
const child4Repository = manager.getRepository(OrgChild4);
|
||||||
|
|
||||||
|
const targetOrgRevision = await repoOrgRevision
|
||||||
|
.createQueryBuilder("orgRevision")
|
||||||
|
.setLock("pessimistic_write")
|
||||||
|
.where("orgRevision.id = :id", { id })
|
||||||
|
.getOne();
|
||||||
|
|
||||||
|
if (!targetOrgRevision) {
|
||||||
|
shouldSkipPublishInTransaction = true;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (targetOrgRevision.orgRevisionIsCurrent && !targetOrgRevision.orgRevisionIsDraft) {
|
||||||
|
shouldSkipPublishInTransaction = true;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!targetOrgRevision.orgRevisionIsDraft || targetOrgRevision.orgRevisionIsCurrent) {
|
||||||
|
shouldSkipPublishInTransaction = true;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const orgRevisionPublish = await repoOrgRevision
|
||||||
|
.createQueryBuilder("orgRevision")
|
||||||
|
.setLock("pessimistic_write")
|
||||||
|
.where("orgRevision.orgRevisionIsDraft = false")
|
||||||
|
.andWhere("orgRevision.orgRevisionIsCurrent = true")
|
||||||
|
.getOne();
|
||||||
|
|
||||||
|
if (!orgRevisionPublish) {
|
||||||
|
throw new Error("[AMQ] Cannot publish in transaction: no current org revision found");
|
||||||
|
}
|
||||||
|
|
||||||
|
const orgRevisionDraft = await repoOrgRevision
|
||||||
|
.createQueryBuilder("orgRevision")
|
||||||
|
.setLock("pessimistic_write")
|
||||||
|
.where("orgRevision.id = :id", { id })
|
||||||
|
.andWhere("orgRevision.orgRevisionIsDraft = true")
|
||||||
|
.andWhere("orgRevision.orgRevisionIsCurrent = false")
|
||||||
|
.getOne();
|
||||||
|
|
||||||
|
if (!orgRevisionDraft) {
|
||||||
|
shouldSkipPublishInTransaction = true;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// 4. Batch save posMasterAssign (chunk 500)
|
// 4. Batch save posMasterAssign (chunk 500)
|
||||||
console.time("[AMQ] batch_save_posMasterAssign");
|
console.time("[AMQ] batch_save_posMasterAssign");
|
||||||
|
|
@ -855,7 +917,7 @@ async function handler_org(msg: amqp.ConsumeMessage): Promise<boolean> {
|
||||||
// 7. Batch create history
|
// 7. Batch create history
|
||||||
console.time("[AMQ] batch_create_history");
|
console.time("[AMQ] batch_create_history");
|
||||||
for (const id of historyCreateIds) {
|
for (const id of historyCreateIds) {
|
||||||
await CreatePosMasterHistoryOfficer(id, null);
|
await CreatePosMasterHistoryOfficer(id, null, undefined, undefined, manager);
|
||||||
}
|
}
|
||||||
console.timeEnd("[AMQ] batch_create_history");
|
console.timeEnd("[AMQ] batch_create_history");
|
||||||
|
|
||||||
|
|
@ -888,7 +950,6 @@ async function handler_org(msg: amqp.ConsumeMessage): Promise<boolean> {
|
||||||
}
|
}
|
||||||
console.timeEnd("[AMQ] clone_oldposMasterAct");
|
console.timeEnd("[AMQ] clone_oldposMasterAct");
|
||||||
|
|
||||||
if (orgRevisionPublish != null && orgRevisionDraft != null) {
|
|
||||||
console.time("[AMQ] clone_org_structure");
|
console.time("[AMQ] clone_org_structure");
|
||||||
//new main revision
|
//new main revision
|
||||||
const before = null;
|
const before = null;
|
||||||
|
|
@ -1001,20 +1062,6 @@ async function handler_org(msg: amqp.ConsumeMessage): Promise<boolean> {
|
||||||
console.log(`[AMQ] orgemployeePosMaster count: ${orgemployeePosMaster.length}`);
|
console.log(`[AMQ] orgemployeePosMaster count: ${orgemployeePosMaster.length}`);
|
||||||
|
|
||||||
let _orgemployeePosMaster: EmployeePosMaster[];
|
let _orgemployeePosMaster: EmployeePosMaster[];
|
||||||
// if (
|
|
||||||
// requestBody.typeDraft.toUpperCase() == "ORG_POSITION" ||
|
|
||||||
// requestBody.typeDraft.toUpperCase() == "ORG_POSITION_PERSON" ||
|
|
||||||
// requestBody.typeDraft.toUpperCase() == "ORG_POSITION_ROLE" ||
|
|
||||||
// requestBody.typeDraft.toUpperCase() == "ORG_POSITION_PERSON_ROLE"
|
|
||||||
// ) {
|
|
||||||
// _orgemployeePosMaster = orgemployeePosMaster.map((x) => ({
|
|
||||||
// ...x,
|
|
||||||
// ancestorDNA:
|
|
||||||
// x.ancestorDNA == null || x.ancestorDNA == "00000000-0000-0000-0000-000000000000"
|
|
||||||
// ? x.id
|
|
||||||
// : x.ancestorDNA,
|
|
||||||
// }));
|
|
||||||
// await repoEmployeePosmaster.save(_orgemployeePosMaster);
|
|
||||||
const validProfileIds = new Set(
|
const validProfileIds = new Set(
|
||||||
(await repoProfileEmployee.find({ select: ["id"] })).map((p) => p.id),
|
(await repoProfileEmployee.find({ select: ["id"] })).map((p) => p.id),
|
||||||
);
|
);
|
||||||
|
|
@ -1042,7 +1089,6 @@ async function handler_org(msg: amqp.ConsumeMessage): Promise<boolean> {
|
||||||
.execute();
|
.execute();
|
||||||
console.timeEnd("[AMQ] insert_employeePosMaster");
|
console.timeEnd("[AMQ] insert_employeePosMaster");
|
||||||
|
|
||||||
// }
|
|
||||||
//หา dna posmaster ถ้าไม่มีให้เอาตัวเองเป็น dna
|
//หา dna posmaster ถ้าไม่มีให้เอาตัวเองเป็น dna
|
||||||
console.time("[AMQ] query_employeeTempPosMaster");
|
console.time("[AMQ] query_employeeTempPosMaster");
|
||||||
const orgemployeeTempPosMaster = await repoEmployeeTempPosmaster.find({
|
const orgemployeeTempPosMaster = await repoEmployeeTempPosmaster.find({
|
||||||
|
|
@ -1053,12 +1099,6 @@ async function handler_org(msg: amqp.ConsumeMessage): Promise<boolean> {
|
||||||
console.log(`[AMQ] orgemployeeTempPosMaster count: ${orgemployeeTempPosMaster.length}`);
|
console.log(`[AMQ] orgemployeeTempPosMaster count: ${orgemployeeTempPosMaster.length}`);
|
||||||
|
|
||||||
let _orgemployeeTempPosMaster: EmployeeTempPosMaster[];
|
let _orgemployeeTempPosMaster: EmployeeTempPosMaster[];
|
||||||
// if (
|
|
||||||
// requestBody.typeDraft.toUpperCase() == "ORG_POSITION" ||
|
|
||||||
// requestBody.typeDraft.toUpperCase() == "ORG_POSITION_PERSON" ||
|
|
||||||
// requestBody.typeDraft.toUpperCase() == "ORG_POSITION_ROLE" ||
|
|
||||||
// requestBody.typeDraft.toUpperCase() == "ORG_POSITION_PERSON_ROLE"
|
|
||||||
// ) {
|
|
||||||
_orgemployeeTempPosMaster = orgemployeeTempPosMaster.map((x) => ({
|
_orgemployeeTempPosMaster = orgemployeeTempPosMaster.map((x) => ({
|
||||||
...x,
|
...x,
|
||||||
ancestorDNA:
|
ancestorDNA:
|
||||||
|
|
@ -1066,7 +1106,6 @@ async function handler_org(msg: amqp.ConsumeMessage): Promise<boolean> {
|
||||||
? x.id
|
? x.id
|
||||||
: x.ancestorDNA,
|
: x.ancestorDNA,
|
||||||
}));
|
}));
|
||||||
// await repoEmployeeTempPosmaster.save(_orgemployeeTempPosMaster);
|
|
||||||
await repoEmployeeTempPosmaster
|
await repoEmployeeTempPosmaster
|
||||||
.createQueryBuilder()
|
.createQueryBuilder()
|
||||||
.insert()
|
.insert()
|
||||||
|
|
@ -1077,7 +1116,6 @@ async function handler_org(msg: amqp.ConsumeMessage): Promise<boolean> {
|
||||||
overwrite: ["ancestorDNA"],
|
overwrite: ["ancestorDNA"],
|
||||||
})
|
})
|
||||||
.execute();
|
.execute();
|
||||||
// }
|
|
||||||
|
|
||||||
//create org
|
//create org
|
||||||
console.time("[AMQ] forEach_orgRoot");
|
console.time("[AMQ] forEach_orgRoot");
|
||||||
|
|
@ -1086,13 +1124,6 @@ async function handler_org(msg: amqp.ConsumeMessage): Promise<boolean> {
|
||||||
const dataId = x.id;
|
const dataId = x.id;
|
||||||
const matchedOrgRoot = findMatchedNodeByAncestorDNA(orgRootCurrent, x);
|
const matchedOrgRoot = findMatchedNodeByAncestorDNA(orgRootCurrent, x);
|
||||||
|
|
||||||
// if (
|
|
||||||
// requestBody.typeDraft.toUpperCase() == "ORG_POSITION" ||
|
|
||||||
// requestBody.typeDraft.toUpperCase() == "ORG_POSITION_PERSON" ||
|
|
||||||
// requestBody.typeDraft.toUpperCase() == "ORG_POSITION_ROLE" ||
|
|
||||||
// requestBody.typeDraft.toUpperCase() == "ORG_POSITION_PERSON_ROLE"
|
|
||||||
// ) {
|
|
||||||
//create employeePosmaster
|
|
||||||
const filteredEmployeePosMaster = _orgemployeePosMaster.filter(
|
const filteredEmployeePosMaster = _orgemployeePosMaster.filter(
|
||||||
(x: EmployeePosMaster) => x.orgRootId == dataId && x.orgChild1Id == null,
|
(x: EmployeePosMaster) => x.orgRootId == dataId && x.orgChild1Id == null,
|
||||||
);
|
);
|
||||||
|
|
@ -1102,24 +1133,6 @@ async function handler_org(msg: amqp.ConsumeMessage): Promise<boolean> {
|
||||||
delete item.id;
|
delete item.id;
|
||||||
const employeePosMaster = Object.assign(new EmployeePosMaster(), item);
|
const employeePosMaster = Object.assign(new EmployeePosMaster(), item);
|
||||||
employeePosMaster.positions = [];
|
employeePosMaster.positions = [];
|
||||||
// if (
|
|
||||||
// requestBody.typeDraft.toUpperCase() == "ORG_POSITION_PERSON" ||
|
|
||||||
// requestBody.typeDraft.toUpperCase() == "ORG_POSITION_PERSON_ROLE"
|
|
||||||
// ) {
|
|
||||||
// employeePosMaster.current_holderId = item.current_holderId;
|
|
||||||
// } else {
|
|
||||||
// // employeePosMaster.next_holderId = null;
|
|
||||||
// employeePosMaster.isSit = false;
|
|
||||||
// }
|
|
||||||
// if (
|
|
||||||
// requestBody.typeDraft.toUpperCase() == "ORG_POSITION_ROLE" ||
|
|
||||||
// requestBody.typeDraft.toUpperCase() == "ORG_POSITION_PERSON_ROLE"
|
|
||||||
// ) {
|
|
||||||
// employeePosMaster.authRoleId = item.authRoleId;
|
|
||||||
// } else {
|
|
||||||
// employeePosMaster.authRoleId = null;
|
|
||||||
// }
|
|
||||||
// employeePosMaster.current_holderId = null;
|
|
||||||
employeePosMaster.orgRevisionId = orgRevisionDraft.id;
|
employeePosMaster.orgRevisionId = orgRevisionDraft.id;
|
||||||
employeePosMaster.orgRootId = matchedOrgRoot?.id ?? null;
|
employeePosMaster.orgRootId = matchedOrgRoot?.id ?? null;
|
||||||
employeePosMaster.createdUserId = "";
|
employeePosMaster.createdUserId = "";
|
||||||
|
|
@ -1130,7 +1143,6 @@ async function handler_org(msg: amqp.ConsumeMessage): Promise<boolean> {
|
||||||
employeePosMaster.lastUpdatedAt = new Date();
|
employeePosMaster.lastUpdatedAt = new Date();
|
||||||
await repoEmployeePosmaster.save(employeePosMaster);
|
await repoEmployeePosmaster.save(employeePosMaster);
|
||||||
|
|
||||||
//create employeePosition
|
|
||||||
await Promise.all(
|
await Promise.all(
|
||||||
item.positions.map(async (pos: any) => {
|
item.positions.map(async (pos: any) => {
|
||||||
delete pos.id;
|
delete pos.id;
|
||||||
|
|
@ -1139,12 +1151,6 @@ async function handler_org(msg: amqp.ConsumeMessage): Promise<boolean> {
|
||||||
pos,
|
pos,
|
||||||
);
|
);
|
||||||
employeePosition.posMasterId = employeePosMaster.id;
|
employeePosition.posMasterId = employeePosMaster.id;
|
||||||
// if (
|
|
||||||
// requestBody.typeDraft.toUpperCase() == "ORG_POSITION" ||
|
|
||||||
// requestBody.typeDraft.toUpperCase() == "ORG_POSITION_ROLE"
|
|
||||||
// ) {
|
|
||||||
// employeePosition.positionIsSelected = false;
|
|
||||||
// }
|
|
||||||
employeePosition.createdUserId = "";
|
employeePosition.createdUserId = "";
|
||||||
employeePosition.createdFullName = "System Administrator";
|
employeePosition.createdFullName = "System Administrator";
|
||||||
employeePosition.createdAt = new Date();
|
employeePosition.createdAt = new Date();
|
||||||
|
|
@ -1156,7 +1162,7 @@ async function handler_org(msg: amqp.ConsumeMessage): Promise<boolean> {
|
||||||
);
|
);
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
//create employeeTempPosmaster
|
|
||||||
await Promise.all(
|
await Promise.all(
|
||||||
_orgemployeeTempPosMaster
|
_orgemployeeTempPosMaster
|
||||||
.filter((x: EmployeeTempPosMaster) => x.orgRootId == dataId && x.orgChild1Id == null)
|
.filter((x: EmployeeTempPosMaster) => x.orgRootId == dataId && x.orgChild1Id == null)
|
||||||
|
|
@ -1164,24 +1170,6 @@ async function handler_org(msg: amqp.ConsumeMessage): Promise<boolean> {
|
||||||
delete item.id;
|
delete item.id;
|
||||||
const employeeTempPosMaster = Object.assign(new EmployeeTempPosMaster(), item);
|
const employeeTempPosMaster = Object.assign(new EmployeeTempPosMaster(), item);
|
||||||
employeeTempPosMaster.positions = [];
|
employeeTempPosMaster.positions = [];
|
||||||
// if (
|
|
||||||
// requestBody.typeDraft.toUpperCase() == "ORG_POSITION_PERSON" ||
|
|
||||||
// requestBody.typeDraft.toUpperCase() == "ORG_POSITION_PERSON_ROLE"
|
|
||||||
// ) {
|
|
||||||
// employeeTempPosMaster.current_holderId = item.current_holderId;
|
|
||||||
// } else {
|
|
||||||
// // employeeTempPosMaster.next_holderId = null;
|
|
||||||
// employeeTempPosMaster.isSit = false;
|
|
||||||
// }
|
|
||||||
// if (
|
|
||||||
// requestBody.typeDraft.toUpperCase() == "ORG_POSITION_ROLE" ||
|
|
||||||
// requestBody.typeDraft.toUpperCase() == "ORG_POSITION_PERSON_ROLE"
|
|
||||||
// ) {
|
|
||||||
// employeeTempPosMaster.authRoleId = item.authRoleId;
|
|
||||||
// } else {
|
|
||||||
// employeeTempPosMaster.authRoleId = null;
|
|
||||||
// }
|
|
||||||
// employeeTempPosMaster.current_holderId = null;
|
|
||||||
employeeTempPosMaster.orgRevisionId = orgRevisionDraft.id;
|
employeeTempPosMaster.orgRevisionId = orgRevisionDraft.id;
|
||||||
employeeTempPosMaster.orgRootId = matchedOrgRoot?.id ?? null;
|
employeeTempPosMaster.orgRootId = matchedOrgRoot?.id ?? null;
|
||||||
employeeTempPosMaster.createdUserId = "";
|
employeeTempPosMaster.createdUserId = "";
|
||||||
|
|
@ -1192,7 +1180,6 @@ async function handler_org(msg: amqp.ConsumeMessage): Promise<boolean> {
|
||||||
employeeTempPosMaster.lastUpdatedAt = new Date();
|
employeeTempPosMaster.lastUpdatedAt = new Date();
|
||||||
await repoEmployeeTempPosmaster.save(employeeTempPosMaster);
|
await repoEmployeeTempPosmaster.save(employeeTempPosMaster);
|
||||||
|
|
||||||
//create employeePosition
|
|
||||||
await Promise.all(
|
await Promise.all(
|
||||||
item.positions.map(async (pos: any) => {
|
item.positions.map(async (pos: any) => {
|
||||||
delete pos.id;
|
delete pos.id;
|
||||||
|
|
@ -1201,12 +1188,6 @@ async function handler_org(msg: amqp.ConsumeMessage): Promise<boolean> {
|
||||||
pos,
|
pos,
|
||||||
);
|
);
|
||||||
employeePosition.posMasterTempId = employeeTempPosMaster.id;
|
employeePosition.posMasterTempId = employeeTempPosMaster.id;
|
||||||
// if (
|
|
||||||
// requestBody.typeDraft.toUpperCase() == "ORG_POSITION" ||
|
|
||||||
// requestBody.typeDraft.toUpperCase() == "ORG_POSITION_ROLE"
|
|
||||||
// ) {
|
|
||||||
// employeePosition.positionIsSelected = false;
|
|
||||||
// }
|
|
||||||
employeePosition.createdUserId = "";
|
employeePosition.createdUserId = "";
|
||||||
employeePosition.createdFullName = "System Administrator";
|
employeePosition.createdFullName = "System Administrator";
|
||||||
employeePosition.createdAt = new Date();
|
employeePosition.createdAt = new Date();
|
||||||
|
|
@ -1218,46 +1199,17 @@ async function handler_org(msg: amqp.ConsumeMessage): Promise<boolean> {
|
||||||
);
|
);
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
// }
|
|
||||||
|
|
||||||
//create org
|
|
||||||
for (const x of orgChild1.filter((item: OrgChild1) => item.orgRootId == dataId)) {
|
for (const x of orgChild1.filter((item: OrgChild1) => item.orgRootId == dataId)) {
|
||||||
const data1Id = x.id;
|
const data1Id = x.id;
|
||||||
const matchedOrgChild1 = findMatchedNodeByAncestorDNA(orgChild1Current, x);
|
const matchedOrgChild1 = findMatchedNodeByAncestorDNA(orgChild1Current, x);
|
||||||
// ("[in case Child1] ancestorDNA", `${x.orgChild1Id == matchedOrgChild1?.id}`);
|
|
||||||
// if (
|
|
||||||
// requestBody.typeDraft.toUpperCase() == "ORG_POSITION" ||
|
|
||||||
// requestBody.typeDraft.toUpperCase() == "ORG_POSITION_PERSON" ||
|
|
||||||
// requestBody.typeDraft.toUpperCase() == "ORG_POSITION_ROLE" ||
|
|
||||||
// requestBody.typeDraft.toUpperCase() == "ORG_POSITION_PERSON_ROLE"
|
|
||||||
// ) {
|
|
||||||
//create employeePosmaster
|
|
||||||
await Promise.all(
|
await Promise.all(
|
||||||
_orgemployeePosMaster
|
_orgemployeePosMaster
|
||||||
.filter((x: EmployeePosMaster) => x.orgChild1Id == data1Id && x.orgChild2Id == null)
|
.filter((x: EmployeePosMaster) => x.orgChild1Id == data1Id && x.orgChild2Id == null)
|
||||||
.map(async (item: any) => {
|
.map(async (item: any) => {
|
||||||
delete item.id;
|
delete item.id;
|
||||||
// console.log("[in case Child1] orgChild1Id == data1Id");
|
|
||||||
const employeePosMaster = Object.assign(new EmployeePosMaster(), item);
|
const employeePosMaster = Object.assign(new EmployeePosMaster(), item);
|
||||||
employeePosMaster.positions = [];
|
employeePosMaster.positions = [];
|
||||||
// if (
|
|
||||||
// requestBody.typeDraft.toUpperCase() == "ORG_POSITION_PERSON" ||
|
|
||||||
// requestBody.typeDraft.toUpperCase() == "ORG_POSITION_PERSON_ROLE"
|
|
||||||
// ) {
|
|
||||||
// employeePosMaster.current_holderId = item.current_holderId;
|
|
||||||
// } else {
|
|
||||||
// // employeePosMaster.next_holderId = null;
|
|
||||||
// employeePosMaster.isSit = false;
|
|
||||||
// }
|
|
||||||
// if (
|
|
||||||
// requestBody.typeDraft.toUpperCase() == "ORG_POSITION_ROLE" ||
|
|
||||||
// requestBody.typeDraft.toUpperCase() == "ORG_POSITION_PERSON_ROLE"
|
|
||||||
// ) {
|
|
||||||
// employeePosMaster.authRoleId = item.authRoleId;
|
|
||||||
// } else {
|
|
||||||
// employeePosMaster.authRoleId = null;
|
|
||||||
// }
|
|
||||||
// employeePosMaster.current_holderId = null;
|
|
||||||
employeePosMaster.orgRevisionId = orgRevisionDraft.id;
|
employeePosMaster.orgRevisionId = orgRevisionDraft.id;
|
||||||
employeePosMaster.orgRootId = matchedOrgRoot?.id ?? null;
|
employeePosMaster.orgRootId = matchedOrgRoot?.id ?? null;
|
||||||
employeePosMaster.orgChild1Id = matchedOrgChild1?.id ?? null;
|
employeePosMaster.orgChild1Id = matchedOrgChild1?.id ?? null;
|
||||||
|
|
@ -1269,7 +1221,6 @@ async function handler_org(msg: amqp.ConsumeMessage): Promise<boolean> {
|
||||||
employeePosMaster.lastUpdatedAt = new Date();
|
employeePosMaster.lastUpdatedAt = new Date();
|
||||||
await repoEmployeePosmaster.save(employeePosMaster);
|
await repoEmployeePosmaster.save(employeePosMaster);
|
||||||
|
|
||||||
//create employeePosition
|
|
||||||
await Promise.all(
|
await Promise.all(
|
||||||
item.positions.map(async (pos: any) => {
|
item.positions.map(async (pos: any) => {
|
||||||
delete pos.id;
|
delete pos.id;
|
||||||
|
|
@ -1278,12 +1229,6 @@ async function handler_org(msg: amqp.ConsumeMessage): Promise<boolean> {
|
||||||
pos,
|
pos,
|
||||||
);
|
);
|
||||||
employeePosition.posMasterId = employeePosMaster.id;
|
employeePosition.posMasterId = employeePosMaster.id;
|
||||||
// if (
|
|
||||||
// requestBody.typeDraft.toUpperCase() == "ORG_POSITION" ||
|
|
||||||
// requestBody.typeDraft.toUpperCase() == "ORG_POSITION_ROLE"
|
|
||||||
// ) {
|
|
||||||
// employeePosition.positionIsSelected = false;
|
|
||||||
// }
|
|
||||||
employeePosition.createdUserId = "";
|
employeePosition.createdUserId = "";
|
||||||
employeePosition.createdFullName = "System Administrator";
|
employeePosition.createdFullName = "System Administrator";
|
||||||
employeePosition.createdAt = new Date();
|
employeePosition.createdAt = new Date();
|
||||||
|
|
@ -1295,7 +1240,7 @@ async function handler_org(msg: amqp.ConsumeMessage): Promise<boolean> {
|
||||||
);
|
);
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
// create employeeTempPosmaster
|
|
||||||
await Promise.all(
|
await Promise.all(
|
||||||
_orgemployeeTempPosMaster
|
_orgemployeeTempPosMaster
|
||||||
.filter(
|
.filter(
|
||||||
|
|
@ -1305,24 +1250,6 @@ async function handler_org(msg: amqp.ConsumeMessage): Promise<boolean> {
|
||||||
delete item.id;
|
delete item.id;
|
||||||
const employeeTempPosMaster = Object.assign(new EmployeeTempPosMaster(), item);
|
const employeeTempPosMaster = Object.assign(new EmployeeTempPosMaster(), item);
|
||||||
employeeTempPosMaster.positions = [];
|
employeeTempPosMaster.positions = [];
|
||||||
// if (
|
|
||||||
// requestBody.typeDraft.toUpperCase() == "ORG_POSITION_PERSON" ||
|
|
||||||
// requestBody.typeDraft.toUpperCase() == "ORG_POSITION_PERSON_ROLE"
|
|
||||||
// ) {
|
|
||||||
// employeeTempPosMaster.current_holderId = item.current_holderId;
|
|
||||||
// } else {
|
|
||||||
// // employeeTempPosMaster.next_holderId = null;
|
|
||||||
// employeeTempPosMaster.isSit = false;
|
|
||||||
// }
|
|
||||||
// if (
|
|
||||||
// requestBody.typeDraft.toUpperCase() == "ORG_POSITION_ROLE" ||
|
|
||||||
// requestBody.typeDraft.toUpperCase() == "ORG_POSITION_PERSON_ROLE"
|
|
||||||
// ) {
|
|
||||||
// employeeTempPosMaster.authRoleId = item.authRoleId;
|
|
||||||
// } else {
|
|
||||||
// employeeTempPosMaster.authRoleId = null;
|
|
||||||
// }
|
|
||||||
// employeeTempPosMaster.current_holderId = null;
|
|
||||||
employeeTempPosMaster.orgRevisionId = orgRevisionDraft.id;
|
employeeTempPosMaster.orgRevisionId = orgRevisionDraft.id;
|
||||||
employeeTempPosMaster.orgRootId = matchedOrgRoot?.id ?? null;
|
employeeTempPosMaster.orgRootId = matchedOrgRoot?.id ?? null;
|
||||||
employeeTempPosMaster.orgChild1Id = matchedOrgChild1?.id ?? null;
|
employeeTempPosMaster.orgChild1Id = matchedOrgChild1?.id ?? null;
|
||||||
|
|
@ -1334,7 +1261,6 @@ async function handler_org(msg: amqp.ConsumeMessage): Promise<boolean> {
|
||||||
employeeTempPosMaster.lastUpdatedAt = new Date();
|
employeeTempPosMaster.lastUpdatedAt = new Date();
|
||||||
await repoEmployeeTempPosmaster.save(employeeTempPosMaster);
|
await repoEmployeeTempPosmaster.save(employeeTempPosMaster);
|
||||||
|
|
||||||
//create employeePosition
|
|
||||||
await Promise.all(
|
await Promise.all(
|
||||||
item.positions.map(async (pos: any) => {
|
item.positions.map(async (pos: any) => {
|
||||||
delete pos.id;
|
delete pos.id;
|
||||||
|
|
@ -1343,12 +1269,6 @@ async function handler_org(msg: amqp.ConsumeMessage): Promise<boolean> {
|
||||||
pos,
|
pos,
|
||||||
);
|
);
|
||||||
employeePosition.posMasterTempId = employeeTempPosMaster.id;
|
employeePosition.posMasterTempId = employeeTempPosMaster.id;
|
||||||
// if (
|
|
||||||
// requestBody.typeDraft.toUpperCase() == "ORG_POSITION" ||
|
|
||||||
// requestBody.typeDraft.toUpperCase() == "ORG_POSITION_ROLE"
|
|
||||||
// ) {
|
|
||||||
// employeePosition.positionIsSelected = false;
|
|
||||||
// }
|
|
||||||
employeePosition.createdUserId = "";
|
employeePosition.createdUserId = "";
|
||||||
employeePosition.createdFullName = "System Administrator";
|
employeePosition.createdFullName = "System Administrator";
|
||||||
employeePosition.createdAt = new Date();
|
employeePosition.createdAt = new Date();
|
||||||
|
|
@ -1360,46 +1280,17 @@ async function handler_org(msg: amqp.ConsumeMessage): Promise<boolean> {
|
||||||
);
|
);
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
// }
|
|
||||||
|
|
||||||
//create org
|
|
||||||
for (const x of orgChild2.filter((item: OrgChild2) => item.orgChild1Id == data1Id)) {
|
for (const x of orgChild2.filter((item: OrgChild2) => item.orgChild1Id == data1Id)) {
|
||||||
const data2Id = x.id;
|
const data2Id = x.id;
|
||||||
const matchedOrgChild2 = findMatchedNodeByAncestorDNA(orgChild2Current, x);
|
const matchedOrgChild2 = findMatchedNodeByAncestorDNA(orgChild2Current, x);
|
||||||
// console.log("[in case Child2] ancestorDNA", `${x.orgChild2Id == matchedOrgChild2?.id}`);
|
|
||||||
// if (
|
|
||||||
// requestBody.typeDraft.toUpperCase() == "ORG_POSITION" ||
|
|
||||||
// requestBody.typeDraft.toUpperCase() == "ORG_POSITION_PERSON" ||
|
|
||||||
// requestBody.typeDraft.toUpperCase() == "ORG_POSITION_ROLE" ||
|
|
||||||
// requestBody.typeDraft.toUpperCase() == "ORG_POSITION_PERSON_ROLE"
|
|
||||||
// ) {
|
|
||||||
//create employeePosmaster
|
|
||||||
await Promise.all(
|
await Promise.all(
|
||||||
_orgemployeePosMaster
|
_orgemployeePosMaster
|
||||||
.filter((x: EmployeePosMaster) => x.orgChild2Id == data2Id && x.orgChild3Id == null)
|
.filter((x: EmployeePosMaster) => x.orgChild2Id == data2Id && x.orgChild3Id == null)
|
||||||
.map(async (item: any) => {
|
.map(async (item: any) => {
|
||||||
delete item.id;
|
delete item.id;
|
||||||
// console.log("[in case Child2] orgChild2Id == data2Id");
|
|
||||||
const employeePosMaster = Object.assign(new EmployeePosMaster(), item);
|
const employeePosMaster = Object.assign(new EmployeePosMaster(), item);
|
||||||
employeePosMaster.positions = [];
|
employeePosMaster.positions = [];
|
||||||
// if (
|
|
||||||
// requestBody.typeDraft.toUpperCase() == "ORG_POSITION_PERSON" ||
|
|
||||||
// requestBody.typeDraft.toUpperCase() == "ORG_POSITION_PERSON_ROLE"
|
|
||||||
// ) {
|
|
||||||
// employeePosMaster.current_holderId = item.current_holderId;
|
|
||||||
// } else {
|
|
||||||
// // employeePosMaster.next_holderId = null;
|
|
||||||
// employeePosMaster.isSit = false;
|
|
||||||
// }
|
|
||||||
// if (
|
|
||||||
// requestBody.typeDraft.toUpperCase() == "ORG_POSITION_ROLE" ||
|
|
||||||
// requestBody.typeDraft.toUpperCase() == "ORG_POSITION_PERSON_ROLE"
|
|
||||||
// ) {
|
|
||||||
// employeePosMaster.authRoleId = item.authRoleId;
|
|
||||||
// } else {
|
|
||||||
// employeePosMaster.authRoleId = null;
|
|
||||||
// }
|
|
||||||
// employeePosMaster.current_holderId = null;
|
|
||||||
employeePosMaster.orgRevisionId = orgRevisionDraft.id;
|
employeePosMaster.orgRevisionId = orgRevisionDraft.id;
|
||||||
employeePosMaster.orgRootId = matchedOrgRoot?.id ?? null;
|
employeePosMaster.orgRootId = matchedOrgRoot?.id ?? null;
|
||||||
employeePosMaster.orgChild1Id = matchedOrgChild1?.id ?? null;
|
employeePosMaster.orgChild1Id = matchedOrgChild1?.id ?? null;
|
||||||
|
|
@ -1412,7 +1303,6 @@ async function handler_org(msg: amqp.ConsumeMessage): Promise<boolean> {
|
||||||
employeePosMaster.lastUpdatedAt = new Date();
|
employeePosMaster.lastUpdatedAt = new Date();
|
||||||
await repoEmployeePosmaster.save(employeePosMaster);
|
await repoEmployeePosmaster.save(employeePosMaster);
|
||||||
|
|
||||||
//create employeePosition
|
|
||||||
await Promise.all(
|
await Promise.all(
|
||||||
item.positions.map(async (pos: any) => {
|
item.positions.map(async (pos: any) => {
|
||||||
delete pos.id;
|
delete pos.id;
|
||||||
|
|
@ -1421,12 +1311,6 @@ async function handler_org(msg: amqp.ConsumeMessage): Promise<boolean> {
|
||||||
pos,
|
pos,
|
||||||
);
|
);
|
||||||
employeePosition.posMasterId = employeePosMaster.id;
|
employeePosition.posMasterId = employeePosMaster.id;
|
||||||
// if (
|
|
||||||
// requestBody.typeDraft.toUpperCase() == "ORG_POSITION" ||
|
|
||||||
// requestBody.typeDraft.toUpperCase() == "ORG_POSITION_ROLE"
|
|
||||||
// ) {
|
|
||||||
// employeePosition.positionIsSelected = false;
|
|
||||||
// }
|
|
||||||
employeePosition.createdUserId = "";
|
employeePosition.createdUserId = "";
|
||||||
employeePosition.createdFullName = "System Administrator";
|
employeePosition.createdFullName = "System Administrator";
|
||||||
employeePosition.createdAt = new Date();
|
employeePosition.createdAt = new Date();
|
||||||
|
|
@ -1438,7 +1322,7 @@ async function handler_org(msg: amqp.ConsumeMessage): Promise<boolean> {
|
||||||
);
|
);
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
// create employeeTempPosmaster
|
|
||||||
await Promise.all(
|
await Promise.all(
|
||||||
_orgemployeeTempPosMaster
|
_orgemployeeTempPosMaster
|
||||||
.filter(
|
.filter(
|
||||||
|
|
@ -1448,24 +1332,6 @@ async function handler_org(msg: amqp.ConsumeMessage): Promise<boolean> {
|
||||||
delete item.id;
|
delete item.id;
|
||||||
const employeeTempPosMaster = Object.assign(new EmployeeTempPosMaster(), item);
|
const employeeTempPosMaster = Object.assign(new EmployeeTempPosMaster(), item);
|
||||||
employeeTempPosMaster.positions = [];
|
employeeTempPosMaster.positions = [];
|
||||||
// if (
|
|
||||||
// requestBody.typeDraft.toUpperCase() == "ORG_POSITION_PERSON" ||
|
|
||||||
// requestBody.typeDraft.toUpperCase() == "ORG_POSITION_PERSON_ROLE"
|
|
||||||
// ) {
|
|
||||||
// employeeTempPosMaster.current_holderId = item.current_holderId;
|
|
||||||
// } else {
|
|
||||||
// // employeeTempPosMaster.next_holderId = null;
|
|
||||||
// employeeTempPosMaster.isSit = false;
|
|
||||||
// }
|
|
||||||
// if (
|
|
||||||
// requestBody.typeDraft.toUpperCase() == "ORG_POSITION_ROLE" ||
|
|
||||||
// requestBody.typeDraft.toUpperCase() == "ORG_POSITION_PERSON_ROLE"
|
|
||||||
// ) {
|
|
||||||
// employeeTempPosMaster.authRoleId = item.authRoleId;
|
|
||||||
// } else {
|
|
||||||
// employeeTempPosMaster.authRoleId = null;
|
|
||||||
// }
|
|
||||||
// employeeTempPosMaster.current_holderId = null;
|
|
||||||
employeeTempPosMaster.orgRevisionId = orgRevisionDraft.id;
|
employeeTempPosMaster.orgRevisionId = orgRevisionDraft.id;
|
||||||
employeeTempPosMaster.orgRootId = dataId;
|
employeeTempPosMaster.orgRootId = dataId;
|
||||||
employeeTempPosMaster.orgChild1Id = data1Id;
|
employeeTempPosMaster.orgChild1Id = data1Id;
|
||||||
|
|
@ -1478,7 +1344,6 @@ async function handler_org(msg: amqp.ConsumeMessage): Promise<boolean> {
|
||||||
employeeTempPosMaster.lastUpdatedAt = new Date();
|
employeeTempPosMaster.lastUpdatedAt = new Date();
|
||||||
await repoEmployeeTempPosmaster.save(employeeTempPosMaster);
|
await repoEmployeeTempPosmaster.save(employeeTempPosMaster);
|
||||||
|
|
||||||
//create employeePosition
|
|
||||||
await Promise.all(
|
await Promise.all(
|
||||||
item.positions.map(async (pos: any) => {
|
item.positions.map(async (pos: any) => {
|
||||||
delete pos.id;
|
delete pos.id;
|
||||||
|
|
@ -1487,12 +1352,6 @@ async function handler_org(msg: amqp.ConsumeMessage): Promise<boolean> {
|
||||||
pos,
|
pos,
|
||||||
);
|
);
|
||||||
employeePosition.posMasterTempId = employeeTempPosMaster.id;
|
employeePosition.posMasterTempId = employeeTempPosMaster.id;
|
||||||
// if (
|
|
||||||
// requestBody.typeDraft.toUpperCase() == "ORG_POSITION" ||
|
|
||||||
// requestBody.typeDraft.toUpperCase() == "ORG_POSITION_ROLE"
|
|
||||||
// ) {
|
|
||||||
// employeePosition.positionIsSelected = false;
|
|
||||||
// }
|
|
||||||
employeePosition.createdUserId = "";
|
employeePosition.createdUserId = "";
|
||||||
employeePosition.createdFullName = "System Administrator";
|
employeePosition.createdFullName = "System Administrator";
|
||||||
employeePosition.createdAt = new Date();
|
employeePosition.createdAt = new Date();
|
||||||
|
|
@ -1504,20 +1363,10 @@ async function handler_org(msg: amqp.ConsumeMessage): Promise<boolean> {
|
||||||
);
|
);
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
// }
|
|
||||||
|
|
||||||
//create org
|
|
||||||
for (const x of orgChild3.filter((item: OrgChild3) => item.orgChild2Id == data2Id)) {
|
for (const x of orgChild3.filter((item: OrgChild3) => item.orgChild2Id == data2Id)) {
|
||||||
const data3Id = x.id;
|
const data3Id = x.id;
|
||||||
const matchedOrgChild3 = findMatchedNodeByAncestorDNA(orgChild3Current, x);
|
const matchedOrgChild3 = findMatchedNodeByAncestorDNA(orgChild3Current, x);
|
||||||
// console.log("[in case Child3] ancestorDNA", `${x.orgChild3Id == matchedOrgChild3?.id}`);
|
|
||||||
// if (
|
|
||||||
// requestBody.typeDraft.toUpperCase() == "ORG_POSITION" ||
|
|
||||||
// requestBody.typeDraft.toUpperCase() == "ORG_POSITION_PERSON" ||
|
|
||||||
// requestBody.typeDraft.toUpperCase() == "ORG_POSITION_ROLE" ||
|
|
||||||
// requestBody.typeDraft.toUpperCase() == "ORG_POSITION_PERSON_ROLE"
|
|
||||||
// ) {
|
|
||||||
//create employeePosmaster
|
|
||||||
await Promise.all(
|
await Promise.all(
|
||||||
_orgemployeePosMaster
|
_orgemployeePosMaster
|
||||||
.filter(
|
.filter(
|
||||||
|
|
@ -1525,27 +1374,8 @@ async function handler_org(msg: amqp.ConsumeMessage): Promise<boolean> {
|
||||||
)
|
)
|
||||||
.map(async (item: any) => {
|
.map(async (item: any) => {
|
||||||
delete item.id;
|
delete item.id;
|
||||||
// console.log("[in case Child3] orgChild3Id == data3Id");
|
|
||||||
const employeePosMaster = Object.assign(new EmployeePosMaster(), item);
|
const employeePosMaster = Object.assign(new EmployeePosMaster(), item);
|
||||||
employeePosMaster.positions = [];
|
employeePosMaster.positions = [];
|
||||||
// if (
|
|
||||||
// requestBody.typeDraft.toUpperCase() == "ORG_POSITION_PERSON" ||
|
|
||||||
// requestBody.typeDraft.toUpperCase() == "ORG_POSITION_PERSON_ROLE"
|
|
||||||
// ) {
|
|
||||||
// employeePosMaster.current_holderId = item.current_holderId;
|
|
||||||
// } else {
|
|
||||||
// // employeePosMaster.next_holderId = null;
|
|
||||||
// employeePosMaster.isSit = false;
|
|
||||||
// }
|
|
||||||
// if (
|
|
||||||
// requestBody.typeDraft.toUpperCase() == "ORG_POSITION_ROLE" ||
|
|
||||||
// requestBody.typeDraft.toUpperCase() == "ORG_POSITION_PERSON_ROLE"
|
|
||||||
// ) {
|
|
||||||
// employeePosMaster.authRoleId = item.authRoleId;
|
|
||||||
// } else {
|
|
||||||
// employeePosMaster.authRoleId = null;
|
|
||||||
// }
|
|
||||||
// employeePosMaster.current_holderId = null;
|
|
||||||
employeePosMaster.orgRevisionId = orgRevisionDraft.id;
|
employeePosMaster.orgRevisionId = orgRevisionDraft.id;
|
||||||
employeePosMaster.orgRootId = matchedOrgRoot?.id ?? null;
|
employeePosMaster.orgRootId = matchedOrgRoot?.id ?? null;
|
||||||
employeePosMaster.orgChild1Id = matchedOrgChild1?.id ?? null;
|
employeePosMaster.orgChild1Id = matchedOrgChild1?.id ?? null;
|
||||||
|
|
@ -1559,7 +1389,6 @@ async function handler_org(msg: amqp.ConsumeMessage): Promise<boolean> {
|
||||||
employeePosMaster.lastUpdatedAt = new Date();
|
employeePosMaster.lastUpdatedAt = new Date();
|
||||||
await repoEmployeePosmaster.save(employeePosMaster);
|
await repoEmployeePosmaster.save(employeePosMaster);
|
||||||
|
|
||||||
//create employeePosition
|
|
||||||
await Promise.all(
|
await Promise.all(
|
||||||
item.positions.map(async (pos: any) => {
|
item.positions.map(async (pos: any) => {
|
||||||
delete pos.id;
|
delete pos.id;
|
||||||
|
|
@ -1568,12 +1397,6 @@ async function handler_org(msg: amqp.ConsumeMessage): Promise<boolean> {
|
||||||
pos,
|
pos,
|
||||||
);
|
);
|
||||||
employeePosition.posMasterId = employeePosMaster.id;
|
employeePosition.posMasterId = employeePosMaster.id;
|
||||||
// if (
|
|
||||||
// requestBody.typeDraft.toUpperCase() == "ORG_POSITION" ||
|
|
||||||
// requestBody.typeDraft.toUpperCase() == "ORG_POSITION_ROLE"
|
|
||||||
// ) {
|
|
||||||
// employeePosition.positionIsSelected = false;
|
|
||||||
// }
|
|
||||||
employeePosition.createdUserId = "";
|
employeePosition.createdUserId = "";
|
||||||
employeePosition.createdFullName = "System Administrator";
|
employeePosition.createdFullName = "System Administrator";
|
||||||
employeePosition.createdAt = new Date();
|
employeePosition.createdAt = new Date();
|
||||||
|
|
@ -1585,7 +1408,7 @@ async function handler_org(msg: amqp.ConsumeMessage): Promise<boolean> {
|
||||||
);
|
);
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
// create employeeTempPosmaster
|
|
||||||
await Promise.all(
|
await Promise.all(
|
||||||
_orgemployeeTempPosMaster
|
_orgemployeeTempPosMaster
|
||||||
.filter(
|
.filter(
|
||||||
|
|
@ -1595,24 +1418,6 @@ async function handler_org(msg: amqp.ConsumeMessage): Promise<boolean> {
|
||||||
delete item.id;
|
delete item.id;
|
||||||
const employeeTempPosMaster = Object.assign(new EmployeeTempPosMaster(), item);
|
const employeeTempPosMaster = Object.assign(new EmployeeTempPosMaster(), item);
|
||||||
employeeTempPosMaster.positions = [];
|
employeeTempPosMaster.positions = [];
|
||||||
// if (
|
|
||||||
// requestBody.typeDraft.toUpperCase() == "ORG_POSITION_PERSON" ||
|
|
||||||
// requestBody.typeDraft.toUpperCase() == "ORG_POSITION_PERSON_ROLE"
|
|
||||||
// ) {
|
|
||||||
// employeeTempPosMaster.current_holderId = item.current_holderId;
|
|
||||||
// } else {
|
|
||||||
// // employeeTempPosMaster.next_holderId = null;
|
|
||||||
// employeeTempPosMaster.isSit = false;
|
|
||||||
// }
|
|
||||||
// if (
|
|
||||||
// requestBody.typeDraft.toUpperCase() == "ORG_POSITION_ROLE" ||
|
|
||||||
// requestBody.typeDraft.toUpperCase() == "ORG_POSITION_PERSON_ROLE"
|
|
||||||
// ) {
|
|
||||||
// employeeTempPosMaster.authRoleId = item.authRoleId;
|
|
||||||
// } else {
|
|
||||||
// employeeTempPosMaster.authRoleId = null;
|
|
||||||
// }
|
|
||||||
// employeeTempPosMaster.current_holderId = null;
|
|
||||||
employeeTempPosMaster.orgRevisionId = orgRevisionDraft.id;
|
employeeTempPosMaster.orgRevisionId = orgRevisionDraft.id;
|
||||||
employeeTempPosMaster.orgRootId = matchedOrgRoot?.id ?? null;
|
employeeTempPosMaster.orgRootId = matchedOrgRoot?.id ?? null;
|
||||||
employeeTempPosMaster.orgChild1Id = matchedOrgChild1?.id ?? null;
|
employeeTempPosMaster.orgChild1Id = matchedOrgChild1?.id ?? null;
|
||||||
|
|
@ -1626,7 +1431,6 @@ async function handler_org(msg: amqp.ConsumeMessage): Promise<boolean> {
|
||||||
employeeTempPosMaster.lastUpdatedAt = new Date();
|
employeeTempPosMaster.lastUpdatedAt = new Date();
|
||||||
await repoEmployeeTempPosmaster.save(employeeTempPosMaster);
|
await repoEmployeeTempPosmaster.save(employeeTempPosMaster);
|
||||||
|
|
||||||
//create employeePosition
|
|
||||||
await Promise.all(
|
await Promise.all(
|
||||||
item.positions.map(async (pos: any) => {
|
item.positions.map(async (pos: any) => {
|
||||||
delete pos.id;
|
delete pos.id;
|
||||||
|
|
@ -1635,12 +1439,6 @@ async function handler_org(msg: amqp.ConsumeMessage): Promise<boolean> {
|
||||||
pos,
|
pos,
|
||||||
);
|
);
|
||||||
employeePosition.posMasterTempId = employeeTempPosMaster.id;
|
employeePosition.posMasterTempId = employeeTempPosMaster.id;
|
||||||
// if (
|
|
||||||
// requestBody.typeDraft.toUpperCase() == "ORG_POSITION" ||
|
|
||||||
// requestBody.typeDraft.toUpperCase() == "ORG_POSITION_ROLE"
|
|
||||||
// ) {
|
|
||||||
// employeePosition.positionIsSelected = false;
|
|
||||||
// }
|
|
||||||
employeePosition.createdUserId = "";
|
employeePosition.createdUserId = "";
|
||||||
employeePosition.createdFullName = "System Administrator";
|
employeePosition.createdFullName = "System Administrator";
|
||||||
employeePosition.createdAt = new Date();
|
employeePosition.createdAt = new Date();
|
||||||
|
|
@ -1652,46 +1450,17 @@ async function handler_org(msg: amqp.ConsumeMessage): Promise<boolean> {
|
||||||
);
|
);
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
// }
|
|
||||||
|
|
||||||
//create org
|
|
||||||
for (const x of orgChild4.filter((item: OrgChild4) => item.orgChild3Id == data3Id)) {
|
for (const x of orgChild4.filter((item: OrgChild4) => item.orgChild3Id == data3Id)) {
|
||||||
const data4Id = x.id;
|
const data4Id = x.id;
|
||||||
const matchedOrgChild4 = findMatchedNodeByAncestorDNA(orgChild4Current, x);
|
const matchedOrgChild4 = findMatchedNodeByAncestorDNA(orgChild4Current, x);
|
||||||
// console.log("[in case Child4] ancestorDNA", `${x.orgChild4Id == matchedOrgChild4?.id}`);
|
|
||||||
// if (
|
|
||||||
// requestBody.typeDraft.toUpperCase() == "ORG_POSITION" ||
|
|
||||||
// requestBody.typeDraft.toUpperCase() == "ORG_POSITION_PERSON" ||
|
|
||||||
// requestBody.typeDraft.toUpperCase() == "ORG_POSITION_ROLE" ||
|
|
||||||
// requestBody.typeDraft.toUpperCase() == "ORG_POSITION_PERSON_ROLE"
|
|
||||||
// ) {
|
|
||||||
//create employeePosmaster
|
|
||||||
await Promise.all(
|
await Promise.all(
|
||||||
_orgemployeePosMaster
|
_orgemployeePosMaster
|
||||||
.filter((x: EmployeePosMaster) => x.orgChild4Id == data4Id)
|
.filter((x: EmployeePosMaster) => x.orgChild4Id == data4Id)
|
||||||
.map(async (item: any) => {
|
.map(async (item: any) => {
|
||||||
delete item.id;
|
delete item.id;
|
||||||
// console.log("[in case Child4] orgChild4Id == data4Id");
|
|
||||||
const employeePosMaster = Object.assign(new EmployeePosMaster(), item);
|
const employeePosMaster = Object.assign(new EmployeePosMaster(), item);
|
||||||
employeePosMaster.positions = [];
|
employeePosMaster.positions = [];
|
||||||
// if (
|
|
||||||
// requestBody.typeDraft.toUpperCase() == "ORG_POSITION_PERSON" ||
|
|
||||||
// requestBody.typeDraft.toUpperCase() == "ORG_POSITION_PERSON_ROLE"
|
|
||||||
// ) {
|
|
||||||
// employeePosMaster.current_holderId = item.current_holderId;
|
|
||||||
// } else {
|
|
||||||
// // employeePosMaster.next_holderId = null;
|
|
||||||
// employeePosMaster.isSit = false;
|
|
||||||
// }
|
|
||||||
// if (
|
|
||||||
// requestBody.typeDraft.toUpperCase() == "ORG_POSITION_ROLE" ||
|
|
||||||
// requestBody.typeDraft.toUpperCase() == "ORG_POSITION_PERSON_ROLE"
|
|
||||||
// ) {
|
|
||||||
// employeePosMaster.authRoleId = item.authRoleId;
|
|
||||||
// } else {
|
|
||||||
// employeePosMaster.authRoleId = null;
|
|
||||||
// }
|
|
||||||
// employeePosMaster.current_holderId = null;
|
|
||||||
employeePosMaster.orgRevisionId = orgRevisionDraft.id;
|
employeePosMaster.orgRevisionId = orgRevisionDraft.id;
|
||||||
employeePosMaster.orgRootId = matchedOrgRoot?.id ?? null;
|
employeePosMaster.orgRootId = matchedOrgRoot?.id ?? null;
|
||||||
employeePosMaster.orgChild1Id = matchedOrgChild1?.id ?? null;
|
employeePosMaster.orgChild1Id = matchedOrgChild1?.id ?? null;
|
||||||
|
|
@ -1706,7 +1475,6 @@ async function handler_org(msg: amqp.ConsumeMessage): Promise<boolean> {
|
||||||
employeePosMaster.lastUpdatedAt = new Date();
|
employeePosMaster.lastUpdatedAt = new Date();
|
||||||
await repoEmployeePosmaster.save(employeePosMaster);
|
await repoEmployeePosmaster.save(employeePosMaster);
|
||||||
|
|
||||||
//create employeePosition
|
|
||||||
await Promise.all(
|
await Promise.all(
|
||||||
item.positions.map(async (pos: any) => {
|
item.positions.map(async (pos: any) => {
|
||||||
delete pos.id;
|
delete pos.id;
|
||||||
|
|
@ -1715,12 +1483,6 @@ async function handler_org(msg: amqp.ConsumeMessage): Promise<boolean> {
|
||||||
pos,
|
pos,
|
||||||
);
|
);
|
||||||
employeePosition.posMasterId = employeePosMaster.id;
|
employeePosition.posMasterId = employeePosMaster.id;
|
||||||
// if (
|
|
||||||
// requestBody.typeDraft.toUpperCase() == "ORG_POSITION" ||
|
|
||||||
// requestBody.typeDraft.toUpperCase() == "ORG_POSITION_ROLE"
|
|
||||||
// ) {
|
|
||||||
// employeePosition.positionIsSelected = false;
|
|
||||||
// }
|
|
||||||
employeePosition.createdUserId = "";
|
employeePosition.createdUserId = "";
|
||||||
employeePosition.createdFullName = "System Administrator";
|
employeePosition.createdFullName = "System Administrator";
|
||||||
employeePosition.createdAt = new Date();
|
employeePosition.createdAt = new Date();
|
||||||
|
|
@ -1732,7 +1494,7 @@ async function handler_org(msg: amqp.ConsumeMessage): Promise<boolean> {
|
||||||
);
|
);
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
//create employeeTempPosmaster
|
|
||||||
await Promise.all(
|
await Promise.all(
|
||||||
_orgemployeeTempPosMaster
|
_orgemployeeTempPosMaster
|
||||||
.filter((x: EmployeeTempPosMaster) => x.orgChild4Id == data4Id)
|
.filter((x: EmployeeTempPosMaster) => x.orgChild4Id == data4Id)
|
||||||
|
|
@ -1743,24 +1505,6 @@ async function handler_org(msg: amqp.ConsumeMessage): Promise<boolean> {
|
||||||
item,
|
item,
|
||||||
);
|
);
|
||||||
employeeTempPosMaster.positions = [];
|
employeeTempPosMaster.positions = [];
|
||||||
// if (
|
|
||||||
// requestBody.typeDraft.toUpperCase() == "ORG_POSITION_PERSON" ||
|
|
||||||
// requestBody.typeDraft.toUpperCase() == "ORG_POSITION_PERSON_ROLE"
|
|
||||||
// ) {
|
|
||||||
// employeeTempPosMaster.current_holderId = item.current_holderId;
|
|
||||||
// } else {
|
|
||||||
// // employeeTempPosMaster.next_holderId = null;
|
|
||||||
// employeeTempPosMaster.isSit = false;
|
|
||||||
// }
|
|
||||||
// if (
|
|
||||||
// requestBody.typeDraft.toUpperCase() == "ORG_POSITION_ROLE" ||
|
|
||||||
// requestBody.typeDraft.toUpperCase() == "ORG_POSITION_PERSON_ROLE"
|
|
||||||
// ) {
|
|
||||||
// employeeTempPosMaster.authRoleId = item.authRoleId;
|
|
||||||
// } else {
|
|
||||||
// employeeTempPosMaster.authRoleId = null;
|
|
||||||
// }
|
|
||||||
// employeeTempPosMaster.current_holderId = null;
|
|
||||||
employeeTempPosMaster.orgRevisionId = orgRevisionDraft.id;
|
employeeTempPosMaster.orgRevisionId = orgRevisionDraft.id;
|
||||||
employeeTempPosMaster.orgRootId = matchedOrgRoot?.id ?? null;
|
employeeTempPosMaster.orgRootId = matchedOrgRoot?.id ?? null;
|
||||||
employeeTempPosMaster.orgChild1Id = matchedOrgChild1?.id ?? null;
|
employeeTempPosMaster.orgChild1Id = matchedOrgChild1?.id ?? null;
|
||||||
|
|
@ -1775,7 +1519,6 @@ async function handler_org(msg: amqp.ConsumeMessage): Promise<boolean> {
|
||||||
employeeTempPosMaster.lastUpdatedAt = new Date();
|
employeeTempPosMaster.lastUpdatedAt = new Date();
|
||||||
await repoEmployeeTempPosmaster.save(employeeTempPosMaster);
|
await repoEmployeeTempPosmaster.save(employeeTempPosMaster);
|
||||||
|
|
||||||
//create employeePosition
|
|
||||||
await Promise.all(
|
await Promise.all(
|
||||||
item.positions.map(async (pos: any) => {
|
item.positions.map(async (pos: any) => {
|
||||||
delete pos.id;
|
delete pos.id;
|
||||||
|
|
@ -1784,12 +1527,6 @@ async function handler_org(msg: amqp.ConsumeMessage): Promise<boolean> {
|
||||||
pos,
|
pos,
|
||||||
);
|
);
|
||||||
employeePosition.posMasterTempId = employeeTempPosMaster.id;
|
employeePosition.posMasterTempId = employeeTempPosMaster.id;
|
||||||
// if (
|
|
||||||
// requestBody.typeDraft.toUpperCase() == "ORG_POSITION" ||
|
|
||||||
// requestBody.typeDraft.toUpperCase() == "ORG_POSITION_ROLE"
|
|
||||||
// ) {
|
|
||||||
// employeePosition.positionIsSelected = false;
|
|
||||||
// }
|
|
||||||
employeePosition.createdUserId = "";
|
employeePosition.createdUserId = "";
|
||||||
employeePosition.createdFullName = "System Administrator";
|
employeePosition.createdFullName = "System Administrator";
|
||||||
employeePosition.createdAt = new Date();
|
employeePosition.createdAt = new Date();
|
||||||
|
|
@ -1801,13 +1538,11 @@ async function handler_org(msg: amqp.ConsumeMessage): Promise<boolean> {
|
||||||
);
|
);
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// }
|
|
||||||
|
|
||||||
const employeePosMaster = await repoEmployeePosmaster.find({
|
const employeePosMaster = await repoEmployeePosmaster.find({
|
||||||
where: { orgRevisionId: orgRevisionDraft.id },
|
where: { orgRevisionId: orgRevisionDraft.id },
|
||||||
|
|
@ -1827,8 +1562,6 @@ async function handler_org(msg: amqp.ConsumeMessage): Promise<boolean> {
|
||||||
await repoProfileEmployee.save(profile);
|
await repoProfileEmployee.save(profile);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// item.current_holderId = item.next_holderId;
|
|
||||||
// item.next_holderId = null;
|
|
||||||
item.lastUpdateUserId = lastUpdateUserId;
|
item.lastUpdateUserId = lastUpdateUserId;
|
||||||
item.lastUpdateFullName = lastUpdateFullName;
|
item.lastUpdateFullName = lastUpdateFullName;
|
||||||
item.lastUpdatedAt = lastUpdatedAt;
|
item.lastUpdatedAt = lastUpdatedAt;
|
||||||
|
|
@ -1852,14 +1585,32 @@ async function handler_org(msg: amqp.ConsumeMessage): Promise<boolean> {
|
||||||
await repoProfileEmployee.save(profile);
|
await repoProfileEmployee.save(profile);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// item.current_holderId = item.next_holderId;
|
|
||||||
// item.next_holderId = null;
|
|
||||||
item.lastUpdateUserId = lastUpdateUserId;
|
item.lastUpdateUserId = lastUpdateUserId;
|
||||||
item.lastUpdateFullName = lastUpdateFullName;
|
item.lastUpdateFullName = lastUpdateFullName;
|
||||||
item.lastUpdatedAt = lastUpdatedAt;
|
item.lastUpdatedAt = lastUpdatedAt;
|
||||||
await repoEmployeeTempPosmaster.save(item);
|
await repoEmployeeTempPosmaster.save(item);
|
||||||
}
|
}
|
||||||
|
console.timeEnd("[AMQ] clone_org_structure");
|
||||||
|
|
||||||
|
console.time("[AMQ] save_revision_status");
|
||||||
|
orgRevisionPublish.orgRevisionIsDraft = false;
|
||||||
|
orgRevisionPublish.orgRevisionIsCurrent = false;
|
||||||
|
await repoOrgRevision.save(orgRevisionPublish);
|
||||||
|
|
||||||
|
orgRevisionDraft.orgRevisionIsCurrent = true;
|
||||||
|
orgRevisionDraft.orgRevisionIsDraft = false;
|
||||||
|
await repoOrgRevision.save(orgRevisionDraft);
|
||||||
|
console.timeEnd("[AMQ] save_revision_status");
|
||||||
|
});
|
||||||
|
|
||||||
|
if (shouldSkipPublishInTransaction) {
|
||||||
|
console.log(
|
||||||
|
`[AMQ] Skip publish in transaction: revision ${id} state changed before write phase`,
|
||||||
|
);
|
||||||
|
console.timeEnd("[AMQ] handler_org_total");
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log("[AMQ] Excecute Organization Success");
|
console.log("[AMQ] Excecute Organization Success");
|
||||||
if (user) {
|
if (user) {
|
||||||
sendWebSocket(
|
sendWebSocket(
|
||||||
|
|
@ -1871,18 +1622,6 @@ async function handler_org(msg: amqp.ConsumeMessage): Promise<boolean> {
|
||||||
{ userId: user?.sub },
|
{ userId: user?.sub },
|
||||||
).catch(console.error);
|
).catch(console.error);
|
||||||
}
|
}
|
||||||
console.timeEnd("[AMQ] clone_org_structure");
|
|
||||||
|
|
||||||
// อัปเดตสถานะ orgRevision หลังจากทำงานเสร็จทั้งหมด
|
|
||||||
console.time("[AMQ] save_revision_status");
|
|
||||||
orgRevisionPublish.orgRevisionIsDraft = false;
|
|
||||||
orgRevisionPublish.orgRevisionIsCurrent = false;
|
|
||||||
await repoOrgRevision.save(orgRevisionPublish);
|
|
||||||
|
|
||||||
orgRevisionDraft.orgRevisionIsCurrent = true;
|
|
||||||
orgRevisionDraft.orgRevisionIsDraft = false;
|
|
||||||
await repoOrgRevision.save(orgRevisionDraft);
|
|
||||||
console.timeEnd("[AMQ] save_revision_status");
|
|
||||||
|
|
||||||
console.log(`[AMQ] handler_org SUCCESS - Total time: ${Date.now() - startTime}ms`);
|
console.log(`[AMQ] handler_org SUCCESS - Total time: ${Date.now() - startTime}ms`);
|
||||||
console.timeEnd("[AMQ] handler_org_total");
|
console.timeEnd("[AMQ] handler_org_total");
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue