Merge branch 'develop' into dev
All checks were successful
Build & Deploy on Dev / build (push) Successful in 49s

This commit is contained in:
harid 2025-12-12 09:57:08 +07:00
commit 11b18db709
3 changed files with 446 additions and 278 deletions

View file

@ -28,7 +28,7 @@ import CallAPI from "../interfaces/call-api";
@Security("bearerAuth") @Security("bearerAuth")
@Response( @Response(
HttpStatusCode.INTERNAL_SERVER_ERROR, HttpStatusCode.INTERNAL_SERVER_ERROR,
"เกิดข้อผิดพลาด ไม่สามารถแสดงรายการได้ กรุณาลองใหม่ในภายหลัง", "เกิดข้อผิดพลาด ไม่สามารถแสดงรายการได้ กรุณาลองใหม่ในภายหลัง"
) )
export class PersonalController extends Controller { export class PersonalController extends Controller {
private personalRepository = AppDataSource.getRepository(Personal); private personalRepository = AppDataSource.getRepository(Personal);
@ -41,7 +41,10 @@ export class PersonalController extends Controller {
* *
*/ */
@Post("add") @Post("add")
async AddPersonal(@Body() requestBody: PostPersonal, @Request() request: RequestWithUser) { async AddPersonal(
@Body() requestBody: PostPersonal,
@Request() request: RequestWithUser
) {
try { try {
await new permission().PermissionCreate(request, "SYS_PROBATION"); await new permission().PermissionCreate(request, "SYS_PROBATION");
@ -51,19 +54,31 @@ export class PersonalController extends Controller {
if (checkPersonal > 0) { if (checkPersonal > 0) {
throw new HttpError( throw new HttpError(
HttpStatusCode.BAD_REQUEST, HttpStatusCode.BAD_REQUEST,
"ผู้ทดลองปฏิบัติหน้าที่ราชการนี้มีอยู่แล้ว", "ผู้ทดลองปฏิบัติหน้าที่ราชการนี้มีอยู่แล้ว"
); );
} }
let organization = await (requestBody.orgChild4Name ? requestBody.orgChild4Name + "\n" : ""); let organization = await (requestBody.orgChild4Name
organization += await (requestBody.orgChild3Name ? requestBody.orgChild3Name + "\n" : ""); ? requestBody.orgChild4Name + "\n"
organization += await (requestBody.orgChild2Name ? requestBody.orgChild2Name + "\n" : ""); : "");
organization += await (requestBody.orgChild1Name ? requestBody.orgChild1Name + "\n" : ""); organization += await (requestBody.orgChild3Name
organization += await (requestBody.orgRootName ? requestBody.orgRootName : ""); ? requestBody.orgChild3Name + "\n"
: "");
organization += await (requestBody.orgChild2Name
? requestBody.orgChild2Name + "\n"
: "");
organization += await (requestBody.orgChild1Name
? requestBody.orgChild1Name + "\n"
: "");
organization += await (requestBody.orgRootName
? requestBody.orgRootName
: "");
const personalData = Object.assign(new Personal()); const personalData = Object.assign(new Personal());
personalData.personal_id = requestBody.id; personalData.personal_id = requestBody.id;
personalData.order_number = requestBody.order_number ? requestBody.order_number : ""; personalData.order_number = requestBody.order_number
? requestBody.order_number
: "";
personalData.probation_status = 1; personalData.probation_status = 1;
personalData.createdUserId = request.user.sub; personalData.createdUserId = request.user.sub;
personalData.createdFullName = request.user.name; personalData.createdFullName = request.user.name;
@ -75,8 +90,12 @@ export class PersonalController extends Controller {
personalData.firstName = requestBody.firstName; personalData.firstName = requestBody.firstName;
personalData.lastName = requestBody.lastName; personalData.lastName = requestBody.lastName;
personalData.isProbation = requestBody.isProbation ? 1 : 0; personalData.isProbation = requestBody.isProbation ? 1 : 0;
personalData.positionLevelName = requestBody.posLevelName ? requestBody.posLevelName : ""; personalData.positionLevelName = requestBody.posLevelName
personalData.positionName = requestBody.position ? requestBody.position : ""; ? requestBody.posLevelName
: "";
personalData.positionName = requestBody.position
? requestBody.position
: "";
personalData.positionLineName = requestBody.posLineName; personalData.positionLineName = requestBody.posLineName;
personalData.positionTypeName = requestBody.posTypeName; personalData.positionTypeName = requestBody.posTypeName;
personalData.posNo = requestBody.posNo ? requestBody.posNo : ""; personalData.posNo = requestBody.posNo ? requestBody.posNo : "";
@ -95,7 +114,8 @@ export class PersonalController extends Controller {
personalData.child3Dna = requestBody.orgChild3Dna; personalData.child3Dna = requestBody.orgChild3Dna;
personalData.child4Dna = requestBody.orgChild4Dna; personalData.child4Dna = requestBody.orgChild4Dna;
const getFieldValue = (field: string | null | undefined): string => field ?? ""; const getFieldValue = (field: string | null | undefined): string =>
field ?? "";
personalData.orgChild1Name = getFieldValue(requestBody.orgChild1Name); personalData.orgChild1Name = getFieldValue(requestBody.orgChild1Name);
personalData.orgChild2Name = getFieldValue(requestBody.orgChild2Name); personalData.orgChild2Name = getFieldValue(requestBody.orgChild2Name);
personalData.orgChild3Name = getFieldValue(requestBody.orgChild3Name); personalData.orgChild3Name = getFieldValue(requestBody.orgChild3Name);
@ -111,7 +131,11 @@ export class PersonalController extends Controller {
} catch (error: any) { } catch (error: any) {
if (error instanceof HttpError) { if (error instanceof HttpError) {
throw error; throw error;
} else throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, error.message); } else
throw new HttpError(
HttpStatusCode.INTERNAL_SERVER_ERROR,
error.message
);
} }
} }
@ -129,13 +153,16 @@ export class PersonalController extends Controller {
@Query("page") page: number = 1, @Query("page") page: number = 1,
@Query("pageSize") pageSize: number = 10, @Query("pageSize") pageSize: number = 10,
@Query("sortBy") sortBy?: string, @Query("sortBy") sortBy?: string,
@Query("descending") descending?: boolean, @Query("descending") descending?: boolean
) { ) {
try { try {
// await new permission().PermissionList(request, "SYS_PROBATION"); // await new permission().PermissionList(request, "SYS_PROBATION");
// const _data = await new permission().PermissionOrgList(request, "SYS_PROBATION"); // const _data = await new permission().PermissionOrgList(request, "SYS_PROBATION");
let _data = await new permission().PermissionOrgList(request, "SYS_PROBATION"); let _data = await new permission().PermissionOrgList(
request,
"SYS_PROBATION"
);
await new CallAPI() await new CallAPI()
.PostData(request, "/org/finddna", _data) .PostData(request, "/org/finddna", _data)
.then((x) => { .then((x) => {
@ -208,17 +235,17 @@ export class PersonalController extends Controller {
: "1=1", : "1=1",
{ {
root: _data.root, root: _data.root,
}, }
) )
.andWhere( .andWhere(
_data.child1 != undefined && _data.child1 != null _data.child1 != undefined && _data.child1 != null
? _data.child1[0] != null ? _data.child1[0] != null
? `personal.child1Dna IN (:...child1)` ? `personal.child1Dna IN (:...child1)`
: `personal.child1Dna is null` : `personal.child1Dna is ${_data.privilege == "PARENT" ? "not null" : "null"}`
: "1=1", : "1=1",
{ {
child1: _data.child1, child1: _data.child1,
}, }
) )
.andWhere( .andWhere(
_data.child2 != undefined && _data.child2 != null _data.child2 != undefined && _data.child2 != null
@ -228,7 +255,7 @@ export class PersonalController extends Controller {
: "1=1", : "1=1",
{ {
child2: _data.child2, child2: _data.child2,
}, }
) )
.andWhere( .andWhere(
_data.child3 != undefined && _data.child3 != null _data.child3 != undefined && _data.child3 != null
@ -238,7 +265,7 @@ export class PersonalController extends Controller {
: "1=1", : "1=1",
{ {
child3: _data.child3, child3: _data.child3,
}, }
) )
.andWhere( .andWhere(
_data.child4 != undefined && _data.child4 != null _data.child4 != undefined && _data.child4 != null
@ -248,7 +275,7 @@ export class PersonalController extends Controller {
: "1=1", : "1=1",
{ {
child4: _data.child4, child4: _data.child4,
}, }
) )
.andWhere( .andWhere(
new Brackets((qb) => { new Brackets((qb) => {
@ -258,36 +285,60 @@ export class PersonalController extends Controller {
: "1=1", : "1=1",
{ {
keyword: `%${searchKeyword}%`, keyword: `%${searchKeyword}%`,
}, }
); );
qb.orWhere(searchKeyword ? `positionName like '%${keyword}%'` : "1=1", { qb.orWhere(
keyword: `%${searchKeyword}%`, searchKeyword ? `positionName like '%${keyword}%'` : "1=1",
}); {
qb.orWhere(searchKeyword ? `positionLevelName like '%${keyword}%'` : "1=1", { keyword: `%${searchKeyword}%`,
keyword: `%${searchKeyword}%`, }
}); );
qb.orWhere(searchKeyword ? `organization like '%${keyword}%'` : "1=1", { qb.orWhere(
keyword: `%${searchKeyword}%`, searchKeyword ? `positionLevelName like '%${keyword}%'` : "1=1",
}); {
qb.orWhere(searchKeyword ? `order_number like '%${keyword}%'` : "1=1", { keyword: `%${searchKeyword}%`,
keyword: `%${searchKeyword}%`, }
}); );
}), qb.orWhere(
searchKeyword ? `organization like '%${keyword}%'` : "1=1",
{
keyword: `%${searchKeyword}%`,
}
);
qb.orWhere(
searchKeyword ? `order_number like '%${keyword}%'` : "1=1",
{
keyword: `%${searchKeyword}%`,
}
);
})
); );
if (sortBy) { if (sortBy) {
if (sortBy === "position_line") { if (sortBy === "position_line") {
query = query.orderBy(`personal.positionName`, descending ? "DESC" : "ASC"); query = query.orderBy(
`personal.positionName`,
descending ? "DESC" : "ASC"
);
} else if (sortBy === "position_level") { } else if (sortBy === "position_level") {
query = query.orderBy(`personal.positionLevelName`, descending ? "DESC" : "ASC"); query = query.orderBy(
`personal.positionLevelName`,
descending ? "DESC" : "ASC"
);
} else if (sortBy === "position_type") { } else if (sortBy === "position_type") {
query = query.orderBy(`personal.positionTypeName`, descending ? "DESC" : "ASC"); query = query.orderBy(
`personal.positionTypeName`,
descending ? "DESC" : "ASC"
);
} else if (sortBy === "name") { } else if (sortBy === "name") {
query = query query = query
.orderBy(`personal.prefixName`, descending ? "DESC" : "ASC") .orderBy(`personal.prefixName`, descending ? "DESC" : "ASC")
.addOrderBy(`personal.firstName`, descending ? "DESC" : "ASC") .addOrderBy(`personal.firstName`, descending ? "DESC" : "ASC")
.addOrderBy(`personal.lastName`, descending ? "DESC" : "ASC"); .addOrderBy(`personal.lastName`, descending ? "DESC" : "ASC");
} else { } else {
query = query.orderBy(`personal.${sortBy}`, descending ? "DESC" : "ASC"); query = query.orderBy(
`personal.${sortBy}`,
descending ? "DESC" : "ASC"
);
} }
} else { } else {
query = query.orderBy("updatedAt", "DESC"); query = query.orderBy("updatedAt", "DESC");
@ -299,7 +350,10 @@ export class PersonalController extends Controller {
.getManyAndCount(); .getManyAndCount();
if (!lists) { if (!lists) {
throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, "ไม่สามารถแสดงข้อมูลได้"); throw new HttpError(
HttpStatusCode.INTERNAL_SERVER_ERROR,
"ไม่สามารถแสดงข้อมูลได้"
);
} }
let result: any = []; let result: any = [];
@ -312,7 +366,8 @@ export class PersonalController extends Controller {
await result.push({ await result.push({
personal_id: lists[i].personal_id, personal_id: lists[i].personal_id,
ordering: i + 1, ordering: i + 1,
name: lists[i].prefixName + lists[i].firstName + " " + lists[i].lastName, name:
lists[i].prefixName + lists[i].firstName + " " + lists[i].lastName,
prefixName: lists[i].prefixName, prefixName: lists[i].prefixName,
firstName: lists[i].firstName, firstName: lists[i].firstName,
lastName: lists[i].lastName, lastName: lists[i].lastName,
@ -357,7 +412,11 @@ export class PersonalController extends Controller {
} catch (error: any) { } catch (error: any) {
if (error instanceof HttpError) { if (error instanceof HttpError) {
throw error; throw error;
} else throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, error.message); } else
throw new HttpError(
HttpStatusCode.INTERNAL_SERVER_ERROR,
error.message
);
} }
} }
@ -368,10 +427,18 @@ export class PersonalController extends Controller {
* *
*/ */
@Get("") @Get("")
async GetPersonal(@Request() request: RequestWithUser, @Query() personal_id: string) { async GetPersonal(
@Request() request: RequestWithUser,
@Query() personal_id: string
) {
try { try {
let _workflow = await new permission().Workflow(request, personal_id, "SYS_PROBATION"); let _workflow = await new permission().Workflow(
if (_workflow == false) await new permission().PermissionGet(request, "SYS_PROBATION"); request,
personal_id,
"SYS_PROBATION"
);
if (_workflow == false)
await new permission().PermissionGet(request, "SYS_PROBATION");
const person = await this.personalRepository.findOne({ const person = await this.personalRepository.findOne({
where: { personal_id: personal_id }, where: { personal_id: personal_id },
}); });
@ -400,7 +467,11 @@ export class PersonalController extends Controller {
} catch (error: any) { } catch (error: any) {
if (error instanceof HttpError) { if (error instanceof HttpError) {
throw error; throw error;
} else throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, error.message); } else
throw new HttpError(
HttpStatusCode.INTERNAL_SERVER_ERROR,
error.message
);
} }
} }
} }

View file

@ -1,245 +1,322 @@
import axios from "axios" import axios from "axios";
import { RequestWithUser } from "../middlewares/user" import { RequestWithUser } from "../middlewares/user";
import CallAPI from "./call-api" import CallAPI from "./call-api";
import HttpError from "./http-error" import HttpError from "./http-error";
import HttpStatus from "./http-status" import HttpStatus from "./http-status";
import { promisify } from "util" import { promisify } from "util";
class CheckAuth { class CheckAuth {
private redis = require("redis") private redis = require("redis");
public async Permission(req: RequestWithUser, system: string, action: string) { public async Permission(
if (req.headers.hasOwnProperty("api_key") && req.headers["api_key"] && req.headers["api_key"] == process.env.API_KEY) { req: RequestWithUser,
return null system: string,
} action: string
return await new CallAPI() ) {
.GetData(req, "/org/permission") if (
.then(x => { req.headers.hasOwnProperty("api_key") &&
let permission = false req.headers["api_key"] &&
let role = x.roles.find((x: any) => x.authSysId == system) req.headers["api_key"] == process.env.API_KEY
if (!role) throw "ไม่มีสิทธิ์เข้าระบบ" ) {
if (role.attrOwnership == "OWNER") return "OWNER" return null;
if (action.trim().toLocaleUpperCase() == "CREATE") permission = role.attrIsCreate }
if (action.trim().toLocaleUpperCase() == "DELETE") permission = role.attrIsDelete return await new CallAPI()
if (action.trim().toLocaleUpperCase() == "GET") permission = role.attrIsGet .GetData(req, "/org/permission")
if (action.trim().toLocaleUpperCase() == "LIST") permission = role.attrIsList .then((x) => {
if (action.trim().toLocaleUpperCase() == "UPDATE") permission = role.attrIsUpdate let permission = false;
if (permission == false) throw "ไม่มีสิทธิ์ใช้งานระบบนี้" let role = x.roles.find((x: any) => x.authSysId == system);
return role.attrPrivilege if (!role) throw "ไม่มีสิทธิ์เข้าระบบ";
}) if (role.attrOwnership == "OWNER") return "OWNER";
.catch(x => { if (action.trim().toLocaleUpperCase() == "CREATE")
if (x.status != undefined) { permission = role.attrIsCreate;
throw new HttpError(x.status, x.message) if (action.trim().toLocaleUpperCase() == "DELETE")
} else { permission = role.attrIsDelete;
throw new HttpError(HttpStatus.FORBIDDEN, x) if (action.trim().toLocaleUpperCase() == "GET")
} permission = role.attrIsGet;
}) if (action.trim().toLocaleUpperCase() == "LIST")
} permission = role.attrIsList;
public async PermissionOrg(req: RequestWithUser, system: string, action: string) { if (action.trim().toLocaleUpperCase() == "UPDATE")
if (req.headers.hasOwnProperty("api_key") && req.headers["api_key"] && req.headers["api_key"] == process.env.API_KEY) { permission = role.attrIsUpdate;
return { if (permission == false) throw "ไม่มีสิทธิ์ใช้งานระบบนี้";
root: null, return role.attrPrivilege;
child1: null, })
child2: null, .catch((x) => {
child3: null, if (x.status != undefined) {
child4: null, throw new HttpError(x.status, x.message);
} } else {
} throw new HttpError(HttpStatus.FORBIDDEN, x);
return await new CallAPI() }
.GetData(req, `/org/permission/org/${system}/${action}`) });
.then(async x => { }
let privilege = x.privilege public async PermissionOrg(
req: RequestWithUser,
system: string,
action: string
) {
if (
req.headers.hasOwnProperty("api_key") &&
req.headers["api_key"] &&
req.headers["api_key"] == process.env.API_KEY
) {
return {
root: null,
child1: null,
child2: null,
child3: null,
child4: null,
};
}
return await new CallAPI()
.GetData(req, `/org/permission/org/${system}/${action}`)
.then(async (x) => {
let privilege = x.privilege;
let data: any = { let data: any = {
root: [null], root: [null],
child1: [null], child1: [null],
child2: [null], child2: [null],
child3: [null], child3: [null],
child4: [null], child4: [null],
privilege: [null], privilege: [null],
} };
let node = 4 let node = 4;
if (x.orgChild1Id == null) { if (x.orgChild1Id == null) {
node = 0 node = 0;
} else if (x.orgChild2Id == null) { } else if (x.orgChild2Id == null) {
node = 1 node = 1;
} else if (x.orgChild3Id == null) { } else if (x.orgChild3Id == null) {
node = 2 node = 2;
} else if (x.orgChild4Id == null) { } else if (x.orgChild4Id == null) {
node = 3 node = 3;
} }
if (privilege == "OWNER") { if (privilege == "OWNER") {
data = { data = {
root: null, root: null,
child1: null, child1: null,
child2: null, child2: null,
child3: null, child3: null,
child4: null, child4: null,
privilege: "OWNER", privilege: "OWNER",
} };
} else if (privilege == "ROOT") { } else if (privilege == "ROOT") {
data = { data = {
root: [x.orgRootId], root: [x.orgRootId],
child1: null, child1: null,
child2: null, child2: null,
child3: null, child3: null,
child4: null, child4: null,
privilege: "ROOT", privilege: "ROOT",
} };
} else if (privilege == "CHILD") { } else if (privilege == "PARENT") {
data = { data = {
root: node >= 0 ? [x.orgRootId] : null, root: [x.orgRootId],
child1: node >= 1 ? [x.orgChild1Id] : null, child1: [null],
child2: node >= 2 ? [x.orgChild2Id] : null, child2: null,
child3: node >= 3 ? [x.orgChild3Id] : null, child3: null,
child4: node >= 4 ? [x.orgChild4Id] : null, child4: null,
privilege: "CHILD", privilege: "PARENT",
} };
} else if (privilege == "NORMAL") { } else if (privilege == "CHILD") {
data = { data = {
root: [x.orgRootId], root: node >= 0 ? [x.orgRootId] : null,
child1: [x.orgChild1Id], child1: node >= 1 ? [x.orgChild1Id] : null,
child2: [x.orgChild2Id], child2: node >= 2 ? [x.orgChild2Id] : null,
child3: [x.orgChild3Id], child3: node >= 3 ? [x.orgChild3Id] : null,
child4: [x.orgChild4Id], child4: node >= 4 ? [x.orgChild4Id] : null,
privilege: "NORMAL", privilege: "CHILD",
} };
} else if (privilege == "SPECIFIC") { } else if (privilege == "BROTHER") {
} data = {
// root: node >= 0 ? [x.orgRootId] : null,
root: node >= 0 ? [x.orgRootId] : null,
child1: node >= 2 ? [x.orgChild1Id] : null,
child2: node >= 3 ? [x.orgChild2Id] : null,
child3: node >= 4 ? [x.orgChild3Id] : null,
privilege: "BROTHER",
};
} else if (privilege == "NORMAL") {
data = {
root: [x.orgRootId],
child1: [x.orgChild1Id],
child2: [x.orgChild2Id],
child3: [x.orgChild3Id],
child4: [x.orgChild4Id],
privilege: "NORMAL",
};
} else if (privilege == "SPECIFIC") {
}
return data return data;
}) })
.catch(x => { .catch((x) => {
if (x.status != undefined) { if (x.status != undefined) {
throw new HttpError(x.status, x.message) throw new HttpError(x.status, x.message);
} else { } else {
throw new HttpError(HttpStatus.FORBIDDEN, x) throw new HttpError(HttpStatus.FORBIDDEN, x);
} }
}) });
} }
public async PermissionOrgByUser(req: RequestWithUser, system: string, action: string, profileId: string) { public async PermissionOrgByUser(
if (req.headers.hasOwnProperty("api_key") && req.headers["api_key"] && req.headers["api_key"] == process.env.API_KEY) { req: RequestWithUser,
return true system: string,
} action: string,
return await new CallAPI() profileId: string
.GetData(req, `/org/permission/user/${system}/${action}/${profileId}`) ) {
.then(async x => { if (
let org = x.org req.headers.hasOwnProperty("api_key") &&
req.headers["api_key"] &&
req.headers["api_key"] == process.env.API_KEY
) {
return true;
}
return await new CallAPI()
.GetData(req, `/org/permission/user/${system}/${action}/${profileId}`)
.then(async (x) => {
let org = x.org;
if (org.root != null) if (x.orgRootId != org.root[0]) throw "ไม่มีสิทธิ์เข้าถึงข้อมูล" if (org.root != null)
if (org.child1 != null) if (x.orgChild1Id != org.child1[0]) throw "ไม่มีสิทธิ์เข้าถึงข้อมูล" if (x.orgRootId != org.root[0]) throw "ไม่มีสิทธิ์เข้าถึงข้อมูล";
if (org.child2 != null) if (x.orgChild2Id != org.child2[0]) throw "ไม่มีสิทธิ์เข้าถึงข้อมูล" if (org.child1 != null)
if (org.child3 != null) if (x.orgChild3Id != org.child3[0]) throw "ไม่มีสิทธิ์เข้าถึงข้อมูล" if (x.orgChild1Id != org.child1[0]) throw "ไม่มีสิทธิ์เข้าถึงข้อมูล";
if (org.child4 != null) if (x.orgChild4Id != org.child4[0]) throw "ไม่มีสิทธิ์เข้าถึงข้อมูล" if (org.child2 != null)
if (x.orgChild2Id != org.child2[0]) throw "ไม่มีสิทธิ์เข้าถึงข้อมูล";
if (org.child3 != null)
if (x.orgChild3Id != org.child3[0]) throw "ไม่มีสิทธิ์เข้าถึงข้อมูล";
if (org.child4 != null)
if (x.orgChild4Id != org.child4[0]) throw "ไม่มีสิทธิ์เข้าถึงข้อมูล";
return true return true;
}) })
.catch(x => { .catch((x) => {
if (x.status != undefined) { if (x.status != undefined) {
throw new HttpError(x.status, x.message) throw new HttpError(x.status, x.message);
} else { } else {
throw new HttpError(HttpStatus.FORBIDDEN, x) throw new HttpError(HttpStatus.FORBIDDEN, x);
} }
}) });
} }
public async Workflow(req: RequestWithUser, id: string, sysName: string) { public async Workflow(req: RequestWithUser, id: string, sysName: string) {
if (req.headers.hasOwnProperty("api_key") && req.headers["api_key"] && req.headers["api_key"] == process.env.API_KEY) { if (
return null req.headers.hasOwnProperty("api_key") &&
} req.headers["api_key"] &&
return await new CallAPI() req.headers["api_key"] == process.env.API_KEY
.PostData(req, "/org/workflow/keycloak/isofficer", { ) {
refId: id, return null;
sysName: sysName, }
}) return await new CallAPI()
.then(x => { .PostData(req, "/org/workflow/keycloak/isofficer", {
return true refId: id,
}) sysName: sysName,
.catch(x => { })
return false .then((x) => {
}) return true;
} })
public async checkOrg(token: any, keycloakId: string) { .catch((x) => {
const redisClient = await this.redis.createClient({ return false;
host: process.env.REDIS_HOST, });
port: process.env.REDIS_PORT, }
}) public async checkOrg(token: any, keycloakId: string) {
const getAsync = promisify(redisClient.get).bind(redisClient) const redisClient = await this.redis.createClient({
try { host: process.env.REDIS_HOST,
let reply = await getAsync("org_" + keycloakId) port: process.env.REDIS_PORT,
if (reply != null) { });
reply = JSON.parse(reply) const getAsync = promisify(redisClient.get).bind(redisClient);
} else { try {
if (!keycloakId) throw new Error("No KeycloakId provided") let reply = await getAsync("org_" + keycloakId);
const x = await new CallAPI().GetData( if (reply != null) {
{ reply = JSON.parse(reply);
headers: { authorization: token }, } else {
}, if (!keycloakId) throw new Error("No KeycloakId provided");
`/org/permission/checkOrg/${keycloakId}`, const x = await new CallAPI().GetData(
false {
) headers: { authorization: token },
},
`/org/permission/checkOrg/${keycloakId}`,
false
);
const data = { const data = {
orgRootId: x.orgRootId, orgRootId: x.orgRootId,
orgChild1Id: x.orgChild1Id, orgChild1Id: x.orgChild1Id,
orgChild2Id: x.orgChild2Id, orgChild2Id: x.orgChild2Id,
orgChild3Id: x.orgChild3Id, orgChild3Id: x.orgChild3Id,
orgChild4Id: x.orgChild4Id, orgChild4Id: x.orgChild4Id,
} };
return data return data;
} }
} catch (error) { } catch (error) {
console.error("Error calling API:", error) console.error("Error calling API:", error);
throw error throw error;
} }
} }
public async PermissionCreate(req: RequestWithUser, system: string) { public async PermissionCreate(req: RequestWithUser, system: string) {
return await this.Permission(req, system, "CREATE") return await this.Permission(req, system, "CREATE");
} }
public async PermissionDelete(req: RequestWithUser, system: string) { public async PermissionDelete(req: RequestWithUser, system: string) {
return await this.Permission(req, system, "DELETE") return await this.Permission(req, system, "DELETE");
} }
public async PermissionGet(req: RequestWithUser, system: string) { public async PermissionGet(req: RequestWithUser, system: string) {
return await this.Permission(req, system, "GET") return await this.Permission(req, system, "GET");
} }
public async PermissionList(req: RequestWithUser, system: string) { public async PermissionList(req: RequestWithUser, system: string) {
return await this.Permission(req, system, "LIST") return await this.Permission(req, system, "LIST");
} }
public async PermissionUpdate(req: RequestWithUser, system: string) { public async PermissionUpdate(req: RequestWithUser, system: string) {
return await this.Permission(req, system, "UPDATE") return await this.Permission(req, system, "UPDATE");
} }
public async PermissionOrgCreate(req: RequestWithUser, system: string) { public async PermissionOrgCreate(req: RequestWithUser, system: string) {
return await this.PermissionOrg(req, system, "CREATE") return await this.PermissionOrg(req, system, "CREATE");
} }
public async PermissionOrgDelete(req: RequestWithUser, system: string) { public async PermissionOrgDelete(req: RequestWithUser, system: string) {
return await this.PermissionOrg(req, system, "DELETE") return await this.PermissionOrg(req, system, "DELETE");
} }
public async PermissionOrgGet(req: RequestWithUser, system: string) { public async PermissionOrgGet(req: RequestWithUser, system: string) {
return await this.PermissionOrg(req, system, "GET") return await this.PermissionOrg(req, system, "GET");
} }
public async PermissionOrgList(req: RequestWithUser, system: string) { public async PermissionOrgList(req: RequestWithUser, system: string) {
return await this.PermissionOrg(req, system, "LIST") return await this.PermissionOrg(req, system, "LIST");
} }
public async PermissionOrgUpdate(req: RequestWithUser, system: string) { public async PermissionOrgUpdate(req: RequestWithUser, system: string) {
return await this.PermissionOrg(req, system, "UPDATE") return await this.PermissionOrg(req, system, "UPDATE");
} }
public async PermissionOrgUserCreate(req: RequestWithUser, system: string, profileId: string) { public async PermissionOrgUserCreate(
return await this.PermissionOrgByUser(req, system, "CREATE", profileId) req: RequestWithUser,
} system: string,
public async PermissionOrgUserDelete(req: RequestWithUser, system: string, profileId: string) { profileId: string
return await this.PermissionOrgByUser(req, system, "DELETE", profileId) ) {
} return await this.PermissionOrgByUser(req, system, "CREATE", profileId);
public async PermissionOrgUserGet(req: RequestWithUser, system: string, profileId: string) { }
return await this.PermissionOrgByUser(req, system, "GET", profileId) public async PermissionOrgUserDelete(
} req: RequestWithUser,
public async PermissionOrgUserList(req: RequestWithUser, system: string, profileId: string) { system: string,
return await this.PermissionOrgByUser(req, system, "LIST", profileId) profileId: string
} ) {
public async PermissionOrgUserUpdate(req: RequestWithUser, system: string, profileId: string) { return await this.PermissionOrgByUser(req, system, "DELETE", profileId);
return await this.PermissionOrgByUser(req, system, "UPDATE", profileId) }
} public async PermissionOrgUserGet(
req: RequestWithUser,
system: string,
profileId: string
) {
return await this.PermissionOrgByUser(req, system, "GET", profileId);
}
public async PermissionOrgUserList(
req: RequestWithUser,
system: string,
profileId: string
) {
return await this.PermissionOrgByUser(req, system, "LIST", profileId);
}
public async PermissionOrgUserUpdate(
req: RequestWithUser,
system: string,
profileId: string
) {
return await this.PermissionOrgByUser(req, system, "UPDATE", profileId);
}
} }
export default CheckAuth export default CheckAuth;

View file

@ -0,0 +1,20 @@
import { MigrationInterface, QueryRunner } from "typeorm";
export class UpdateDatatypeEvaluateCommander1764585452499 implements MigrationInterface {
name = 'UpdateDatatypeEvaluateCommander1764585452499'
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE \`evaluateCommander\` DROP COLUMN \`behavior_strength_desc\``);
await queryRunner.query(`ALTER TABLE \`evaluateCommander\` ADD \`behavior_strength_desc\` longtext NOT NULL COMMENT 'จุดเด่นของความประพฤติ'`);
await queryRunner.query(`ALTER TABLE \`evaluateCommander\` DROP COLUMN \`behavior_improve_desc\``);
await queryRunner.query(`ALTER TABLE \`evaluateCommander\` ADD \`behavior_improve_desc\` longtext NOT NULL COMMENT 'สิ่งที่ควรปรับปรุงของความประพฤติ'`);
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE \`evaluateCommander\` DROP COLUMN \`behavior_improve_desc\``);
await queryRunner.query(`ALTER TABLE \`evaluateCommander\` ADD \`behavior_improve_desc\` varchar(255) NOT NULL COMMENT 'สิ่งที่ควรปรับปรุงของความประพฤติ'`);
await queryRunner.query(`ALTER TABLE \`evaluateCommander\` DROP COLUMN \`behavior_strength_desc\``);
await queryRunner.query(`ALTER TABLE \`evaluateCommander\` ADD \`behavior_strength_desc\` varchar(255) NOT NULL COMMENT 'จุดเด่นของความประพฤติ'`);
}
}