diff --git a/src/controllers/CommandController.ts b/src/controllers/CommandController.ts index 232d2689..27d2671c 100644 --- a/src/controllers/CommandController.ts +++ b/src/controllers/CommandController.ts @@ -104,6 +104,10 @@ import { LeaveType } from "../entities/LeaveType"; import { KeycloakAttributeService } from "../services/KeycloakAttributeService"; import { reOrderCommandRecivesAndDelete } from "../services/CommandService"; import { RetirementService } from "../services/RetirementService"; +import { promisify } from "util"; +const REDIS_HOST = process.env.REDIS_HOST; +const REDIS_PORT = process.env.REDIS_PORT; + @Route("api/v1/org/command") @Tags("Command") @Security("bearerAuth") @@ -112,6 +116,7 @@ import { RetirementService } from "../services/RetirementService"; "เกิดข้อผิดพลาด ไม่สามารถแสดงรายการได้ กรุณาลองใหม่ในภายหลัง", ) export class CommandController extends Controller { + private redis = require("redis"); private commandRepository = AppDataSource.getRepository(Command); private commandTypeRepository = AppDataSource.getRepository(CommandType); private commandSendRepository = AppDataSource.getRepository(CommandSend); @@ -7654,6 +7659,8 @@ export class CommandController extends Controller { throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบข้อมูล refIds"); } + const profileIdsToClearCache = new Set(); + await Promise.all( posMasters.map(async (item) => { // 4. ตรวจสอบข้อมูลที่จำเป็นทั้งหมด @@ -7662,6 +7669,10 @@ export class CommandController extends Controller { return; } + if (item.posMasterChild.current_holderId) { + profileIdsToClearCache.add(item.posMasterChild.current_holderId); + } + // 5. สร้าง orgShortName แบบปลอดภัย const orgShortName = [ @@ -7749,6 +7760,23 @@ export class CommandController extends Controller { }), ); + if (profileIdsToClearCache.size > 0) { + await Promise.all( + Array.from(profileIdsToClearCache).map(async (profileId) => { + const redisClient = await this.redis.createClient({ + host: REDIS_HOST, + port: REDIS_PORT, + }); + + const delAsync = promisify(redisClient.del).bind(redisClient); + await delAsync("role_" + profileId); + await delAsync("menu_" + profileId); + + redisClient.quit(); + }), + ); + } + return new HttpSuccess(); }