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();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,10 +25,6 @@ import HttpStatus from "../interfaces/http-status";
|
|||
import HttpSuccess from "../interfaces/http-success";
|
||||
import permission from "../interfaces/permission";
|
||||
import { setLogDataDiff } from "../interfaces/utils";
|
||||
|
||||
const REDIS_HOST = process.env.REDIS_HOST;
|
||||
const REDIS_PORT = process.env.REDIS_PORT;
|
||||
|
||||
@Route("api/v1/org/profile/actposition")
|
||||
@Tags("ProfileActposition")
|
||||
@Security("bearerAuth")
|
||||
|
|
@ -36,23 +32,6 @@ export class ProfileActpositionController extends Controller {
|
|||
private profileRepo = AppDataSource.getRepository(Profile);
|
||||
private profileActpositionRepo = AppDataSource.getRepository(ProfileActposition);
|
||||
private profileActpositionHistoryRepo = AppDataSource.getRepository(ProfileActpositionHistory);
|
||||
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}`);
|
||||
}
|
||||
}
|
||||
|
||||
@Get("user")
|
||||
public async detailProfileActpositionUser(@Request() request: { user: Record<string, any> }) {
|
||||
|
|
@ -182,10 +161,6 @@ export class ProfileActpositionController extends Controller {
|
|||
history.profileActpositionId = data.id;
|
||||
await this.profileActpositionHistoryRepo.save(history, { data: req });
|
||||
//setLogDataDiff(req, { before, after: history });
|
||||
|
||||
// ลบ cache เมื่อสร้าง acting position ใหม่
|
||||
await this.invalidatePermissionCache([body.profileId]);
|
||||
|
||||
return new HttpSuccess(data.id);
|
||||
}
|
||||
|
||||
|
|
@ -223,9 +198,6 @@ export class ProfileActpositionController extends Controller {
|
|||
// setLogDataDiff(req, { before: before_null, after: history }),
|
||||
]);
|
||||
|
||||
// ลบ cache เมื่อแก้ไข acting position
|
||||
await this.invalidatePermissionCache([record.profileId]);
|
||||
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
||||
|
|
@ -264,9 +236,6 @@ export class ProfileActpositionController extends Controller {
|
|||
this.profileActpositionHistoryRepo.save(history, { data: req }),
|
||||
]);
|
||||
|
||||
// ลบ cache เมื่อ soft delete acting position
|
||||
await this.invalidatePermissionCache([record.profileId]);
|
||||
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
||||
|
|
@ -276,7 +245,6 @@ export class ProfileActpositionController extends Controller {
|
|||
@Request() req: RequestWithUser,
|
||||
) {
|
||||
const _record = await this.profileActpositionRepo.findOneBy({ id: actpositionId });
|
||||
const profileId = _record?.profileId;
|
||||
if (_record) {
|
||||
await new permission().PermissionOrgUserDelete(
|
||||
req,
|
||||
|
|
@ -293,11 +261,6 @@ export class ProfileActpositionController extends Controller {
|
|||
if (result.affected == undefined || result.affected <= 0)
|
||||
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
|
||||
// ลบ cache เมื่อ delete acting position
|
||||
if (profileId) {
|
||||
await this.invalidatePermissionCache([profileId]);
|
||||
}
|
||||
|
||||
return new HttpSuccess();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue