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, ancestorDNA: rootDnaId,
orgRevisionId: drafRevisionId, orgRevisionId: drafRevisionId,
}, },
select: ["id"], // select: ["id"],
}), }),
this.orgRootRepository.findOne({ this.orgRootRepository.findOne({
where: { where: {
@ -7981,7 +7981,22 @@ export class OrganizationController extends Controller {
// Process from top (Root) to bottom (Child4) to handle foreign key constraints // Process from top (Root) to bottom (Child4) to handle foreign key constraints
// OrgRoot (sync first - no parent dependencies) // OrgRoot (sync first - no parent dependencies)
const orgRootResult = await this.syncOrgLevel( // 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, queryRunner,
OrgRoot, OrgRoot,
this.orgRootRepository, this.orgRootRepository,
@ -7991,6 +8006,7 @@ export class OrganizationController extends Controller {
orgRootDraft?.id, orgRootDraft?.id,
orgRootCurrent?.id, orgRootCurrent?.id,
); );
}
allMappings.orgRoot = orgRootResult.mapping; allMappings.orgRoot = orgRootResult.mapping;
orgSyncStats.orgRoot = orgRootResult.counts; orgSyncStats.orgRoot = orgRootResult.counts;