updated permission menu

This commit is contained in:
Warunee Tamkoo 2024-07-24 15:44:34 +07:00
parent c49884fdd9
commit 1e3699b049
2 changed files with 77 additions and 51 deletions

View file

@ -9,6 +9,7 @@ import { AuthRole } from "../entities/AuthRole";
import { AuthRoleAttr } from "../entities/AuthRoleAttr";
import { PosMaster } from "../entities/PosMaster";
import { Profile } from "../entities/Profile";
import { AuthSys } from "../entities/AuthSys";
const REDIS_HOST = process.env.REDIS_HOST;
const REDIS_PORT = process.env.REDIS_PORT;
@ -20,6 +21,7 @@ export class PermissionController extends Controller {
private posMasterRepository = AppDataSource.getRepository(PosMaster);
private authRoleRepo = AppDataSource.getRepository(AuthRole);
private authRoleAttrRepo = AppDataSource.getRepository(AuthRoleAttr);
private authSysRepo = AppDataSource.getRepository(AuthSys);
private redis = require("redis");
@Get("")
@ -28,61 +30,85 @@ export class PermissionController extends Controller {
host: REDIS_HOST,
port: REDIS_PORT,
});
const formattedData = null;
// const formattedData = null;
// await Promise.all([
return new HttpSuccess(
redisClient.get(request.user.sub, async (err: any, reply: any) => {
if (reply != null) {
return JSON.parse(reply);
} else {
const profile = await this.profileRepo.findOne({
select: ["id"],
where: { keycloak: request.user.sub },
});
if (!profile) {
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลบุคคลนี้ในระบบ");
}
// return new HttpSuccess(
// redisClient.get(request.user.sub, async (err: any, reply: any) => {
// if (reply != null) {
// return JSON.parse(reply);
// } else {
const profile = await this.profileRepo.findOne({
select: ["id"],
where: { keycloak: request.user.sub },
});
if (!profile) {
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลบุคคลนี้ในระบบ");
}
const posMaster = await this.posMasterRepository.findOne({
select: ["authRoleId"],
where: { current_holderId: profile.id },
});
if (!posMaster) {
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลสิทธิ์");
}
const posMaster = await this.posMasterRepository.findOne({
select: ["authRoleId"],
where: { current_holderId: profile.id },
});
if (!posMaster) {
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลสิทธิ์");
}
const getDetail = await this.authRoleRepo.findOne({
select: ["id", "roleName", "roleDescription"],
where: { id: posMaster.authRoleId },
});
if (!getDetail) {
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
}
const getDetail = await this.authRoleRepo.findOne({
select: ["id", "roleName", "roleDescription"],
where: { id: posMaster.authRoleId },
});
if (!getDetail) {
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
}
const roleAttrData = await this.authRoleAttrRepo.find({
select: [
"authSysId",
"parentNode",
"attrOwnership",
"attrIsCreate",
"attrIsList",
"attrIsGet",
"attrIsUpdate",
"attrIsDelete",
"attrPrivilege",
],
where: { authRoleId: getDetail.id },
});
const roleAttrData = await this.authRoleAttrRepo.find({
select: [
"authSysId",
"parentNode",
"attrOwnership",
"attrIsCreate",
"attrIsList",
"attrIsGet",
"attrIsUpdate",
"attrIsDelete",
"attrPrivilege",
],
where: { authRoleId: getDetail.id },
});
const formattedData = {
...getDetail,
roleAttributes: roleAttrData,
};
redisClient.setex(request.user.sub, 20, JSON.stringify(formattedData));
return formattedData;
}
}),
);
const formattedData = {
...getDetail,
roles: roleAttrData,
};
return new HttpSuccess(formattedData);
// redisClient.setex(request.user.sub, 20, JSON.stringify(formattedData));
// return formattedData;
// }
// }),
// );
// ]);
}
@Get("menu")
public async listAuthSys() {
const getList = await this.authSysRepo.find({
select: ["id", "parentId", "sysName", "sysDescription", "icon", "path", "order"],
});
if (!getList || getList.length === 0) {
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
}
const lists = getList
.filter((x) => x.parentId == null)
.map((item) => {
return {
...item,
children: getList.filter((x) => x.parentId == item.id).sort((a, b) => a.order - b.order),
};
})
.sort((a, b) => a.order - b.order);
return new HttpSuccess(lists);
}
}

View file

@ -75,7 +75,7 @@ export class AuthRoleAttr extends EntityBase {
})
parentNode?: string;
// @ManyToOne(() => AuthSys, (authSys) => authSys.authSys)
// @ManyToOne(() => AuthSys, (authSys) => authSys)
// @JoinColumn({ name: "authSysId" })
// authRoleAttrForSys: AuthSys;