add radis
This commit is contained in:
parent
dc48548db3
commit
8546044fdc
1 changed files with 53 additions and 53 deletions
|
|
@ -28,59 +28,59 @@ export class PermissionController extends Controller {
|
|||
host: REDIS_HOST,
|
||||
port: REDIS_PORT,
|
||||
});
|
||||
|
||||
await Promise.all([
|
||||
await redisClient.get(request.user.sub, async (err: any, reply: any) => {
|
||||
if (reply != null) {
|
||||
return new HttpSuccess(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 getDetail = await this.authRoleRepo.findOne({
|
||||
select: ["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 formattedData = {
|
||||
...getDetail,
|
||||
roleAttributes: roleAttrData,
|
||||
};
|
||||
redisClient.setex(request.user.sub, 20, JSON.stringify(formattedData));
|
||||
return new HttpSuccess(formattedData);
|
||||
const formattedData = null;
|
||||
// await Promise.all([
|
||||
return redisClient.get(request.user.sub, async (err: any, reply: any) => {
|
||||
if (reply != null) {
|
||||
return new HttpSuccess(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 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 formattedData = {
|
||||
...getDetail,
|
||||
roleAttributes: roleAttrData,
|
||||
};
|
||||
redisClient.setex(request.user.sub, 20, JSON.stringify(formattedData));
|
||||
return new HttpSuccess(formattedData);
|
||||
}
|
||||
});
|
||||
// ]);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue