update validate privilege (#201)

This commit is contained in:
AdisakKanthawilang 2025-10-20 17:45:43 +07:00 committed by GitHub
parent 25f3a6535f
commit 45cc074e81
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 57 additions and 9 deletions

View file

@ -2134,7 +2134,6 @@ export class PositionController extends Controller {
orgChild1Id: IsNull(),
};
searchShortName = `CONCAT(orgRoot.orgRootShortName," ",posMaster.posMasterNo) like '%${body.keyword}%'`;
} else {
}
} else if (body.type === 1) {
typeCondition = {
@ -2145,7 +2144,6 @@ export class PositionController extends Controller {
orgChild2Id: IsNull(),
};
searchShortName = `CONCAT(orgChild1.orgChild1ShortName," ",posMaster.posMasterNo) like '%${body.keyword}%'`;
} else {
}
} else if (body.type === 2) {
typeCondition = {
@ -2156,7 +2154,6 @@ export class PositionController extends Controller {
orgChild3Id: IsNull(),
};
searchShortName = `CONCAT(orgChild2.orgChild2ShortName," ",posMaster.posMasterNo) like '%${body.keyword}%'`;
} else {
}
} else if (body.type === 3) {
typeCondition = {
@ -2167,7 +2164,6 @@ export class PositionController extends Controller {
orgChild4Id: IsNull(),
};
searchShortName = `CONCAT(orgChild3.orgChild3ShortName," ",posMaster.posMasterNo) like '%${body.keyword}%'`;
} else {
}
} else if (body.type === 4) {
typeCondition = {
@ -2524,6 +2520,40 @@ export class PositionController 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 });
}