1. เพิ่ม helper สำหรับ build clone rows จาก metadata ของ repository แล้ว pre-generate UUID ให้ parent และ child ล่วงหน้า
2. เปลี่ยน inner clone flow เป็น cloneEmployeeNodeBatch(...) ที่ทำงานเป็นชุด แทนการ save() parent แล้ว save() children ทีละรายการ 3. ใช้ insertInChunks(...) สำหรับ batch insert ของ parent rows และ EmployeePosition rows 4. ใช้ helper เดียวกันซ้ำทุกระดับของ tree (root, child1, child2, child3, child4) เพื่อลด code duplication และคง mapping ของ destination org ids ตาม logic เดิม
This commit is contained in:
parent
e7e4e2075b
commit
750947f34f
1 changed files with 180 additions and 363 deletions
|
|
@ -1,3 +1,4 @@
|
|||
import { randomUUID } from "crypto";
|
||||
import amqp from "amqplib";
|
||||
import { AppDataSource } from "../database/data-source";
|
||||
import { Command } from "../entities/Command";
|
||||
|
|
@ -20,7 +21,7 @@ import { OrgChild4 } from "../entities/OrgChild4";
|
|||
import { OrgRoot } from "../entities/OrgRoot";
|
||||
import { PosMasterAssign, PosMasterAssignDTO } from "../entities/PosMasterAssign";
|
||||
import { Position } from "../entities/Position";
|
||||
import { In, Not } from "typeorm";
|
||||
import { In, Not, Repository } from "typeorm";
|
||||
import { PosMasterAct } from "../entities/PosMasterAct";
|
||||
import { PermissionOrg } from "../entities/PermissionOrg";
|
||||
import { sendWebSocket } from "./webSocket";
|
||||
|
|
@ -1292,6 +1293,98 @@ async function handler_org(msg: amqp.ConsumeMessage): Promise<boolean> {
|
|||
const orgChild2ByChild1 = groupByParentId(orgChild2, (item) => item.orgChild1Id);
|
||||
const orgChild3ByChild2 = groupByParentId(orgChild3, (item) => item.orgChild2Id);
|
||||
const orgChild4ByChild3 = groupByParentId(orgChild4, (item) => item.orgChild3Id);
|
||||
type OrgDestinationIds = {
|
||||
orgRootId?: string | null;
|
||||
orgChild1Id?: string | null;
|
||||
orgChild2Id?: string | null;
|
||||
orgChild3Id?: string | null;
|
||||
orgChild4Id?: string | null;
|
||||
};
|
||||
type CloneEmployeeSource = {
|
||||
positions: EmployeePosition[];
|
||||
} & (EmployeePosMaster | EmployeeTempPosMaster);
|
||||
const buildAuditFields = (timestamp: Date) => ({
|
||||
createdUserId: "",
|
||||
createdFullName: "System Administrator",
|
||||
createdAt: timestamp,
|
||||
lastUpdateUserId: "",
|
||||
lastUpdateFullName: "System Administrator",
|
||||
lastUpdatedAt: timestamp,
|
||||
});
|
||||
const buildColumnData = <T extends object>(repository: Repository<T>, source: T): Partial<T> => {
|
||||
const row = {} as Partial<T>;
|
||||
const target = row as Record<string, unknown>;
|
||||
const sourceRecord = source as Record<string, unknown>;
|
||||
for (const column of repository.metadata.columns) {
|
||||
target[column.propertyName] = sourceRecord[column.propertyName];
|
||||
}
|
||||
return row;
|
||||
};
|
||||
const insertInChunks = async <T extends object>(
|
||||
repository: Repository<T>,
|
||||
rows: Partial<T>[],
|
||||
chunkSize: number,
|
||||
) => {
|
||||
if (rows.length === 0) {
|
||||
return;
|
||||
}
|
||||
for (const chunk of chunkArray(rows, chunkSize) as Partial<T>[][]) {
|
||||
await repository.insert(chunk as Parameters<Repository<T>["insert"]>[0]);
|
||||
}
|
||||
};
|
||||
const buildEmployeeCloneBatch = <T extends CloneEmployeeSource>(
|
||||
items: T[],
|
||||
parentRepository: Repository<T>,
|
||||
positionParentKey: "posMasterId" | "posMasterTempId",
|
||||
targetIds: OrgDestinationIds,
|
||||
) => {
|
||||
const parentRows: Partial<T>[] = [];
|
||||
const positionRows: Partial<EmployeePosition>[] = [];
|
||||
|
||||
for (const item of items) {
|
||||
const parentId = randomUUID();
|
||||
const parentTimestamp = new Date();
|
||||
parentRows.push({
|
||||
...buildColumnData(parentRepository, item),
|
||||
id: parentId,
|
||||
orgRevisionId: orgRevisionDraft.id,
|
||||
...targetIds,
|
||||
...buildAuditFields(parentTimestamp),
|
||||
});
|
||||
|
||||
for (const position of item.positions ?? []) {
|
||||
const positionTimestamp = new Date();
|
||||
positionRows.push({
|
||||
...buildColumnData(employeePositionRepository, position),
|
||||
id: randomUUID(),
|
||||
posMasterId: positionParentKey === "posMasterId" ? parentId : undefined,
|
||||
posMasterTempId:
|
||||
positionParentKey === "posMasterTempId" ? parentId : undefined,
|
||||
...buildAuditFields(positionTimestamp),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return { parentRows, positionRows };
|
||||
};
|
||||
const cloneEmployeeNodeBatch = async <T extends CloneEmployeeSource>(
|
||||
items: T[],
|
||||
parentRepository: Repository<T>,
|
||||
positionParentKey: "posMasterId" | "posMasterTempId",
|
||||
targetIds: OrgDestinationIds,
|
||||
) => {
|
||||
if (items.length === 0) {
|
||||
return;
|
||||
}
|
||||
const { parentRows, positionRows } = buildEmployeeCloneBatch(
|
||||
items,
|
||||
parentRepository,
|
||||
positionParentKey,
|
||||
targetIds,
|
||||
);
|
||||
await insertInChunks(parentRepository, parentRows, 200);
|
||||
await insertInChunks(employeePositionRepository, positionRows, 500);
|
||||
};
|
||||
|
||||
await repoEmployeeTempPosmaster
|
||||
.createQueryBuilder()
|
||||
|
|
@ -1313,398 +1406,122 @@ async function handler_org(msg: amqp.ConsumeMessage): Promise<boolean> {
|
|||
|
||||
const filteredEmployeePosMaster = employeePosMasterByNode.get(getNodeKey("root", dataId)) ?? [];
|
||||
|
||||
await Promise.all(
|
||||
filteredEmployeePosMaster.map(async (item: any) => {
|
||||
delete item.id;
|
||||
const employeePosMaster = Object.assign(new EmployeePosMaster(), item);
|
||||
employeePosMaster.positions = [];
|
||||
employeePosMaster.orgRevisionId = orgRevisionDraft.id;
|
||||
employeePosMaster.orgRootId = matchedOrgRoot?.id ?? null;
|
||||
employeePosMaster.createdUserId = "";
|
||||
employeePosMaster.createdFullName = "System Administrator";
|
||||
employeePosMaster.createdAt = new Date();
|
||||
employeePosMaster.lastUpdateUserId = "";
|
||||
employeePosMaster.lastUpdateFullName = "System Administrator";
|
||||
employeePosMaster.lastUpdatedAt = new Date();
|
||||
await repoEmployeePosmaster.save(employeePosMaster);
|
||||
|
||||
await Promise.all(
|
||||
item.positions.map(async (pos: any) => {
|
||||
delete pos.id;
|
||||
const employeePosition: EmployeePosition = Object.assign(
|
||||
new EmployeePosition(),
|
||||
pos,
|
||||
);
|
||||
employeePosition.posMasterId = employeePosMaster.id;
|
||||
employeePosition.createdUserId = "";
|
||||
employeePosition.createdFullName = "System Administrator";
|
||||
employeePosition.createdAt = new Date();
|
||||
employeePosition.lastUpdateUserId = "";
|
||||
employeePosition.lastUpdateFullName = "System Administrator";
|
||||
employeePosition.lastUpdatedAt = new Date();
|
||||
await employeePositionRepository.save(employeePosition);
|
||||
}),
|
||||
);
|
||||
}),
|
||||
await cloneEmployeeNodeBatch(
|
||||
filteredEmployeePosMaster,
|
||||
repoEmployeePosmaster,
|
||||
"posMasterId",
|
||||
{ orgRootId: matchedOrgRoot?.id ?? null },
|
||||
);
|
||||
|
||||
await Promise.all(
|
||||
(employeeTempPosMasterByNode.get(getNodeKey("root", dataId)) ?? [])
|
||||
.map(async (item: any) => {
|
||||
delete item.id;
|
||||
const employeeTempPosMaster = Object.assign(new EmployeeTempPosMaster(), item);
|
||||
employeeTempPosMaster.positions = [];
|
||||
employeeTempPosMaster.orgRevisionId = orgRevisionDraft.id;
|
||||
employeeTempPosMaster.orgRootId = matchedOrgRoot?.id ?? null;
|
||||
employeeTempPosMaster.createdUserId = "";
|
||||
employeeTempPosMaster.createdFullName = "System Administrator";
|
||||
employeeTempPosMaster.createdAt = new Date();
|
||||
employeeTempPosMaster.lastUpdateUserId = "";
|
||||
employeeTempPosMaster.lastUpdateFullName = "System Administrator";
|
||||
employeeTempPosMaster.lastUpdatedAt = new Date();
|
||||
await repoEmployeeTempPosmaster.save(employeeTempPosMaster);
|
||||
|
||||
await Promise.all(
|
||||
item.positions.map(async (pos: any) => {
|
||||
delete pos.id;
|
||||
const employeePosition: EmployeePosition = Object.assign(
|
||||
new EmployeePosition(),
|
||||
pos,
|
||||
);
|
||||
employeePosition.posMasterTempId = employeeTempPosMaster.id;
|
||||
employeePosition.createdUserId = "";
|
||||
employeePosition.createdFullName = "System Administrator";
|
||||
employeePosition.createdAt = new Date();
|
||||
employeePosition.lastUpdateUserId = "";
|
||||
employeePosition.lastUpdateFullName = "System Administrator";
|
||||
employeePosition.lastUpdatedAt = new Date();
|
||||
await employeePositionRepository.save(employeePosition);
|
||||
}),
|
||||
);
|
||||
}),
|
||||
await cloneEmployeeNodeBatch(
|
||||
employeeTempPosMasterByNode.get(getNodeKey("root", dataId)) ?? [],
|
||||
repoEmployeeTempPosmaster,
|
||||
"posMasterTempId",
|
||||
{ orgRootId: matchedOrgRoot?.id ?? null },
|
||||
);
|
||||
|
||||
for (const x of orgChild1ByRoot.get(dataId) ?? []) {
|
||||
const data1Id = x.id;
|
||||
const matchedOrgChild1 = findMatchedNodeByAncestorDNA(orgChild1Current, x);
|
||||
await Promise.all(
|
||||
(employeePosMasterByNode.get(getNodeKey("child1", data1Id)) ?? [])
|
||||
.map(async (item: any) => {
|
||||
delete item.id;
|
||||
const employeePosMaster = Object.assign(new EmployeePosMaster(), item);
|
||||
employeePosMaster.positions = [];
|
||||
employeePosMaster.orgRevisionId = orgRevisionDraft.id;
|
||||
employeePosMaster.orgRootId = matchedOrgRoot?.id ?? null;
|
||||
employeePosMaster.orgChild1Id = matchedOrgChild1?.id ?? null;
|
||||
employeePosMaster.createdUserId = "";
|
||||
employeePosMaster.createdFullName = "System Administrator";
|
||||
employeePosMaster.createdAt = new Date();
|
||||
employeePosMaster.lastUpdateUserId = "";
|
||||
employeePosMaster.lastUpdateFullName = "System Administrator";
|
||||
employeePosMaster.lastUpdatedAt = new Date();
|
||||
await repoEmployeePosmaster.save(employeePosMaster);
|
||||
|
||||
await Promise.all(
|
||||
item.positions.map(async (pos: any) => {
|
||||
delete pos.id;
|
||||
const employeePosition: EmployeePosition = Object.assign(
|
||||
new EmployeePosition(),
|
||||
pos,
|
||||
);
|
||||
employeePosition.posMasterId = employeePosMaster.id;
|
||||
employeePosition.createdUserId = "";
|
||||
employeePosition.createdFullName = "System Administrator";
|
||||
employeePosition.createdAt = new Date();
|
||||
employeePosition.lastUpdateUserId = "";
|
||||
employeePosition.lastUpdateFullName = "System Administrator";
|
||||
employeePosition.lastUpdatedAt = new Date();
|
||||
await employeePositionRepository.save(employeePosition);
|
||||
}),
|
||||
);
|
||||
}),
|
||||
await cloneEmployeeNodeBatch(
|
||||
employeePosMasterByNode.get(getNodeKey("child1", data1Id)) ?? [],
|
||||
repoEmployeePosmaster,
|
||||
"posMasterId",
|
||||
{
|
||||
orgRootId: matchedOrgRoot?.id ?? null,
|
||||
orgChild1Id: matchedOrgChild1?.id ?? null,
|
||||
},
|
||||
);
|
||||
|
||||
await Promise.all(
|
||||
(employeeTempPosMasterByNode.get(getNodeKey("child1", data1Id)) ?? [])
|
||||
.map(async (item: any) => {
|
||||
delete item.id;
|
||||
const employeeTempPosMaster = Object.assign(new EmployeeTempPosMaster(), item);
|
||||
employeeTempPosMaster.positions = [];
|
||||
employeeTempPosMaster.orgRevisionId = orgRevisionDraft.id;
|
||||
employeeTempPosMaster.orgRootId = matchedOrgRoot?.id ?? null;
|
||||
employeeTempPosMaster.orgChild1Id = matchedOrgChild1?.id ?? null;
|
||||
employeeTempPosMaster.createdUserId = "";
|
||||
employeeTempPosMaster.createdFullName = "System Administrator";
|
||||
employeeTempPosMaster.createdAt = new Date();
|
||||
employeeTempPosMaster.lastUpdateUserId = "";
|
||||
employeeTempPosMaster.lastUpdateFullName = "System Administrator";
|
||||
employeeTempPosMaster.lastUpdatedAt = new Date();
|
||||
await repoEmployeeTempPosmaster.save(employeeTempPosMaster);
|
||||
|
||||
await Promise.all(
|
||||
item.positions.map(async (pos: any) => {
|
||||
delete pos.id;
|
||||
const employeePosition: EmployeePosition = Object.assign(
|
||||
new EmployeePosition(),
|
||||
pos,
|
||||
);
|
||||
employeePosition.posMasterTempId = employeeTempPosMaster.id;
|
||||
employeePosition.createdUserId = "";
|
||||
employeePosition.createdFullName = "System Administrator";
|
||||
employeePosition.createdAt = new Date();
|
||||
employeePosition.lastUpdateUserId = "";
|
||||
employeePosition.lastUpdateFullName = "System Administrator";
|
||||
employeePosition.lastUpdatedAt = new Date();
|
||||
await employeePositionRepository.save(employeePosition);
|
||||
}),
|
||||
);
|
||||
}),
|
||||
await cloneEmployeeNodeBatch(
|
||||
employeeTempPosMasterByNode.get(getNodeKey("child1", data1Id)) ?? [],
|
||||
repoEmployeeTempPosmaster,
|
||||
"posMasterTempId",
|
||||
{
|
||||
orgRootId: matchedOrgRoot?.id ?? null,
|
||||
orgChild1Id: matchedOrgChild1?.id ?? null,
|
||||
},
|
||||
);
|
||||
|
||||
for (const x of orgChild2ByChild1.get(data1Id) ?? []) {
|
||||
const data2Id = x.id;
|
||||
const matchedOrgChild2 = findMatchedNodeByAncestorDNA(orgChild2Current, x);
|
||||
await Promise.all(
|
||||
(employeePosMasterByNode.get(getNodeKey("child2", data2Id)) ?? [])
|
||||
.map(async (item: any) => {
|
||||
delete item.id;
|
||||
const employeePosMaster = Object.assign(new EmployeePosMaster(), item);
|
||||
employeePosMaster.positions = [];
|
||||
employeePosMaster.orgRevisionId = orgRevisionDraft.id;
|
||||
employeePosMaster.orgRootId = matchedOrgRoot?.id ?? null;
|
||||
employeePosMaster.orgChild1Id = matchedOrgChild1?.id ?? null;
|
||||
employeePosMaster.orgChild2Id = matchedOrgChild2?.id ?? null;
|
||||
employeePosMaster.createdUserId = "";
|
||||
employeePosMaster.createdFullName = "System Administrator";
|
||||
employeePosMaster.createdAt = new Date();
|
||||
employeePosMaster.lastUpdateUserId = "";
|
||||
employeePosMaster.lastUpdateFullName = "System Administrator";
|
||||
employeePosMaster.lastUpdatedAt = new Date();
|
||||
await repoEmployeePosmaster.save(employeePosMaster);
|
||||
|
||||
await Promise.all(
|
||||
item.positions.map(async (pos: any) => {
|
||||
delete pos.id;
|
||||
const employeePosition: EmployeePosition = Object.assign(
|
||||
new EmployeePosition(),
|
||||
pos,
|
||||
);
|
||||
employeePosition.posMasterId = employeePosMaster.id;
|
||||
employeePosition.createdUserId = "";
|
||||
employeePosition.createdFullName = "System Administrator";
|
||||
employeePosition.createdAt = new Date();
|
||||
employeePosition.lastUpdateUserId = "";
|
||||
employeePosition.lastUpdateFullName = "System Administrator";
|
||||
employeePosition.lastUpdatedAt = new Date();
|
||||
await employeePositionRepository.save(employeePosition);
|
||||
}),
|
||||
);
|
||||
}),
|
||||
await cloneEmployeeNodeBatch(
|
||||
employeePosMasterByNode.get(getNodeKey("child2", data2Id)) ?? [],
|
||||
repoEmployeePosmaster,
|
||||
"posMasterId",
|
||||
{
|
||||
orgRootId: matchedOrgRoot?.id ?? null,
|
||||
orgChild1Id: matchedOrgChild1?.id ?? null,
|
||||
orgChild2Id: matchedOrgChild2?.id ?? null,
|
||||
},
|
||||
);
|
||||
|
||||
await Promise.all(
|
||||
(employeeTempPosMasterByNode.get(getNodeKey("child2", data2Id)) ?? [])
|
||||
.map(async (item: any) => {
|
||||
delete item.id;
|
||||
const employeeTempPosMaster = Object.assign(new EmployeeTempPosMaster(), item);
|
||||
employeeTempPosMaster.positions = [];
|
||||
employeeTempPosMaster.orgRevisionId = orgRevisionDraft.id;
|
||||
employeeTempPosMaster.orgRootId = dataId;
|
||||
employeeTempPosMaster.orgChild1Id = data1Id;
|
||||
employeeTempPosMaster.orgChild2Id = data2Id;
|
||||
employeeTempPosMaster.createdUserId = "";
|
||||
employeeTempPosMaster.createdFullName = "System Administrator";
|
||||
employeeTempPosMaster.createdAt = new Date();
|
||||
employeeTempPosMaster.lastUpdateUserId = "";
|
||||
employeeTempPosMaster.lastUpdateFullName = "System Administrator";
|
||||
employeeTempPosMaster.lastUpdatedAt = new Date();
|
||||
await repoEmployeeTempPosmaster.save(employeeTempPosMaster);
|
||||
|
||||
await Promise.all(
|
||||
item.positions.map(async (pos: any) => {
|
||||
delete pos.id;
|
||||
const employeePosition: EmployeePosition = Object.assign(
|
||||
new EmployeePosition(),
|
||||
pos,
|
||||
);
|
||||
employeePosition.posMasterTempId = employeeTempPosMaster.id;
|
||||
employeePosition.createdUserId = "";
|
||||
employeePosition.createdFullName = "System Administrator";
|
||||
employeePosition.createdAt = new Date();
|
||||
employeePosition.lastUpdateUserId = "";
|
||||
employeePosition.lastUpdateFullName = "System Administrator";
|
||||
employeePosition.lastUpdatedAt = new Date();
|
||||
await employeePositionRepository.save(employeePosition);
|
||||
}),
|
||||
);
|
||||
}),
|
||||
await cloneEmployeeNodeBatch(
|
||||
employeeTempPosMasterByNode.get(getNodeKey("child2", data2Id)) ?? [],
|
||||
repoEmployeeTempPosmaster,
|
||||
"posMasterTempId",
|
||||
{
|
||||
orgRootId: dataId,
|
||||
orgChild1Id: data1Id,
|
||||
orgChild2Id: data2Id,
|
||||
},
|
||||
);
|
||||
|
||||
for (const x of orgChild3ByChild2.get(data2Id) ?? []) {
|
||||
const data3Id = x.id;
|
||||
const matchedOrgChild3 = findMatchedNodeByAncestorDNA(orgChild3Current, x);
|
||||
await Promise.all(
|
||||
(employeePosMasterByNode.get(getNodeKey("child3", data3Id)) ?? [])
|
||||
.map(async (item: any) => {
|
||||
delete item.id;
|
||||
const employeePosMaster = Object.assign(new EmployeePosMaster(), item);
|
||||
employeePosMaster.positions = [];
|
||||
employeePosMaster.orgRevisionId = orgRevisionDraft.id;
|
||||
employeePosMaster.orgRootId = matchedOrgRoot?.id ?? null;
|
||||
employeePosMaster.orgChild1Id = matchedOrgChild1?.id ?? null;
|
||||
employeePosMaster.orgChild2Id = matchedOrgChild2?.id ?? null;
|
||||
employeePosMaster.orgChild3Id = matchedOrgChild3?.id ?? null;
|
||||
employeePosMaster.createdUserId = "";
|
||||
employeePosMaster.createdFullName = "System Administrator";
|
||||
employeePosMaster.createdAt = new Date();
|
||||
employeePosMaster.lastUpdateUserId = "";
|
||||
employeePosMaster.lastUpdateFullName = "System Administrator";
|
||||
employeePosMaster.lastUpdatedAt = new Date();
|
||||
await repoEmployeePosmaster.save(employeePosMaster);
|
||||
|
||||
await Promise.all(
|
||||
item.positions.map(async (pos: any) => {
|
||||
delete pos.id;
|
||||
const employeePosition: EmployeePosition = Object.assign(
|
||||
new EmployeePosition(),
|
||||
pos,
|
||||
);
|
||||
employeePosition.posMasterId = employeePosMaster.id;
|
||||
employeePosition.createdUserId = "";
|
||||
employeePosition.createdFullName = "System Administrator";
|
||||
employeePosition.createdAt = new Date();
|
||||
employeePosition.lastUpdateUserId = "";
|
||||
employeePosition.lastUpdateFullName = "System Administrator";
|
||||
employeePosition.lastUpdatedAt = new Date();
|
||||
await employeePositionRepository.save(employeePosition);
|
||||
}),
|
||||
);
|
||||
}),
|
||||
await cloneEmployeeNodeBatch(
|
||||
employeePosMasterByNode.get(getNodeKey("child3", data3Id)) ?? [],
|
||||
repoEmployeePosmaster,
|
||||
"posMasterId",
|
||||
{
|
||||
orgRootId: matchedOrgRoot?.id ?? null,
|
||||
orgChild1Id: matchedOrgChild1?.id ?? null,
|
||||
orgChild2Id: matchedOrgChild2?.id ?? null,
|
||||
orgChild3Id: matchedOrgChild3?.id ?? null,
|
||||
},
|
||||
);
|
||||
|
||||
await Promise.all(
|
||||
(employeeTempPosMasterByNode.get(getNodeKey("child3", data3Id)) ?? [])
|
||||
.map(async (item: any) => {
|
||||
delete item.id;
|
||||
const employeeTempPosMaster = Object.assign(new EmployeeTempPosMaster(), item);
|
||||
employeeTempPosMaster.positions = [];
|
||||
employeeTempPosMaster.orgRevisionId = orgRevisionDraft.id;
|
||||
employeeTempPosMaster.orgRootId = matchedOrgRoot?.id ?? null;
|
||||
employeeTempPosMaster.orgChild1Id = matchedOrgChild1?.id ?? null;
|
||||
employeeTempPosMaster.orgChild2Id = matchedOrgChild2?.id ?? null;
|
||||
employeeTempPosMaster.orgChild3Id = matchedOrgChild3?.id ?? null;
|
||||
employeeTempPosMaster.createdUserId = "";
|
||||
employeeTempPosMaster.createdFullName = "System Administrator";
|
||||
employeeTempPosMaster.createdAt = new Date();
|
||||
employeeTempPosMaster.lastUpdateUserId = "";
|
||||
employeeTempPosMaster.lastUpdateFullName = "System Administrator";
|
||||
employeeTempPosMaster.lastUpdatedAt = new Date();
|
||||
await repoEmployeeTempPosmaster.save(employeeTempPosMaster);
|
||||
|
||||
await Promise.all(
|
||||
item.positions.map(async (pos: any) => {
|
||||
delete pos.id;
|
||||
const employeePosition: EmployeePosition = Object.assign(
|
||||
new EmployeePosition(),
|
||||
pos,
|
||||
);
|
||||
employeePosition.posMasterTempId = employeeTempPosMaster.id;
|
||||
employeePosition.createdUserId = "";
|
||||
employeePosition.createdFullName = "System Administrator";
|
||||
employeePosition.createdAt = new Date();
|
||||
employeePosition.lastUpdateUserId = "";
|
||||
employeePosition.lastUpdateFullName = "System Administrator";
|
||||
employeePosition.lastUpdatedAt = new Date();
|
||||
await employeePositionRepository.save(employeePosition);
|
||||
}),
|
||||
);
|
||||
}),
|
||||
await cloneEmployeeNodeBatch(
|
||||
employeeTempPosMasterByNode.get(getNodeKey("child3", data3Id)) ?? [],
|
||||
repoEmployeeTempPosmaster,
|
||||
"posMasterTempId",
|
||||
{
|
||||
orgRootId: matchedOrgRoot?.id ?? null,
|
||||
orgChild1Id: matchedOrgChild1?.id ?? null,
|
||||
orgChild2Id: matchedOrgChild2?.id ?? null,
|
||||
orgChild3Id: matchedOrgChild3?.id ?? null,
|
||||
},
|
||||
);
|
||||
|
||||
for (const x of orgChild4ByChild3.get(data3Id) ?? []) {
|
||||
const data4Id = x.id;
|
||||
const matchedOrgChild4 = findMatchedNodeByAncestorDNA(orgChild4Current, x);
|
||||
await Promise.all(
|
||||
(employeePosMasterByNode.get(getNodeKey("child4", data4Id)) ?? [])
|
||||
.map(async (item: any) => {
|
||||
delete item.id;
|
||||
const employeePosMaster = Object.assign(new EmployeePosMaster(), item);
|
||||
employeePosMaster.positions = [];
|
||||
employeePosMaster.orgRevisionId = orgRevisionDraft.id;
|
||||
employeePosMaster.orgRootId = matchedOrgRoot?.id ?? null;
|
||||
employeePosMaster.orgChild1Id = matchedOrgChild1?.id ?? null;
|
||||
employeePosMaster.orgChild2Id = matchedOrgChild2?.id ?? null;
|
||||
employeePosMaster.orgChild3Id = matchedOrgChild3?.id ?? null;
|
||||
employeePosMaster.orgChild4Id = matchedOrgChild4?.id ?? null;
|
||||
employeePosMaster.createdUserId = "";
|
||||
employeePosMaster.createdFullName = "System Administrator";
|
||||
employeePosMaster.createdAt = new Date();
|
||||
employeePosMaster.lastUpdateUserId = "";
|
||||
employeePosMaster.lastUpdateFullName = "System Administrator";
|
||||
employeePosMaster.lastUpdatedAt = new Date();
|
||||
await repoEmployeePosmaster.save(employeePosMaster);
|
||||
|
||||
await Promise.all(
|
||||
item.positions.map(async (pos: any) => {
|
||||
delete pos.id;
|
||||
const employeePosition: EmployeePosition = Object.assign(
|
||||
new EmployeePosition(),
|
||||
pos,
|
||||
);
|
||||
employeePosition.posMasterId = employeePosMaster.id;
|
||||
employeePosition.createdUserId = "";
|
||||
employeePosition.createdFullName = "System Administrator";
|
||||
employeePosition.createdAt = new Date();
|
||||
employeePosition.lastUpdateUserId = "";
|
||||
employeePosition.lastUpdateFullName = "System Administrator";
|
||||
employeePosition.lastUpdatedAt = new Date();
|
||||
await employeePositionRepository.save(employeePosition);
|
||||
}),
|
||||
);
|
||||
}),
|
||||
await cloneEmployeeNodeBatch(
|
||||
employeePosMasterByNode.get(getNodeKey("child4", data4Id)) ?? [],
|
||||
repoEmployeePosmaster,
|
||||
"posMasterId",
|
||||
{
|
||||
orgRootId: matchedOrgRoot?.id ?? null,
|
||||
orgChild1Id: matchedOrgChild1?.id ?? null,
|
||||
orgChild2Id: matchedOrgChild2?.id ?? null,
|
||||
orgChild3Id: matchedOrgChild3?.id ?? null,
|
||||
orgChild4Id: matchedOrgChild4?.id ?? null,
|
||||
},
|
||||
);
|
||||
|
||||
await Promise.all(
|
||||
(employeeTempPosMasterByNode.get(getNodeKey("child4", data4Id)) ?? [])
|
||||
.map(async (item: any) => {
|
||||
delete item.id;
|
||||
const employeeTempPosMaster = Object.assign(
|
||||
new EmployeeTempPosMaster(),
|
||||
item,
|
||||
);
|
||||
employeeTempPosMaster.positions = [];
|
||||
employeeTempPosMaster.orgRevisionId = orgRevisionDraft.id;
|
||||
employeeTempPosMaster.orgRootId = matchedOrgRoot?.id ?? null;
|
||||
employeeTempPosMaster.orgChild1Id = matchedOrgChild1?.id ?? null;
|
||||
employeeTempPosMaster.orgChild2Id = matchedOrgChild2?.id ?? null;
|
||||
employeeTempPosMaster.orgChild3Id = matchedOrgChild3?.id ?? null;
|
||||
employeeTempPosMaster.orgChild4Id = matchedOrgChild4?.id ?? null;
|
||||
employeeTempPosMaster.createdUserId = "";
|
||||
employeeTempPosMaster.createdFullName = "System Administrator";
|
||||
employeeTempPosMaster.createdAt = new Date();
|
||||
employeeTempPosMaster.lastUpdateUserId = "";
|
||||
employeeTempPosMaster.lastUpdateFullName = "System Administrator";
|
||||
employeeTempPosMaster.lastUpdatedAt = new Date();
|
||||
await repoEmployeeTempPosmaster.save(employeeTempPosMaster);
|
||||
|
||||
await Promise.all(
|
||||
item.positions.map(async (pos: any) => {
|
||||
delete pos.id;
|
||||
const employeePosition: EmployeePosition = Object.assign(
|
||||
new EmployeePosition(),
|
||||
pos,
|
||||
);
|
||||
employeePosition.posMasterTempId = employeeTempPosMaster.id;
|
||||
employeePosition.createdUserId = "";
|
||||
employeePosition.createdFullName = "System Administrator";
|
||||
employeePosition.createdAt = new Date();
|
||||
employeePosition.lastUpdateUserId = "";
|
||||
employeePosition.lastUpdateFullName = "System Administrator";
|
||||
employeePosition.lastUpdatedAt = new Date();
|
||||
await employeePositionRepository.save(employeePosition);
|
||||
}),
|
||||
);
|
||||
}),
|
||||
await cloneEmployeeNodeBatch(
|
||||
employeeTempPosMasterByNode.get(getNodeKey("child4", data4Id)) ?? [],
|
||||
repoEmployeeTempPosmaster,
|
||||
"posMasterTempId",
|
||||
{
|
||||
orgRootId: matchedOrgRoot?.id ?? null,
|
||||
orgChild1Id: matchedOrgChild1?.id ?? null,
|
||||
orgChild2Id: matchedOrgChild2?.id ?? null,
|
||||
orgChild3Id: matchedOrgChild3?.id ?? null,
|
||||
orgChild4Id: matchedOrgChild4?.id ?? null,
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue