This commit is contained in:
parent
0f22605784
commit
35011ea959
3 changed files with 224 additions and 3 deletions
|
|
@ -1006,6 +1006,7 @@ export class EmployeePositionController extends Controller {
|
|||
*/
|
||||
@Post("master/list")
|
||||
async listEmp(
|
||||
@Request() request: RequestWithUser,
|
||||
@Body()
|
||||
body: {
|
||||
id: string;
|
||||
|
|
@ -1026,7 +1027,7 @@ export class EmployeePositionController extends Controller {
|
|||
let searchShortName2 = `CONCAT(orgChild2.orgChild2ShortName," ",posMaster.posMasterNoPrefix,posMaster.posMasterNo,posMaster.posMasterNoSuffix)`;
|
||||
let searchShortName3 = `CONCAT(orgChild3.orgChild3ShortName," ",posMaster.posMasterNoPrefix,posMaster.posMasterNo,posMaster.posMasterNoSuffix)`;
|
||||
let searchShortName4 = `CONCAT(orgChild4.orgChild4ShortName," ",posMaster.posMasterNoPrefix,posMaster.posMasterNo,posMaster.posMasterNoSuffix)`;
|
||||
|
||||
let _data = await new permission().PermissionOrgList(request, "SYS_ORG_EMP");
|
||||
if (body.type === 0) {
|
||||
typeCondition = {
|
||||
orgRootId: body.id,
|
||||
|
|
@ -1139,6 +1140,56 @@ export class EmployeePositionController extends Controller {
|
|||
.leftJoinAndSelect("positions.posType", "posType")
|
||||
.leftJoinAndSelect("positions.posLevel", "posLevel")
|
||||
.where(conditions)
|
||||
.andWhere(
|
||||
_data.root != undefined && _data.root != null
|
||||
? _data.root[0] != null
|
||||
? `posMaster.orgRootId IN (:...root)`
|
||||
: `posMaster.orgRootId is null`
|
||||
: "1=1",
|
||||
{
|
||||
root: _data.root,
|
||||
},
|
||||
)
|
||||
.andWhere(
|
||||
_data.child1 != undefined && _data.child1 != null
|
||||
? _data.child1[0] != null
|
||||
? `posMaster.orgChild1Id IN (:...child1)`
|
||||
: `posMaster.orgChild1Id is null`
|
||||
: "1=1",
|
||||
{
|
||||
child1: _data.child1,
|
||||
},
|
||||
)
|
||||
.andWhere(
|
||||
_data.child2 != undefined && _data.child2 != null
|
||||
? _data.child2[0] != null
|
||||
? `posMaster.orgChild2Id IN (:...child2)`
|
||||
: `posMaster.orgChild2Id is null`
|
||||
: "1=1",
|
||||
{
|
||||
child2: _data.child2,
|
||||
},
|
||||
)
|
||||
.andWhere(
|
||||
_data.child3 != undefined && _data.child3 != null
|
||||
? _data.child3[0] != null
|
||||
? `posMaster.orgChild3Id IN (:...child3)`
|
||||
: `posMaster.orgChild3Id is null`
|
||||
: "1=1",
|
||||
{
|
||||
child3: _data.child3,
|
||||
},
|
||||
)
|
||||
.andWhere(
|
||||
_data.child4 != undefined && _data.child4 != null
|
||||
? _data.child4[0] != null
|
||||
? `posMaster.orgChild4Id IN (:...child4)`
|
||||
: `posMaster.orgChild4Id is null`
|
||||
: "1=1",
|
||||
{
|
||||
child4: _data.child4,
|
||||
},
|
||||
)
|
||||
.orWhere(
|
||||
new Brackets((qb) => {
|
||||
qb.andWhere(
|
||||
|
|
@ -1330,6 +1381,40 @@ export class EmployeePositionController extends Controller {
|
|||
};
|
||||
}),
|
||||
);
|
||||
|
||||
if(_data.privilege === 'NORMAL'|| _data.privilege === 'PARENT'|| _data.privilege === 'CHILD'){ //PARENT จะไม่มีทางเห็น ROOT , CHILD ยึดจาก CHILD ที่อยู่ลงไปข้างล่างและจะไม่เห็น CHILD ที่อยู่เหนือกว่า
|
||||
const nextChildMap:any = { //เอาไวเช็ค CHILD ถัดไป
|
||||
0: _data.child1,
|
||||
1: _data.child2,
|
||||
2: _data.child3,
|
||||
3: _data.child4,
|
||||
};
|
||||
const childValue = nextChildMap[body.type];
|
||||
if(_data.privilege === 'NORMAL'){
|
||||
if (Array.isArray(childValue) && childValue.some(item => item != null)) {
|
||||
return new HttpSuccess({ data: [], total: 0 });
|
||||
}
|
||||
}else if(_data.privilege === 'PARENT'){
|
||||
if (body.type == 0){
|
||||
return new HttpSuccess({ data: [], total: 0 });
|
||||
}
|
||||
} else if (_data.privilege === 'CHILD') {
|
||||
const higherChildChecks = [
|
||||
{ type: [0], child: _data.child1, next: _data.child2 },
|
||||
{ type: [0, 1], child: _data.child2, next: _data.child3 },
|
||||
{ type: [0, 1, 2], child: _data.child3, next: _data.child4 },
|
||||
{ type: [0, 1, 2, 3], child: _data.child4, next: true },
|
||||
];
|
||||
|
||||
for (const check of higherChildChecks) {
|
||||
if (Array.isArray(check.child) && check.next == null) {
|
||||
if (check.type.includes(body.type)) {
|
||||
return new HttpSuccess({ data: [], total: 0 });
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return new HttpSuccess({ data: formattedData, total });
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue