From 12885adf17c8987aa2df112a45cb3aa8527bf76a Mon Sep 17 00:00:00 2001 From: waruneeauy Date: Wed, 7 Aug 2024 11:49:11 +0700 Subject: [PATCH] updated menu & del permission --- src/controllers/AuthRoleController.ts | 13 ++++++++++++ src/controllers/PermissionController.ts | 28 ++++++++++++++++++------- 2 files changed, 34 insertions(+), 7 deletions(-) diff --git a/src/controllers/AuthRoleController.ts b/src/controllers/AuthRoleController.ts index 3084cf32..b6b747b1 100644 --- a/src/controllers/AuthRoleController.ts +++ b/src/controllers/AuthRoleController.ts @@ -101,6 +101,19 @@ export class AuthRoleController extends Controller { posMaster.lastUpdateFullName = req.user.name; posMaster.authRoleId = body.authRoleId; await this.posMasterRepository.save(posMaster); + + // เช็คว่าถ้ามีค่า current_holderId ให้ลบ key สิทธิ์ใน redis + if (posMaster.current_holderId) { + const redisClient = await this.redis.createClient({ + host: REDIS_HOST, + port: REDIS_PORT, + }); + redisClient.del("role_" + posMaster.current_holderId, (err: Error, response: Response) => { + if (err) throw err; + console.log(response); + }); + } + return new HttpSuccess(); } diff --git a/src/controllers/PermissionController.ts b/src/controllers/PermissionController.ts index f84e5e1c..8016639d 100644 --- a/src/controllers/PermissionController.ts +++ b/src/controllers/PermissionController.ts @@ -142,22 +142,36 @@ export class PermissionController extends Controller { const getList = await this.authSysRepo.find({ select: ["id", "parentId", "sysName", "sysDescription", "icon", "path", "order"], - where: { - id: In(sysId), - }, + where: [ + { + id: In(sysId), + }, + { + parentId: In(sysId), + }, + ], }); - reply = getList + reply = await getList .filter((x) => x.parentId == null) + .sort((a, b) => a.order - b.order) .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) + .map((item2) => { + return { + ...item2, + children: getList + .filter((x) => x.parentId == item2.id) + .sort((a, b) => a.order - b.order), + }; + }), }; - }) - .sort((a, b) => a.order - b.order); + }); + redisClient.setex("menu_" + request.user.sub, 86400, JSON.stringify(reply)); }