no message

This commit is contained in:
Kittapath 2024-07-24 10:09:55 +07:00
parent 53e6d66788
commit c49884fdd9

View file

@ -28,59 +28,61 @@ 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 redisClient.get(request.user.sub, async (err: any, reply: any) => { return new HttpSuccess(
// if (reply != null) { redisClient.get(request.user.sub, async (err: any, reply: any) => {
// return new HttpSuccess(JSON.parse(reply)); if (reply != null) {
// } else { return JSON.parse(reply);
const profile = await this.profileRepo.findOne({ } else {
select: ["id"], const profile = await this.profileRepo.findOne({
where: { keycloak: request.user.sub }, select: ["id"],
}); where: { keycloak: request.user.sub },
if (!profile) { });
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลบุคคลนี้ในระบบ"); if (!profile) {
} 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, roleAttributes: roleAttrData,
}; };
redisClient.setex(request.user.sub, 20, JSON.stringify(formattedData)); redisClient.setex(request.user.sub, 20, JSON.stringify(formattedData));
return new HttpSuccess(formattedData); return formattedData;
// } }
// }); }),
);
// ]); // ]);
} }
} }