From b8a13ef003ed01c64dd23682d62d196da23ef010 Mon Sep 17 00:00:00 2001 From: kittapath Date: Sat, 7 Dec 2024 09:31:06 +0700 Subject: [PATCH 1/5] test build discord --- .github/workflows/release.yaml | 59 ++++++++++++++++++++++------------ 1 file changed, 39 insertions(+), 20 deletions(-) diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 705c538..3bb0e5b 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -1,5 +1,5 @@ -name: release-test -run-name: release-test ${{ github.actor }} +name: release +run-name: release ${{ github.actor }} on: push: tags: @@ -9,11 +9,11 @@ env: REGISTRY: docker.frappet.com IMAGE_NAME: ehr/bma-ehr-kpi-service DEPLOY_HOST: frappet.com - # COMPOSE_PATH: /home/frappet/docker/bma-ehr COMPOSE_PATH: /home/frappet/docker/bma/bma-ehr-kpi + jobs: # act workflow_dispatch -W .github/workflows/release.yaml --input IMAGE_VER=latest -s DOCKER_USER=admin -s DOCKER_PASS=FPTadmin2357 -s SSH_PASSWORD=FPTadmin2357 - release-test: + release: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 @@ -67,21 +67,40 @@ jobs: docker compose pull docker compose up -d echo "${{ steps.gen_ver.outputs.image_ver }}"> success - - uses: snow-actions/line-notify@v1.1.0 + - name: Notify Discord Success if: success() - with: - access_token: ${{ secrets.TOKEN_LINE }} - message: | - -Success✅✅✅ - Image: ${{env.IMAGE_NAME}} - Version: ${{ steps.gen_ver.outputs.IMAGE_VER }} - By: ${{github.actor}} - - uses: snow-actions/line-notify@v1.1.0 + run: | + curl -H "Content-Type: application/json" \ + -X POST \ + -d '{ + "embeds": [{ + "title": "✅ Deployment Success!", + "description": "**Details:**\n- Image: `${{env.IMAGE_NAME}}`\n- Version: `${{ steps.gen_ver.outputs.image_ver }}`\n- Deployed by: `${{github.actor}}`", + "color": 3066993, + "footer": { + "text": "Release Notification", + "icon_url": "https://example.com/success-icon.png" + }, + "timestamp": "'$(date -u +%Y-%m-%dT%H:%M:%SZ)'" + }] + }' \ + ${{ secrets.DISCORD_WEBHOOK }} + + - name: Notify Discord Failure if: failure() - with: - access_token: ${{ secrets.TOKEN_LINE }} - message: | - -Failure❌❌❌ - Image: ${{env.IMAGE_NAME}} - Version: ${{ steps.gen_ver.outputs.IMAGE_VER }} - By: ${{github.actor}} + run: | + curl -H "Content-Type: application/json" \ + -X POST \ + -d '{ + "embeds": [{ + "title": "❌ Deployment Failed!", + "description": "**Details:**\n- Image: `${{env.IMAGE_NAME}}`\n- Version: `${{ steps.gen_ver.outputs.image_ver }}`\n- Attempted by: `${{github.actor}}`", + "color": 15158332, + "footer": { + "text": "Release Notification", + "icon_url": "https://example.com/failure-icon.png" + }, + "timestamp": "'$(date -u +%Y-%m-%dT%H:%M:%SZ)'" + }] + }' \ + ${{ secrets.DISCORD_WEBHOOK }} From cb26678af0edfed7392b1b1630cd256a7b8270f0 Mon Sep 17 00:00:00 2001 From: Bright Date: Fri, 13 Dec 2024 18:22:28 +0700 Subject: [PATCH 2/5] fix --- src/controllers/KpiPeriodController.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/controllers/KpiPeriodController.ts b/src/controllers/KpiPeriodController.ts index fefe614..3de8a72 100644 --- a/src/controllers/KpiPeriodController.ts +++ b/src/controllers/KpiPeriodController.ts @@ -331,7 +331,12 @@ export class kpiPeriodController extends Controller { const kpiUserEvaluation = await this.kpiUserEvaluationRepository.find({ where: { kpiPeriodId: id }, }); - + if (kpiUserEvaluation && kpiUserEvaluation.length > 0) { + throw new HttpError( + HttpStatusCode.NOT_FOUND, + "ไม่สามารถลบรอบการประเมินนี้ได้ เนื่องจากพบรายการผู้รับการประเมินในรอบนี้", + ); + } const kpiUserRole = await this.kpiUserRoleRepository.find({ where: { kpiRoleId: In(kpiRole.map((x) => x.id)) }, }); From 8d38768494cf50963ee02de939ea48ea465df805 Mon Sep 17 00:00:00 2001 From: kittapath Date: Fri, 13 Dec 2024 23:30:21 +0700 Subject: [PATCH 3/5] =?UTF-8?q?=E0=B9=81=E0=B8=81=E0=B9=89=E0=B8=9A?= =?UTF-8?q?=E0=B8=B1=E0=B8=84=20kpi?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/KpiCapacityController.ts | 6 +----- src/controllers/KpiGroupController.ts | 12 ++++++++++-- src/controllers/KpiRoleController.ts | 5 ++--- 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/src/controllers/KpiCapacityController.ts b/src/controllers/KpiCapacityController.ts index 210983a..1f20c24 100644 --- a/src/controllers/KpiCapacityController.ts +++ b/src/controllers/KpiCapacityController.ts @@ -350,11 +350,7 @@ export class kpiCapacityController extends Controller { const [kpiCapacity, total] = await AppDataSource.getRepository(KpiCapacity) .createQueryBuilder("kpiCapacity") .leftJoinAndSelect("kpiCapacity.kpiCapacityDetails", "kpiCapacityDetail") - .andWhere( - keyword == undefined - ? "1=1" - : [{ name: Like(`%${keyword}%`) }, { description: Like(`%${keyword}%`) }], - ) + .andWhere(keyword == undefined ? "1=1" : [{ name: Like(`%${keyword}%`) }]) .andWhere(type == undefined ? "1=1" : { type: type }) .orderBy("kpiCapacity.createdAt", "ASC") .skip((page - 1) * pageSize) diff --git a/src/controllers/KpiGroupController.ts b/src/controllers/KpiGroupController.ts index 5e03bd6..a0b82e1 100644 --- a/src/controllers/KpiGroupController.ts +++ b/src/controllers/KpiGroupController.ts @@ -18,12 +18,14 @@ import { import { AppDataSource } from "../database/data-source"; import HttpSuccess from "../interfaces/http-success"; import HttpError from "../interfaces/http-error"; -import { Like, Not } from "typeorm"; +import { In, Like, Not } from "typeorm"; import HttpStatusCode from "../interfaces/http-status"; import { KpiGroup, createKpiGroup, updateKpiGroup } from "../entities/kpiGroup"; import permission from "../interfaces/permission"; import { RequestWithUser } from "../middlewares/user"; import { setLogDataDiff } from "../interfaces/utils"; +import { KpiLink } from "../entities/kpiLink"; +import { Position } from "../entities/position"; @Route("api/v1/kpi/group") @Tags("kpiGroup") @@ -35,6 +37,8 @@ import { setLogDataDiff } from "../interfaces/utils"; @SuccessResponse(HttpStatusCode.OK, "สำเร็จ") export class kpiGroupController extends Controller { private kpiGroupRepository = AppDataSource.getRepository(KpiGroup); + private kpiLinkRepository = AppDataSource.getRepository(KpiLink); + private positionRepository = AppDataSource.getRepository(Position); /** * API สร้างกลุ่มงาน @@ -192,7 +196,11 @@ export class kpiGroupController extends Controller { if (!kpiGroup) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลกลุ่มงานนี้"); } - + const kpiLink = await this.kpiLinkRepository.find({ + where: { kpiGroupId: id }, + }); + await this.positionRepository.delete({ kpiLinkId: In(kpiLink.map((x) => x.id)) }); + await this.kpiLinkRepository.remove(kpiLink, { data: request }); await this.kpiGroupRepository.remove(kpiGroup, { data: request }); return new HttpSuccess(); } diff --git a/src/controllers/KpiRoleController.ts b/src/controllers/KpiRoleController.ts index be3fb42..6a80ee0 100644 --- a/src/controllers/KpiRoleController.ts +++ b/src/controllers/KpiRoleController.ts @@ -47,17 +47,16 @@ export class kpiRoleController extends Controller { async createKpiRole(@Body() requestBody: createKpiRole, @Request() request: RequestWithUser) { await new permission().PermissionCreate(request, "SYS_EVA_INDICATOR"); const kpiRole = Object.assign(new KpiRole(), requestBody); - if (requestBody.year != null && requestBody.period != null) { + if (requestBody.year != null && requestBody.period != null && requestBody.period != "") { const kpiPeriod = await this.kpiPeriodRepository .createQueryBuilder("kpiPeriod") .where("kpiPeriod.year = :year", { year: requestBody.year }) .andWhere("kpiPeriod.durationKPI = :durationKPI", { durationKPI: requestBody.period }) .getOne(); if (!kpiPeriod) { - // throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลตัวชี้วัดตามตำแหน่งนี้"); throw new HttpError( HttpStatusCode.NOT_FOUND, - "ไม่พบข้อมูลรอบการประเมินนี้ในปีงบประมาณ " + requestBody.year, + "ไม่พบข้อมูลรอบการประเมินนี้ในปีงบประมาณ " + (requestBody.year + 543), ); } } From 53302147ef916ee47012de9871ed3000a4ab3746 Mon Sep 17 00:00:00 2001 From: kittapath Date: Sat, 14 Dec 2024 01:04:37 +0700 Subject: [PATCH 4/5] edit permission --- src/interfaces/permission.ts | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/interfaces/permission.ts b/src/interfaces/permission.ts index 33ca393..d8d700a 100644 --- a/src/interfaces/permission.ts +++ b/src/interfaces/permission.ts @@ -183,7 +183,7 @@ class CheckAuth { return false; }); } - public async checkOrg(token: any,keycloakId: string) { + public async checkOrg(token: any, keycloakId: string) { const redisClient = await this.redis.createClient({ host: process.env.REDIS_HOST, port: process.env.REDIS_PORT, @@ -194,14 +194,15 @@ class CheckAuth { reply = JSON.parse(reply); } else { try { + if (!keycloakId) throw "Error calling API No KeycloakId"; const x = await new CallAPI().GetData( { headers: { authorization: token }, - }, - `/org/permission/checkOrg/${keycloakId}`, - false + }, + `/org/permission/checkOrg/${keycloakId}`, + false, ); - + const data = { orgRootId: x.orgRootId, orgChild1Id: x.orgChild1Id, @@ -209,7 +210,7 @@ class CheckAuth { orgChild3Id: x.orgChild3Id, orgChild4Id: x.orgChild4Id, }; - + return data; } catch (error) { console.error("Error calling API:", error); From 29447e308c1e656d6d983c5df5e7abba14598c31 Mon Sep 17 00:00:00 2001 From: Bright Date: Mon, 16 Dec 2024 11:55:34 +0700 Subject: [PATCH 5/5] =?UTF-8?q?fix=20issue=20#858=20:=20=E0=B8=81=E0=B8=A3?= =?UTF-8?q?=E0=B8=93=E0=B8=B5=E0=B8=97=E0=B8=B5=E0=B9=88=E0=B8=9F=E0=B8=B4?= =?UTF-8?q?=E0=B8=A5=E0=B8=94=E0=B9=8C=E0=B9=83=E0=B8=94=E0=B9=86=E0=B9=83?= =?UTF-8?q?=E0=B8=99=20report=20=E0=B8=A1=E0=B8=B5=E0=B8=84=E0=B9=88?= =?UTF-8?q?=E0=B8=B2=20Null=20=E0=B8=9B=E0=B8=A3=E0=B8=B1=E0=B8=9A?= =?UTF-8?q?=E0=B9=83=E0=B8=AB=E0=B9=89=E0=B9=81=E0=B8=AA=E0=B8=94=E0=B8=87?= =?UTF-8?q?=20"-"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/ReportController.ts | 92 +++++++++++++++++++++++++++++ 1 file changed, 92 insertions(+) diff --git a/src/controllers/ReportController.ts b/src/controllers/ReportController.ts index b3a11fa..6728421 100644 --- a/src/controllers/ReportController.ts +++ b/src/controllers/ReportController.ts @@ -770,6 +770,12 @@ export class ReportController extends Controller { acc.posType = x.posTypeName; acc.posLevel = x.posLevelName; acc.affiliation = affiliation; + } else { + acc.fullName = "-"; + acc.position = "-"; + acc.posType = "-"; + acc.posLevel = "-"; + acc.affiliation = "-"; } if (x.kpiPeriod.year === yearNow - 4 && x.kpiPeriod.durationKPI === "APR") { @@ -781,6 +787,11 @@ export class ReportController extends Controller { acc.yearAPR1 = x.kpiPeriod.year ? Extension.ToThaiNumber(Extension.ToThaiYear(x.kpiPeriod.year).toString()) : null; + } else { + acc.summaryPointAPR1 = "-" + acc.textPointAPR1 = "-" + acc.periodAPR1 = "-" + acc.yearAPR1 = "-" } if (x.kpiPeriod.year === yearNow - 4 && x.kpiPeriod.durationKPI === "OCT") { @@ -792,6 +803,11 @@ export class ReportController extends Controller { acc.yearOCT1 = x.kpiPeriod.year ? Extension.ToThaiNumber(Extension.ToThaiYear(x.kpiPeriod.year).toString()) : null; + } else { + acc.summaryPointOCT1 = "-" + acc.textPointOCT1 = "-" + acc.periodOCT1 = "-" + acc.yearOCT1 = "-" } if (x.kpiPeriod.year === yearNow - 3 && x.kpiPeriod.durationKPI === "APR") { @@ -803,6 +819,11 @@ export class ReportController extends Controller { acc.yearAPR2 = x.kpiPeriod.year ? Extension.ToThaiNumber(Extension.ToThaiYear(x.kpiPeriod.year).toString()) : null; + } else { + acc.summaryPointAPR2 = "-" + acc.textPointAPR2 = "-" + acc.periodAPR2 = "-" + acc.yearAPR2 = "-" } if (x.kpiPeriod.year === yearNow - 3 && x.kpiPeriod.durationKPI === "OCT") { @@ -814,6 +835,11 @@ export class ReportController extends Controller { acc.yearOCT2 = x.kpiPeriod.year ? Extension.ToThaiNumber(Extension.ToThaiYear(x.kpiPeriod.year).toString()) : null; + } else { + acc.summaryPointOCT2 = "-" + acc.textPointOCT2 = "-" + acc.periodOCT2 = "-" + acc.yearOCT2 = "-" } if (x.kpiPeriod.year === yearNow - 2 && x.kpiPeriod.durationKPI === "APR") { @@ -825,6 +851,11 @@ export class ReportController extends Controller { acc.yearAPR3 = x.kpiPeriod.year ? Extension.ToThaiNumber(Extension.ToThaiYear(x.kpiPeriod.year).toString()) : null; + } else { + acc.summaryPointAPR3 = "-" + acc.textPointAPR3 = "-" + acc.periodAPR3 = "-" + acc.yearAPR3 = "-" } if (x.kpiPeriod.year === yearNow - 2 && x.kpiPeriod.durationKPI === "OCT") { @@ -836,6 +867,11 @@ export class ReportController extends Controller { acc.yearOCT3 = x.kpiPeriod.year ? Extension.ToThaiNumber(Extension.ToThaiYear(x.kpiPeriod.year).toString()) : null; + } else { + acc.summaryPointOCT3 = "-" + acc.textPointOCT3 = "-" + acc.periodOCT3 = "-" + acc.yearOCT3 = "-" } if (x.kpiPeriod.year === yearNow - 1 && x.kpiPeriod.durationKPI === "APR") { @@ -847,6 +883,11 @@ export class ReportController extends Controller { acc.yearAPR4 = x.kpiPeriod.year ? Extension.ToThaiNumber(Extension.ToThaiYear(x.kpiPeriod.year).toString()) : null; + } else { + acc.summaryPointAPR4 = "-" + acc.textPointAPR4 = "-" + acc.periodAPR4 = "-" + acc.yearAPR4 = "-" } if (x.kpiPeriod.year === yearNow - 1 && x.kpiPeriod.durationKPI === "OCT") { @@ -858,6 +899,11 @@ export class ReportController extends Controller { acc.yearOCT4 = x.kpiPeriod.year ? Extension.ToThaiNumber(Extension.ToThaiYear(x.kpiPeriod.year).toString()) : null; + } else { + acc.summaryPointOCT4 = "-" + acc.textPointOCT4 = "-" + acc.periodOCT4 = "-" + acc.yearOCT4 = "-" } if (x.kpiPeriod.year === yearNow && x.kpiPeriod.durationKPI === "APR") { @@ -869,6 +915,11 @@ export class ReportController extends Controller { acc.yearAPR5 = x.kpiPeriod.year ? Extension.ToThaiNumber(Extension.ToThaiYear(x.kpiPeriod.year).toString()) : null; + } else { + acc.summaryPointAPR5 = "-" + acc.textPointAPR5 = "-" + acc.periodAPR5 = "-" + acc.yearAPR5 = "-" } if (x.kpiPeriod.year === yearNow && x.kpiPeriod.durationKPI === "OCT") { @@ -880,6 +931,11 @@ export class ReportController extends Controller { acc.yearOCT5 = x.kpiPeriod.year ? Extension.ToThaiNumber(Extension.ToThaiYear(x.kpiPeriod.year).toString()) : null; + } else { + acc.summaryPointOCT5 = "-" + acc.textPointOCT5 = "-" + acc.periodOCT5 = "-" + acc.yearOCT5 = "-" } return acc; @@ -1069,6 +1125,12 @@ export class ReportController extends Controller { acc.posType = x.posTypeName; acc.posLevel = x.posLevelName; acc.affiliation = affiliation; + } else { + acc.fullName = "-"; + acc.position = "-"; + acc.posType = "-"; + acc.posLevel = "-"; + acc.affiliation = "-"; } if (x.kpiPeriod.year === yearNow - 2 && x.kpiPeriod.durationKPI === "APR") { @@ -1080,6 +1142,11 @@ export class ReportController extends Controller { acc.yearAPR1 = x.kpiPeriod.year ? Extension.ToThaiNumber(Extension.ToThaiYear(x.kpiPeriod.year).toString()) : null; + } else { + acc.summaryPointAPR1 = "-" + acc.textPointAPR1 = "-" + acc.periodAPR1 = "-" + acc.yearAPR1 = "-" } if (x.kpiPeriod.year === yearNow - 2 && x.kpiPeriod.durationKPI === "OCT") { @@ -1091,6 +1158,11 @@ export class ReportController extends Controller { acc.yearOCT1 = x.kpiPeriod.year ? Extension.ToThaiNumber(Extension.ToThaiYear(x.kpiPeriod.year).toString()) : null; + } else { + acc.summaryPointOCT1 = "-" + acc.textPointOCT1 = "-" + acc.periodOCT1 = "-" + acc.yearOCT1 = "-" } if (x.kpiPeriod.year === yearNow - 1 && x.kpiPeriod.durationKPI === "APR") { @@ -1102,6 +1174,11 @@ export class ReportController extends Controller { acc.yearAPR2 = x.kpiPeriod.year ? Extension.ToThaiNumber(Extension.ToThaiYear(x.kpiPeriod.year).toString()) : null; + } else { + acc.summaryPointAPR2 = "-" + acc.textPointAPR2 = "-" + acc.periodAPR2 = "-" + acc.yearAPR2 = "-" } if (x.kpiPeriod.year === yearNow - 1 && x.kpiPeriod.durationKPI === "OCT") { @@ -1113,6 +1190,11 @@ export class ReportController extends Controller { acc.yearOCT2 = x.kpiPeriod.year ? Extension.ToThaiNumber(Extension.ToThaiYear(x.kpiPeriod.year).toString()) : null; + } else { + acc.summaryPointOCT2 = "-" + acc.textPointOCT2 = "-" + acc.periodOCT2 = "-" + acc.yearOCT2 = "-" } if (x.kpiPeriod.year === yearNow && x.kpiPeriod.durationKPI === "APR") { @@ -1124,6 +1206,11 @@ export class ReportController extends Controller { acc.yearAPR3 = x.kpiPeriod.year ? Extension.ToThaiNumber(Extension.ToThaiYear(x.kpiPeriod.year).toString()) : null; + } else { + acc.summaryPointAPR3 = "-" + acc.textPointAPR3 = "-" + acc.periodAPR3 = "-" + acc.yearAPR3 = "-" } if (x.kpiPeriod.year === yearNow && x.kpiPeriod.durationKPI === "OCT") { @@ -1135,6 +1222,11 @@ export class ReportController extends Controller { acc.yearOCT3 = x.kpiPeriod.year ? Extension.ToThaiNumber(Extension.ToThaiYear(x.kpiPeriod.year).toString()) : null; + } else { + acc.summaryPointOCT3 = "-" + acc.textPointOCT3 = "-" + acc.periodOCT3 = "-" + acc.yearOCT3 = "-" } return acc;