list org permission

This commit is contained in:
kittapath 2024-09-06 13:47:58 +07:00
parent 1a6c8826be
commit 2017557392

View file

@ -266,18 +266,20 @@ export class PermissionOrgController extends Controller {
IFNULL(current_holders.posMasterNo , '') IFNULL(current_holders.posMasterNo , '')
) LIKE :keyword`; ) LIKE :keyword`;
} }
const [record, total] = await this.profileRepository const [record, total] = await this.permissionOrgRepository
.createQueryBuilder("profile") .createQueryBuilder("permissionOrg")
.leftJoinAndSelect("profile.posLevel", "posLevel") .leftJoinAndSelect("permissionOrg.orgRootTree", "orgRootTree")
.leftJoinAndSelect("profile.posType", "posType") .leftJoinAndSelect("permissionOrg.profileTree", "profileTree")
.leftJoinAndSelect("profile.current_holders", "current_holders") .leftJoinAndSelect("profileTree.posLevel", "posLevel")
.leftJoinAndSelect("profileTree.posType", "posType")
.leftJoinAndSelect("profileTree.current_holders", "current_holders")
.leftJoinAndSelect("current_holders.positions", "positions") .leftJoinAndSelect("current_holders.positions", "positions")
.leftJoinAndSelect("current_holders.orgRoot", "orgRoot") .leftJoinAndSelect("current_holders.orgRoot", "orgRoot")
.leftJoinAndSelect("current_holders.orgChild1", "orgChild1") .leftJoinAndSelect("current_holders.orgChild1", "orgChild1")
.leftJoinAndSelect("current_holders.orgChild2", "orgChild2") .leftJoinAndSelect("current_holders.orgChild2", "orgChild2")
.leftJoinAndSelect("current_holders.orgChild3", "orgChild3") .leftJoinAndSelect("current_holders.orgChild3", "orgChild3")
.leftJoinAndSelect("current_holders.orgChild4", "orgChild4") .leftJoinAndSelect("current_holders.orgChild4", "orgChild4")
.andWhere(`profile.id IN (:...profiles)`, { .andWhere(`profileTree.id IN (:...profiles)`, {
profiles: profiles == null || profiles.length == 0 ? ["null"] : profiles, profiles: profiles == null || profiles.length == 0 ? ["null"] : profiles,
}) })
.andWhere( .andWhere(
@ -303,64 +305,81 @@ export class PermissionOrgController extends Controller {
const data = await Promise.all( const data = await Promise.all(
record.map((_data) => { record.map((_data) => {
const shortName = const shortName =
_data.current_holders.length == 0 _data.profileTree.current_holders.length == 0
? null ? null
: _data.current_holders.find((x) => x.orgRevisionId == findRevision.id) != null && : _data.profileTree.current_holders.find((x) => x.orgRevisionId == findRevision.id) !=
_data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild4 != null &&
null _data.profileTree.current_holders.find((x) => x.orgRevisionId == findRevision.id)
? `${_data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild4.orgChild4ShortName}${_data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.posMasterNo}` ?.orgChild4 != null
: _data.current_holders.find((x) => x.orgRevisionId == findRevision.id) != null && ? `${_data.profileTree.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild4.orgChild4ShortName}${_data.profileTree.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.posMasterNo}`
_data.current_holders.find((x) => x.orgRevisionId == findRevision.id) : _data.profileTree.current_holders.find((x) => x.orgRevisionId == findRevision.id) !=
null &&
_data.profileTree.current_holders.find((x) => x.orgRevisionId == findRevision.id)
?.orgChild3 != null ?.orgChild3 != null
? `${_data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild3.orgChild3ShortName}${_data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.posMasterNo}` ? `${_data.profileTree.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild3.orgChild3ShortName}${_data.profileTree.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.posMasterNo}`
: _data.current_holders.find((x) => x.orgRevisionId == findRevision.id) != null && : _data.profileTree.current_holders.find(
_data.current_holders.find((x) => x.orgRevisionId == findRevision.id) (x) => x.orgRevisionId == findRevision.id,
?.orgChild2 != null ) != null &&
? `${_data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild2.orgChild2ShortName}${_data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.posMasterNo}` _data.profileTree.current_holders.find(
: _data.current_holders.find((x) => x.orgRevisionId == findRevision.id) != null && (x) => x.orgRevisionId == findRevision.id,
_data.current_holders.find((x) => x.orgRevisionId == findRevision.id) )?.orgChild2 != null
?.orgChild1 != null ? `${_data.profileTree.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild2.orgChild2ShortName}${_data.profileTree.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.posMasterNo}`
? `${_data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild1.orgChild1ShortName}${_data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.posMasterNo}` : _data.profileTree.current_holders.find(
: _data.current_holders.find((x) => x.orgRevisionId == findRevision.id) != (x) => x.orgRevisionId == findRevision.id,
null && ) != null &&
_data.current_holders.find((x) => x.orgRevisionId == findRevision.id) _data.profileTree.current_holders.find(
?.orgRoot != null (x) => x.orgRevisionId == findRevision.id,
? `${_data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgRoot.orgRootShortName}${_data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.posMasterNo}` )?.orgChild1 != null
? `${_data.profileTree.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild1.orgChild1ShortName}${_data.profileTree.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.posMasterNo}`
: _data.profileTree.current_holders.find(
(x) => x.orgRevisionId == findRevision.id,
) != null &&
_data.profileTree.current_holders.find(
(x) => x.orgRevisionId == findRevision.id,
)?.orgRoot != null
? `${_data.profileTree.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgRoot.orgRootShortName}${_data.profileTree.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.posMasterNo}`
: null; : null;
const root = const root =
_data.current_holders.length == 0 || _data.profileTree.current_holders.length == 0 ||
(_data.current_holders.find((x) => x.orgRevisionId == findRevision.id) != null && (_data.profileTree.current_holders.find((x) => x.orgRevisionId == findRevision.id) !=
_data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgRoot == null) null &&
_data.profileTree.current_holders.find((x) => x.orgRevisionId == findRevision.id)
?.orgRoot == null)
? null ? null
: _data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgRoot; : _data.profileTree.current_holders.find((x) => x.orgRevisionId == findRevision.id)
?.orgRoot;
const child1 = const child1 =
_data.current_holders == null || _data.profileTree.current_holders == null ||
_data.current_holders.length == 0 || _data.profileTree.current_holders.length == 0 ||
_data.current_holders.find((x) => x.orgRevisionId == findRevision.id) == null _data.profileTree.current_holders.find((x) => x.orgRevisionId == findRevision.id) == null
? null ? null
: _data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild1; : _data.profileTree.current_holders.find((x) => x.orgRevisionId == findRevision.id)
?.orgChild1;
const child2 = const child2 =
_data.current_holders == null || _data.profileTree.current_holders == null ||
_data.current_holders.length == 0 || _data.profileTree.current_holders.length == 0 ||
_data.current_holders.find((x) => x.orgRevisionId == findRevision.id) == null _data.profileTree.current_holders.find((x) => x.orgRevisionId == findRevision.id) == null
? null ? null
: _data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild2; : _data.profileTree.current_holders.find((x) => x.orgRevisionId == findRevision.id)
?.orgChild2;
const child3 = const child3 =
_data.current_holders == null || _data.profileTree.current_holders == null ||
_data.current_holders.length == 0 || _data.profileTree.current_holders.length == 0 ||
_data.current_holders.find((x) => x.orgRevisionId == findRevision.id) == null _data.profileTree.current_holders.find((x) => x.orgRevisionId == findRevision.id) == null
? null ? null
: _data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild3; : _data.profileTree.current_holders.find((x) => x.orgRevisionId == findRevision.id)
?.orgChild3;
const child4 = const child4 =
_data.current_holders == null || _data.profileTree.current_holders == null ||
_data.current_holders.length == 0 || _data.profileTree.current_holders.length == 0 ||
_data.current_holders.find((x) => x.orgRevisionId == findRevision.id) == null _data.profileTree.current_holders.find((x) => x.orgRevisionId == findRevision.id) == null
? null ? null
: _data.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild4; : _data.profileTree.current_holders.find((x) => x.orgRevisionId == findRevision.id)
?.orgChild4;
let _child1 = child1 == null ? "" : `${child1.orgChild1Name}/`; let _child1 = child1 == null ? "" : `${child1.orgChild1Name}/`;
let _child2 = child2 == null ? "" : `${child2.orgChild2Name}/`; let _child2 = child2 == null ? "" : `${child2.orgChild2Name}/`;
@ -368,18 +387,20 @@ export class PermissionOrgController extends Controller {
let _child4 = child4 == null ? "" : `${child4.orgChild4Name}/`; let _child4 = child4 == null ? "" : `${child4.orgChild4Name}/`;
return { return {
id: _data.id, id: _data.profileTree.id,
avatar: _data.avatar, avatar: _data.profileTree.avatar,
avatarName: _data.avatarName, avatarName: _data.profileTree.avatarName,
prefix: _data.prefix, prefix: _data.profileTree.prefix,
rank: _data.rank, rank: _data.profileTree.rank,
firstName: _data.firstName, firstName: _data.profileTree.firstName,
lastName: _data.lastName, lastName: _data.profileTree.lastName,
org: `${_child4}${_child3}${_child2}${_child1}${root?.orgRootName ?? ""}`, org: `${_child4}${_child3}${_child2}${_child1}${root?.orgRootName ?? ""}`,
orgNew: _data.orgRootTree.orgRootName,
posNo: shortName, posNo: shortName,
position: _data.position, position: _data.profileTree.position,
posType: _data.posType == null ? null : _data.posType.posTypeName, posType: _data.profileTree.posType == null ? null : _data.profileTree.posType.posTypeName,
posLevel: _data.posLevel == null ? null : _data.posLevel.posLevelName, posLevel:
_data.profileTree.posLevel == null ? null : _data.profileTree.posLevel.posLevelName,
}; };
}), }),
); );