edit permission

This commit is contained in:
DESKTOP-2S5P7D1\Windows 10 2024-12-14 01:04:30 +07:00
parent 3737b2ed73
commit 31a98ea777
3 changed files with 21 additions and 9 deletions

View file

@ -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),
});
}),
);
}),

View file

@ -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);

View file

@ -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;
}