fix: save posMasterHistory null
All checks were successful
Build & Deploy on Dev / build (push) Successful in 1m19s

This commit is contained in:
Warunee Tamkoo 2026-02-12 14:06:07 +07:00
parent ed70999eac
commit 82ecf2cb81

View file

@ -7952,6 +7952,8 @@ export class OrganizationController extends Controller {
if (!orgRootDraft) return new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงสร้างร่าง"); if (!orgRootDraft) return new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงสร้างร่าง");
// 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() },
@ -8075,7 +8077,9 @@ export class OrganizationController extends Controller {
}); });
// Save history BEFORE clearing current_holderId // Save history BEFORE clearing current_holderId
const historyOps = posMastersToUpdate.map((pos) => ({ const historyOps = posMastersToUpdate
.filter((x) => x.orgRootId != orgRootCurrent?.id)
.map((pos) => ({
posMasterDnaId: pos.ancestorDNA, posMasterDnaId: pos.ancestorDNA,
profileId: null, profileId: null,
pm: null, pm: null,
@ -8151,10 +8155,22 @@ 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(draftPos.orgChild1Id ?? null, allMappings.orgChild1); const orgChild1Id = this.resolveOrgId(
const orgChild2Id = this.resolveOrgId(draftPos.orgChild2Id ?? null, allMappings.orgChild2); draftPos.orgChild1Id ?? null,
const orgChild3Id = this.resolveOrgId(draftPos.orgChild3Id ?? null, allMappings.orgChild3); allMappings.orgChild1,
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
@ -8258,6 +8274,9 @@ 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();