diff --git a/src/controllers/EvaluationController.ts b/src/controllers/EvaluationController.ts index 4dc97a8..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"; @@ -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), + }); }), ); }), 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; +}