From a4647e102a416b892f8bb8383172d05eb2bd1c76 Mon Sep 17 00:00:00 2001 From: kittapath Date: Tue, 22 Oct 2024 08:21:16 +0700 Subject: [PATCH] check workflow --- src/controllers/KpiCapacityController.ts | 13 ++-- src/controllers/KpiGroupController.ts | 3 +- src/controllers/KpiLinkController.ts | 5 +- src/controllers/KpiPeriodController.ts | 3 +- src/controllers/KpiPlanController.ts | 3 +- src/controllers/KpiRoleController.ts | 3 +- src/controllers/KpiSpecialController.ts | 3 +- src/controllers/KpiUserCapacityController.ts | 2 - .../KpiUserDevelopmentController.ts | 41 ++++++------ .../KpiUserEvaluationController.ts | 12 ++-- src/controllers/KpiUserPlannedController.ts | 2 - src/controllers/KpiUserRoleController.ts | 2 - src/controllers/KpiUserSpecialController.ts | 1 - src/interfaces/permission.ts | 64 ++++++++++--------- 14 files changed, 84 insertions(+), 73 deletions(-) diff --git a/src/controllers/KpiCapacityController.ts b/src/controllers/KpiCapacityController.ts index 60e054d..210983a 100644 --- a/src/controllers/KpiCapacityController.ts +++ b/src/controllers/KpiCapacityController.ts @@ -230,18 +230,18 @@ export class kpiCapacityController extends Controller { @Get("group") async GetKpiCapacityTypeGROUP(@Query("positionName") positionName: string) { let position = await this.positionRepository.findOne({ - where: { + where: { name: Like(`${positionName}`), - kpiLink: Not(IsNull()) || Not("") + kpiLink: Not(IsNull()) || Not(""), }, relations: ["kpiLink", "kpiLink.kpiCapacitys"], }); if (position == null) { position = await this.positionRepository.findOne({ - where: { - name: "นักจัดการงานทั่วไป", - kpiLink: Not(IsNull()) || Not("") + where: { + name: "นักจัดการงานทั่วไป", + kpiLink: Not(IsNull()) || Not(""), }, relations: ["kpiLink", "kpiLink.kpiCapacitys"], }); @@ -310,7 +310,8 @@ export class kpiCapacityController extends Controller { ], }) async GetKpiCapacityByIdEdit(@Request() request: RequestWithUser, @Path() id: string) { - let _data = await new permission().PermissionGet(request, "SYS_EVA_COMPETENCY"); + let _workflow = await new permission().Workflow(request, id, "SYS_EVA_COMPETENCY"); + if (_workflow == false) await new permission().PermissionGet(request, "SYS_EVA_COMPETENCY"); const kpiCapacity = await this.kpiCapacityRepository.findOne({ where: { id: id }, select: ["type", "name", "description"], diff --git a/src/controllers/KpiGroupController.ts b/src/controllers/KpiGroupController.ts index 78c0a39..5e03bd6 100644 --- a/src/controllers/KpiGroupController.ts +++ b/src/controllers/KpiGroupController.ts @@ -118,7 +118,8 @@ export class kpiGroupController extends Controller { nameGroupKPI: "string", //ชื่อกลุ่มงาน }) async KpiGroupByIdEdit(@Request() request: RequestWithUser, @Path() id: string) { - let _data = await new permission().PermissionGet(request, "SYS_EVA_COMPETENCY"); + let _workflow = await new permission().Workflow(request, id, "SYS_EVA_COMPETENCY"); + if (_workflow == false) await new permission().PermissionGet(request, "SYS_EVA_COMPETENCY"); const kpiGroup = await this.kpiGroupRepository.findOne({ where: { id: id }, select: ["nameGroupKPI"], diff --git a/src/controllers/KpiLinkController.ts b/src/controllers/KpiLinkController.ts index 72b45b5..f6cc67d 100644 --- a/src/controllers/KpiLinkController.ts +++ b/src/controllers/KpiLinkController.ts @@ -136,7 +136,7 @@ export class kpiLinkController extends Controller { ...requestBody, kpiCapacitys: [], }); - + const chkCapacity = await this.kpiCapacityRepository.find({ where: { id: In(requestBody.kpiCapacityIds), @@ -181,7 +181,8 @@ export class kpiLinkController extends Controller { */ @Get("edit/{id}") async KpiLinkByIdEdit(@Request() request: RequestWithUser, @Path() id: string) { - let _data = await new permission().PermissionGet(request, "SYS_EVA_COMPETENCY"); + let _workflow = await new permission().Workflow(request, id, "SYS_EVA_COMPETENCY"); + if (_workflow == false) await new permission().PermissionGet(request, "SYS_EVA_COMPETENCY"); const kpiLink = await this.kpiLinkRepository.findOne({ where: { id: id }, relations: ["positions", "kpiCapacitys", "kpiGroup"], diff --git a/src/controllers/KpiPeriodController.ts b/src/controllers/KpiPeriodController.ts index 980471a..0cef731 100644 --- a/src/controllers/KpiPeriodController.ts +++ b/src/controllers/KpiPeriodController.ts @@ -175,7 +175,8 @@ export class kpiPeriodController extends Controller { endDate: "datetime", //วันสิ้นสุด }) async OpenKpiPeriodById(@Path() id: string, @Request() request: RequestWithUser) { - await new permission().PermissionGet(request, "SYS_KPI_ROUND"); + let _workflow = await new permission().Workflow(request, id, "SYS_KPI_ROUND"); + if (_workflow == false) await new permission().PermissionGet(request, "SYS_KPI_ROUND"); const kpiPeriod = await this.kpiPeriodRepository.findOne({ where: { id: id }, }); diff --git a/src/controllers/KpiPlanController.ts b/src/controllers/KpiPlanController.ts index e0b08fc..630c476 100644 --- a/src/controllers/KpiPlanController.ts +++ b/src/controllers/KpiPlanController.ts @@ -310,7 +310,8 @@ export class kpiPlanController extends Controller { */ @Get("edit/{id}") async GetKpiPlanByIdEdit(@Request() request: RequestWithUser, @Path() id: string) { - let _data = await new permission().PermissionGet(request, "SYS_EVA_INDICATOR"); + let _workflow = await new permission().Workflow(request, id, "SYS_EVA_INDICATOR"); + if (_workflow == false) await new permission().PermissionGet(request, "SYS_EVA_INDICATOR"); const kpiPlan = await this.kpiPlanRepository.findOne({ where: { id: id }, relations: { kpiPeriod: true }, diff --git a/src/controllers/KpiRoleController.ts b/src/controllers/KpiRoleController.ts index 86df23f..be3fb42 100644 --- a/src/controllers/KpiRoleController.ts +++ b/src/controllers/KpiRoleController.ts @@ -286,7 +286,8 @@ export class kpiRoleController extends Controller { */ @Get("edit/{id}") async GetKpiRoleByIdEdit(@Request() request: RequestWithUser, @Path() id: string) { - let _data = await new permission().PermissionGet(request, "SYS_EVA_INDICATOR"); + let _workflow = await new permission().Workflow(request, id, "SYS_EVA_INDICATOR"); + if (_workflow == false) await new permission().PermissionGet(request, "SYS_EVA_INDICATOR"); const kpiRole = await this.kpiRoleRepository.findOne({ where: { id: id }, relations: { kpiPeriod: true }, diff --git a/src/controllers/KpiSpecialController.ts b/src/controllers/KpiSpecialController.ts index 6e626a9..279190e 100644 --- a/src/controllers/KpiSpecialController.ts +++ b/src/controllers/KpiSpecialController.ts @@ -126,7 +126,8 @@ export class kpiSpecialController extends Controller { */ @Get("edit/{id}") async GetKpiSpecialByIdEdit(@Request() request: RequestWithUser, @Path() id: string) { - let _data = await new permission().PermissionGet(request, "SYS_EVA_INDICATOR"); + let _workflow = await new permission().Workflow(request, id, "SYS_EVA_INDICATOR"); + if (_workflow == false) await new permission().PermissionGet(request, "SYS_EVA_INDICATOR"); const KpiSpecial = await this.kpiSpecialRepository.findOne({ where: { id: id }, }); diff --git a/src/controllers/KpiUserCapacityController.ts b/src/controllers/KpiUserCapacityController.ts index 78830d4..be6c5c4 100644 --- a/src/controllers/KpiUserCapacityController.ts +++ b/src/controllers/KpiUserCapacityController.ts @@ -177,7 +177,6 @@ export class KpiUserCapacityController extends Controller { */ @Get("{id}") async GetKpiUserCapacityById(@Request() request: RequestWithUser, @Path() id: string) { - // await new permission().PermissionGet(request, "SYS_KPI_LIST"); const kpiUserCapacity = await this.kpiUserCapacityRepository.findOne({ where: { id: id }, relations: ["kpiCapacity"], @@ -212,7 +211,6 @@ export class KpiUserCapacityController extends Controller { @Query("id") id: string, //kpiUserEvaluationId @Query("type") type: string, ) { - // await new permission().PermissionGet(request, "SYS_KPI_LIST"); const [kpiUserCapacity, total] = await AppDataSource.getRepository(KpiUserCapacity) .createQueryBuilder("kpiUserCapacity") .leftJoinAndSelect("kpiUserCapacity.kpiCapacity", "kpiCapacity") diff --git a/src/controllers/KpiUserDevelopmentController.ts b/src/controllers/KpiUserDevelopmentController.ts index ffb6d2f..e3d0aea 100644 --- a/src/controllers/KpiUserDevelopmentController.ts +++ b/src/controllers/KpiUserDevelopmentController.ts @@ -240,7 +240,6 @@ export class KpiUserDevelopmentController extends Controller { */ @Get("{id}") async GetKpiUserDevelopmentDetail(@Request() request: RequestWithUser, @Path() id: string) { - // await new permission().PermissionGet(request, "SYS_KPI_LIST"); const getKpiUserDevelopment = await this.kpiUserDevelopmentRepository.findOne({ relations: ["kpiUserEvaluation", "developmentProjects"], where: { id: id }, @@ -282,7 +281,6 @@ export class KpiUserDevelopmentController extends Controller { */ @Get() async GetKpiUserDevelopment(@Request() request: RequestWithUser, @Query("id") id: string) { - // await new permission().PermissionGet(request, "SYS_KPI_LIST");//USER const kpiUserDevelopment = await this.kpiUserDevelopmentRepository.find({ where: { kpiUserEvaluationId: id, @@ -452,7 +450,8 @@ export class KpiUserDevelopmentController extends Controller { @Request() request: RequestWithUser, @Path("id") id: string, ) { - await new permission().PermissionGet(request, "SYS_RESULT"); + let _workflow = await new permission().Workflow(request, id, "SYS_RESULT"); + if (_workflow == false) await new permission().PermissionGet(request, "SYS_RESULT"); const kpiUserDevelopment = await this.kpiUserDevelopmentRepository.findOne({ relations: [ "kpiUserEvaluation", @@ -514,23 +513,29 @@ export class KpiUserDevelopmentController extends Controller { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลพัฒนาตนเองนี้"); } if (type.trim().toLocaleUpperCase() == "OFFICER") { - await new permission().PermissionOrgUserGet( - request, - "SYS_REGISTRY_OFFICER", - getKpiUserDevelopment.kpiUserEvaluation.profileId, - ); + let _workflow = await new permission().Workflow(request, id, "SYS_REGISTRY_OFFICER"); + if (_workflow == false) + await new permission().PermissionOrgUserGet( + request, + "SYS_REGISTRY_OFFICER", + getKpiUserDevelopment.kpiUserEvaluation.profileId, + ); } else if (type.trim().toLocaleUpperCase() == "EMPLOYEE") { - await new permission().PermissionOrgUserGet( - request, - "SYS_REGISTRY_EMP", - getKpiUserDevelopment.kpiUserEvaluation.profileId, - ); + let _workflow = await new permission().Workflow(request, id, "SYS_REGISTRY_EMP"); + if (_workflow == false) + await new permission().PermissionOrgUserGet( + request, + "SYS_REGISTRY_EMP", + getKpiUserDevelopment.kpiUserEvaluation.profileId, + ); } else if (type.trim().toLocaleUpperCase() == "TEMP") { - await new permission().PermissionOrgUserGet( - request, - "SYS_REGISTRY_TEMP", - getKpiUserDevelopment.kpiUserEvaluation.profileId, - ); + let _workflow = await new permission().Workflow(request, id, "SYS_REGISTRY_TEMP"); + if (_workflow == false) + await new permission().PermissionOrgUserGet( + request, + "SYS_REGISTRY_TEMP", + getKpiUserDevelopment.kpiUserEvaluation.profileId, + ); } else if (type.trim().toLocaleUpperCase() == "USER") { } else { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่สามารถเข้าถึงข้อมูลนี้ได้"); diff --git a/src/controllers/KpiUserEvaluationController.ts b/src/controllers/KpiUserEvaluationController.ts index b1dd3a8..1ac5555 100644 --- a/src/controllers/KpiUserEvaluationController.ts +++ b/src/controllers/KpiUserEvaluationController.ts @@ -1327,7 +1327,8 @@ export class KpiUserEvaluationController extends Controller { */ @Get("admin/{id}") async GetKpiAdminEvaluationById(@Path() id: string, @Request() req: RequestWithUser) { - await new permission().PermissionGet(req, "SYS_KPI_LIST"); + let _workflow = await new permission().Workflow(req, id, "SYS_KPI_LIST"); + if (_workflow == false) await new permission().PermissionGet(req, "SYS_KPI_LIST"); const kpiUserEvaluation = await this.kpiUserEvalutionRepository.findOne({ relations: ["kpiPeriod"], where: { id: id }, @@ -1631,7 +1632,7 @@ export class KpiUserEvaluationController extends Controller { }) .then(async () => {}) .catch((error) => { - console.error('Error details:', error.response.data); + console.error("Error details:", error.response.data); }); kpiUserEvaluation.kpiUserDevelopments.map(async (kpiUserDevelopment) => { @@ -1652,12 +1653,13 @@ export class KpiUserEvaluationController extends Controller { isDevelopment20: kpiUserDevelopment.isDevelopment20, isDevelopment10: kpiUserDevelopment.isDevelopment10, developmentResults: `${kpiUserDevelopment.achievement10}(10), ${kpiUserDevelopment.achievement5}(5), ${kpiUserDevelopment.achievement0}(0)`, - developmentReport: kpiUserDevelopment.point != null ?kpiUserDevelopment.point.toString():null, + developmentReport: + kpiUserDevelopment.point != null ? kpiUserDevelopment.point.toString() : null, developmentProjects: kpiUserDevelopment.developmentProjects.map((x) => x.name), }) .then(async () => {}) .catch((error) => { - console.error('Error details:', error.response.data); + console.error("Error details:", error.response.data); }); }); @@ -1673,7 +1675,7 @@ export class KpiUserEvaluationController extends Controller { }) .then(async () => {}) .catch((error) => { - console.error('Error details:', error.response.data); + console.error("Error details:", error.response.data); }); const before = null; kpiUserEvaluation.lastUpdateUserId = request.user.sub; diff --git a/src/controllers/KpiUserPlannedController.ts b/src/controllers/KpiUserPlannedController.ts index 772df2c..9253ed5 100644 --- a/src/controllers/KpiUserPlannedController.ts +++ b/src/controllers/KpiUserPlannedController.ts @@ -190,7 +190,6 @@ export class KpiUserPlannedController extends Controller { */ @Get("{id}") async GetKpiUserPlannedDetail(@Request() request: RequestWithUser, @Path() id: string) { - // await new permission().PermissionGet(request, "SYS_KPI_LIST"); const getKpiUserPlanned = await this.kpiUserPlannedRepository.findOne({ relations: ["kpiPlan", "kpiUserEvaluation"], where: { id: id }, @@ -233,7 +232,6 @@ export class KpiUserPlannedController extends Controller { */ @Get() async GetKpiUserPlanned(@Request() request: RequestWithUser, @Query("id") id: string) { - // await new permission().PermissionGet(request, "SYS_KPI_LIST");//USER const kpiUserPlanned = await this.kpiUserPlannedRepository.find({ where: { kpiUserEvaluationId: id, diff --git a/src/controllers/KpiUserRoleController.ts b/src/controllers/KpiUserRoleController.ts index 5f9c322..4de3c2f 100644 --- a/src/controllers/KpiUserRoleController.ts +++ b/src/controllers/KpiUserRoleController.ts @@ -194,7 +194,6 @@ export class KpiUserRoleController extends Controller { */ @Get("{id}") async GetKpiUserRoleDetail(@Request() request: RequestWithUser, @Path() id: string) { - // await new permission().PermissionGet(request, "SYS_KPI_LIST"); const getKpiUserRole = await this.kpiUserRoleRepository.findOne({ relations: ["kpiRole", "kpiUserEvaluation"], where: { id: id }, @@ -237,7 +236,6 @@ export class KpiUserRoleController extends Controller { */ @Get() async GetKpiUserRole(@Request() request: RequestWithUser, @Query("id") id: string) { - // await new permission().PermissionGet(request, "SYS_KPI_LIST");//USER const kpiUserRole = await this.kpiUserRoleRepository.find({ where: { kpiUserEvaluationId: id, diff --git a/src/controllers/KpiUserSpecialController.ts b/src/controllers/KpiUserSpecialController.ts index 4eb2f80..275b555 100644 --- a/src/controllers/KpiUserSpecialController.ts +++ b/src/controllers/KpiUserSpecialController.ts @@ -280,7 +280,6 @@ export class KpiUserSpecialController extends Controller { */ @Get() async GetKpiUserSpecial(@Request() request: RequestWithUser, @Query("id") id: string) { - // await new permission().PermissionGet(request, "SYS_KPI_LIST"); const kpiUserSpecial = await this.kpiUserSpecialRepository.find({ where: { kpiUserEvaluationId: id, diff --git a/src/interfaces/permission.ts b/src/interfaces/permission.ts index fb2d669..870d2fe 100644 --- a/src/interfaces/permission.ts +++ b/src/interfaces/permission.ts @@ -53,18 +53,7 @@ class CheckAuth { return await new CallAPI() .GetData(req, `/org/permission/org/${system}/${action}`) .then(async (x) => { - console.log(x); let privilege = x.privilege; - // if (action.trim().toLocaleUpperCase() == "CREATE") - // privilege = await this.PermissionCreate(req, system); - // if (action.trim().toLocaleUpperCase() == "DELETE") - // privilege = await this.PermissionDelete(req, system); - // if (action.trim().toLocaleUpperCase() == "GET") - // privilege = await this.PermissionGet(req, system); - // if (action.trim().toLocaleUpperCase() == "LIST") - // privilege = await this.PermissionList(req, system); - // if (action.trim().toLocaleUpperCase() == "UPDATE") - // privilege = await this.PermissionUpdate(req, system); let data: any = { root: [null], @@ -72,6 +61,7 @@ class CheckAuth { child2: [null], child3: [null], child4: [null], + privilege: [null], }; let node = 4; if (x.orgChild1Id == null) { @@ -83,13 +73,23 @@ class CheckAuth { } else if (x.orgChild4Id == null) { node = 3; } - if (privilege == "ROOT") { + if (privilege == "OWNER") { + data = { + root: null, + child1: null, + child2: null, + child3: null, + child4: null, + privilege: "OWNER", + }; + } else if (privilege == "ROOT") { data = { root: [x.orgRootId], child1: null, child2: null, child3: null, child4: null, + privilege: "ROOT", }; } else if (privilege == "CHILD") { data = { @@ -98,6 +98,7 @@ class CheckAuth { child2: node >= 2 ? [x.orgChild2Id] : null, child3: node >= 3 ? [x.orgChild3Id] : null, child4: node >= 4 ? [x.orgChild4Id] : null, + privilege: "CHILD", }; } else if (privilege == "NORMAL") { data = { @@ -106,16 +107,9 @@ class CheckAuth { child2: [x.orgChild2Id], child3: [x.orgChild3Id], child4: [x.orgChild4Id], + privilege: "NORMAL", }; } else if (privilege == "SPECIFIC") { - } else if (privilege == "OWNER") { - data = { - root: null, - child1: null, - child2: null, - child3: null, - child4: null, - }; } return data; @@ -145,16 +139,6 @@ class CheckAuth { .GetData(req, `/org/permission/user/${system}/${action}/${profileId}`) .then(async (x) => { let org = x.org; - // if (action.trim().toLocaleUpperCase() == "CREATE") - // org = await this.PermissionOrgCreate(req, system); - // if (action.trim().toLocaleUpperCase() == "DELETE") - // org = await this.PermissionOrgDelete(req, system); - // if (action.trim().toLocaleUpperCase() == "GET") - // org = await this.PermissionOrgGet(req, system); - // if (action.trim().toLocaleUpperCase() == "LIST") - // org = await this.PermissionOrgList(req, system); - // if (action.trim().toLocaleUpperCase() == "UPDATE") - // org = await this.PermissionOrgUpdate(req, system); if (org.root != null) if (x.orgRootId != org.root[0]) throw "ไม่มีสิทธิ์เข้าถึงข้อมูล"; if (org.child1 != null) @@ -176,6 +160,26 @@ class CheckAuth { } }); } + public async Workflow(req: RequestWithUser, id: string, sysName: string) { + if ( + req.headers.hasOwnProperty("api_key") && + req.headers["api_key"] && + req.headers["api_key"] == process.env.API_KEY + ) { + return null; + } + return await new CallAPI() + .PostData(req, "/org/workflow/keycloak/isofficer", { + refId: id, + sysName: sysName, + }) + .then((x) => { + return true; + }) + .catch((x) => { + return false; + }); + } public async PermissionCreate(req: RequestWithUser, system: string) { return await this.Permission(req, system, "CREATE"); }