fix: #2239
All checks were successful
Build & Deploy on Dev / build (push) Successful in 48s
All checks were successful
Build & Deploy on Dev / build (push) Successful in 48s
This commit is contained in:
parent
1696890f74
commit
8a649086f7
3 changed files with 242 additions and 164 deletions
|
|
@ -33,7 +33,7 @@ import { PosMaster } from "../entities/PosMaster";
|
|||
import { Profile } from "../entities/Profile";
|
||||
import { RequestWithUser } from "../middlewares/user";
|
||||
import permission from "../interfaces/permission";
|
||||
import { checkQueueInProgress, setLogDataDiff } from "../interfaces/utils";
|
||||
import { checkQueueInProgress, resolveNodeId, resolveNodeLevel, setLogDataDiff } from "../interfaces/utils";
|
||||
import { sendToQueueOrg, sendToQueueOrgDraft } from "../services/rabbitmq";
|
||||
import { PosType } from "../entities/PosType";
|
||||
import { PosLevel } from "../entities/PosLevel";
|
||||
|
|
@ -5516,6 +5516,8 @@ export class OrganizationController extends Controller {
|
|||
}
|
||||
}
|
||||
|
||||
const orgDna = await new permission().checkDna(request, request.user.sub)
|
||||
let level: any = resolveNodeLevel(orgDna);
|
||||
|
||||
const orgRootData = await AppDataSource.getRepository(OrgRoot)
|
||||
.createQueryBuilder("orgRoot")
|
||||
|
|
@ -5623,6 +5625,36 @@ export class OrganizationController extends Controller {
|
|||
.getMany()
|
||||
: [];
|
||||
|
||||
const cannotViewRootPosMaster =
|
||||
(_privilege.privilege === "PARENT") ||
|
||||
(_privilege.privilege === "BROTHER" && level > 1) ||
|
||||
(_privilege.privilege === "CHILD" && level != 0) ||
|
||||
(_privilege.privilege === "NORMAL" && level != 0);
|
||||
|
||||
const cannotViewChild1PosMaster =
|
||||
(_privilege.privilege === "PARENT" && level > 1) ||
|
||||
(_privilege.privilege === "BROTHER" && level > 2) ||
|
||||
(_privilege.privilege === "CHILD" && level !== 1) ||
|
||||
(_privilege.privilege === "NORMAL" && level !== 1);
|
||||
|
||||
const cannotViewChild2PosMaster =
|
||||
(_privilege.privilege === "PARENT" && level > 2) ||
|
||||
(_privilege.privilege === "BROTHER" && level > 3) ||
|
||||
(_privilege.privilege === "CHILD" && level !== 2) ||
|
||||
(_privilege.privilege === "NORMAL" && level !== 2);
|
||||
|
||||
const cannotViewChild3PosMaster =
|
||||
(_privilege.privilege === "PARENT" && level > 3) ||
|
||||
(_privilege.privilege === "BROTHER" && level > 4) ||
|
||||
(_privilege.privilege === "CHILD" && level !== 3) ||
|
||||
(_privilege.privilege === "NORMAL" && level !== 3);
|
||||
|
||||
const cannotViewChild4PosMaster =
|
||||
(_privilege.privilege === "PARENT" && level > 4) ||
|
||||
(_privilege.privilege === "CHILD" && level !== 4) ||
|
||||
(_privilege.privilege === "NORMAL" && level !== 4);
|
||||
|
||||
|
||||
// const formattedData = orgRootData.map((orgRoot) => {
|
||||
const formattedData = await Promise.all(
|
||||
orgRootData.map(async (orgRoot) => {
|
||||
|
|
@ -5637,27 +5669,29 @@ export class OrganizationController extends Controller {
|
|||
orgRootName: orgRoot.orgRootName,
|
||||
labelName:
|
||||
orgRoot.orgRootName + " " + orgRoot.orgRootCode + "00" + " " + orgRoot.orgRootShortName,
|
||||
posMaster: await Promise.all(
|
||||
orgRoot.posMasters
|
||||
.filter(
|
||||
(x) =>
|
||||
x.orgChild1Id == null &&
|
||||
// x.current_holderId != null &&
|
||||
x.isDirector === true,
|
||||
)
|
||||
// .sort((a, b) => a.posMasterOrder - b.posMasterOrder) // Sort by posMasterOrder ASC
|
||||
// .slice(0, 3) // Select the first 3 rows
|
||||
.map(async (x) => ({
|
||||
posmasterId: x.id,
|
||||
posNo: `${orgRoot.orgRootShortName} ${x.posMasterNo}`,
|
||||
orgTreeId: orgRoot.id,
|
||||
orgLevel: 0,
|
||||
fullNameCurrentHolder:
|
||||
x.current_holder == null
|
||||
? null
|
||||
: `${x.current_holder.prefix}${x.current_holder.firstName} ${x.current_holder.lastName}`,
|
||||
})),
|
||||
),
|
||||
posMaster:
|
||||
cannotViewRootPosMaster ? [] :
|
||||
await Promise.all(
|
||||
orgRoot.posMasters
|
||||
.filter(
|
||||
(x) =>
|
||||
x.orgChild1Id == null &&
|
||||
// x.current_holderId != null &&
|
||||
x.isDirector === true,
|
||||
)
|
||||
// .sort((a, b) => a.posMasterOrder - b.posMasterOrder) // Sort by posMasterOrder ASC
|
||||
// .slice(0, 3) // Select the first 3 rows
|
||||
.map(async (x) => ({
|
||||
posmasterId: x.id,
|
||||
posNo: `${orgRoot.orgRootShortName} ${x.posMasterNo}`,
|
||||
orgTreeId: orgRoot.id,
|
||||
orgLevel: 0,
|
||||
fullNameCurrentHolder:
|
||||
x.current_holder == null
|
||||
? null
|
||||
: `${x.current_holder.prefix}${x.current_holder.firstName} ${x.current_holder.lastName}`,
|
||||
})),
|
||||
),
|
||||
children: await Promise.all(
|
||||
orgChild1Data
|
||||
.filter((orgChild1) => orgChild1.orgRootId === orgRoot.id)
|
||||
|
|
@ -5685,27 +5719,29 @@ export class OrganizationController extends Controller {
|
|||
"00" +
|
||||
" " +
|
||||
orgRoot.orgRootShortName,
|
||||
posMaster: await Promise.all(
|
||||
orgChild1.posMasters
|
||||
.filter(
|
||||
(x) =>
|
||||
x.orgChild2Id == null &&
|
||||
// x.current_holderId != null &&
|
||||
x.isDirector === true,
|
||||
)
|
||||
// .sort((a, b) => a.posMasterOrder - b.posMasterOrder) // Sort by posMasterOrder ASC
|
||||
// .slice(0, 3) // Select the first 3 rows
|
||||
.map(async (x) => ({
|
||||
posmasterId: x.id,
|
||||
posNo: `${orgChild1.orgChild1ShortName} ${x.posMasterNo}`,
|
||||
orgTreeId: orgChild1.id,
|
||||
orgLevel: 1,
|
||||
fullNameCurrentHolder:
|
||||
x.current_holder == null
|
||||
? null
|
||||
: `${x.current_holder.prefix}${x.current_holder.firstName} ${x.current_holder.lastName}`,
|
||||
})),
|
||||
),
|
||||
posMaster:
|
||||
cannotViewChild1PosMaster ? [] :
|
||||
await Promise.all(
|
||||
orgChild1.posMasters
|
||||
.filter(
|
||||
(x) =>
|
||||
x.orgChild2Id == null &&
|
||||
// x.current_holderId != null &&
|
||||
x.isDirector === true,
|
||||
)
|
||||
// .sort((a, b) => a.posMasterOrder - b.posMasterOrder) // Sort by posMasterOrder ASC
|
||||
// .slice(0, 3) // Select the first 3 rows
|
||||
.map(async (x) => ({
|
||||
posmasterId: x.id,
|
||||
posNo: `${orgChild1.orgChild1ShortName} ${x.posMasterNo}`,
|
||||
orgTreeId: orgChild1.id,
|
||||
orgLevel: 1,
|
||||
fullNameCurrentHolder:
|
||||
x.current_holder == null
|
||||
? null
|
||||
: `${x.current_holder.prefix}${x.current_holder.firstName} ${x.current_holder.lastName}`,
|
||||
})),
|
||||
),
|
||||
|
||||
children: await Promise.all(
|
||||
orgChild2Data
|
||||
|
|
@ -5741,27 +5777,29 @@ export class OrganizationController extends Controller {
|
|||
"00" +
|
||||
" " +
|
||||
orgRoot.orgRootShortName,
|
||||
posMaster: await Promise.all(
|
||||
orgChild2.posMasters
|
||||
.filter(
|
||||
(x) =>
|
||||
x.orgChild3Id == null &&
|
||||
// x.current_holderId != null &&
|
||||
x.isDirector === true,
|
||||
)
|
||||
// .sort((a, b) => a.posMasterOrder - b.posMasterOrder) // Sort by posMasterOrder ASC
|
||||
// .slice(0, 3) // Select the first 3 rows
|
||||
.map(async (x) => ({
|
||||
posmasterId: x.id,
|
||||
posNo: `${orgChild2.orgChild2ShortName} ${x.posMasterNo}`,
|
||||
orgTreeId: orgChild2.id,
|
||||
orgLevel: 2,
|
||||
fullNameCurrentHolder:
|
||||
x.current_holder == null
|
||||
? null
|
||||
: `${x.current_holder.prefix}${x.current_holder.firstName} ${x.current_holder.lastName}`,
|
||||
})),
|
||||
),
|
||||
posMaster:
|
||||
cannotViewChild2PosMaster ? [] :
|
||||
await Promise.all(
|
||||
orgChild2.posMasters
|
||||
.filter(
|
||||
(x) =>
|
||||
x.orgChild3Id == null &&
|
||||
// x.current_holderId != null &&
|
||||
x.isDirector === true,
|
||||
)
|
||||
// .sort((a, b) => a.posMasterOrder - b.posMasterOrder) // Sort by posMasterOrder ASC
|
||||
// .slice(0, 3) // Select the first 3 rows
|
||||
.map(async (x) => ({
|
||||
posmasterId: x.id,
|
||||
posNo: `${orgChild2.orgChild2ShortName} ${x.posMasterNo}`,
|
||||
orgTreeId: orgChild2.id,
|
||||
orgLevel: 2,
|
||||
fullNameCurrentHolder:
|
||||
x.current_holder == null
|
||||
? null
|
||||
: `${x.current_holder.prefix}${x.current_holder.firstName} ${x.current_holder.lastName}`,
|
||||
})),
|
||||
),
|
||||
|
||||
children: await Promise.all(
|
||||
orgChild3Data
|
||||
|
|
@ -5804,27 +5842,29 @@ export class OrganizationController extends Controller {
|
|||
"00" +
|
||||
" " +
|
||||
orgRoot.orgRootShortName,
|
||||
posMaster: await Promise.all(
|
||||
orgChild3.posMasters
|
||||
.filter(
|
||||
(x) =>
|
||||
x.orgChild4Id == null &&
|
||||
// x.current_holderId != null &&
|
||||
x.isDirector === true,
|
||||
)
|
||||
// .sort((a, b) => a.posMasterOrder - b.posMasterOrder) // Sort by posMasterOrder ASC
|
||||
// .slice(0, 3) // Select the first 3 rows
|
||||
.map(async (x) => ({
|
||||
posmasterId: x.id,
|
||||
posNo: `${orgChild3.orgChild3ShortName} ${x.posMasterNo}`,
|
||||
orgTreeId: orgChild3.id,
|
||||
orgLevel: 3,
|
||||
fullNameCurrentHolder:
|
||||
x.current_holder == null
|
||||
? null
|
||||
: `${x.current_holder.prefix}${x.current_holder.firstName} ${x.current_holder.lastName}`,
|
||||
})),
|
||||
),
|
||||
posMaster:
|
||||
cannotViewChild3PosMaster ? [] :
|
||||
await Promise.all(
|
||||
orgChild3.posMasters
|
||||
.filter(
|
||||
(x) =>
|
||||
x.orgChild4Id == null &&
|
||||
// x.current_holderId != null &&
|
||||
x.isDirector === true,
|
||||
)
|
||||
// .sort((a, b) => a.posMasterOrder - b.posMasterOrder) // Sort by posMasterOrder ASC
|
||||
// .slice(0, 3) // Select the first 3 rows
|
||||
.map(async (x) => ({
|
||||
posmasterId: x.id,
|
||||
posNo: `${orgChild3.orgChild3ShortName} ${x.posMasterNo}`,
|
||||
orgTreeId: orgChild3.id,
|
||||
orgLevel: 3,
|
||||
fullNameCurrentHolder:
|
||||
x.current_holder == null
|
||||
? null
|
||||
: `${x.current_holder.prefix}${x.current_holder.firstName} ${x.current_holder.lastName}`,
|
||||
})),
|
||||
),
|
||||
|
||||
children: await Promise.all(
|
||||
orgChild4Data
|
||||
|
|
@ -5874,26 +5914,28 @@ export class OrganizationController extends Controller {
|
|||
"00" +
|
||||
" " +
|
||||
orgRoot.orgRootShortName,
|
||||
posMaster: await Promise.all(
|
||||
orgChild4.posMasters
|
||||
.filter(
|
||||
(x) =>
|
||||
// x.current_holderId != null &&
|
||||
x.isDirector === true,
|
||||
)
|
||||
// .sort((a, b) => a.posMasterOrder - b.posMasterOrder) // Sort by posMasterOrder ASC
|
||||
// .slice(0, 3) // Select the first 3 rows
|
||||
.map(async (x) => ({
|
||||
posmasterId: x.id,
|
||||
posNo: `${orgChild4.orgChild4ShortName} ${x.posMasterNo}`,
|
||||
orgTreeId: orgChild4.id,
|
||||
orgLevel: 4,
|
||||
fullNameCurrentHolder:
|
||||
x.current_holder == null
|
||||
? null
|
||||
: `${x.current_holder.prefix}${x.current_holder.firstName} ${x.current_holder.lastName}`,
|
||||
})),
|
||||
),
|
||||
posMaster:
|
||||
cannotViewChild4PosMaster ? [] :
|
||||
await Promise.all(
|
||||
orgChild4.posMasters
|
||||
.filter(
|
||||
(x) =>
|
||||
// x.current_holderId != null &&
|
||||
x.isDirector === true,
|
||||
)
|
||||
// .sort((a, b) => a.posMasterOrder - b.posMasterOrder) // Sort by posMasterOrder ASC
|
||||
// .slice(0, 3) // Select the first 3 rows
|
||||
.map(async (x) => ({
|
||||
posmasterId: x.id,
|
||||
posNo: `${orgChild4.orgChild4ShortName} ${x.posMasterNo}`,
|
||||
orgTreeId: orgChild4.id,
|
||||
orgLevel: 4,
|
||||
fullNameCurrentHolder:
|
||||
x.current_holder == null
|
||||
? null
|
||||
: `${x.current_holder.prefix}${x.current_holder.firstName} ${x.current_holder.lastName}`,
|
||||
})),
|
||||
),
|
||||
})),
|
||||
),
|
||||
})),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue