fix script

This commit is contained in:
Warunee Tamkoo 2026-02-12 18:06:46 +07:00
parent 22fd9152bf
commit 0f4bee4489

View file

@ -7938,7 +7938,7 @@ export class OrganizationController extends Controller {
ancestorDNA: rootDnaId,
orgRevisionId: drafRevisionId,
},
select: ["id"],
// select: ["id"],
}),
this.orgRootRepository.findOne({
where: {
@ -7981,16 +7981,32 @@ export class OrganizationController extends Controller {
// Process from top (Root) to bottom (Child4) to handle foreign key constraints
// OrgRoot (sync first - no parent dependencies)
const orgRootResult = await this.syncOrgLevel(
queryRunner,
OrgRoot,
this.orgRootRepository,
drafRevisionId,
currentRevisionId,
allMappings,
orgRootDraft?.id,
orgRootCurrent?.id,
);
// If we manually created orgRootCurrent, skip syncOrgLevel and set up mapping directly
// to avoid double insert (syncOrgLevel would try to insert again because IDs don't match)
let orgRootResult: { mapping: OrgIdMapping; counts: { deleted: number; updated: number; inserted: number } };
if (orgRootCurrent && orgRootDraft && orgRootCurrent.ancestorDNA === orgRootDraft.ancestorDNA) {
// Manually created - set up mapping directly
const rootMapping: OrgIdMapping = {
byAncestorDNA: new Map([[orgRootDraft.ancestorDNA, orgRootCurrent.id]]),
byDraftId: new Map([[orgRootDraft.id, orgRootCurrent.id]]),
};
orgRootResult = {
mapping: rootMapping,
counts: { deleted: 0, updated: 0, inserted: 1 }, // Count as insert since we created it
};
} else {
// Not manually created - use normal syncOrgLevel flow
orgRootResult = await this.syncOrgLevel(
queryRunner,
OrgRoot,
this.orgRootRepository,
drafRevisionId,
currentRevisionId,
allMappings,
orgRootDraft?.id,
orgRootCurrent?.id,
);
}
allMappings.orgRoot = orgRootResult.mapping;
orgSyncStats.orgRoot = orgRootResult.counts;