diff --git a/src/controllers/PermissionController.ts b/src/controllers/PermissionController.ts index 298d8d6b..b4db2ec6 100644 --- a/src/controllers/PermissionController.ts +++ b/src/controllers/PermissionController.ts @@ -35,54 +35,54 @@ 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, "ไม่พบข้อมูลบุคคลนี้ในระบบ"); - } - - 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 }, - }); - - reply = { - ...getDetail, - roles: roleAttrData, - }; - redisClient.setex("role_" + request.user.sub, 86400, JSON.stringify(reply)); + // 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 }, + }); + 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)); + // } return new HttpSuccess(reply); }