This commit is contained in:
parent
d916334537
commit
22fd9152bf
1 changed files with 306 additions and 308 deletions
|
|
@ -7932,7 +7932,7 @@ export class OrganizationController extends Controller {
|
||||||
const currentRevisionId = currentRevision.id;
|
const currentRevisionId = currentRevision.id;
|
||||||
|
|
||||||
// ตรวจสอบว่ามี rootDnaId ในโครงสร้างร่าง และในโครงสร้างปัจจุบันหรือไม่
|
// ตรวจสอบว่ามี rootDnaId ในโครงสร้างร่าง และในโครงสร้างปัจจุบันหรือไม่
|
||||||
const [orgRootDraft, orgRootCurrent] = await Promise.all([
|
let [orgRootDraft, orgRootCurrent] = await Promise.all([
|
||||||
this.orgRootRepository.findOne({
|
this.orgRootRepository.findOne({
|
||||||
where: {
|
where: {
|
||||||
ancestorDNA: rootDnaId,
|
ancestorDNA: rootDnaId,
|
||||||
|
|
@ -7950,10 +7950,23 @@ export class OrganizationController extends Controller {
|
||||||
]);
|
]);
|
||||||
|
|
||||||
if (!orgRootDraft) return new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงสร้างร่าง");
|
if (!orgRootDraft) return new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงสร้างร่าง");
|
||||||
|
|
||||||
|
// if current record not found, create new one
|
||||||
|
if (!orgRootCurrent) {
|
||||||
|
// Create new current record using draft's ID
|
||||||
|
const newCurrentRoot = queryRunner.manager.create(OrgRoot, {
|
||||||
|
...orgRootDraft,
|
||||||
|
id: undefined, // Let database generate new ID
|
||||||
|
orgRevisionId: currentRevisionId, // Change to current revision
|
||||||
|
});
|
||||||
|
|
||||||
|
const savedRoot = await queryRunner.manager.save(OrgRoot, newCurrentRoot);
|
||||||
|
orgRootCurrent = savedRoot; // Use saved record for sync
|
||||||
|
}
|
||||||
|
|
||||||
// Part 1: Differential sync of organization structure (bottom-up)
|
// Part 1: Differential sync of organization structure (bottom-up)
|
||||||
// Build mapping incrementally as we process each level
|
// Build mapping incrementally as we process each level
|
||||||
|
|
||||||
if (orgRootCurrent) {
|
|
||||||
const allMappings: AllOrgMappings = {
|
const allMappings: AllOrgMappings = {
|
||||||
orgRoot: { byAncestorDNA: new Map(), byDraftId: new Map() },
|
orgRoot: { byAncestorDNA: new Map(), byDraftId: new Map() },
|
||||||
orgChild1: { byAncestorDNA: new Map(), byDraftId: new Map() },
|
orgChild1: { byAncestorDNA: new Map(), byDraftId: new Map() },
|
||||||
|
|
@ -8155,22 +8168,10 @@ export class OrganizationController extends Controller {
|
||||||
|
|
||||||
// Map organization IDs using new IDs from Part 1
|
// Map organization IDs using new IDs from Part 1
|
||||||
const orgRootId = this.resolveOrgId(draftPos.orgRootId ?? null, allMappings.orgRoot);
|
const orgRootId = this.resolveOrgId(draftPos.orgRootId ?? null, allMappings.orgRoot);
|
||||||
const orgChild1Id = this.resolveOrgId(
|
const orgChild1Id = this.resolveOrgId(draftPos.orgChild1Id ?? null, allMappings.orgChild1);
|
||||||
draftPos.orgChild1Id ?? null,
|
const orgChild2Id = this.resolveOrgId(draftPos.orgChild2Id ?? null, allMappings.orgChild2);
|
||||||
allMappings.orgChild1,
|
const orgChild3Id = this.resolveOrgId(draftPos.orgChild3Id ?? null, allMappings.orgChild3);
|
||||||
);
|
const orgChild4Id = this.resolveOrgId(draftPos.orgChild4Id ?? null, allMappings.orgChild4);
|
||||||
const orgChild2Id = this.resolveOrgId(
|
|
||||||
draftPos.orgChild2Id ?? null,
|
|
||||||
allMappings.orgChild2,
|
|
||||||
);
|
|
||||||
const orgChild3Id = this.resolveOrgId(
|
|
||||||
draftPos.orgChild3Id ?? null,
|
|
||||||
allMappings.orgChild3,
|
|
||||||
);
|
|
||||||
const orgChild4Id = this.resolveOrgId(
|
|
||||||
draftPos.orgChild4Id ?? null,
|
|
||||||
allMappings.orgChild4,
|
|
||||||
);
|
|
||||||
|
|
||||||
if (current) {
|
if (current) {
|
||||||
// UPDATE existing position
|
// UPDATE existing position
|
||||||
|
|
@ -8274,9 +8275,6 @@ export class OrganizationController extends Controller {
|
||||||
|
|
||||||
await queryRunner.commitTransaction();
|
await queryRunner.commitTransaction();
|
||||||
return new HttpSuccess(summary);
|
return new HttpSuccess(summary);
|
||||||
}
|
|
||||||
|
|
||||||
return new HttpSuccess({});
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Error moving draft to current:", error);
|
console.error("Error moving draft to current:", error);
|
||||||
await queryRunner.rollbackTransaction();
|
await queryRunner.rollbackTransaction();
|
||||||
|
|
@ -8465,7 +8463,7 @@ export class OrganizationController extends Controller {
|
||||||
for (const draft of toInsert) {
|
for (const draft of toInsert) {
|
||||||
const newNode: any = queryRunner.manager.create(entityClass, {
|
const newNode: any = queryRunner.manager.create(entityClass, {
|
||||||
...draft,
|
...draft,
|
||||||
id: undefined,
|
id: draft.id,
|
||||||
orgRevisionId: currentRevisionId,
|
orgRevisionId: currentRevisionId,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue