กำหนดสิทธิ์จัดการโครงสร้าง ผูกกับแบบร่าง

This commit is contained in:
kittapath 2024-09-09 14:45:00 +07:00
parent b544380018
commit 1b57a23e97

View file

@ -600,7 +600,7 @@ export class OrganizationController extends Controller {
*/
@Get("{id}")
async detail(@Path() id: string, @Request() request: RequestWithUser) {
let _data = {
let _data: any = {
root: null,
child1: null,
child2: null,
@ -608,14 +608,36 @@ export class OrganizationController extends Controller {
child4: null,
};
if (!request.user.role.includes("SUPER_ADMIN")) {
_data = await new permission().PermissionOrgList(request, "SYS_ORG");
}
const orgRevision = await this.orgRevisionRepository.findOne({ where: { id } });
if (!orgRevision) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
}
if (
!request.user.role.includes("SUPER_ADMIN") &&
orgRevision.orgRevisionIsCurrent == true &&
orgRevision.orgRevisionIsDraft == false
) {
_data = await new permission().PermissionOrgList(request, "SYS_ORG");
}
if (orgRevision.orgRevisionIsDraft == true && orgRevision.orgRevisionIsCurrent == false) {
const profile = await this.profileRepo.findOne({
where: { keycloak: request.user.sub },
relations: ["permissionProfiles"],
});
if (!profile) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลผู้ใช้งานในทะเบียนประวัติ");
}
_data = {
root: profile.permissionProfiles.map((x) => x.orgRootId),
child1: null,
child2: null,
child3: null,
child4: null,
};
}
const orgRootData = await AppDataSource.getRepository(OrgRoot)
.createQueryBuilder("orgRoot")
.where("orgRoot.orgRevisionId = :id", { id })