diff --git a/src/controllers/PositionController.ts b/src/controllers/PositionController.ts index ecac4071..30452ae2 100644 --- a/src/controllers/PositionController.ts +++ b/src/controllers/PositionController.ts @@ -1514,11 +1514,6 @@ export class PositionController extends Controller { let maxPosMasterOrder = Math.max(...allLastPosMasterNo.map((pos) => pos.posMasterOrder), 0); posMasters.forEach(async (posMaster: any) => { - posMaster.orgRootId = null; - posMaster.orgChild1Id = null; - posMaster.orgChild2Id = null; - posMaster.orgChild3Id = null; - posMaster.orgChild4Id = null; let change = true; if (requestBody.type == 0) { @@ -1526,9 +1521,20 @@ export class PositionController extends Controller { where: { id: requestBody.id }, }); if (org != null) { - if (posMaster.orgRootId == org.id) change = false; + if ( + posMaster.orgRootId == org.id && + posMaster.orgChild1Id == null && + posMaster.orgChild2Id == null && + posMaster.orgChild3Id == null && + posMaster.orgChild4Id == null + ) + change = false; posMaster.orgRootId = org.id; posMaster.orgRevisionId = org.orgRevisionId; + posMaster.orgChild1Id = null; + posMaster.orgChild2Id = null; + posMaster.orgChild3Id = null; + posMaster.orgChild4Id = null; } } if (requestBody.type == 1) { @@ -1536,10 +1542,19 @@ export class PositionController extends Controller { where: { id: requestBody.id }, }); if (org != null) { - if (posMaster.orgChild1Id == org.id) change = false; + if ( + posMaster.orgChild1Id == org.id && + posMaster.orgChild2Id == null && + posMaster.orgChild3Id == null && + posMaster.orgChild4Id == null + ) + change = false; posMaster.orgRootId = org.orgRootId; posMaster.orgChild1Id = org.id; posMaster.orgRevisionId = org.orgRevisionId; + posMaster.orgChild2Id = null; + posMaster.orgChild3Id = null; + posMaster.orgChild4Id = null; } } if (requestBody.type == 2) { @@ -1547,11 +1562,18 @@ export class PositionController extends Controller { where: { id: requestBody.id }, }); if (org != null) { - if (posMaster.orgChild2Id == org.id) change = false; + if ( + posMaster.orgChild2Id == org.id && + posMaster.orgChild3Id == null && + posMaster.orgChild4Id == null + ) + change = false; posMaster.orgRootId = org.orgRootId; posMaster.orgChild1Id = org.orgChild1Id; posMaster.orgChild2Id = org.id; posMaster.orgRevisionId = org.orgRevisionId; + posMaster.orgChild3Id = null; + posMaster.orgChild4Id = null; } } if (requestBody.type == 3) { @@ -1559,12 +1581,13 @@ export class PositionController extends Controller { where: { id: requestBody.id }, }); if (org != null) { - if (posMaster.orgChild3Id == org.id) change = false; + if (posMaster.orgChild3Id == org.id && posMaster.orgChild4Id == null) change = false; posMaster.orgRootId = org.orgRootId; posMaster.orgChild1Id = org.orgChild1Id; posMaster.orgChild2Id = org.orgChild2Id; posMaster.orgChild3Id = org.id; posMaster.orgRevisionId = org.orgRevisionId; + posMaster.orgChild4Id = null; } } if (requestBody.type == 4) { @@ -1572,9 +1595,7 @@ export class PositionController extends Controller { where: { id: requestBody.id }, }); if (org != null) { - if (posMaster.orgChild4Id == org.id) { - change = false; - } + if (posMaster.orgChild4Id == org.id) change = false; posMaster.orgRootId = org.orgRootId; posMaster.orgChild1Id = org.orgChild1Id; posMaster.orgChild2Id = org.orgChild2Id;