diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index bfae554..7ee8e4b 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-evaluation-service DEPLOY_HOST: frappet.com - # COMPOSE_PATH: /home/frappet/docker/bma-ehr COMPOSE_PATH: /home/frappet/docker/bma/bma-ehr-evaluation + 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 }} diff --git a/src/controllers/DirectorController.ts b/src/controllers/DirectorController.ts index 1446b00..6551d60 100644 --- a/src/controllers/DirectorController.ts +++ b/src/controllers/DirectorController.ts @@ -47,21 +47,6 @@ export class DirectorController { @Query("keyword") keyword?: string, ) { await new permission().PermissionList(request, "SYS_EVA_INFO"); - // const directors = await this.directorRepository.find({ - // skip: (page - 1) * pageSize, - // take: pageSize, - // }); - // if (keyword != undefined && keyword !== "") { - // return directors.filter( - // (x) => - // x.prefix?.includes(keyword) || - // x.firstName?.includes(keyword) || - // x.lastName?.includes(keyword) || - // x.position?.includes(keyword) || - // x.email?.includes(keyword) || - // x.phone?.includes(keyword), - // ); - // } const directors = await AppDataSource.getRepository(Director) .createQueryBuilder("director") .andWhere( @@ -74,30 +59,15 @@ export class DirectorController { keyword: `%${keyword}%`, }, ) - .orWhere( - keyword != null && keyword != "" - ? "director.position LIKE :keyword" - : "1=1", - { + .orWhere(keyword != null && keyword != "" ? "director.position LIKE :keyword" : "1=1", { keyword: `%${keyword}%`, - }, - ) - .orWhere( - keyword != null && keyword != "" - ? "director.email LIKE :keyword" - : "1=1", - { + }) + .orWhere(keyword != null && keyword != "" ? "director.email LIKE :keyword" : "1=1", { keyword: `%${keyword}%`, - }, - ) - .orWhere( - keyword != null && keyword != "" - ? "director.phone LIKE :keyword" - : "1=1", - { + }) + .orWhere(keyword != null && keyword != "" ? "director.phone LIKE :keyword" : "1=1", { keyword: `%${keyword}%`, - }, - ); + }); }), ) .orderBy("director.createdAt", "DESC") @@ -115,21 +85,6 @@ export class DirectorController { @Query("pageSize") pageSize: number = 10, @Query("keyword") keyword?: string, ) { - // const directors = await this.directorRepository.find({ - // skip: (page - 1) * pageSize, - // take: pageSize, - // }); - // if (keyword != undefined && keyword !== "") { - // return directors.filter( - // (x) => - // x.prefix?.includes(keyword) || - // x.firstName?.includes(keyword) || - // x.lastName?.includes(keyword) || - // x.position?.includes(keyword) || - // x.email?.includes(keyword) || - // x.phone?.includes(keyword), - // ); - // } const directors = await AppDataSource.getRepository(Director) .createQueryBuilder("director") .andWhere( @@ -142,30 +97,15 @@ export class DirectorController { keyword: `%${keyword}%`, }, ) - .orWhere( - keyword != null && keyword != "" - ? "director.position LIKE :keyword" - : "1=1", - { + .orWhere(keyword != null && keyword != "" ? "director.position LIKE :keyword" : "1=1", { keyword: `%${keyword}%`, - }, - ) - .orWhere( - keyword != null && keyword != "" - ? "director.email LIKE :keyword" - : "1=1", - { + }) + .orWhere(keyword != null && keyword != "" ? "director.email LIKE :keyword" : "1=1", { keyword: `%${keyword}%`, - }, - ) - .orWhere( - keyword != null && keyword != "" - ? "director.phone LIKE :keyword" - : "1=1", - { + }) + .orWhere(keyword != null && keyword != "" ? "director.phone LIKE :keyword" : "1=1", { keyword: `%${keyword}%`, - }, - ); + }); }), ) .orderBy("director.createdAt", "DESC") diff --git a/src/controllers/EvaluationController.ts b/src/controllers/EvaluationController.ts index 2857673..5a0f72c 100644 --- a/src/controllers/EvaluationController.ts +++ b/src/controllers/EvaluationController.ts @@ -26,7 +26,7 @@ import { Training } from "../entities/Training"; import { Assessment } from "../entities/Assessment"; import { Director } from "../entities/Director"; import { Meeting } from "../entities/Meeting"; -import { ConvertToThaiStep, ConvertToThaiType } from "../services/storage"; +import { ConvertThaiToType, ConvertToThaiStep, ConvertToThaiType } from "../services/storage"; import { Brackets } from "typeorm"; import CallAPI from "../interfaces/call-api"; import permission from "../interfaces/permission"; @@ -78,15 +78,15 @@ export class EvaluationController { }, ) { // await new permission().PermissionList(request, "SYS_EVA_REQ"); - let _data = await new permission().PermissionOrgList(request,"SYS_EVA_REQ"); + let _data = await new permission().PermissionOrgList(request, "SYS_EVA_REQ"); const [evaluation, total] = await AppDataSource.getRepository(Evaluation) .createQueryBuilder("evaluation") .andWhere( - _data.root != undefined && _data.root != null - ? _data.root[0] != null - ? `evaluation.rootId IN (:...root)` - : `evaluation.rootId is null` - : "1=1", + _data.root != undefined && _data.root != null + ? _data.root[0] != null + ? `evaluation.rootId IN (:...root)` + : `evaluation.rootId is null` + : "1=1", { root: _data.root, }, @@ -120,7 +120,7 @@ export class EvaluationController { { child3: _data.child3, }, - ) + ) .andWhere( _data.child4 != undefined && _data.child4 != null ? _data.child4[0] != null @@ -146,7 +146,10 @@ export class EvaluationController { .orWhere("evaluation.citizenId LIKE :keyword", { keyword: `%${body.keyword}%` }) .orWhere("evaluation.position LIKE :keyword", { keyword: `%${body.keyword}%` }) .orWhere("evaluation.posNo LIKE :keyword", { keyword: `%${body.keyword}%` }) - .orWhere("evaluation.oc LIKE :keyword", { keyword: `%${body.keyword}%` }); + .orWhere("evaluation.oc LIKE :keyword", { keyword: `%${body.keyword}%` }) + .orWhere("evaluation.type IN (:...type)", { + type: body.keyword == null ? [""] : ConvertThaiToType(body.keyword), + }); }), ); }), @@ -198,13 +201,6 @@ export class EvaluationController { ).andWhere("evaluation.createdUserId = :createdUserId", { createdUserId: request.user.sub, }); - // .andWhere( - // new Brackets((qb) => { - // qb.orWhere("evaluation.positionLevel LIKE :keyword", { - // keyword: `%${body.keyword}%`, - // }); - // }), - // ); }), ) .orderBy("evaluation.lastUpdatedAt", "DESC") @@ -408,7 +404,6 @@ export class EvaluationController { const before = null; - //Evaluation evaluation.step = "PREPARE_DOC_V1"; evaluation.type = requestBody.type == "EXPERT" ? "EXPERT" : "SPECIAL_EXPERT"; evaluation.fullName = requestBody.fullName; diff --git a/src/controllers/MeetingController.ts b/src/controllers/MeetingController.ts index 97aceac..3a7a7fa 100644 --- a/src/controllers/MeetingController.ts +++ b/src/controllers/MeetingController.ts @@ -48,33 +48,15 @@ export class MeetingController { @Query("keyword") keyword?: string, ) { await new permission().PermissionList(request, "SYS_EVA_INFO"); - // const meetings = await this.meetingRepository.find({ - // skip: (page - 1) * pageSize, - // take: pageSize, - // }); - // if (keyword != undefined && keyword !== "") { - // return meetings.filter((x) => x.title?.includes(keyword) || x.round?.includes(keyword)); - // } const meetings = await AppDataSource.getRepository(Meeting) .createQueryBuilder("meeting") .andWhere( new Brackets((qb) => { - qb.where( - keyword != null && keyword != "" - ? "meeting.title LIKE :keyword" - : "1=1", - { - keyword: `%${keyword}%`, - }, - ) - .orWhere( - keyword != null && keyword != "" - ? "meeting.round LIKE :keyword" - : "1=1", - { - keyword: `%${keyword}%`, - }, - ); + qb.where(keyword != null && keyword != "" ? "meeting.title LIKE :keyword" : "1=1", { + keyword: `%${keyword}%`, + }).orWhere(keyword != null && keyword != "" ? "meeting.round LIKE :keyword" : "1=1", { + keyword: `%${keyword}%`, + }); }), ) .orderBy("meeting.createdAt", "DESC") @@ -91,34 +73,15 @@ export class MeetingController { @Query("pageSize") pageSize: number = 10, @Query("keyword") keyword?: string, ) { - // const meetings = await this.meetingRepository.find({ - // skip: (page - 1) * pageSize, - // take: pageSize, - // }); - // if (keyword != undefined && keyword !== "") { - // return meetings.filter((x) => x.title?.includes(keyword) || x.round?.includes(keyword)); - // } - const meetings = await AppDataSource.getRepository(Meeting) .createQueryBuilder("meeting") .andWhere( new Brackets((qb) => { - qb.where( - keyword != null && keyword != "" - ? "meeting.title LIKE :keyword" - : "1=1", - { - keyword: `%${keyword}%`, - }, - ) - .orWhere( - keyword != null && keyword != "" - ? "meeting.round LIKE :keyword" - : "1=1", - { - keyword: `%${keyword}%`, - }, - ); + qb.where(keyword != null && keyword != "" ? "meeting.title LIKE :keyword" : "1=1", { + keyword: `%${keyword}%`, + }).orWhere(keyword != null && keyword != "" ? "meeting.round LIKE :keyword" : "1=1", { + keyword: `%${keyword}%`, + }); }), ) .orderBy("meeting.createdAt", "DESC") diff --git a/src/interfaces/permission.ts b/src/interfaces/permission.ts index 6543518..d8d700a 100644 --- a/src/interfaces/permission.ts +++ b/src/interfaces/permission.ts @@ -7,7 +7,7 @@ import { promisify } from "util"; class CheckAuth { private redis = require("redis"); - + public async Permission(req: RequestWithUser, system: string, action: string) { if ( req.headers.hasOwnProperty("api_key") && @@ -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); diff --git a/src/services/storage.ts b/src/services/storage.ts index b240edf..60cbf17 100644 --- a/src/services/storage.ts +++ b/src/services/storage.ts @@ -263,3 +263,11 @@ export function ConvertToThaiType(val: string) { return null; } } + +export function ConvertThaiToType(val: string) { + const data = [""]; + if ("ชำนาญการ".includes(val)) data.push("EXPERT"); + if ("ชำนาญการพิเศษ".includes(val)) data.push("SPECIAL_EXPERT"); + if ("เชี่ยวชาญ".includes(val)) data.push("EXPERTISE"); + return data; +}