diff --git a/src/controllers/KpiPlanController.ts b/src/controllers/KpiPlanController.ts index 12951e1..06c5a25 100644 --- a/src/controllers/KpiPlanController.ts +++ b/src/controllers/KpiPlanController.ts @@ -98,7 +98,7 @@ export class kpiPlanController extends Controller { kpiPlan.child4DnaId = requestBody.node <= 3 ? null : x.child4DnaId; kpiPlan.child4ShortName = requestBody.node <= 3 ? null : x.child4ShortName; }) - .catch((x) => {}); + .catch((x) => { }); await new CallAPI() .PostData(request, "/development/strategy/find/all", { strategy: requestBody.strategy, @@ -116,7 +116,7 @@ export class kpiPlanController extends Controller { kpiPlan.strategyChild5 = requestBody.strategy <= 4 ? null : x.strategyChild5; kpiPlan.strategyChild5Id = requestBody.strategy <= 4 ? null : x.strategyChild5Id; }) - .catch((x) => {}); + .catch((x) => { }); let maxIncludingPlan: any; if (requestBody.node == 0) { @@ -274,7 +274,7 @@ export class kpiPlanController extends Controller { kpiPlan.child4DnaId = requestBody.node <= 3 ? null : x.child4DnaId; kpiPlan.child4ShortName = requestBody.node <= 3 ? null : x.child4ShortName; }) - .catch((x) => {}); + .catch((x) => { }); await new CallAPI() .PostData(request, "/development/strategy/find/all", { strategy: requestBody.strategy, @@ -292,7 +292,7 @@ export class kpiPlanController extends Controller { kpiPlan.strategyChild5 = requestBody.strategy <= 4 ? null : x.strategyChild5; kpiPlan.strategyChild5Id = requestBody.strategy <= 4 ? null : x.strategyChild5Id; }) - .catch((x) => {}); + .catch((x) => { }); const before = structuredClone(kpiPlan); @@ -435,6 +435,121 @@ export class kpiPlanController extends Controller { return new HttpSuccess(formattedData); } + /** + * API ตัวชี้วัดตามแผนฯสิทธิ์ KPI EDIT + * @param id Guid, *Id ตัวชี้วัดตามแผนฯสิทธิ์ KPI EDIT + */ + @Get("edit-indicator/{id}") + async GetKpiPlanByIdEditIndicator(@Request() request: RequestWithUser, @Path() id: string) { + let _workflow = await new permission().Workflow(request, id, "SYS_KPI_LIST"); + if (_workflow == false) await new permission().PermissionUpdate(request, "SYS_KPI_LIST"); + const kpiPlan = await this.kpiPlanRepository.findOne({ + where: { id: id }, + relations: { kpiPeriod: true }, + }); + if (!kpiPlan) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลตัวชี้วัดตามแผนฯนี้"); + } + let node = null; + let nodeId = null; + let nodeDnaId = null; + let nodeName = null; + if (kpiPlan.child4Id != null) { + node = 4; + nodeId = kpiPlan.child4Id; + nodeDnaId = kpiPlan.child4DnaId; + nodeName = kpiPlan.child4; + } else if (kpiPlan.child3Id != null) { + node = 3; + nodeId = kpiPlan.child3Id; + nodeDnaId = kpiPlan.child3DnaId; + nodeName = kpiPlan.child3; + } else if (kpiPlan.child2Id != null) { + node = 2; + nodeId = kpiPlan.child2Id; + nodeDnaId = kpiPlan.child2DnaId; + nodeName = kpiPlan.child2; + } else if (kpiPlan.child1Id != null) { + node = 1; + nodeId = kpiPlan.child1Id; + nodeDnaId = kpiPlan.child1DnaId; + nodeName = kpiPlan.child1; + } else if (kpiPlan.rootId != null) { + node = 0; + nodeId = kpiPlan.rootId; + nodeDnaId = kpiPlan.rootDnaId; + nodeName = kpiPlan.root; + } + let strategy = null; + let strategyId = null; + let strategyName = null; + if (kpiPlan.strategyChild5Id != null) { + strategy = 5; + strategyId = kpiPlan.strategyChild5Id; + } else if (kpiPlan.strategyChild4Id != null) { + strategy = 4; + strategyId = kpiPlan.strategyChild4Id; + strategyName = kpiPlan.strategyChild4; + } else if (kpiPlan.strategyChild3Id != null) { + strategy = 3; + strategyId = kpiPlan.strategyChild3Id; + strategyName = kpiPlan.strategyChild3; + } else if (kpiPlan.strategyChild2Id != null) { + strategy = 2; + strategyId = kpiPlan.strategyChild2Id; + strategyName = kpiPlan.strategyChild2; + } else if (kpiPlan.strategyChild1Id != null) { + strategy = 1; + strategyId = kpiPlan.strategyChild1Id; + strategyName = kpiPlan.strategyChild1; + } + const formattedData = { + id: kpiPlan.id, + // year: kpiPlan.kpiPeriod == null ? null : kpiPlan.kpiPeriod.year, + // round: kpiPlan.kpiPeriod == null ? null : kpiPlan.kpiPeriod.durationKPI, + year: kpiPlan.year == null ? null : kpiPlan.year, + round: kpiPlan.period == null ? null : kpiPlan.period, + kpiPeriodId: kpiPlan.kpiPeriodId, + including: kpiPlan.including, + includingName: kpiPlan.includingName, + target: kpiPlan.target, + unit: kpiPlan.unit, + weight: kpiPlan.weight, + achievement1: kpiPlan.achievement1, + achievement2: kpiPlan.achievement2, + achievement3: kpiPlan.achievement3, + achievement4: kpiPlan.achievement4, + achievement5: kpiPlan.achievement5, + meaning: kpiPlan.meaning, + formula: kpiPlan.formula, + root: kpiPlan.rootId, + child1: kpiPlan.child1Id, + child2: kpiPlan.child2Id, + child3: kpiPlan.child3Id, + child4: kpiPlan.child4Id, + rootDna: kpiPlan.rootDnaId, + child1Dna: kpiPlan.child1DnaId, + child2Dna: kpiPlan.child2DnaId, + child3Dna: kpiPlan.child3DnaId, + child4Dna: kpiPlan.child4DnaId, + node: node, + nodeId: nodeId, + nodeDnaId: nodeDnaId, + nodeName: nodeName, + orgRevisionId: kpiPlan.orgRevisionId, + strategy: strategy, + strategyId: strategyId, + strategyName: strategyName, + strategyChild1: kpiPlan.strategyChild1Id, + strategyChild2: kpiPlan.strategyChild2Id, + strategyChild3: kpiPlan.strategyChild3Id, + strategyChild4: kpiPlan.strategyChild4Id, + strategyChild5: kpiPlan.strategyChild5Id, + documentInfoEvidence: kpiPlan.documentInfoEvidence, + }; + return new HttpSuccess(formattedData); + } + /** * API ตัวชี้วัดตามแผนฯ * @param id Guid, *Id ตัวชี้วัดตามแผนฯ @@ -880,12 +995,12 @@ export class kpiPlanController extends Controller { ]) .orderBy("kpiPlan.createdAt", "DESC") - if (requestBody.sortBy) { - query = query.orderBy( - `kpiPlan.${requestBody.sortBy}`, - requestBody.descending ? "DESC" : "ASC" - ); - } + if (requestBody.sortBy) { + query = query.orderBy( + `kpiPlan.${requestBody.sortBy}`, + requestBody.descending ? "DESC" : "ASC" + ); + } const [kpiPlan, total] = await query .skip((requestBody.page - 1) * requestBody.pageSize) diff --git a/src/controllers/KpiRoleController.ts b/src/controllers/KpiRoleController.ts index 4e49aec..ece1f07 100644 --- a/src/controllers/KpiRoleController.ts +++ b/src/controllers/KpiRoleController.ts @@ -91,7 +91,7 @@ export class kpiRoleController extends Controller { kpiRole.child4DnaId = requestBody.node <= 3 ? null : x.child4DnaId; kpiRole.child4ShortName = requestBody.node <= 3 ? null : x.child4ShortName; }) - .catch((x) => {}); + .catch((x) => { }); let maxIncludingRole: any; if (requestBody.node == 0) { @@ -267,7 +267,7 @@ export class kpiRoleController extends Controller { kpiRole.child4DnaId = requestBody.node <= 3 ? null : x.child4DnaId; kpiRole.child4ShortName = requestBody.node <= 3 ? null : x.child4ShortName; }) - .catch((x) => {}); + .catch((x) => { }); let before = null; before = structuredClone(kpiRole); @@ -380,6 +380,91 @@ export class kpiRoleController extends Controller { return new HttpSuccess(formattedData); } + /** + * API ตัวชี้วัดตามตำแหน่ง สิทธิ์ KPI EDIT + * @param id Guid, *Id ตัวชี้วัดตามตำแหน่ง สิทธิ์ KPI EDIT + */ + @Get("edit-indicator/{id}") + async GetKpiRoleByIdEditIndicator(@Request() request: RequestWithUser, @Path() id: string) { + let _workflow = await new permission().Workflow(request, id, "SYS_KPI_LIST"); + if (_workflow == false) await new permission().PermissionUpdate(request, "SYS_KPI_LIST"); + const kpiRole = await this.kpiRoleRepository.findOne({ + where: { id: id }, + relations: { kpiPeriod: true }, + }); + if (!kpiRole) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลตัวชี้วัดตามตำแหน่งนี้"); + } + let node = null; + let nodeId = null; + let nodeDnaId = null; + let nodeName = null; + if (kpiRole.child4Id != null) { + node = 4; + nodeId = kpiRole.child4Id; + nodeDnaId = kpiRole.child4DnaId; + nodeName = kpiRole.child4; + } else if (kpiRole.child3Id != null) { + node = 3; + nodeId = kpiRole.child3Id; + nodeDnaId = kpiRole.child3DnaId; + nodeName = kpiRole.child3; + } else if (kpiRole.child2Id != null) { + node = 2; + nodeId = kpiRole.child2Id; + nodeDnaId = kpiRole.child2DnaId; + nodeName = kpiRole.child2; + } else if (kpiRole.child1Id != null) { + node = 1; + nodeId = kpiRole.child1Id; + nodeDnaId = kpiRole.child1DnaId; + nodeName = kpiRole.child1; + } else if (kpiRole.rootId != null) { + node = 0; + nodeId = kpiRole.rootId; + nodeDnaId = kpiRole.rootDnaId; + nodeName = kpiRole.root; + } + const formattedData = { + id: kpiRole.id, + // year: kpiRole.kpiPeriod == null ? null : kpiRole.kpiPeriod.year, + // round: kpiRole.kpiPeriod == null ? null : kpiRole.kpiPeriod.durationKPI, + year: kpiRole.year == null ? null : kpiRole.year, + round: kpiRole.period == null ? null : kpiRole.period, + kpiPeriodId: kpiRole.kpiPeriodId, + including: kpiRole.including, + includingName: kpiRole.includingName, + target: kpiRole.target, + unit: kpiRole.unit, + weight: kpiRole.weight, + achievement1: kpiRole.achievement1, + achievement2: kpiRole.achievement2, + achievement3: kpiRole.achievement3, + achievement4: kpiRole.achievement4, + achievement5: kpiRole.achievement5, + meaning: kpiRole.meaning, + formula: kpiRole.formula, + root: kpiRole.rootId, + child1: kpiRole.child1Id, + child2: kpiRole.child2Id, + child3: kpiRole.child3Id, + child4: kpiRole.child4Id, + rootDna: kpiRole.rootDnaId, + child1Dna: kpiRole.child1DnaId, + child2Dna: kpiRole.child2DnaId, + child3Dna: kpiRole.child3DnaId, + child4Dna: kpiRole.child4DnaId, + node: node, + nodeId: nodeId, + nodeDnaId: nodeDnaId, + nodeName: nodeName, + orgRevisionId: kpiRole.orgRevisionId, + position: kpiRole.position, + documentInfoEvidence: kpiRole.documentInfoEvidence, + }; + return new HttpSuccess(formattedData); + } + /** * API ตัวชี้วัดตามตำแหน่ง * @param id Guid, *Id ตัวชี้วัดตามตำแหน่ง @@ -833,14 +918,14 @@ export class kpiRoleController extends Controller { ]) .orderBy("kpiRole.createdAt", "DESC") - if (requestBody.sortBy) { - query = query.orderBy( - `kpiRole.${requestBody.sortBy}`, - requestBody.descending ? "DESC" : "ASC" - ); - } + if (requestBody.sortBy) { + query = query.orderBy( + `kpiRole.${requestBody.sortBy}`, + requestBody.descending ? "DESC" : "ASC" + ); + } - const [kpiRole, total] = await query + const [kpiRole, total] = await query .skip((requestBody.page - 1) * requestBody.pageSize) .take(requestBody.pageSize) .getManyAndCount(); diff --git a/src/controllers/KpiSpecialController.ts b/src/controllers/KpiSpecialController.ts index 04d63ca..97c41aa 100644 --- a/src/controllers/KpiSpecialController.ts +++ b/src/controllers/KpiSpecialController.ts @@ -121,7 +121,7 @@ export class kpiSpecialController extends Controller { } /** - * API ตัวชี้วัด Special + * API ตัวชี้วัด Special * @param id Guid, *Id ตัวชี้วัด Special */ @Get("edit/{id}") @@ -160,6 +160,46 @@ export class kpiSpecialController extends Controller { return new HttpSuccess(mapData); } + /** + * API ตัวชี้วัด Special สิทธิ์ KPI EDIT + * @param id Guid, *Id ตัวชี้วัด Special สิทธิ์ KPI EDIT + */ + @Get("edit-indicator/{id}") + async GetKpiSpecialByIdEditIndicator(@Request() request: RequestWithUser, @Path() id: string) { + let _workflow = await new permission().Workflow(request, id, "SYS_KPI_LIST"); + if (_workflow == false) await new permission().PermissionUpdate(request, "SYS_KPI_LIST"); + const KpiSpecial = await this.kpiSpecialRepository.findOne({ + where: { id: id }, + }); + if (!KpiSpecial) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลตัวชี้วัด Specialนี้"); + } + + const mapData = { + id: KpiSpecial.id, + period: KpiSpecial.period, + year: KpiSpecial.year, + including: KpiSpecial.including, + includingName: KpiSpecial.includingName, + target: KpiSpecial.target, + unit: KpiSpecial.unit, + weight: KpiSpecial.weight, + point: KpiSpecial.point, + summary: KpiSpecial.summary, + documentInfoEvidence: KpiSpecial.documentInfoEvidence, + startDate: KpiSpecial.startDate, + endDate: KpiSpecial.endDate, + achievement1: KpiSpecial.achievement1, + achievement2: KpiSpecial.achievement2, + achievement3: KpiSpecial.achievement3, + achievement4: KpiSpecial.achievement4, + achievement5: KpiSpecial.achievement5, + meaning: KpiSpecial.meaning, + formula: KpiSpecial.formula, + }; + return new HttpSuccess(mapData); + } + /** * API ตัวชี้วัด Special * @param id Guid, *Id ตัวชี้วัด Special @@ -375,14 +415,14 @@ export class kpiSpecialController extends Controller { ]) .orderBy("kpiSpecial.createdAt", "DESC") - if (requestBody.sortBy) { - query = query.orderBy( - `kpiSpecial.${requestBody.sortBy}`, - requestBody.descending ? "DESC" : "ASC" - ); - } + if (requestBody.sortBy) { + query = query.orderBy( + `kpiSpecial.${requestBody.sortBy}`, + requestBody.descending ? "DESC" : "ASC" + ); + } - const [kpiSpecial, total] = await query + const [kpiSpecial, total] = await query .skip((requestBody.page - 1) * requestBody.pageSize) .take(requestBody.pageSize) .getManyAndCount();