diff --git a/src/controllers/OrganizationDotnetController.ts b/src/controllers/OrganizationDotnetController.ts index a1ac4736..ae5129b6 100644 --- a/src/controllers/OrganizationDotnetController.ts +++ b/src/controllers/OrganizationDotnetController.ts @@ -4121,19 +4121,39 @@ export class OrganizationDotnetController extends Controller { if (body.role === "OWNER" || body.role === "CHILD") { switch (node) { case 0: - typeCondition = { orgRootId: body.nodeId }; + typeCondition = { + orgRoot: { + ancestorDNA: body.nodeId + } + }; break; case 1: - typeCondition = { orgChild1Id: body.nodeId }; + typeCondition = { + orgChild1: { + ancestorDNA: body.nodeId + } + }; break; case 2: - typeCondition = { orgChild2Id: body.nodeId }; + typeCondition = { + orgChild2: { + ancestorDNA: body.nodeId + } + }; break; case 3: - typeCondition = { orgChild3Id: body.nodeId }; + typeCondition = { + orgChild3: { + ancestorDNA: body.nodeId + } + }; break; case 4: - typeCondition = { orgChild4Id: body.nodeId }; + typeCondition = { + orgChild4: { + ancestorDNA: body.nodeId + } + }; break; case null: typeCondition = {}; @@ -4150,26 +4170,41 @@ export class OrganizationDotnetController extends Controller { switch (node) { case 0: typeCondition = { - orgRootId: body.nodeId, - orgChild1Id: IsNull(), + orgRoot: { + ancestorDNA: body.nodeId + }, + orgChild1: IsNull() }; break; case 1: typeCondition = { - orgChild1Id: body.nodeId, - orgChild2Id: IsNull(), + orgChild1: { + ancestorDNA: body.nodeId + }, + orgChild2: IsNull() }; break; case 2: typeCondition = { - orgChild2Id: body.nodeId, - orgChild3Id: IsNull(), + orgChild2: { + ancestorDNA: body.nodeId + }, + orgChild3: IsNull() }; break; case 3: typeCondition = { - orgChild3Id: body.nodeId, - orgChild4Id: IsNull(), + orgChild3: { + ancestorDNA: body.nodeId + }, + orgChild4: IsNull() + }; + break; + case 4: + typeCondition = { + orgChild4: { + ancestorDNA: body.nodeId + }, }; break; default: @@ -4211,7 +4246,7 @@ export class OrganizationDotnetController extends Controller { }); } let findRevision = await this.orgRevisionRepo.findOne({ - where: { orgRevisionIsCurrent: true }, + where: { orgRevisionIsCurrent: true, orgRevisionIsDraft: false }, }); if (body.revisionId) { @@ -4221,7 +4256,7 @@ export class OrganizationDotnetController extends Controller { } const profile_ = await Promise.all( - profile.map((item: Profile) => { + profile.map(async(item: Profile) => { const shortName = item.current_holders.length == 0 ? null @@ -4250,17 +4285,25 @@ export class OrganizationDotnetController extends Controller { const Oc = item.current_holders.length == 0 ? null - : body.node == 4 && item.current_holders[0].orgChild4 != null + : (node == 4 || node == null) && item.current_holders[0].orgChild4 != null ? `${item.current_holders[0].orgChild4.orgChild4Name}/${item.current_holders[0].orgChild3.orgChild3Name}/${item.current_holders[0].orgChild2.orgChild2Name}/${item.current_holders[0].orgChild1.orgChild1Name}/${item.current_holders[0].orgRoot.orgRootName}` - : body.node == 3 && item.current_holders[0].orgChild3 != null + : (node == 3 || node == null) && item.current_holders[0].orgChild3 != null ? `${item.current_holders[0].orgChild3.orgChild3Name}/${item.current_holders[0].orgChild2.orgChild2Name}/${item.current_holders[0].orgChild1.orgChild1Name}/${item.current_holders[0].orgRoot.orgRootName}` - : body.node == 2 && item.current_holders[0].orgChild2 != null + : (node == 2 || node == null) && item.current_holders[0].orgChild2 != null ? `${item.current_holders[0].orgChild2.orgChild2Name}/${item.current_holders[0].orgChild1.orgChild1Name}/${item.current_holders[0].orgRoot.orgRootName}` - : body.node == 1 && item.current_holders[0].orgChild1 != null + : (node == 1 || node == null) && item.current_holders[0].orgChild1 != null ? `${item.current_holders[0].orgChild1.orgChild1Name}/${item.current_holders[0].orgRoot.orgRootName}` - : body.node == 0 && item.current_holders[0].orgRoot != null + : (node == 0 || node == null) && item.current_holders[0].orgRoot != null ? `${item.current_holders[0].orgRoot.orgRootName}` : null; + + let _posMaster = await this.posMasterRepository.findOne({ + where: { + orgRevisionId: findRevision?.id, + current_holderId: item.id + } + }); + return { id: item.id, prefix: item.prefix, @@ -4273,6 +4316,11 @@ export class OrganizationDotnetController extends Controller { positionLevel: item.posLevel?.posLevelName ?? null, positionType: item.posType?.posTypeName ?? null, oc: Oc, + orgRootId: _posMaster?.orgRootId, + orgChild1Id: _posMaster?.orgChild1Id, + orgChild2Id: _posMaster?.orgChild2Id, + orgChild3Id: _posMaster?.orgChild3Id, + orgChild4Id: _posMaster?.orgChild4Id }; }), );