fix
This commit is contained in:
parent
fe1ebaa1cf
commit
bd102a9609
2 changed files with 0 additions and 79 deletions
|
|
@ -25,9 +25,6 @@ import { ProfileActposition } from "../entities/ProfileActposition";
|
|||
import { RequestWithUser } from "../middlewares/user";
|
||||
import { escape } from "querystring";
|
||||
|
||||
const REDIS_HOST = process.env.REDIS_HOST;
|
||||
const REDIS_PORT = process.env.REDIS_PORT;
|
||||
|
||||
@Route("api/v1/org/pos/act")
|
||||
@Tags("PosMasterAct")
|
||||
@Security("bearerAuth")
|
||||
|
|
@ -40,23 +37,6 @@ export class PosMasterActController extends Controller {
|
|||
private posMasterActRepository = AppDataSource.getRepository(PosMasterAct);
|
||||
private posMasterRepository = AppDataSource.getRepository(PosMaster);
|
||||
private actpositionRepository = AppDataSource.getRepository(ProfileActposition);
|
||||
private redis = require("redis");
|
||||
|
||||
/**
|
||||
* Helper function สำหรับลบ cache เมื่อมีการเปลี่ยนแปลง acting position
|
||||
*/
|
||||
private async invalidatePermissionCache(profileIds: string[]) {
|
||||
const redisClient = await this.redis.createClient({
|
||||
host: REDIS_HOST,
|
||||
port: REDIS_PORT,
|
||||
});
|
||||
|
||||
for (const profileId of profileIds) {
|
||||
redisClient.del(`role_${profileId}_acting`);
|
||||
redisClient.del(`role_${profileId}_normal`);
|
||||
redisClient.del(`menu_${profileId}`);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* API เพิ่มรักษาการในตำแหน่ง
|
||||
|
|
@ -109,12 +89,6 @@ export class PosMasterActController extends Controller {
|
|||
posMasterAct.createdAt = new Date();
|
||||
posMasterAct.lastUpdatedAt = new Date();
|
||||
await this.posMasterActRepository.save(posMasterAct);
|
||||
|
||||
// ลบ cache ของผู้ถูกรักษาการ (current_holder ของ posMasterChild)
|
||||
if (posMasterChild.current_holderId) {
|
||||
await this.invalidatePermissionCache([posMasterChild.current_holderId]);
|
||||
}
|
||||
|
||||
return new HttpSuccess(posMasterAct);
|
||||
}
|
||||
|
||||
|
|
@ -321,7 +295,6 @@ export class PosMasterActController extends Controller {
|
|||
where: {
|
||||
id: id,
|
||||
},
|
||||
relations: ["posMasterChild"],
|
||||
});
|
||||
try {
|
||||
result = await this.posMasterActRepository.delete({ id: id });
|
||||
|
|
@ -345,11 +318,6 @@ export class PosMasterActController extends Controller {
|
|||
p.posMasterOrder = i + 1;
|
||||
await this.posMasterActRepository.save(p);
|
||||
});
|
||||
|
||||
// ลบ cache ของผู้ถูกรักษาการ
|
||||
if (posMasterAct.posMasterChild?.current_holderId) {
|
||||
await this.invalidatePermissionCache([posMasterAct.posMasterChild.current_holderId]);
|
||||
}
|
||||
}
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
|
@ -800,9 +768,6 @@ export class PosMasterActController extends Controller {
|
|||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลรักษาการในตำแหน่งของหน่วยงานนี้");
|
||||
}
|
||||
|
||||
// เก็บ profileIds ที่ได้รับผลกระทบเพื่อลบ cache
|
||||
const affectedProfileIds: string[] = [];
|
||||
|
||||
await Promise.all(
|
||||
posMasterActs.map(async (posMasterAct) => {
|
||||
const orgShortName =
|
||||
|
|
@ -817,8 +782,6 @@ export class PosMasterActController extends Controller {
|
|||
const profileId = posMasterAct.posMasterChild?.current_holderId;
|
||||
|
||||
if (profileId) {
|
||||
affectedProfileIds.push(profileId);
|
||||
|
||||
const existingActivePositions = await this.actpositionRepository.find({
|
||||
select: [
|
||||
"id",
|
||||
|
|
@ -871,11 +834,6 @@ export class PosMasterActController extends Controller {
|
|||
}),
|
||||
);
|
||||
|
||||
// ลบ cache ของผู้ถูกรักษาการทั้งหมด
|
||||
if (affectedProfileIds.length > 0) {
|
||||
await this.invalidatePermissionCache(affectedProfileIds);
|
||||
}
|
||||
|
||||
return new HttpSuccess();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue