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;
|
||||
|
||||
// ตรวจสอบว่ามี rootDnaId ในโครงสร้างร่าง และในโครงสร้างปัจจุบันหรือไม่
|
||||
const [orgRootDraft, orgRootCurrent] = await Promise.all([
|
||||
let [orgRootDraft, orgRootCurrent] = await Promise.all([
|
||||
this.orgRootRepository.findOne({
|
||||
where: {
|
||||
ancestorDNA: rootDnaId,
|
||||
|
|
@ -7950,10 +7950,23 @@ export class OrganizationController extends Controller {
|
|||
]);
|
||||
|
||||
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)
|
||||
// Build mapping incrementally as we process each level
|
||||
|
||||
if (orgRootCurrent) {
|
||||
const allMappings: AllOrgMappings = {
|
||||
orgRoot: { 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
|
||||
const orgRootId = this.resolveOrgId(draftPos.orgRootId ?? null, allMappings.orgRoot);
|
||||
const orgChild1Id = this.resolveOrgId(
|
||||
draftPos.orgChild1Id ?? null,
|
||||
allMappings.orgChild1,
|
||||
);
|
||||
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,
|
||||
);
|
||||
const orgChild1Id = this.resolveOrgId(draftPos.orgChild1Id ?? null, allMappings.orgChild1);
|
||||
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) {
|
||||
// UPDATE existing position
|
||||
|
|
@ -8274,9 +8275,6 @@ export class OrganizationController extends Controller {
|
|||
|
||||
await queryRunner.commitTransaction();
|
||||
return new HttpSuccess(summary);
|
||||
}
|
||||
|
||||
return new HttpSuccess({});
|
||||
} catch (error) {
|
||||
console.error("Error moving draft to current:", error);
|
||||
await queryRunner.rollbackTransaction();
|
||||
|
|
@ -8465,7 +8463,7 @@ export class OrganizationController extends Controller {
|
|||
for (const draft of toInsert) {
|
||||
const newNode: any = queryRunner.manager.create(entityClass, {
|
||||
...draft,
|
||||
id: undefined,
|
||||
id: draft.id,
|
||||
orgRevisionId: currentRevisionId,
|
||||
});
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue