diff --git a/src/controllers/ProfileController.ts b/src/controllers/ProfileController.ts index 16a1d002..041027fb 100644 --- a/src/controllers/ProfileController.ts +++ b/src/controllers/ProfileController.ts @@ -306,7 +306,7 @@ export class ProfileController extends Controller { bloodGroup: null, posLevel: null, posType: null, - org: null + org: null, }, ], total: 1, @@ -444,32 +444,32 @@ export class ProfileController extends Controller { _data.current_holders.find((x) => x.orgRevisionId == findRevision.id) == null ? null : _data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild1; - + const child2 = _data.current_holders == null || _data.current_holders.length == 0 || _data.current_holders.find((x) => x.orgRevisionId == findRevision.id) == null ? null : _data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild2; - + const child3 = _data.current_holders == null || _data.current_holders.length == 0 || _data.current_holders.find((x) => x.orgRevisionId == findRevision.id) == null ? null : _data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild3; - + const child4 = _data.current_holders == null || _data.current_holders.length == 0 || _data.current_holders.find((x) => x.orgRevisionId == findRevision.id) == null ? null : _data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild4; - - let _child1 = child1 == null ? "" : `${child1.orgChild1Name}/` - let _child2 = child2 == null ? "" : `${child2.orgChild2Name}/` - let _child3 = child3 == null ? "" : `${child3.orgChild3Name}/` - let _child4 = child4 == null ? "" : `${child4.orgChild4Name}/` + + let _child1 = child1 == null ? "" : `${child1.orgChild1Name}/`; + let _child2 = child2 == null ? "" : `${child2.orgChild2Name}/`; + let _child3 = child3 == null ? "" : `${child3.orgChild3Name}/`; + let _child4 = child4 == null ? "" : `${child4.orgChild4Name}/`; return { id: _data.id, @@ -647,7 +647,7 @@ export class ProfileController extends Controller { throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบแบบร่างโครงสร้าง"); } - const _profile = { + const _profile: any = { profileId: profile.id, prefix: profile.prefix, rank: profile.rank, @@ -731,7 +731,26 @@ export class ProfileController extends Controller { ? null : profile.current_holders.find((x) => x.orgRevisionId == orgRevisionPublish.id)?.orgChild4 .orgChild4Name, + node: null, + nodeId: null, }; + + if (_profile.child4Id != null) { + _profile.node = 4; + _profile.nodeId = _profile.child4Id; + } else if (_profile.child3Id != null) { + _profile.node = 3; + _profile.nodeId = _profile.child3Id; + } else if (_profile.child2Id != null) { + _profile.node = 2; + _profile.nodeId = _profile.child2Id; + } else if (_profile.child1Id != null) { + _profile.node = 1; + _profile.nodeId = _profile.child1Id; + } else if (_profile.rootId != null) { + _profile.node = 0; + _profile.nodeId = _profile.rootId; + } return new HttpSuccess(_profile); }