API permission with acting positions
All checks were successful
Build & Deploy on Dev / build (push) Successful in 1m36s

This commit is contained in:
harid 2026-04-17 14:18:54 +07:00
parent 99bd789702
commit 7f3408e2f5
2 changed files with 245 additions and 0 deletions

View file

@ -15,6 +15,7 @@ import permission from "../interfaces/permission";
import { ProfileEmployee } from "../entities/ProfileEmployee";
import { EmployeePosMaster } from "../entities/EmployeePosMaster";
import { OrgRevision } from "../entities/OrgRevision";
import { actingPositionService } from "../services/ActingPositionService";
const REDIS_HOST = process.env.REDIS_HOST;
const REDIS_PORT = process.env.REDIS_PORT;
@ -254,6 +255,64 @@ export class PermissionController extends Controller {
return new HttpSuccess(res);
}
/**
* API permission with acting positions
* @summary permission with acting positions (dotnet api)
* @param {string} action action
* @param {string} system authSysId
*/
@Get("dotnet-acting/{action}/{system}")
public async dotnetActing(
@Request() req: RequestWithUser,
@Path() action: string,
@Path() system: string,
) {
if (!["CREATE", "DELETE", "GET", "LIST", "UPDATE"].includes(action)) {
throw new HttpError(HttpStatus.NOT_FOUND, "Action ไม่ถูกต้อง");
}
// ดึง privilege ตามปกติ
let privilege = await new permission().Permission(req, system.toLocaleUpperCase(), action);
// ดึงข้อมูล profile และ orgRevision
let profile: any = await this.profileRepo.findOne({
select: ["id"],
where: { keycloak: req.user.sub },
});
if (!profile) {
profile = await this.profileEmployeeRepo.findOne({
select: ["id"],
where: { keycloak: req.user.sub },
});
if (!profile) {
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลบุคคลนี้ในระบบ");
}
}
const orgRevision = await this.orgRevisionRepository.findOne({
select: ["id"],
where: {
orgRevisionIsDraft: false,
orgRevisionIsCurrent: true,
},
});
// ดึงข้อมูลตำแหน่งที่รักษาการ
const actingData = await actingPositionService.getActingPositionsWithPrivilege(
profile.id,
orgRevision?.id,
action,
system.toLocaleUpperCase()
);
// ส่งค่ากลับเหมือน dotnet endpoint แต่เพิ่ม isAct และ posMasterActs
return new HttpSuccess({
privilege,
isAct: actingData.isAct,
posMasterActs: actingData.posMasterActs,
});
}
/**
* API permission (dotnet api)
* @summary permission (dotnet api)