add admin parth เมนู กำหนดสิทธื์ permission
This commit is contained in:
parent
3c881d531c
commit
367fb7227e
2 changed files with 1168 additions and 4 deletions
|
|
@ -597,6 +597,813 @@ export class OrganizationController extends Controller {
|
|||
return new HttpSuccess(revision);
|
||||
}
|
||||
|
||||
/**
|
||||
* API รายละเอียดโครงสร้าง
|
||||
*
|
||||
* @summary ORG_023 - รายละเอียดโครงสร้าง (ADMIN Menu) #25
|
||||
*
|
||||
*/
|
||||
@Get("admin/{id}")
|
||||
async detailForAdmin(@Path() id: string, @Request() request: RequestWithUser) {
|
||||
// let _data: any = {
|
||||
// root: null,
|
||||
// child1: null,
|
||||
// child2: null,
|
||||
// child3: null,
|
||||
// child4: null,
|
||||
// };
|
||||
|
||||
const orgRevision = await this.orgRevisionRepository.findOne({ where: { id } });
|
||||
if (!orgRevision) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
}
|
||||
// let attrOwnership = null;
|
||||
if (
|
||||
orgRevision.orgRevisionIsDraft == true &&
|
||||
orgRevision.orgRevisionIsCurrent == false
|
||||
// attrOwnership == false
|
||||
) {
|
||||
const profile = await this.profileRepo.findOne({
|
||||
where: { keycloak: request.user.sub },
|
||||
// relations: ["permissionProfiles"],
|
||||
});
|
||||
if (!profile) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลผู้ใช้งานในทะเบียนประวัติ");
|
||||
}
|
||||
// _data = {
|
||||
// root: profile.permissionProfiles.map((x) => x.orgRootId),
|
||||
// child1: null,
|
||||
// child2: null,
|
||||
// child3: null,
|
||||
// child4: null,
|
||||
// };
|
||||
}
|
||||
|
||||
const orgRootData = await AppDataSource.getRepository(OrgRoot)
|
||||
.createQueryBuilder("orgRoot")
|
||||
.where("orgRoot.orgRevisionId = :id", { id })
|
||||
// .andWhere(
|
||||
// _data.root != undefined && _data.root != null
|
||||
// ? _data.root[0] != null
|
||||
// ? `orgRoot.id IN (:...node)`
|
||||
// : `orgRoot.id is null`
|
||||
// : "1=1",
|
||||
// {
|
||||
// node: _data.root,
|
||||
// },
|
||||
// )
|
||||
.select([
|
||||
"orgRoot.id",
|
||||
"orgRoot.orgRootName",
|
||||
"orgRoot.orgRootShortName",
|
||||
"orgRoot.orgRootCode",
|
||||
"orgRoot.orgRootOrder",
|
||||
"orgRoot.orgRootPhoneEx",
|
||||
"orgRoot.orgRootPhoneIn",
|
||||
"orgRoot.orgRootFax",
|
||||
"orgRoot.orgRevisionId",
|
||||
"orgRoot.orgRootRank",
|
||||
"orgRoot.orgRootRankSub",
|
||||
"orgRoot.responsibility",
|
||||
])
|
||||
.orderBy("orgRoot.orgRootOrder", "ASC")
|
||||
.getMany();
|
||||
const orgRootIds = orgRootData.map((orgRoot) => orgRoot.id) || null;
|
||||
const orgChild1Data =
|
||||
orgRootIds && orgRootIds.length > 0
|
||||
? await AppDataSource.getRepository(OrgChild1)
|
||||
.createQueryBuilder("orgChild1")
|
||||
.where("orgChild1.orgRootId IN (:...ids)", { ids: orgRootIds })
|
||||
// .andWhere(
|
||||
// _data.child1 != undefined && _data.child1 != null
|
||||
// ? _data.child1[0] != null
|
||||
// ? `orgChild1.id IN (:...node)`
|
||||
// : `orgChild1.id is null`
|
||||
// : "1=1",
|
||||
// {
|
||||
// node: _data.child1,
|
||||
// },
|
||||
// )
|
||||
.select([
|
||||
"orgChild1.id",
|
||||
"orgChild1.isOfficer",
|
||||
"orgChild1.orgChild1Name",
|
||||
"orgChild1.orgChild1ShortName",
|
||||
"orgChild1.orgChild1Code",
|
||||
"orgChild1.orgChild1Order",
|
||||
"orgChild1.orgChild1PhoneEx",
|
||||
"orgChild1.orgChild1PhoneIn",
|
||||
"orgChild1.orgChild1Fax",
|
||||
"orgChild1.orgRootId",
|
||||
"orgChild1.orgChild1Rank",
|
||||
"orgChild1.orgChild1RankSub",
|
||||
"orgChild1.responsibility",
|
||||
])
|
||||
.orderBy("orgChild1.orgChild1Order", "ASC")
|
||||
.getMany()
|
||||
: [];
|
||||
|
||||
const orgChild1Ids = orgChild1Data.map((orgChild1) => orgChild1.id) || null;
|
||||
const orgChild2Data =
|
||||
orgChild1Ids && orgChild1Ids.length > 0
|
||||
? await AppDataSource.getRepository(OrgChild2)
|
||||
.createQueryBuilder("orgChild2")
|
||||
.where("orgChild2.orgChild1Id IN (:...ids)", { ids: orgChild1Ids })
|
||||
// .andWhere(
|
||||
// _data.child2 != undefined && _data.child2 != null
|
||||
// ? _data.child2[0] != null
|
||||
// ? `orgChild2.id IN (:...node)`
|
||||
// : `orgChild2.id is null`
|
||||
// : "1=1",
|
||||
// {
|
||||
// node: _data.child2,
|
||||
// },
|
||||
// )
|
||||
.select([
|
||||
"orgChild2.id",
|
||||
"orgChild2.orgChild2Name",
|
||||
"orgChild2.orgChild2ShortName",
|
||||
"orgChild2.orgChild2Code",
|
||||
"orgChild2.orgChild2Order",
|
||||
"orgChild2.orgChild2PhoneEx",
|
||||
"orgChild2.orgChild2PhoneIn",
|
||||
"orgChild2.orgChild2Fax",
|
||||
"orgChild2.orgRootId",
|
||||
"orgChild2.orgChild2Rank",
|
||||
"orgChild2.orgChild2RankSub",
|
||||
"orgChild2.orgChild1Id",
|
||||
"orgChild2.responsibility",
|
||||
])
|
||||
.orderBy("orgChild2.orgChild2Order", "ASC")
|
||||
.getMany()
|
||||
: [];
|
||||
|
||||
const orgChild2Ids = orgChild2Data.map((orgChild2) => orgChild2.id) || null;
|
||||
const orgChild3Data =
|
||||
orgChild2Ids && orgChild2Ids.length > 0
|
||||
? await AppDataSource.getRepository(OrgChild3)
|
||||
.createQueryBuilder("orgChild3")
|
||||
.where("orgChild3.orgChild2Id IN (:...ids)", { ids: orgChild2Ids })
|
||||
// .andWhere(
|
||||
// _data.child3 != undefined && _data.child3 != null
|
||||
// ? _data.child3[0] != null
|
||||
// ? `orgChild3.id IN (:...node)`
|
||||
// : `orgChild3.id is null`
|
||||
// : "1=1",
|
||||
// {
|
||||
// node: _data.child3,
|
||||
// },
|
||||
// )
|
||||
.select([
|
||||
"orgChild3.id",
|
||||
"orgChild3.orgChild3Name",
|
||||
"orgChild3.orgChild3ShortName",
|
||||
"orgChild3.orgChild3Code",
|
||||
"orgChild3.orgChild3Order",
|
||||
"orgChild3.orgChild3PhoneEx",
|
||||
"orgChild3.orgChild3PhoneIn",
|
||||
"orgChild3.orgChild3Fax",
|
||||
"orgChild3.orgRootId",
|
||||
"orgChild3.orgChild3Rank",
|
||||
"orgChild3.orgChild3RankSub",
|
||||
"orgChild3.orgChild2Id",
|
||||
"orgChild3.responsibility",
|
||||
])
|
||||
.orderBy("orgChild3.orgChild3Order", "ASC")
|
||||
.getMany()
|
||||
: [];
|
||||
|
||||
const orgChild3Ids = orgChild3Data.map((orgChild3) => orgChild3.id) || null;
|
||||
const orgChild4Data =
|
||||
orgChild3Ids && orgChild3Ids.length > 0
|
||||
? await AppDataSource.getRepository(OrgChild4)
|
||||
.createQueryBuilder("orgChild4")
|
||||
.where("orgChild4.orgChild3Id IN (:...ids)", { ids: orgChild3Ids })
|
||||
// .andWhere(
|
||||
// _data.child4 != undefined && _data.child4 != null
|
||||
// ? _data.child4[0] != null
|
||||
// ? `orgChild4.id IN (:...node)`
|
||||
// : `orgChild4.id is null`
|
||||
// : "1=1",
|
||||
// {
|
||||
// node: _data.child4,
|
||||
// },
|
||||
// )
|
||||
.select([
|
||||
"orgChild4.id",
|
||||
"orgChild4.orgChild4Name",
|
||||
"orgChild4.orgChild4ShortName",
|
||||
"orgChild4.orgChild4Code",
|
||||
"orgChild4.orgChild4Order",
|
||||
"orgChild4.orgChild4PhoneEx",
|
||||
"orgChild4.orgChild4PhoneIn",
|
||||
"orgChild4.orgChild4Fax",
|
||||
"orgChild4.orgRootId",
|
||||
"orgChild4.orgChild4Rank",
|
||||
"orgChild4.orgChild4RankSub",
|
||||
"orgChild4.orgChild3Id",
|
||||
"orgChild4.responsibility",
|
||||
])
|
||||
.orderBy("orgChild4.orgChild4Order", "ASC")
|
||||
.getMany()
|
||||
: [];
|
||||
|
||||
const formattedData = await Promise.all(
|
||||
orgRootData.map(async (orgRoot) => {
|
||||
return {
|
||||
orgTreeId: orgRoot.id,
|
||||
orgLevel: 0,
|
||||
orgName: orgRoot.orgRootName,
|
||||
orgTreeName: orgRoot.orgRootName,
|
||||
orgTreeShortName: orgRoot.orgRootShortName,
|
||||
orgTreeCode: orgRoot.orgRootCode,
|
||||
orgCode: orgRoot.orgRootCode + "00",
|
||||
orgTreeRank: orgRoot.orgRootRank,
|
||||
orgTreeRankSub: orgRoot.orgRootRankSub,
|
||||
orgTreeOrder: orgRoot.orgRootOrder,
|
||||
orgTreePhoneEx: orgRoot.orgRootPhoneEx,
|
||||
orgTreePhoneIn: orgRoot.orgRootPhoneIn,
|
||||
orgTreeFax: orgRoot.orgRootFax,
|
||||
orgRevisionId: orgRoot.orgRevisionId,
|
||||
orgRootName: orgRoot.orgRootName,
|
||||
responsibility: orgRoot.responsibility,
|
||||
labelName:
|
||||
orgRoot.orgRootName + " " + orgRoot.orgRootCode + "00" + " " + orgRoot.orgRootShortName,
|
||||
totalPosition: await this.posMasterRepository.count({
|
||||
where: { orgRevisionId: orgRoot.orgRevisionId, orgRootId: orgRoot.id },
|
||||
}),
|
||||
totalPositionCurrentUse: await this.posMasterRepository.count({
|
||||
where: {
|
||||
orgRevisionId: orgRoot.orgRevisionId,
|
||||
orgRootId: orgRoot.id,
|
||||
current_holderId: Not(IsNull()) || Not(""),
|
||||
},
|
||||
}),
|
||||
totalPositionCurrentVacant: await this.posMasterRepository.count({
|
||||
where: {
|
||||
orgRevisionId: orgRoot.orgRevisionId,
|
||||
orgRootId: orgRoot.id,
|
||||
current_holderId: IsNull() || "",
|
||||
},
|
||||
}),
|
||||
totalPositionNextUse: await this.posMasterRepository.count({
|
||||
where: {
|
||||
orgRevisionId: orgRoot.orgRevisionId,
|
||||
orgRootId: orgRoot.id,
|
||||
next_holderId: Not(IsNull()) || Not(""),
|
||||
},
|
||||
}),
|
||||
totalPositionNextVacant: await this.posMasterRepository.count({
|
||||
where: {
|
||||
orgRevisionId: orgRoot.orgRevisionId,
|
||||
orgRootId: orgRoot.id,
|
||||
next_holderId: IsNull() || "",
|
||||
},
|
||||
}),
|
||||
totalRootPosition: await this.posMasterRepository.count({
|
||||
where: {
|
||||
orgRevisionId: orgRoot.orgRevisionId,
|
||||
orgRootId: orgRoot.id,
|
||||
orgChild1Id: IsNull() || "",
|
||||
orgChild2Id: IsNull() || "",
|
||||
orgChild3Id: IsNull() || "",
|
||||
orgChild4Id: IsNull() || "",
|
||||
},
|
||||
}),
|
||||
totalRootPositionCurrentUse: await this.posMasterRepository.count({
|
||||
where: {
|
||||
orgRevisionId: orgRoot.orgRevisionId,
|
||||
orgRootId: orgRoot.id,
|
||||
orgChild1Id: IsNull() || "",
|
||||
orgChild2Id: IsNull() || "",
|
||||
orgChild3Id: IsNull() || "",
|
||||
orgChild4Id: IsNull() || "",
|
||||
current_holderId: Not(IsNull()) || Not(""),
|
||||
},
|
||||
}),
|
||||
totalRootPositionCurrentVacant: await this.posMasterRepository.count({
|
||||
where: {
|
||||
orgRevisionId: orgRoot.orgRevisionId,
|
||||
orgRootId: orgRoot.id,
|
||||
orgChild1Id: IsNull() || "",
|
||||
orgChild2Id: IsNull() || "",
|
||||
orgChild3Id: IsNull() || "",
|
||||
orgChild4Id: IsNull() || "",
|
||||
current_holderId: IsNull() || "",
|
||||
},
|
||||
}),
|
||||
totalRootPositionNextUse: await this.posMasterRepository.count({
|
||||
where: {
|
||||
orgRevisionId: orgRoot.orgRevisionId,
|
||||
orgRootId: orgRoot.id,
|
||||
orgChild1Id: IsNull() || "",
|
||||
orgChild2Id: IsNull() || "",
|
||||
orgChild3Id: IsNull() || "",
|
||||
orgChild4Id: IsNull() || "",
|
||||
next_holderId: Not(IsNull()) || Not(""),
|
||||
},
|
||||
}),
|
||||
totalRootPositionNextVacant: await this.posMasterRepository.count({
|
||||
where: {
|
||||
orgRevisionId: orgRoot.orgRevisionId,
|
||||
orgRootId: orgRoot.id,
|
||||
orgChild1Id: IsNull() || "",
|
||||
orgChild2Id: IsNull() || "",
|
||||
orgChild3Id: IsNull() || "",
|
||||
orgChild4Id: IsNull() || "",
|
||||
next_holderId: IsNull() || "",
|
||||
},
|
||||
}),
|
||||
|
||||
children: await Promise.all(
|
||||
orgChild1Data
|
||||
.filter((orgChild1) => orgChild1.orgRootId === orgRoot.id)
|
||||
.map(async (orgChild1) => ({
|
||||
orgTreeId: orgChild1.id,
|
||||
orgRootId: orgRoot.id,
|
||||
orgLevel: 1,
|
||||
orgName: `${orgChild1.orgChild1Name}/${orgRoot.orgRootName}`,
|
||||
orgTreeName: orgChild1.orgChild1Name,
|
||||
orgTreeShortName: orgChild1.orgChild1ShortName,
|
||||
orgTreeCode: orgChild1.orgChild1Code,
|
||||
orgCode: orgRoot.orgRootCode + orgChild1.orgChild1Code,
|
||||
orgTreeRank: orgChild1.orgChild1Rank,
|
||||
orgTreeRankSub: orgChild1.orgChild1RankSub,
|
||||
orgTreeOrder: orgChild1.orgChild1Order,
|
||||
orgRootCode: orgRoot.orgRootCode,
|
||||
orgTreePhoneEx: orgChild1.orgChild1PhoneEx,
|
||||
orgTreePhoneIn: orgChild1.orgChild1PhoneIn,
|
||||
orgTreeFax: orgChild1.orgChild1Fax,
|
||||
orgRevisionId: orgRoot.orgRevisionId,
|
||||
orgRootName: orgRoot.orgRootName,
|
||||
responsibility: orgChild1.responsibility,
|
||||
isOfficer: orgChild1.isOfficer,
|
||||
labelName:
|
||||
orgChild1.orgChild1Name +
|
||||
" " +
|
||||
orgRoot.orgRootCode +
|
||||
orgChild1.orgChild1Code +
|
||||
" " +
|
||||
orgChild1.orgChild1ShortName,
|
||||
totalPosition: await this.posMasterRepository.count({
|
||||
where: { orgRevisionId: orgRoot.orgRevisionId, orgChild1Id: orgChild1.id },
|
||||
}),
|
||||
totalPositionCurrentUse: await this.posMasterRepository.count({
|
||||
where: {
|
||||
orgRevisionId: orgRoot.orgRevisionId,
|
||||
orgChild1Id: orgChild1.id,
|
||||
current_holderId: Not(IsNull()) || Not(""),
|
||||
},
|
||||
}),
|
||||
totalPositionCurrentVacant: await this.posMasterRepository.count({
|
||||
where: {
|
||||
orgRevisionId: orgRoot.orgRevisionId,
|
||||
orgChild1Id: orgChild1.id,
|
||||
current_holderId: IsNull() || "",
|
||||
},
|
||||
}),
|
||||
totalPositionNextUse: await this.posMasterRepository.count({
|
||||
where: {
|
||||
orgRevisionId: orgRoot.orgRevisionId,
|
||||
orgChild1Id: orgChild1.id,
|
||||
next_holderId: Not(IsNull()) || Not(""),
|
||||
},
|
||||
}),
|
||||
totalPositionNextVacant: await this.posMasterRepository.count({
|
||||
where: {
|
||||
orgRevisionId: orgRoot.orgRevisionId,
|
||||
orgChild1Id: orgChild1.id,
|
||||
next_holderId: IsNull() || "",
|
||||
},
|
||||
}),
|
||||
totalRootPosition: await this.posMasterRepository.count({
|
||||
where: {
|
||||
orgRevisionId: orgRoot.orgRevisionId,
|
||||
orgRootId: orgRoot.id,
|
||||
orgChild1Id: orgChild1.id,
|
||||
orgChild2Id: IsNull() || "",
|
||||
orgChild3Id: IsNull() || "",
|
||||
orgChild4Id: IsNull() || "",
|
||||
},
|
||||
}),
|
||||
totalRootPositionCurrentUse: await this.posMasterRepository.count({
|
||||
where: {
|
||||
orgRevisionId: orgRoot.orgRevisionId,
|
||||
orgRootId: orgRoot.id,
|
||||
orgChild1Id: orgChild1.id,
|
||||
orgChild2Id: IsNull() || "",
|
||||
orgChild3Id: IsNull() || "",
|
||||
orgChild4Id: IsNull() || "",
|
||||
current_holderId: Not(IsNull()) || Not(""),
|
||||
},
|
||||
}),
|
||||
totalRootPositionCurrentVacant: await this.posMasterRepository.count({
|
||||
where: {
|
||||
orgRevisionId: orgRoot.orgRevisionId,
|
||||
orgRootId: orgRoot.id,
|
||||
orgChild1Id: orgChild1.id,
|
||||
orgChild2Id: IsNull() || "",
|
||||
orgChild3Id: IsNull() || "",
|
||||
orgChild4Id: IsNull() || "",
|
||||
current_holderId: IsNull() || "",
|
||||
},
|
||||
}),
|
||||
totalRootPositionNextUse: await this.posMasterRepository.count({
|
||||
where: {
|
||||
orgRevisionId: orgRoot.orgRevisionId,
|
||||
orgRootId: orgRoot.id,
|
||||
orgChild1Id: orgChild1.id,
|
||||
orgChild2Id: IsNull() || "",
|
||||
orgChild3Id: IsNull() || "",
|
||||
orgChild4Id: IsNull() || "",
|
||||
next_holderId: Not(IsNull()) || Not(""),
|
||||
},
|
||||
}),
|
||||
totalRootPositionNextVacant: await this.posMasterRepository.count({
|
||||
where: {
|
||||
orgRevisionId: orgRoot.orgRevisionId,
|
||||
orgRootId: orgRoot.id,
|
||||
orgChild1Id: orgChild1.id,
|
||||
orgChild2Id: IsNull() || "",
|
||||
orgChild3Id: IsNull() || "",
|
||||
orgChild4Id: IsNull() || "",
|
||||
next_holderId: IsNull() || "",
|
||||
},
|
||||
}),
|
||||
|
||||
children: await Promise.all(
|
||||
orgChild2Data
|
||||
.filter((orgChild2) => orgChild2.orgChild1Id === orgChild1.id)
|
||||
.map(async (orgChild2) => ({
|
||||
orgTreeId: orgChild2.id,
|
||||
orgRootId: orgChild1.id,
|
||||
orgLevel: 2,
|
||||
orgName: `${orgChild2.orgChild2Name}/${orgChild1.orgChild1Name}/${orgRoot.orgRootName}`,
|
||||
orgTreeName: orgChild2.orgChild2Name,
|
||||
orgTreeShortName: orgChild2.orgChild2ShortName,
|
||||
orgTreeCode: orgChild2.orgChild2Code,
|
||||
orgCode: orgRoot.orgRootCode + orgChild2.orgChild2Code,
|
||||
orgTreeRank: orgChild2.orgChild2Rank,
|
||||
orgTreeRankSub: orgChild2.orgChild2RankSub,
|
||||
orgTreeOrder: orgChild2.orgChild2Order,
|
||||
orgRootCode: orgRoot.orgRootCode,
|
||||
orgTreePhoneEx: orgChild2.orgChild2PhoneEx,
|
||||
orgTreePhoneIn: orgChild2.orgChild2PhoneIn,
|
||||
orgTreeFax: orgChild2.orgChild2Fax,
|
||||
orgRevisionId: orgRoot.orgRevisionId,
|
||||
orgRootName: orgRoot.orgRootName,
|
||||
responsibility: orgChild2.responsibility,
|
||||
labelName:
|
||||
orgChild2.orgChild2Name +
|
||||
" " +
|
||||
orgRoot.orgRootCode +
|
||||
orgChild2.orgChild2Code +
|
||||
" " +
|
||||
orgChild2.orgChild2ShortName,
|
||||
totalPosition: await this.posMasterRepository.count({
|
||||
where: {
|
||||
orgRevisionId: orgRoot.orgRevisionId,
|
||||
orgChild2Id: orgChild2.id,
|
||||
},
|
||||
}),
|
||||
totalPositionCurrentUse: await this.posMasterRepository.count({
|
||||
where: {
|
||||
orgRevisionId: orgRoot.orgRevisionId,
|
||||
orgChild2Id: orgChild2.id,
|
||||
current_holderId: Not(IsNull()) || Not(""),
|
||||
},
|
||||
}),
|
||||
totalPositionCurrentVacant: await this.posMasterRepository.count({
|
||||
where: {
|
||||
orgRevisionId: orgRoot.orgRevisionId,
|
||||
orgChild2Id: orgChild2.id,
|
||||
current_holderId: IsNull() || "",
|
||||
},
|
||||
}),
|
||||
totalPositionNextUse: await this.posMasterRepository.count({
|
||||
where: {
|
||||
orgRevisionId: orgRoot.orgRevisionId,
|
||||
orgChild2Id: orgChild2.id,
|
||||
next_holderId: Not(IsNull()) || Not(""),
|
||||
},
|
||||
}),
|
||||
totalPositionNextVacant: await this.posMasterRepository.count({
|
||||
where: {
|
||||
orgRevisionId: orgRoot.orgRevisionId,
|
||||
orgChild2Id: orgChild2.id,
|
||||
next_holderId: IsNull() || "",
|
||||
},
|
||||
}),
|
||||
totalRootPosition: await this.posMasterRepository.count({
|
||||
where: {
|
||||
orgRevisionId: orgRoot.orgRevisionId,
|
||||
orgRootId: orgRoot.id,
|
||||
orgChild1Id: orgChild1.id,
|
||||
orgChild2Id: orgChild2.id,
|
||||
orgChild3Id: IsNull() || "",
|
||||
orgChild4Id: IsNull() || "",
|
||||
},
|
||||
}),
|
||||
totalRootPositionCurrentUse: await this.posMasterRepository.count({
|
||||
where: {
|
||||
orgRevisionId: orgRoot.orgRevisionId,
|
||||
orgRootId: orgRoot.id,
|
||||
orgChild1Id: orgChild1.id,
|
||||
orgChild2Id: orgChild2.id,
|
||||
orgChild3Id: IsNull() || "",
|
||||
orgChild4Id: IsNull() || "",
|
||||
current_holderId: Not(IsNull()) || Not(""),
|
||||
},
|
||||
}),
|
||||
totalRootPositionCurrentVacant: await this.posMasterRepository.count({
|
||||
where: {
|
||||
orgRevisionId: orgRoot.orgRevisionId,
|
||||
orgRootId: orgRoot.id,
|
||||
orgChild1Id: orgChild1.id,
|
||||
orgChild2Id: orgChild2.id,
|
||||
orgChild3Id: IsNull() || "",
|
||||
orgChild4Id: IsNull() || "",
|
||||
current_holderId: IsNull() || "",
|
||||
},
|
||||
}),
|
||||
totalRootPositionNextUse: await this.posMasterRepository.count({
|
||||
where: {
|
||||
orgRevisionId: orgRoot.orgRevisionId,
|
||||
orgRootId: orgRoot.id,
|
||||
orgChild1Id: orgChild1.id,
|
||||
orgChild2Id: orgChild2.id,
|
||||
orgChild3Id: IsNull() || "",
|
||||
orgChild4Id: IsNull() || "",
|
||||
next_holderId: Not(IsNull()) || Not(""),
|
||||
},
|
||||
}),
|
||||
totalRootPositionNextVacant: await this.posMasterRepository.count({
|
||||
where: {
|
||||
orgRevisionId: orgRoot.orgRevisionId,
|
||||
orgRootId: orgRoot.id,
|
||||
orgChild1Id: orgChild1.id,
|
||||
orgChild2Id: orgChild2.id,
|
||||
orgChild3Id: IsNull() || "",
|
||||
orgChild4Id: IsNull() || "",
|
||||
next_holderId: IsNull() || "",
|
||||
},
|
||||
}),
|
||||
|
||||
children: await Promise.all(
|
||||
orgChild3Data
|
||||
.filter((orgChild3) => orgChild3.orgChild2Id === orgChild2.id)
|
||||
.map(async (orgChild3) => ({
|
||||
orgTreeId: orgChild3.id,
|
||||
orgRootId: orgChild2.id,
|
||||
orgLevel: 3,
|
||||
orgName: `${orgChild3.orgChild3Name}/${orgChild2.orgChild2Name}/${orgChild1.orgChild1Name}/${orgRoot.orgRootName}`,
|
||||
orgTreeName: orgChild3.orgChild3Name,
|
||||
orgTreeShortName: orgChild3.orgChild3ShortName,
|
||||
orgTreeCode: orgChild3.orgChild3Code,
|
||||
orgCode: orgRoot.orgRootCode + orgChild3.orgChild3Code,
|
||||
orgTreeRank: orgChild3.orgChild3Rank,
|
||||
orgTreeRankSub: orgChild3.orgChild3RankSub,
|
||||
orgTreeOrder: orgChild3.orgChild3Order,
|
||||
orgRootCode: orgRoot.orgRootCode,
|
||||
orgTreePhoneEx: orgChild3.orgChild3PhoneEx,
|
||||
orgTreePhoneIn: orgChild3.orgChild3PhoneIn,
|
||||
orgTreeFax: orgChild3.orgChild3Fax,
|
||||
orgRevisionId: orgRoot.orgRevisionId,
|
||||
orgRootName: orgRoot.orgRootName,
|
||||
responsibility: orgChild3.responsibility,
|
||||
labelName:
|
||||
orgChild3.orgChild3Name +
|
||||
" " +
|
||||
orgRoot.orgRootCode +
|
||||
orgChild3.orgChild3Code +
|
||||
" " +
|
||||
orgChild3.orgChild3ShortName,
|
||||
totalPosition: await this.posMasterRepository.count({
|
||||
where: {
|
||||
orgRevisionId: orgRoot.orgRevisionId,
|
||||
orgChild3Id: orgChild3.id,
|
||||
},
|
||||
}),
|
||||
totalPositionCurrentUse: await this.posMasterRepository.count({
|
||||
where: {
|
||||
orgRevisionId: orgRoot.orgRevisionId,
|
||||
orgChild3Id: orgChild3.id,
|
||||
current_holderId: Not(IsNull()) || Not(""),
|
||||
},
|
||||
}),
|
||||
totalPositionCurrentVacant: await this.posMasterRepository.count({
|
||||
where: {
|
||||
orgRevisionId: orgRoot.orgRevisionId,
|
||||
orgChild3Id: orgChild3.id,
|
||||
current_holderId: IsNull() || "",
|
||||
},
|
||||
}),
|
||||
totalPositionNextUse: await this.posMasterRepository.count({
|
||||
where: {
|
||||
orgRevisionId: orgRoot.orgRevisionId,
|
||||
orgChild3Id: orgChild3.id,
|
||||
next_holderId: Not(IsNull()) || Not(""),
|
||||
},
|
||||
}),
|
||||
totalPositionNextVacant: await this.posMasterRepository.count({
|
||||
where: {
|
||||
orgRevisionId: orgRoot.orgRevisionId,
|
||||
orgChild3Id: orgChild3.id,
|
||||
next_holderId: IsNull() || "",
|
||||
},
|
||||
}),
|
||||
totalRootPosition: await this.posMasterRepository.count({
|
||||
where: {
|
||||
orgRevisionId: orgRoot.orgRevisionId,
|
||||
orgRootId: orgRoot.id,
|
||||
orgChild1Id: orgChild1.id,
|
||||
orgChild2Id: orgChild2.id,
|
||||
orgChild3Id: orgChild3.id,
|
||||
orgChild4Id: IsNull() || "",
|
||||
},
|
||||
}),
|
||||
totalRootPositionCurrentUse: await this.posMasterRepository.count({
|
||||
where: {
|
||||
orgRevisionId: orgRoot.orgRevisionId,
|
||||
orgRootId: orgRoot.id,
|
||||
orgChild1Id: orgChild1.id,
|
||||
orgChild2Id: orgChild2.id,
|
||||
orgChild3Id: orgChild3.id,
|
||||
orgChild4Id: IsNull() || "",
|
||||
current_holderId: Not(IsNull()) || Not(""),
|
||||
},
|
||||
}),
|
||||
totalRootPositionCurrentVacant: await this.posMasterRepository.count({
|
||||
where: {
|
||||
orgRevisionId: orgRoot.orgRevisionId,
|
||||
orgRootId: orgRoot.id,
|
||||
orgChild1Id: orgChild1.id,
|
||||
orgChild2Id: orgChild2.id,
|
||||
orgChild3Id: orgChild3.id,
|
||||
orgChild4Id: IsNull() || "",
|
||||
current_holderId: IsNull() || "",
|
||||
},
|
||||
}),
|
||||
totalRootPositionNextUse: await this.posMasterRepository.count({
|
||||
where: {
|
||||
orgRevisionId: orgRoot.orgRevisionId,
|
||||
orgRootId: orgRoot.id,
|
||||
orgChild1Id: orgChild1.id,
|
||||
orgChild2Id: orgChild2.id,
|
||||
orgChild3Id: orgChild3.id,
|
||||
orgChild4Id: IsNull() || "",
|
||||
next_holderId: Not(IsNull()) || Not(""),
|
||||
},
|
||||
}),
|
||||
totalRootPositionNextVacant: await this.posMasterRepository.count({
|
||||
where: {
|
||||
orgRevisionId: orgRoot.orgRevisionId,
|
||||
orgRootId: orgRoot.id,
|
||||
orgChild1Id: orgChild1.id,
|
||||
orgChild2Id: orgChild2.id,
|
||||
orgChild3Id: orgChild3.id,
|
||||
orgChild4Id: IsNull() || "",
|
||||
next_holderId: IsNull() || "",
|
||||
},
|
||||
}),
|
||||
|
||||
children: await Promise.all(
|
||||
orgChild4Data
|
||||
.filter((orgChild4) => orgChild4.orgChild3Id === orgChild3.id)
|
||||
.map(async (orgChild4) => ({
|
||||
orgTreeId: orgChild4.id,
|
||||
orgRootId: orgChild3.id,
|
||||
orgLevel: 4,
|
||||
orgName: `${orgChild4.orgChild4Name}/${orgChild3.orgChild3Name}/${orgChild2.orgChild2Name}/${orgChild1.orgChild1Name}/${orgRoot.orgRootName}`,
|
||||
orgTreeName: orgChild4.orgChild4Name,
|
||||
orgTreeShortName: orgChild4.orgChild4ShortName,
|
||||
orgTreeCode: orgChild4.orgChild4Code,
|
||||
orgCode: orgRoot.orgRootCode + orgChild4.orgChild4Code,
|
||||
orgTreeRank: orgChild4.orgChild4Rank,
|
||||
orgTreeRankSub: orgChild4.orgChild4RankSub,
|
||||
orgTreeOrder: orgChild4.orgChild4Order,
|
||||
orgRootCode: orgRoot.orgRootCode,
|
||||
orgTreePhoneEx: orgChild4.orgChild4PhoneEx,
|
||||
orgTreePhoneIn: orgChild4.orgChild4PhoneIn,
|
||||
orgTreeFax: orgChild4.orgChild4Fax,
|
||||
orgRevisionId: orgRoot.orgRevisionId,
|
||||
orgRootName: orgRoot.orgRootName,
|
||||
responsibility: orgChild4.responsibility,
|
||||
labelName:
|
||||
orgChild4.orgChild4Name +
|
||||
" " +
|
||||
orgRoot.orgRootCode +
|
||||
orgChild4.orgChild4Code +
|
||||
" " +
|
||||
orgChild4.orgChild4ShortName,
|
||||
totalPosition: await this.posMasterRepository.count({
|
||||
where: {
|
||||
orgRevisionId: orgRoot.orgRevisionId,
|
||||
orgChild4Id: orgChild4.id,
|
||||
},
|
||||
}),
|
||||
totalPositionCurrentUse: await this.posMasterRepository.count({
|
||||
where: {
|
||||
orgRevisionId: orgRoot.orgRevisionId,
|
||||
orgChild4Id: orgChild4.id,
|
||||
current_holderId: Not(IsNull()) || Not(""),
|
||||
},
|
||||
}),
|
||||
totalPositionCurrentVacant: await this.posMasterRepository.count({
|
||||
where: {
|
||||
orgRevisionId: orgRoot.orgRevisionId,
|
||||
orgChild4Id: orgChild4.id,
|
||||
current_holderId: IsNull() || "",
|
||||
},
|
||||
}),
|
||||
totalPositionNextUse: await this.posMasterRepository.count({
|
||||
where: {
|
||||
orgRevisionId: orgRoot.orgRevisionId,
|
||||
orgChild4Id: orgChild4.id,
|
||||
next_holderId: Not(IsNull()) || Not(""),
|
||||
},
|
||||
}),
|
||||
totalPositionNextVacant: await this.posMasterRepository.count({
|
||||
where: {
|
||||
orgRevisionId: orgRoot.orgRevisionId,
|
||||
orgChild4Id: orgChild4.id,
|
||||
next_holderId: IsNull() || "",
|
||||
},
|
||||
}),
|
||||
totalRootPosition: await this.posMasterRepository.count({
|
||||
where: {
|
||||
orgRevisionId: orgRoot.orgRevisionId,
|
||||
orgRootId: orgRoot.id,
|
||||
orgChild1Id: orgChild1.id,
|
||||
orgChild2Id: orgChild2.id,
|
||||
orgChild3Id: orgChild3.id,
|
||||
orgChild4Id: orgChild4.id,
|
||||
},
|
||||
}),
|
||||
totalRootPositionCurrentUse: await this.posMasterRepository.count(
|
||||
{
|
||||
where: {
|
||||
orgRevisionId: orgRoot.orgRevisionId,
|
||||
orgRootId: orgRoot.id,
|
||||
orgChild1Id: orgChild1.id,
|
||||
orgChild2Id: orgChild2.id,
|
||||
orgChild3Id: orgChild3.id,
|
||||
orgChild4Id: orgChild4.id,
|
||||
current_holderId: Not(IsNull()) || Not(""),
|
||||
},
|
||||
},
|
||||
),
|
||||
totalRootPositionCurrentVacant:
|
||||
await this.posMasterRepository.count({
|
||||
where: {
|
||||
orgRevisionId: orgRoot.orgRevisionId,
|
||||
orgRootId: orgRoot.id,
|
||||
orgChild1Id: orgChild1.id,
|
||||
orgChild2Id: orgChild2.id,
|
||||
orgChild3Id: orgChild3.id,
|
||||
orgChild4Id: orgChild4.id,
|
||||
current_holderId: IsNull() || "",
|
||||
},
|
||||
}),
|
||||
totalRootPositionNextUse: await this.posMasterRepository.count({
|
||||
where: {
|
||||
orgRevisionId: orgRoot.orgRevisionId,
|
||||
orgRootId: orgRoot.id,
|
||||
orgChild1Id: orgChild1.id,
|
||||
orgChild2Id: orgChild2.id,
|
||||
orgChild3Id: orgChild3.id,
|
||||
orgChild4Id: orgChild4.id,
|
||||
next_holderId: Not(IsNull()) || Not(""),
|
||||
},
|
||||
}),
|
||||
totalRootPositionNextVacant: await this.posMasterRepository.count(
|
||||
{
|
||||
where: {
|
||||
orgRevisionId: orgRoot.orgRevisionId,
|
||||
orgRootId: orgRoot.id,
|
||||
orgChild1Id: orgChild1.id,
|
||||
orgChild2Id: orgChild2.id,
|
||||
orgChild3Id: orgChild3.id,
|
||||
orgChild4Id: orgChild4.id,
|
||||
next_holderId: IsNull() || "",
|
||||
},
|
||||
},
|
||||
),
|
||||
})),
|
||||
),
|
||||
})),
|
||||
),
|
||||
})),
|
||||
),
|
||||
})),
|
||||
),
|
||||
};
|
||||
}),
|
||||
);
|
||||
|
||||
return new HttpSuccess(formattedData);
|
||||
}
|
||||
|
||||
/**
|
||||
* API รายละเอียดโครงสร้าง
|
||||
*
|
||||
|
|
@ -618,10 +1425,8 @@ export class OrganizationController extends Controller {
|
|||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
}
|
||||
let attrOwnership = null;
|
||||
if (!request.user.role.includes("SUPER_ADMIN")) {
|
||||
let _privilege = await new permission().PermissionOrgList(request, "SYS_ORG");
|
||||
attrOwnership = _privilege.root == null ? true : false;
|
||||
}
|
||||
let _privilege = await new permission().PermissionOrgList(request, "SYS_ORG");
|
||||
attrOwnership = _privilege.root == null ? true : false;
|
||||
if (
|
||||
orgRevision.orgRevisionIsDraft == true &&
|
||||
orgRevision.orgRevisionIsCurrent == false &&
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue