แก้ api get menu
This commit is contained in:
parent
813fc68221
commit
af35988275
1 changed files with 53 additions and 55 deletions
|
|
@ -35,60 +35,60 @@ export class PermissionController extends Controller {
|
|||
const getAsync = promisify(redisClient.get).bind(redisClient);
|
||||
|
||||
let reply = await getAsync("role_" + request.user.sub);
|
||||
// if (reply != null) {
|
||||
// reply = 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, "ไม่พบข้อมูลบุคคลนี้ในระบบ");
|
||||
}
|
||||
if (reply != null) {
|
||||
reply = 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,
|
||||
orgRevision: {
|
||||
orgRevisionIsDraft: false,
|
||||
orgRevisionIsCurrent: true,
|
||||
const posMaster = await this.posMasterRepository.findOne({
|
||||
// select: ["authRoleId"],
|
||||
where: {
|
||||
current_holderId: profile.id,
|
||||
orgRevision: {
|
||||
orgRevisionIsDraft: false,
|
||||
orgRevisionIsCurrent: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
if (!posMaster) {
|
||||
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลสิทธิ์");
|
||||
});
|
||||
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 },
|
||||
});
|
||||
|
||||
reply = {
|
||||
...getDetail,
|
||||
roles: roleAttrData,
|
||||
};
|
||||
redisClient.setex("role_" + request.user.sub, 86400, JSON.stringify(reply));
|
||||
}
|
||||
|
||||
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 },
|
||||
});
|
||||
|
||||
reply = {
|
||||
...getDetail,
|
||||
roles: roleAttrData,
|
||||
};
|
||||
// redisClient.setex("role_" + request.user.sub, 86400, JSON.stringify(reply));
|
||||
// }
|
||||
return new HttpSuccess(reply);
|
||||
}
|
||||
|
||||
|
|
@ -100,11 +100,10 @@ export class PermissionController extends Controller {
|
|||
});
|
||||
const getAsync = promisify(redisClient.get).bind(redisClient);
|
||||
|
||||
let reply = await getAsync("menu_" + request.user.sub);
|
||||
let reply = await getAsync("menu_xasdasdP@ssw0rd" + request.user.sub);
|
||||
if (reply != null) {
|
||||
reply = JSON.parse(reply);
|
||||
} else {
|
||||
console.log(request.user.sub);
|
||||
const profile = await this.profileRepo.findOne({
|
||||
select: ["id"],
|
||||
where: { keycloak: request.user.sub },
|
||||
|
|
@ -148,7 +147,7 @@ export class PermissionController extends Controller {
|
|||
},
|
||||
});
|
||||
|
||||
const reply = getList
|
||||
reply = getList
|
||||
.filter((x) => x.parentId == null)
|
||||
.map((item) => {
|
||||
return {
|
||||
|
|
@ -159,7 +158,6 @@ export class PermissionController extends Controller {
|
|||
};
|
||||
})
|
||||
.sort((a, b) => a.order - b.order);
|
||||
// console.log(JSON.stringify(reply));
|
||||
redisClient.setex("menu_" + request.user.sub, 86400, JSON.stringify(reply));
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue