fix: case clear position all in draft to public to current
All checks were successful
Build & Deploy on Dev / build (push) Successful in 1m34s
All checks were successful
Build & Deploy on Dev / build (push) Successful in 1m34s
This commit is contained in:
parent
92e20966d0
commit
8497e5df57
1 changed files with 61 additions and 11 deletions
|
|
@ -8294,6 +8294,15 @@ export class OrganizationController extends Controller {
|
|||
orgChild4: [...allMappings.orgChild4.byDraftId.keys()],
|
||||
};
|
||||
|
||||
// Get current organization IDs from the mappings (moved up for reuse)
|
||||
const currentOrgIds = {
|
||||
orgRoot: [...allMappings.orgRoot.byDraftId.values()],
|
||||
orgChild1: [...allMappings.orgChild1.byDraftId.values()],
|
||||
orgChild2: [...allMappings.orgChild2.byDraftId.values()],
|
||||
orgChild3: [...allMappings.orgChild3.byDraftId.values()],
|
||||
orgChild4: [...allMappings.orgChild4.byDraftId.values()],
|
||||
};
|
||||
|
||||
// Get draft positions that belong to any org under the rootDnaId
|
||||
const posMasterDraft = await this.posMasterRepository.find({
|
||||
where: [
|
||||
|
|
@ -8305,8 +8314,58 @@ export class OrganizationController extends Controller {
|
|||
],
|
||||
});
|
||||
|
||||
if (posMasterDraft.length <= 0)
|
||||
return new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลตำแหน่งในโครงสร้างร่าง");
|
||||
// Special case: If draft has no positions, delete all current positions
|
||||
if (posMasterDraft.length <= 0) {
|
||||
// Fetch current positions
|
||||
const posMasterCurrent = await this.posMasterRepository.find({
|
||||
where: [
|
||||
{ orgRevisionId: currentRevisionId, orgRootId: In(currentOrgIds.orgRoot) },
|
||||
{ orgRevisionId: currentRevisionId, orgChild1Id: In(currentOrgIds.orgChild1) },
|
||||
{ orgRevisionId: currentRevisionId, orgChild2Id: In(currentOrgIds.orgChild2) },
|
||||
{ orgRevisionId: currentRevisionId, orgChild3Id: In(currentOrgIds.orgChild3) },
|
||||
{ orgRevisionId: currentRevisionId, orgChild4Id: In(currentOrgIds.orgChild4) },
|
||||
],
|
||||
});
|
||||
|
||||
if (posMasterCurrent.length > 0) {
|
||||
const toDeleteIds = posMasterCurrent.map((p) => p.id);
|
||||
|
||||
// Cascade delete positions first
|
||||
await queryRunner.manager.delete(Position, { posMasterId: In(toDeleteIds) });
|
||||
|
||||
// Then delete posMaster records
|
||||
await queryRunner.manager.delete(PosMaster, toDeleteIds);
|
||||
|
||||
// Save history
|
||||
const deleteHistoryOps = posMasterCurrent.map((pos) => ({
|
||||
posMasterDnaId: pos.ancestorDNA,
|
||||
profileId: null,
|
||||
pm: null,
|
||||
}));
|
||||
await BatchSavePosMasterHistoryOfficer(queryRunner, deleteHistoryOps);
|
||||
}
|
||||
|
||||
// Build summary for this special case
|
||||
const summary = {
|
||||
message: "ย้ายโครงสร้างสำเร็จ",
|
||||
organization: {
|
||||
orgRoot: orgSyncStats.orgRoot,
|
||||
orgChild1: orgSyncStats.orgChild1,
|
||||
orgChild2: orgSyncStats.orgChild2,
|
||||
orgChild3: orgSyncStats.orgChild3,
|
||||
orgChild4: orgSyncStats.orgChild4,
|
||||
},
|
||||
positionMaster: {
|
||||
deleted: posMasterCurrent.length,
|
||||
updated: 0,
|
||||
inserted: 0,
|
||||
},
|
||||
position: { deleted: 0, updated: 0, inserted: 0 },
|
||||
};
|
||||
|
||||
await queryRunner.commitTransaction();
|
||||
return new HttpSuccess(summary);
|
||||
}
|
||||
|
||||
// Clear current_holderId for positions that will have new holders
|
||||
const nextHolderIds = posMasterDraft
|
||||
|
|
@ -8344,15 +8403,6 @@ export class OrganizationController extends Controller {
|
|||
}
|
||||
|
||||
// 2.2 Fetch current positions for comparison
|
||||
// Get current organization IDs from the mappings
|
||||
const currentOrgIds = {
|
||||
orgRoot: [...allMappings.orgRoot.byDraftId.values()],
|
||||
orgChild1: [...allMappings.orgChild1.byDraftId.values()],
|
||||
orgChild2: [...allMappings.orgChild2.byDraftId.values()],
|
||||
orgChild3: [...allMappings.orgChild3.byDraftId.values()],
|
||||
orgChild4: [...allMappings.orgChild4.byDraftId.values()],
|
||||
};
|
||||
|
||||
const posMasterCurrent = await this.posMasterRepository.find({
|
||||
where: [
|
||||
{ orgRevisionId: currentRevisionId, orgRootId: In(currentOrgIds.orgRoot) },
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue