updated permission menu
This commit is contained in:
parent
c49884fdd9
commit
1e3699b049
2 changed files with 77 additions and 51 deletions
|
|
@ -9,6 +9,7 @@ import { AuthRole } from "../entities/AuthRole";
|
||||||
import { AuthRoleAttr } from "../entities/AuthRoleAttr";
|
import { AuthRoleAttr } from "../entities/AuthRoleAttr";
|
||||||
import { PosMaster } from "../entities/PosMaster";
|
import { PosMaster } from "../entities/PosMaster";
|
||||||
import { Profile } from "../entities/Profile";
|
import { Profile } from "../entities/Profile";
|
||||||
|
import { AuthSys } from "../entities/AuthSys";
|
||||||
const REDIS_HOST = process.env.REDIS_HOST;
|
const REDIS_HOST = process.env.REDIS_HOST;
|
||||||
const REDIS_PORT = process.env.REDIS_PORT;
|
const REDIS_PORT = process.env.REDIS_PORT;
|
||||||
|
|
||||||
|
|
@ -20,6 +21,7 @@ export class PermissionController extends Controller {
|
||||||
private posMasterRepository = AppDataSource.getRepository(PosMaster);
|
private posMasterRepository = AppDataSource.getRepository(PosMaster);
|
||||||
private authRoleRepo = AppDataSource.getRepository(AuthRole);
|
private authRoleRepo = AppDataSource.getRepository(AuthRole);
|
||||||
private authRoleAttrRepo = AppDataSource.getRepository(AuthRoleAttr);
|
private authRoleAttrRepo = AppDataSource.getRepository(AuthRoleAttr);
|
||||||
|
private authSysRepo = AppDataSource.getRepository(AuthSys);
|
||||||
private redis = require("redis");
|
private redis = require("redis");
|
||||||
|
|
||||||
@Get("")
|
@Get("")
|
||||||
|
|
@ -28,61 +30,85 @@ export class PermissionController extends Controller {
|
||||||
host: REDIS_HOST,
|
host: REDIS_HOST,
|
||||||
port: REDIS_PORT,
|
port: REDIS_PORT,
|
||||||
});
|
});
|
||||||
const formattedData = null;
|
// const formattedData = null;
|
||||||
// await Promise.all([
|
// await Promise.all([
|
||||||
return new HttpSuccess(
|
// return new HttpSuccess(
|
||||||
redisClient.get(request.user.sub, async (err: any, reply: any) => {
|
// redisClient.get(request.user.sub, async (err: any, reply: any) => {
|
||||||
if (reply != null) {
|
// if (reply != null) {
|
||||||
return JSON.parse(reply);
|
// return JSON.parse(reply);
|
||||||
} else {
|
// } else {
|
||||||
const profile = await this.profileRepo.findOne({
|
const profile = await this.profileRepo.findOne({
|
||||||
select: ["id"],
|
select: ["id"],
|
||||||
where: { keycloak: request.user.sub },
|
where: { keycloak: request.user.sub },
|
||||||
});
|
});
|
||||||
if (!profile) {
|
if (!profile) {
|
||||||
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลบุคคลนี้ในระบบ");
|
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลบุคคลนี้ในระบบ");
|
||||||
}
|
}
|
||||||
|
|
||||||
const posMaster = await this.posMasterRepository.findOne({
|
const posMaster = await this.posMasterRepository.findOne({
|
||||||
select: ["authRoleId"],
|
select: ["authRoleId"],
|
||||||
where: { current_holderId: profile.id },
|
where: { current_holderId: profile.id },
|
||||||
});
|
});
|
||||||
if (!posMaster) {
|
if (!posMaster) {
|
||||||
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลสิทธิ์");
|
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลสิทธิ์");
|
||||||
}
|
}
|
||||||
|
|
||||||
const getDetail = await this.authRoleRepo.findOne({
|
const getDetail = await this.authRoleRepo.findOne({
|
||||||
select: ["id", "roleName", "roleDescription"],
|
select: ["id", "roleName", "roleDescription"],
|
||||||
where: { id: posMaster.authRoleId },
|
where: { id: posMaster.authRoleId },
|
||||||
});
|
});
|
||||||
if (!getDetail) {
|
if (!getDetail) {
|
||||||
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
||||||
}
|
}
|
||||||
|
|
||||||
const roleAttrData = await this.authRoleAttrRepo.find({
|
const roleAttrData = await this.authRoleAttrRepo.find({
|
||||||
select: [
|
select: [
|
||||||
"authSysId",
|
"authSysId",
|
||||||
"parentNode",
|
"parentNode",
|
||||||
"attrOwnership",
|
"attrOwnership",
|
||||||
"attrIsCreate",
|
"attrIsCreate",
|
||||||
"attrIsList",
|
"attrIsList",
|
||||||
"attrIsGet",
|
"attrIsGet",
|
||||||
"attrIsUpdate",
|
"attrIsUpdate",
|
||||||
"attrIsDelete",
|
"attrIsDelete",
|
||||||
"attrPrivilege",
|
"attrPrivilege",
|
||||||
],
|
],
|
||||||
where: { authRoleId: getDetail.id },
|
where: { authRoleId: getDetail.id },
|
||||||
});
|
});
|
||||||
|
|
||||||
const formattedData = {
|
const formattedData = {
|
||||||
...getDetail,
|
...getDetail,
|
||||||
roleAttributes: roleAttrData,
|
roles: roleAttrData,
|
||||||
};
|
};
|
||||||
redisClient.setex(request.user.sub, 20, JSON.stringify(formattedData));
|
return new HttpSuccess(formattedData);
|
||||||
return 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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -75,7 +75,7 @@ export class AuthRoleAttr extends EntityBase {
|
||||||
})
|
})
|
||||||
parentNode?: string;
|
parentNode?: string;
|
||||||
|
|
||||||
// @ManyToOne(() => AuthSys, (authSys) => authSys.authSys)
|
// @ManyToOne(() => AuthSys, (authSys) => authSys)
|
||||||
// @JoinColumn({ name: "authSysId" })
|
// @JoinColumn({ name: "authSysId" })
|
||||||
// authRoleAttrForSys: AuthSys;
|
// authRoleAttrForSys: AuthSys;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue