This commit is contained in:
parent
0f22605784
commit
35011ea959
3 changed files with 224 additions and 3 deletions
|
|
@ -6098,7 +6098,7 @@ export class OrganizationController extends Controller {
|
|||
if (!orgRevision) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
}
|
||||
let _data = {
|
||||
let _data:any = {
|
||||
root: null,
|
||||
child1: null,
|
||||
child2: null,
|
||||
|
|
@ -6111,6 +6111,58 @@ export class OrganizationController extends Controller {
|
|||
) {
|
||||
_data = await new permission().PermissionOrgList(request, system.trim().toUpperCase());
|
||||
}
|
||||
|
||||
const profile = await this.profileRepo.findOne({
|
||||
where: { keycloak: request.user.sub },
|
||||
relations: ["permissionProfiles", "current_holders"],
|
||||
});
|
||||
|
||||
if (!profile) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลผู้ใช้งานในทะเบียนประวัติ");
|
||||
}
|
||||
|
||||
let _privilege = await new permission().PermissionOrgList(request, system);
|
||||
const attrOwnership = _privilege.root === null ? true : false;
|
||||
|
||||
if (orgRevision.orgRevisionIsDraft && !orgRevision.orgRevisionIsCurrent && !attrOwnership) {
|
||||
if(Array.isArray(profile.permissionProfiles) && profile.permissionProfiles.length > 0){
|
||||
_data.root = profile.permissionProfiles.map((x) => x.orgRootId);
|
||||
}else{
|
||||
return new HttpSuccess({ remark: "", data: [] });
|
||||
}
|
||||
}
|
||||
|
||||
// กำหนดการเข้าถึงข้อมูลตามสถานะและสิทธิ์
|
||||
const isCurrentActive = !orgRevision.orgRevisionIsDraft && orgRevision.orgRevisionIsCurrent;
|
||||
if (isCurrentActive) {
|
||||
if(_privilege.privilege == "NORMAL"){
|
||||
const holder = profile.current_holders.find(x => x.orgRevisionId === id);
|
||||
if (!holder) return;
|
||||
_data.root = [holder.orgRootId];
|
||||
_data.child1 = [holder.orgChild1Id];
|
||||
_data.child2 = [holder.orgChild2Id];
|
||||
_data.child3 = [holder.orgChild3Id];
|
||||
_data.child4 = [holder.orgChild4Id];
|
||||
}else if(_privilege.privilege == "CHILD"){
|
||||
const holder = profile.current_holders.find(x => x.orgRevisionId === id);
|
||||
if (!holder) return;
|
||||
_data.root = [holder.orgRootId];
|
||||
if (_privilege.root && _privilege.child1 === null) {
|
||||
} else if (_privilege.child1 && _privilege.child2 === null) {
|
||||
_data.child1 = [holder.orgChild1Id];
|
||||
} else if (_privilege.child2 && _privilege.child3 === null) {
|
||||
_data.child1 = [holder.orgChild1Id];
|
||||
_data.child2 = [holder.orgChild2Id];
|
||||
} else if (_privilege.child3 && _privilege.child4 === null) {
|
||||
_data.child1 = [holder.orgChild1Id];
|
||||
_data.child2 = [holder.orgChild2Id];
|
||||
_data.child3 = [holder.orgChild3Id];
|
||||
_data.child4 = [holder.orgChild4Id];
|
||||
}
|
||||
}else{
|
||||
_data.root = [profile.current_holders.find((x) => x.orgRevisionId === id)?.orgRootId];
|
||||
}
|
||||
}
|
||||
|
||||
const orgRootData = await AppDataSource.getRepository(OrgRoot)
|
||||
.createQueryBuilder("orgRoot")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue