แก้ bug list tree

This commit is contained in:
Kittapath 2024-02-02 10:15:03 +07:00
parent e90e3a27c6
commit 97b85acbd0

View file

@ -704,130 +704,230 @@ export class OrganizationController extends Controller {
: []; : [];
// const formattedData = orgRootData.map((orgRoot) => { // const formattedData = orgRootData.map((orgRoot) => {
const formattedData = await Promise.all(orgRootData.map(async (orgRoot) => { const formattedData = await Promise.all(
return { orgRootData.map(async (orgRoot) => {
orgTreeId: orgRoot.id, return {
orgLevel: 0, orgTreeId: orgRoot.id,
orgName: orgRoot.orgRootName, orgLevel: 0,
orgTreeName: orgRoot.orgRootName, orgName: orgRoot.orgRootName,
orgTreeShortName: orgRoot.orgRootShortName, orgTreeName: orgRoot.orgRootName,
orgTreeCode: orgRoot.orgRootCode, orgTreeShortName: orgRoot.orgRootShortName,
orgCode: orgRoot.orgRootCode + "00", orgTreeCode: orgRoot.orgRootCode,
orgTreeRank: orgRoot.orgRootRank, orgCode: orgRoot.orgRootCode + "00",
orgTreeOrder: orgRoot.orgRootOrder, orgTreeRank: orgRoot.orgRootRank,
orgTreePhoneEx: orgRoot.orgRootPhoneEx, orgTreeOrder: orgRoot.orgRootOrder,
orgTreePhoneIn: orgRoot.orgRootPhoneIn, orgTreePhoneEx: orgRoot.orgRootPhoneEx,
orgTreeFax: orgRoot.orgRootFax, orgTreePhoneIn: orgRoot.orgRootPhoneIn,
orgRevisionId: orgRoot.orgRevisionId, orgTreeFax: orgRoot.orgRootFax,
orgRootName: orgRoot.orgRootName, orgRevisionId: orgRoot.orgRevisionId,
totalPosition: await this.posMasterRepository.count({ where: { orgRootId: orgRoot.id }}), orgRootName: orgRoot.orgRootName,
totalPositionCurrentUse: await this.posMasterRepository.count({ where: { orgRootId: orgRoot.id, profileIdCurrentHolder: Not(IsNull()) && Not("") }}), totalPosition: await this.posMasterRepository.count({
totalPositionCurrentVacant: await this.posMasterRepository.count({ where: { orgRootId: orgRoot.id, profileIdCurrentHolder: IsNull() && "" }}), where: { orgRootId: orgRoot.id },
totalPositionNextUse: await this.posMasterRepository.count({ where: { orgRootId: orgRoot.id, profileIdNextHolder: Not(IsNull()) && Not("") }}), }),
totalPositionNextVacant: await this.posMasterRepository.count({ where: { orgRootId: orgRoot.id, profileIdNextHolder: IsNull() && "" }}), totalPositionCurrentUse: await this.posMasterRepository.count({
where: { orgRootId: orgRoot.id, profileIdCurrentHolder: Not(IsNull()) && Not("") },
}),
totalPositionCurrentVacant: await this.posMasterRepository.count({
where: { orgRootId: orgRoot.id, profileIdCurrentHolder: IsNull() && "" },
}),
totalPositionNextUse: await this.posMasterRepository.count({
where: { orgRootId: orgRoot.id, profileIdNextHolder: Not(IsNull()) && Not("") },
}),
totalPositionNextVacant: await this.posMasterRepository.count({
where: { orgRootId: orgRoot.id, profileIdNextHolder: IsNull() && "" },
}),
children: orgChild1Data children: await Promise.all(
.filter((orgChild1) => orgChild1.orgRootId === orgRoot.id) orgChild1Data
.map(async (orgChild1) => ({ .filter((orgChild1) => orgChild1.orgRootId === orgRoot.id)
orgTreeId: orgChild1.id, .map(async (orgChild1) => ({
orgRootId: orgRoot.id, orgTreeId: orgChild1.id,
orgLevel: 1, orgRootId: orgRoot.id,
orgName: `${orgChild1.orgChild1Name}/${orgRoot.orgRootName}`, orgLevel: 1,
orgTreeName: orgChild1.orgChild1Name, orgName: `${orgChild1.orgChild1Name}/${orgRoot.orgRootName}`,
orgTreeShortName: orgChild1.orgChild1ShortName, orgTreeName: orgChild1.orgChild1Name,
orgTreeCode: orgChild1.orgChild1Code, orgTreeShortName: orgChild1.orgChild1ShortName,
orgCode: orgRoot.orgRootCode + orgChild1.orgChild1Code, orgTreeCode: orgChild1.orgChild1Code,
orgTreeRank: orgChild1.orgChild1Rank, orgCode: orgRoot.orgRootCode + orgChild1.orgChild1Code,
orgTreeOrder: orgChild1.orgChild1Order, orgTreeRank: orgChild1.orgChild1Rank,
orgRootCode: orgRoot.orgRootCode, orgTreeOrder: orgChild1.orgChild1Order,
orgTreePhoneEx: orgChild1.orgChild1PhoneEx,
orgTreePhoneIn: orgChild1.orgChild1PhoneIn,
orgTreeFax: orgChild1.orgChild1Fax,
orgRevisionId: orgRoot.orgRevisionId,
orgRootName: orgRoot.orgRootName,
totalPosition: await this.posMasterRepository.count({ where: { orgChild1Id: orgChild1.id }}),
totalPositionCurrentUse: await this.posMasterRepository.count({ where: { orgChild1Id: orgChild1.id, profileIdCurrentHolder: Not(IsNull()) && Not("") }}),
totalPositionCurrentVacant: await this.posMasterRepository.count({ where: { orgChild1Id: orgChild1.id, profileIdCurrentHolder: IsNull() && "" }}),
totalPositionNextUse: await this.posMasterRepository.count({ where: { orgChild1Id: orgChild1.id, profileIdNextHolder: Not(IsNull()) && Not("") }}),
totalPositionNextVacant: await this.posMasterRepository.count({ where: { orgChild1Id: orgChild1.id, profileIdNextHolder: IsNull() && "" }}),
children: 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,
orgTreeOrder: orgChild2.orgChild2Order,
orgRootCode: orgRoot.orgRootCode, orgRootCode: orgRoot.orgRootCode,
orgTreePhoneEx: orgChild2.orgChild2PhoneEx, orgTreePhoneEx: orgChild1.orgChild1PhoneEx,
orgTreePhoneIn: orgChild2.orgChild2PhoneIn, orgTreePhoneIn: orgChild1.orgChild1PhoneIn,
orgTreeFax: orgChild2.orgChild2Fax, orgTreeFax: orgChild1.orgChild1Fax,
orgRevisionId: orgRoot.orgRevisionId, orgRevisionId: orgRoot.orgRevisionId,
orgRootName: orgRoot.orgRootName, orgRootName: orgRoot.orgRootName,
totalPosition: await this.posMasterRepository.count({ where: { orgChild2Id: orgChild2.id }}), totalPosition: await this.posMasterRepository.count({
totalPositionCurrentUse: await this.posMasterRepository.count({ where: { orgChild2Id: orgChild2.id, profileIdCurrentHolder: Not(IsNull()) && Not("") }}), where: { orgChild1Id: orgChild1.id },
totalPositionCurrentVacant: await this.posMasterRepository.count({ where: { orgChild2Id: orgChild2.id, profileIdCurrentHolder: IsNull() && "" }}), }),
totalPositionNextUse: await this.posMasterRepository.count({ where: { orgChild2Id: orgChild2.id, profileIdNextHolder: Not(IsNull()) && Not("") }}), totalPositionCurrentUse: await this.posMasterRepository.count({
totalPositionNextVacant: await this.posMasterRepository.count({ where: { orgChild2Id: orgChild2.id, profileIdNextHolder: IsNull() && "" }}), where: {
children: orgChild3Data orgChild1Id: orgChild1.id,
.filter((orgChild3) => orgChild3.orgChild2Id === orgChild2.id) profileIdCurrentHolder: Not(IsNull()) && Not(""),
.map(async (orgChild3) => ({ },
orgTreeId: orgChild3.id, }),
orgRootId: orgChild2.id, totalPositionCurrentVacant: await this.posMasterRepository.count({
orgLevel: 3, where: { orgChild1Id: orgChild1.id, profileIdCurrentHolder: IsNull() && "" },
orgName: `${orgChild3.orgChild3Name}/${orgChild2.orgChild2Name}/${orgChild1.orgChild1Name}/${orgRoot.orgRootName}`, }),
orgTreeName: orgChild3.orgChild3Name, totalPositionNextUse: await this.posMasterRepository.count({
orgTreeShortName: orgChild3.orgChild3ShortName, where: {
orgTreeCode: orgChild3.orgChild3Code, orgChild1Id: orgChild1.id,
orgCode: orgRoot.orgRootCode + orgChild3.orgChild3Code, profileIdNextHolder: Not(IsNull()) && Not(""),
orgTreeRank: orgChild3.orgChild3Rank, },
orgTreeOrder: orgChild3.orgChild3Order, }),
orgRootCode: orgRoot.orgRootCode, totalPositionNextVacant: await this.posMasterRepository.count({
orgTreePhoneEx: orgChild3.orgChild3PhoneEx, where: { orgChild1Id: orgChild1.id, profileIdNextHolder: IsNull() && "" },
orgTreePhoneIn: orgChild3.orgChild3PhoneIn, }),
orgTreeFax: orgChild3.orgChild3Fax, children: await Promise.all(
orgRevisionId: orgRoot.orgRevisionId, orgChild2Data
orgRootName: orgRoot.orgRootName, .filter((orgChild2) => orgChild2.orgChild1Id === orgChild1.id)
totalPosition: await this.posMasterRepository.count({ where: { orgChild3Id: orgChild3.id }}), .map(async (orgChild2) => ({
totalPositionCurrentUse: await this.posMasterRepository.count({ where: { orgChild3Id: orgChild3.id, profileIdCurrentHolder: Not(IsNull()) && Not("") }}), orgTreeId: orgChild2.id,
totalPositionCurrentVacant: await this.posMasterRepository.count({ where: { orgChild3Id: orgChild3.id, profileIdCurrentHolder: IsNull() && "" }}), orgRootId: orgChild1.id,
totalPositionNextUse: await this.posMasterRepository.count({ where: { orgChild3Id: orgChild3.id, profileIdNextHolder: Not(IsNull()) && Not("") }}), orgLevel: 2,
totalPositionNextVacant: await this.posMasterRepository.count({ where: { orgChild3Id: orgChild3.id, profileIdNextHolder: IsNull() && "" }}), orgName: `${orgChild2.orgChild2Name}/${orgChild1.orgChild1Name}/${orgRoot.orgRootName}`,
children: orgChild4Data orgTreeName: orgChild2.orgChild2Name,
.filter((orgChild4) => orgChild4.orgChild3Id === orgChild3.id) orgTreeShortName: orgChild2.orgChild2ShortName,
.map(async (orgChild4) => ({ orgTreeCode: orgChild2.orgChild2Code,
orgTreeId: orgChild4.id, orgCode: orgRoot.orgRootCode + orgChild2.orgChild2Code,
orgRootId: orgChild3.id, orgTreeRank: orgChild2.orgChild2Rank,
orgLevel: 4, orgTreeOrder: orgChild2.orgChild2Order,
orgName: `${orgChild4.orgChild4Name}/${orgChild3.orgChild3Name}/${orgChild2.orgChild2Name}/${orgChild1.orgChild1Name}/${orgRoot.orgRootName}`, orgRootCode: orgRoot.orgRootCode,
orgTreeName: orgChild4.orgChild4Name, orgTreePhoneEx: orgChild2.orgChild2PhoneEx,
orgTreeShortName: orgChild4.orgChild4ShortName, orgTreePhoneIn: orgChild2.orgChild2PhoneIn,
orgTreeCode: orgChild4.orgChild4Code, orgTreeFax: orgChild2.orgChild2Fax,
orgCode: orgRoot.orgRootCode + orgChild4.orgChild4Code, orgRevisionId: orgRoot.orgRevisionId,
orgTreeRank: orgChild4.orgChild4Rank, orgRootName: orgRoot.orgRootName,
orgTreeOrder: orgChild4.orgChild4Order, totalPosition: await this.posMasterRepository.count({
orgRootCode: orgRoot.orgRootCode, where: { orgChild2Id: orgChild2.id },
orgTreePhoneEx: orgChild4.orgChild4PhoneEx, }),
orgTreePhoneIn: orgChild4.orgChild4PhoneIn, totalPositionCurrentUse: await this.posMasterRepository.count({
orgTreeFax: orgChild4.orgChild4Fax, where: {
orgRevisionId: orgRoot.orgRevisionId, orgChild2Id: orgChild2.id,
orgRootName: orgRoot.orgRootName, profileIdCurrentHolder: Not(IsNull()) && Not(""),
totalPosition: await this.posMasterRepository.count({ where: { orgChild4Id: orgChild4.id }}), },
totalPositionCurrentUse: await this.posMasterRepository.count({ where: { orgChild4Id: orgChild4.id, profileIdCurrentHolder: Not(IsNull()) && Not("") }}), }),
totalPositionCurrentVacant: await this.posMasterRepository.count({ where: { orgChild4Id: orgChild4.id, profileIdCurrentHolder: IsNull() && "" }}), totalPositionCurrentVacant: await this.posMasterRepository.count({
totalPositionNextUse: await this.posMasterRepository.count({ where: { orgChild4Id: orgChild4.id, profileIdNextHolder: Not(IsNull()) && Not("") }}), where: {
totalPositionNextVacant: await this.posMasterRepository.count({ where: { orgChild4Id: orgChild4.id, profileIdNextHolder: IsNull() && "" }}), orgChild2Id: orgChild2.id,
})), profileIdCurrentHolder: IsNull() && "",
})), },
}),
totalPositionNextUse: await this.posMasterRepository.count({
where: {
orgChild2Id: orgChild2.id,
profileIdNextHolder: Not(IsNull()) && Not(""),
},
}),
totalPositionNextVacant: await this.posMasterRepository.count({
where: { orgChild2Id: orgChild2.id, profileIdNextHolder: 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,
orgTreeOrder: orgChild3.orgChild3Order,
orgRootCode: orgRoot.orgRootCode,
orgTreePhoneEx: orgChild3.orgChild3PhoneEx,
orgTreePhoneIn: orgChild3.orgChild3PhoneIn,
orgTreeFax: orgChild3.orgChild3Fax,
orgRevisionId: orgRoot.orgRevisionId,
orgRootName: orgRoot.orgRootName,
totalPosition: await this.posMasterRepository.count({
where: { orgChild3Id: orgChild3.id },
}),
totalPositionCurrentUse: await this.posMasterRepository.count({
where: {
orgChild3Id: orgChild3.id,
profileIdCurrentHolder: Not(IsNull()) && Not(""),
},
}),
totalPositionCurrentVacant: await this.posMasterRepository.count({
where: {
orgChild3Id: orgChild3.id,
profileIdCurrentHolder: IsNull() && "",
},
}),
totalPositionNextUse: await this.posMasterRepository.count({
where: {
orgChild3Id: orgChild3.id,
profileIdNextHolder: Not(IsNull()) && Not(""),
},
}),
totalPositionNextVacant: await this.posMasterRepository.count({
where: {
orgChild3Id: orgChild3.id,
profileIdNextHolder: 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,
orgTreeOrder: orgChild4.orgChild4Order,
orgRootCode: orgRoot.orgRootCode,
orgTreePhoneEx: orgChild4.orgChild4PhoneEx,
orgTreePhoneIn: orgChild4.orgChild4PhoneIn,
orgTreeFax: orgChild4.orgChild4Fax,
orgRevisionId: orgRoot.orgRevisionId,
orgRootName: orgRoot.orgRootName,
totalPosition: await this.posMasterRepository.count({
where: { orgChild4Id: orgChild4.id },
}),
totalPositionCurrentUse: await this.posMasterRepository.count({
where: {
orgChild4Id: orgChild4.id,
profileIdCurrentHolder: Not(IsNull()) && Not(""),
},
}),
totalPositionCurrentVacant:
await this.posMasterRepository.count({
where: {
orgChild4Id: orgChild4.id,
profileIdCurrentHolder: IsNull() && "",
},
}),
totalPositionNextUse: await this.posMasterRepository.count({
where: {
orgChild4Id: orgChild4.id,
profileIdNextHolder: Not(IsNull()) && Not(""),
},
}),
totalPositionNextVacant: await this.posMasterRepository.count({
where: {
orgChild4Id: orgChild4.id,
profileIdNextHolder: IsNull() && "",
},
}),
})),
),
})),
),
})),
),
})), })),
})), ),
}; };
})); }),
);
return new HttpSuccess(formattedData); return new HttpSuccess(formattedData);
} catch (error) { } catch (error) {