Clear Cache ออกคำสั่งรักษาการ

This commit is contained in:
harid 2026-05-11 17:57:23 +07:00
parent 384a9d7926
commit 5c2b3e9689

View file

@ -104,6 +104,10 @@ import { LeaveType } from "../entities/LeaveType";
import { KeycloakAttributeService } from "../services/KeycloakAttributeService"; import { KeycloakAttributeService } from "../services/KeycloakAttributeService";
import { reOrderCommandRecivesAndDelete } from "../services/CommandService"; import { reOrderCommandRecivesAndDelete } from "../services/CommandService";
import { RetirementService } from "../services/RetirementService"; 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") @Route("api/v1/org/command")
@Tags("Command") @Tags("Command")
@Security("bearerAuth") @Security("bearerAuth")
@ -112,6 +116,7 @@ import { RetirementService } from "../services/RetirementService";
"เกิดข้อผิดพลาด ไม่สามารถแสดงรายการได้ กรุณาลองใหม่ในภายหลัง", "เกิดข้อผิดพลาด ไม่สามารถแสดงรายการได้ กรุณาลองใหม่ในภายหลัง",
) )
export class CommandController extends Controller { export class CommandController extends Controller {
private redis = require("redis");
private commandRepository = AppDataSource.getRepository(Command); private commandRepository = AppDataSource.getRepository(Command);
private commandTypeRepository = AppDataSource.getRepository(CommandType); private commandTypeRepository = AppDataSource.getRepository(CommandType);
private commandSendRepository = AppDataSource.getRepository(CommandSend); private commandSendRepository = AppDataSource.getRepository(CommandSend);
@ -7654,6 +7659,8 @@ export class CommandController extends Controller {
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบข้อมูล refIds"); throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบข้อมูล refIds");
} }
const profileIdsToClearCache = new Set<string>();
await Promise.all( await Promise.all(
posMasters.map(async (item) => { posMasters.map(async (item) => {
// 4. ตรวจสอบข้อมูลที่จำเป็นทั้งหมด // 4. ตรวจสอบข้อมูลที่จำเป็นทั้งหมด
@ -7662,6 +7669,10 @@ export class CommandController extends Controller {
return; return;
} }
if (item.posMasterChild.current_holderId) {
profileIdsToClearCache.add(item.posMasterChild.current_holderId);
}
// 5. สร้าง orgShortName แบบปลอดภัย // 5. สร้าง orgShortName แบบปลอดภัย
const 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(); return new HttpSuccess();
} }