From 2590054f9effb1a07069dc7d338443363844dd65 Mon Sep 17 00:00:00 2001 From: Kittapath Date: Mon, 4 Mar 2024 16:29:37 +0700 Subject: [PATCH] =?UTF-8?q?=E0=B9=81=E0=B8=81=E0=B9=89=E0=B8=9A=E0=B8=B1?= =?UTF-8?q?=E0=B8=84=E0=B8=A2=E0=B9=89=E0=B8=B2=E0=B8=A2=E0=B8=95=E0=B8=B3?= =?UTF-8?q?=E0=B9=81=E0=B8=AB=E0=B8=99=E0=B9=88=E0=B8=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/PositionController.ts | 45 ++++++++++++++++++++------- 1 file changed, 33 insertions(+), 12 deletions(-) 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;