This commit is contained in:
DESKTOP-2S5P7D1\Windows 10 2024-12-04 17:25:34 +07:00
commit 925c5d1ab2
60 changed files with 18843 additions and 0 deletions

7
.dockerignore Normal file
View file

@ -0,0 +1,7 @@
.DS_Store
node_modules
/dist
.env
.env.*
!.env.example

12
.env.example Normal file
View file

@ -0,0 +1,12 @@
AUTH_REALM_URL=http://192.168.1.200:8080/realms/dev
AUTH_PUBLIC_KEY=MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA1/QAH75nWgiRzWCTrGJv8q2A7z0qggC2IQ9Sva/Ok1RxeGE/ED2m4ELbF5B9MtugyXYGMUBXaKhooMpTE3wyR1OwsUlv/GtYSmMuKUnsSEXklsP8nIq8gZkCvISOVdvIC4ng5aZ5nBcp9cQ3eVbz4dfZcbLzcqLIIkxQmFBK0m1eFL5IdNj8Ac7U4eH4ylOckOu174f35NnFH6wDva6Iic3EXapMcE2BnXXCTajk2dmlWAzH13ybQBgHDfrOtulrmn1CzQxe9WUJes4qX5z72N05KsHvtUObaeN6cb+mIeH36GdysqgAdd2hhKkgUFXwtLPzldtrEc7xVyf3OLEg1QIDAQAB
AUTH_PREFERRED_MODE=online
APP_HOST=0.0.0.0
APP_PORT=3000
DB_HOST=192.168.1.200
DB_PORT=3306
DB_USERNAME=root
DB_PASSWORD=
DB_NAME=dev

87
.github/workflows/release.yaml vendored Normal file
View file

@ -0,0 +1,87 @@
name: release-test
run-name: release-test ${{ github.actor }}
on:
push:
tags:
- "version-[0-9]+.[0-9]+.[0-9]+"
workflow_dispatch:
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:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
# skip Set up QEMU because it fail on act and container
# Gen Version try to get version from tag or inut
- name: Set output tags
id: vars
run: echo "tag=${GITHUB_REF#refs/*/}" >> $GITHUB_OUTPUT
- name: Gen Version
id: gen_ver
run: |
if [[ $GITHUB_REF == 'refs/tags/'* ]]; then
IMAGE_VER=${{ steps.vars.outputs.tag }}
else
IMAGE_VER=${{ github.event.inputs.IMAGE_VER }}
fi
if [[ $IMAGE_VER == '' ]]; then
IMAGE_VER='test-vBeta'
fi
echo '::set-output name=image_ver::'$IMAGE_VER
- name: Check Version
run: |
echo $GITHUB_REF
echo ${{ steps.gen_ver.outputs.image_ver }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Login in to registry
uses: docker/login-action@v2
with:
registry: ${{env.REGISTRY}}
username: ${{secrets.DOCKER_USER}}
password: ${{secrets.DOCKER_PASS}}
- name: Build and push docker image
uses: docker/build-push-action@v3
with:
context: .
platforms: linux/amd64
file: docker/Dockerfile
push: true
tags: ${{env.REGISTRY}}/${{env.IMAGE_NAME}}:${{ steps.gen_ver.outputs.image_ver }},${{env.REGISTRY}}/${{env.IMAGE_NAME}}:latest
- name: Remote Deployment
uses: appleboy/ssh-action@v0.1.8
with:
host: ${{env.DEPLOY_HOST}}
username: frappet
password: ${{ secrets.SSH_PASSWORD }}
port: 10102
script: |
cd "${{env.COMPOSE_PATH}}"
docker compose pull
docker compose up -d
echo "${{ steps.gen_ver.outputs.image_ver }}"> success
- uses: snow-actions/line-notify@v1.1.0
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
if: failure()
with:
access_token: ${{ secrets.TOKEN_LINE }}
message: |
-Failure❌❌❌
Image: ${{env.IMAGE_NAME}}
Version: ${{ steps.gen_ver.outputs.IMAGE_VER }}
By: ${{github.actor}}

133
.gitignore vendored Normal file
View file

@ -0,0 +1,133 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*
.pnpm-debug.log*
# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
# Runtime data
pids
*.pid
*.seed
*.pid.lock
# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov
# Coverage directory used by tools like istanbul
coverage
*.lcov
# nyc test coverage
.nyc_output
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt
# Bower dependency directory (https://bower.io/)
bower_components
# node-waf configuration
.lock-wscript
# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release
# Dependency directories
node_modules/
jspm_packages/
# Snowpack dependency directory (https://snowpack.dev/)
web_modules/
# TypeScript cache
*.tsbuildinfo
# Optional npm cache directory
.npm
# Optional eslint cache
.eslintcache
# Optional stylelint cache
.stylelintcache
# Microbundle cache
.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/
# Optional REPL history
.node_repl_history
# Output of 'npm pack'
*.tgz
# Yarn Integrity file
.yarn-integrity
# dotenv environment variable files
.env
.env.evaluation.local
.env.test.local
.env.production.local
.env.local
[Ss]rc/swagger.json
[Ss]rc/routes.ts
# parcel-bundler cache (https://parceljs.org/)
.cache
.parcel-cache
# Next.js build output
.next
out
# Nuxt.js build / generate output
.nuxt
dist
# Gatsby files
.cache/
# Comment in the public line in if your project uses Gatsby and not Next.js
# https://nextjs.org/blog/next-9-1#public-directory-support
# public
# vuepress build output
.vuepress/dist
# vuepress v2.x temp and cache directory
.temp
.cache
# Docusaurus cache and generated files
.docusaurus
# Serverless directories
.serverless/
# FuseBox cache
.fusebox/
# DynamoDB Local files
.dynamodb/
# TernJS port file
.tern-port
# Stores VSCode versions used for testing VSCode extensions
.vscode-test
# yarn v2
.yarn/cache
.yarn/unplugged
.yarn/build-state.yml
.yarn/install-state.gz
.pnp.*

18
.prettierignore Normal file
View file

@ -0,0 +1,18 @@
.DS_Store
node_modules
.env
.env.*
!.env.example
/dist
/static
/src/routes.ts
/src/swagger.json
# Any log
*.log
# Ignore files for PNPM, NPM and YARN
pnpm-lock.yaml
package-lock.json
yarn.lock

5
.prettierrc Normal file
View file

@ -0,0 +1,5 @@
{
"tabWidth": 2,
"printWidth": 100,
"trailingComma": "all"
}

1
README.md Normal file
View file

@ -0,0 +1 @@
# bma-ehr-evaluation

34
docker/Dockerfile Normal file
View file

@ -0,0 +1,34 @@
# Build Stage
FROM node:lts-alpine AS build-stage
# Create app directory
WORKDIR /app
# Install app dependencies
COPY package*.json ./
RUN npm ci
# Copy source files and build the app
COPY . .
RUN npm run build
# Production Stage
FROM node:lts-alpine
ENV NODE_ENV production
USER node
# Create app directory
WORKDIR /app
# Copy built app from build stage
COPY --from=build-stage /app/dist ./dist
# Install only production dependencies
COPY package*.json ./
RUN npm ci --production
# Define the entrypoint and default command
# If you have a custom entrypoint script
CMD [ "node", "dist/app.js" ]

6
nodemon.json Normal file
View file

@ -0,0 +1,6 @@
{
"exec": "tsoa spec-and-routes && ts-node src/app.ts",
"ext": "ts",
"watch": ["src"],
"ignore": ["src/routes.ts"]
}

5438
package-lock.json generated Normal file

File diff suppressed because it is too large Load diff

50
package.json Normal file
View file

@ -0,0 +1,50 @@
{
"name": "template",
"version": "1.0.0",
"description": "",
"main": "src/app.js",
"scripts": {
"dev": "nodemon",
"check": "tsc --noEmit",
"start": "node ./dist/app.js",
"format": "prettier --write .",
"build": "tsoa spec-and-routes && tsc",
"migration:generate": "typeorm-ts-node-commonjs migration:generate -d src/database/data-source.ts",
"migration:run": "typeorm-ts-node-commonjs migration:run -d src/database/data-source.ts"
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"@types/cors": "^2.8.17",
"@types/express": "^4.17.21",
"@types/node": "^20.11.5",
"@types/node-cron": "^3.0.11",
"@types/swagger-ui-express": "^4.1.6",
"nodemon": "^3.0.3",
"prettier": "^3.2.2",
"ts-node": "^10.9.2",
"typescript": "^5.3.3"
},
"dependencies": {
"@elastic/elasticsearch": "^8.14.0",
"@nestjs/platform-express": "^10.3.7",
"@tsoa/runtime": "^6.0.0",
"axios": "^1.6.8",
"cors": "^2.8.5",
"dotenv": "^16.3.1",
"express": "^4.18.2",
"fast-jwt": "^3.3.2",
"multer": "^1.4.5-lts.1",
"mysql2": "^3.9.1",
"node-cron": "^3.0.3",
"promise.any": "^2.0.6",
"reflect-metadata": "^0.2.1",
"swagger-ui-express": "^5.0.0",
"tsoa": "^6.0.1",
"typeorm": "^0.3.19",
"typeorm-cli": "^1.0.7",
"xlsx": "^0.18.5",
"redis": "~3.1.2"
}
}

2904
pnpm-lock.yaml generated Normal file

File diff suppressed because it is too large Load diff

45
src/app.ts Normal file
View file

@ -0,0 +1,45 @@
import "dotenv/config";
import "reflect-metadata";
import cors from "cors";
import express from "express";
import swaggerUi from "swagger-ui-express";
import swaggerDocument from "./swagger.json";
import * as cron from "node-cron";
import error from "./middlewares/error";
import { AppDataSource } from "./database/data-source";
import { RegisterRoutes } from "./routes";
import logMiddleware from "./middlewares/logs";
async function main() {
await AppDataSource.initialize();
const app = express();
app.use(
cors({
origin: "*",
}),
);
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
app.use(logMiddleware);
app.use("/", express.static("static"));
app.use("/api-docs", swaggerUi.serve, swaggerUi.setup(swaggerDocument));
RegisterRoutes(app);
app.use(error);
const APP_HOST = process.env.APP_HOST || "0.0.0.0";
const APP_PORT = +(process.env.APP_PORT || 3000);
app.listen(
APP_PORT,
APP_HOST,
() => (
console.log(`[APP] Application is running on: http://localhost:${APP_PORT}`),
console.log(`[APP] Swagger on: http://localhost:${APP_PORT}/api-docs`)
),
);
}
main();

View file

@ -0,0 +1,271 @@
import { AppDataSource } from "../database/data-source";
import { CreateDirector, Director } from "../entities/Director";
import {
Body,
Delete,
Get,
Path,
Post,
Put,
Response,
Route,
SuccessResponse,
Tags,
Query,
Request,
Security,
} from "tsoa";
import HttpStatusCode from "../interfaces/http-status";
import HttpSuccess from "../interfaces/http-success";
import HttpError from "../interfaces/http-error";
import { Not, Brackets } from "typeorm";
import permission from "../interfaces/permission";
import { RequestWithUser } from "../middlewares/user";
import { setLogDataDiff } from "../interfaces/utils";
@Route("api/v1/evaluation/director")
@Tags("director")
@Security("bearerAuth")
@Response(
HttpStatusCode.INTERNAL_SERVER_ERROR,
"เกิดข้อผิดพลาด ไม่สามารถแสดงรายการได้ กรุณาลองใหม่ในภายหลัง",
)
@SuccessResponse(HttpStatusCode.OK, "สำเร็จ")
export class DirectorController {
private directorRepository = AppDataSource.getRepository(Director);
/**
* API
*
* @summary EV4_001 - (ADMIN)
*
*/
@Get()
async all(
@Request() request: RequestWithUser,
@Query("page") page: number = 1,
@Query("pageSize") pageSize: number = 10,
@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(
new Brackets((qb) => {
qb.where(
keyword != null && keyword != ""
? "CONCAT(director.prefix, director.firstName, ' ', director.lastName) LIKE :keyword"
: "1=1",
{
keyword: `%${keyword}%`,
},
)
.orWhere(
keyword != null && keyword != ""
? "director.position LIKE :keyword"
: "1=1",
{
keyword: `%${keyword}%`,
},
)
.orWhere(
keyword != null && keyword != ""
? "director.email LIKE :keyword"
: "1=1",
{
keyword: `%${keyword}%`,
},
)
.orWhere(
keyword != null && keyword != ""
? "director.phone LIKE :keyword"
: "1=1",
{
keyword: `%${keyword}%`,
},
);
}),
)
.orderBy("director.createdAt", "DESC")
.skip((page - 1) * pageSize)
.take(pageSize)
.getMany();
return new HttpSuccess(directors);
}
@Get("admin")
async allAdmin(
@Request() request: RequestWithUser,
@Query("page") page: number = 1,
@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(
new Brackets((qb) => {
qb.where(
keyword != null && keyword != ""
? "CONCAT(director.prefix, director.firstName, ' ', director.lastName) LIKE :keyword"
: "1=1",
{
keyword: `%${keyword}%`,
},
)
.orWhere(
keyword != null && keyword != ""
? "director.position LIKE :keyword"
: "1=1",
{
keyword: `%${keyword}%`,
},
)
.orWhere(
keyword != null && keyword != ""
? "director.email LIKE :keyword"
: "1=1",
{
keyword: `%${keyword}%`,
},
)
.orWhere(
keyword != null && keyword != ""
? "director.phone LIKE :keyword"
: "1=1",
{
keyword: `%${keyword}%`,
},
);
}),
)
.orderBy("director.createdAt", "DESC")
.skip((page - 1) * pageSize)
.take(pageSize)
.getMany();
return new HttpSuccess(directors);
}
/**
* API
*
* @summary EV4_002 - (ADMIN)
*
*/
@Get("{id}")
async one(@Path() id: string, @Request() request: RequestWithUser) {
let _workflow = await new permission().Workflow(request, id, "SYS_EVA_INFO");
if (_workflow == false) await new permission().PermissionGet(request, "SYS_EVA_INFO");
const director = await this.directorRepository.findOne({ where: { id } });
if (!director) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found.");
}
return new HttpSuccess(director);
}
/**
* API
*
* @summary EV4_003 - (ADMIN)
*
*/
@Post()
async save(@Body() requestBody: CreateDirector, @Request() request: RequestWithUser) {
await new permission().PermissionCreate(request, "SYS_EVA_INFO");
let directorDup = await this.directorRepository.findOne({
where: { firstName: requestBody.firstName, lastName: requestBody.lastName },
});
if (directorDup != null) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ชื่อกรรมการนี้มีอยู่ในระบบแล้ว");
}
const director = Object.assign(new Director(), requestBody);
director.createdUserId = request.user.sub;
director.createdFullName = request.user.name;
director.createdAt = new Date();
director.lastUpdateUserId = request.user.sub;
director.lastUpdateFullName = request.user.name;
director.lastUpdatedAt = new Date();
const before = null;
await this.directorRepository.save(director, { data: request });
setLogDataDiff(request, { before, after: director });
return new HttpSuccess();
}
/**
* API
*
* @summary EV4_004 - (ADMIN)
*
*/
@Put("{id}")
async update(@Path() id: string, @Body() u: CreateDirector, @Request() request: RequestWithUser) {
await new permission().PermissionUpdate(request, "SYS_EVA_INFO");
let directorDup = await this.directorRepository.findOne({
where: { firstName: u.firstName, lastName: u.lastName, id: Not(id) },
});
if (directorDup != null) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ชื่อกรรมการนี้มีอยู่ในระบบแล้ว");
}
let director = await this.directorRepository.findOneBy({ id });
if (!director) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found.");
}
const before = structuredClone(directorDup);
director.lastUpdateUserId = request.user.sub;
director.lastUpdateFullName = request.user.name;
director.lastUpdatedAt = new Date();
this.directorRepository.merge(director, u);
await this.directorRepository.save(director, { data: request });
setLogDataDiff(request, { before, after: director });
return new HttpSuccess();
}
/**
* API
*
* @summary EV4_005 - (ADMIN)
*
*/
@Delete("{id}")
async remove(id: string, @Request() request: RequestWithUser) {
await new permission().PermissionDelete(request, "SYS_EVA_INFO");
let director = await this.directorRepository.findOneBy({ id });
if (!director) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found.");
}
await this.directorRepository.remove(director, { data: request });
return new HttpSuccess();
}
}

View file

@ -0,0 +1,320 @@
import {
Body,
Controller,
Delete,
Example,
Get,
Patch,
Path,
Post,
Route,
SuccessResponse,
Tags,
} from "tsoa";
import HttpStatus from "../interfaces/http-status";
import {
createFile,
createFolder,
deleteFile,
deleteFolder,
downloadFile,
listFile,
updateFile,
} from "../services/storage";
import { AppDataSource } from "../database/data-source";
import { Evaluation } from "../entities/Evaluation";
@Route("api/v1/evaluation/document")
@Tags("document")
export class DocumentController extends Controller {
/**
* @example volume "เล่ม 1"
* @example id "00000000-0000-0000-0000-000000000000"
*
* @summary
*/
@Get("{volume}/{id}")
@SuccessResponse(200, "สำเร็จ")
@Example([
{
pathname: "string",
path: "ระบบประเมิน/เล่ม 1/1-แบบพิจารณาคุณสมบัติบุคคล",
title: "1-แบบพิจารณาคุณสมบัติบุคคล.docx",
description: "",
author: "นายก",
metadata: {
tag: 1,
},
keyword: [],
category: [],
fileType: "",
fileSize: 1024,
fileName: "1-แบบพิจารณาคุณสมบัติบุคคล.docx",
upload: true,
createdAt: "2021-07-20T12:33:13.018Z",
createdBy: "service-account-ext-api",
updatedAt: "2021-07-20T12:33:13.018Z",
updatedBy: "service-account-ext-api",
},
])
public async getFile(@Path() volume: string, @Path() id: string) {
const list = await listFile(["ระบบประเมิน", volume, id]);
if (!list) throw new Error("เกิดข้อผิดพลาดกับระบบจัดการไฟล์ ไม่สามารถสร้างแฟ้มได้");
return list;
}
/**
* ข้อควรระวัง: หากลิงก์ยาวเกินไปอาจทำให้ไม่สามารถอัปโหลดได้
*
* @example volume "เล่ม 1"
* @example id "00000000-0000-0000-0000-000000000000"
* @example file "1-แบบพิจารณาคุณสมบัติบุคคล"
*
* @summary
*/
@Get("{volume}/{id}/{file}")
@SuccessResponse(200, "สำเร็จ")
@Example({
pathname: "string",
path: "ระบบประเมิน/เล่ม 1/1-แบบพิจารณาคุณสมบัติบุคคล",
title: "1-แบบพิจารณาคุณสมบัติบุคคล.docx",
description: "",
author: "นายก",
keyword: [],
category: [],
metadata: {
tag: 1,
},
fileName: "1-แบบพิจารณาคุณสมบัติบุคคล.docx",
fileType: "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
fileSize: 1024,
hidden: false,
upload: true,
createdAt: "2021-07-20T12:33:13.018Z",
createdBy: "service-account-ext-api",
updatedAt: "2021-07-20T12:33:13.018Z",
updatedBy: "service-account-ext-api",
downloadUrl: "https://.../...", // Presigned Download URL 7 Days Exp
})
public async getFileDownload(@Path() id: string, @Path() volume: string, @Path() file: string) {
const data = await downloadFile(["ระบบประเมิน", volume, id], file);
if (!data) throw new Error("เกิดข้อผิดพลาดกับระบบจัดการไฟล์ ไม่สามารถสร้างแฟ้มได้");
return data;
}
/**
* ข้อควรระวัง: หากลิงก์ภาษาไทยยาวเกินไปอาจทำให้ไม่สามารถอัปโหลดได้ ( DNS)
*
* PUT Method Content-Type
* Content-Type mime-type docx application/vnd.openxmlformats-officedocument.wordprocessingml.document
* Content-Type
*
* Browser Object File attribute type mime-type
*
* title EDM title
*
* @example volume "เล่ม 1"
* @example id "00000000-0000-0000-0000-000000000000"
*
* @summary
*/
@Post("{volume}/{id}")
@Example([
{
pathname: "string",
path: "ระบบประเมิน/เล่ม 1/1-แบบพิจารณาคุณสมบัติบุคคล",
title: "1-แบบพิจารณาคุณสมบัติบุคคล.docx",
description: "1-แบบพิจารณาคุณสมบัติบุคคล.docx",
author: "นายก",
keyword: [],
category: [],
metadata: {
tag: 1,
},
fileName: "1-แบบพิจารณาคุณสมบัติบุคคล.docx",
fileSize: 0,
fileType: "",
hidden: false,
upload: false,
createdAt: "2021-07-20T12:33:13.018Z",
createdBy: "service-account-ext-api",
updatedAt: "2021-07-20T12:33:13.018Z",
updatedBy: "service-account-ext-api",
uploadUrl: "https://.../...", // Presigned Upload URL 7 Days Exp
},
])
@SuccessResponse(200, "Success")
public async uploadFile(
@Path() volume: string,
@Path() id: string,
@Body()
body: {
/**
* @example [
* {
* "fileName": "1-แบบพิจารณาคุณสมบัติบุคคล.docx",
* "title": "1-แบบพิจารณาคุณสมบัติบุคคล.docx"
* },
* {
* "fileName": "2-แบบแสดงรายละเอียดการเสนอผลงาน.docx",
* "description": "2-แบบแสดงรายละเอียดการเสนอผลงาน.docx"
* },
* {
* "fileName": "3-แบบตรวจสอบความถูกต้องครบถ้วนของข้อมูล.docx",
* "keyword": ["3-แบบตรวจสอบความถูกต้องครบถ้วนของข้อมูล.docx"]
* },
* {
* "fileName": "4-แบบประเมินคุณลักษณะบุคคล.docx",
* "category": ["4-แบบประเมินคุณลักษณะบุคคล.docx"]
* },
* {
* "fileName": "5-แบบสรุปข้อมูลของผู้ขอรับการคัดเลือก.docx",
* "author": "นายก"
* },
* {
* "fileName": "6-ผลงานที่จะส่งประเมิน.docx",
* "metadata": { "tag1": "value1", "tag2": "value2" }
* }
* ]
*/
fileList: {
fileName: string;
title?: string;
description?: string;
keyword?: string[];
category?: string[];
author?: string;
metadata?: {
[key: string]: unknown;
};
}[];
/**
* @example false
*/
replace?: boolean;
},
) {
const path = ["ระบบประเมิน", volume];
if (!(await createFolder(path, id, true))) {
throw new Error("เกิดข้อผิดพลาดกับระบบจัดการไฟล์ ไม่สามารถสร้างแฟ้มได้");
}
const list = await listFile(["ระบบประเมิน", volume, id]);
if (!list || !Array.isArray(list)) {
throw new Error("เกิดข้อผิดพลาดกับระบบจัดการไฟล์ ไม่สามารถสร้างแฟ้มได้");
}
let used: string[] = [];
const evaluation = AppDataSource.getRepository(Evaluation);
let author = await evaluation.findOne({
where: { id },
});
let fileList = !body.replace
? body.fileList.map(({ fileName, ...props }) => {
const dotIndex = fileName.lastIndexOf(".");
const originalName =
dotIndex !== -1 && !fileName.startsWith(".") ? fileName.slice(0, dotIndex) : fileName;
const extension =
dotIndex !== -1 && !fileName.startsWith(".") ? fileName.slice(dotIndex) : "";
let i = 1;
while (list.findIndex((v) => v.fileName === fileName) !== -1 || used.includes(fileName)) {
fileName = `${originalName} (${i++})`;
if (dotIndex !== -1) fileName += extension;
}
if(author){
props.author = `${author.prefix}${author.fullName}`;
}else{
props.author = "ไม่พบข้อมูล";
}
used.push(fileName);
return { fileName: fileName, ...props };
})
: body.fileList;
const map = fileList.map(async ({ fileName, ...props }) => [
fileName,
await createFile([...path, id], fileName, props),
]);
const result = await Promise.all(map).catch((e) =>
console.error(`Storage Service Error: ${e}`),
);
if (!result || result.some((v) => !v[1])) {
throw new Error("เกิดข้อผิดพลาดกับระบบจัดการไฟล์ ไม่สามารถอัปโหลดไฟล์ได้");
}
return Object.fromEntries(result);
}
/**
* @example volume "เล่ม 1"
* @example id "00000000-0000-0000-0000-000000000000"
* @example file "1-แบบพิจารณาคุณสมบัติบุคคล.docx"
*
* @summary id
*/
@Patch("{volume}/{id}/{file}")
public async updateFile(
@Path() volume: string,
@Path() id: string,
@Path() file: string,
@Body()
body: {
title?: string;
description?: string;
keyword?: string[];
category?: string[];
author?: string;
metadata?: { [key: string]: unknown };
},
) {
const props = body;
const result = await updateFile(["ระบบประเมิน", volume, id], file, props);
if (!result) {
throw new Error("เกิดข้อผิดพลาดกับระบบจัดการไฟล์ ไม่สามารถอัปโหลดไฟล์ได้");
}
return this.setStatus(HttpStatus.NO_CONTENT);
}
/**
* @example volume "เล่ม 1"
* @example id "00000000-0000-0000-0000-000000000000"
*
* @summary id
*/
@Delete("{volume}/{id}")
public async deleteFolder(@Path() volume: string, @Path() id: string) {
const result = await deleteFolder(["ระบบประเมิน", volume], id);
if (!result) {
throw new Error("เกิดข้อผิดพลาดกับระบบจัดการไฟล์ ไม่สามารถอัปโหลดไฟล์ได้");
}
return this.setStatus(HttpStatus.NO_CONTENT);
}
/**
* @example volume "เล่ม 1"
* @example id "00000000-0000-0000-0000-000000000000"
* @example file "1-แบบพิจารณาคุณสมบัติบุคคล.docx"
*
* @summary id
*/
@Delete("{volume}/{id}/{file}")
public async deleteFile(@Path() volume: string, @Path() id: string, @Path() file: string) {
const result = await deleteFile(["ระบบประเมิน", volume, id], file);
if (!result) {
throw new Error("เกิดข้อผิดพลาดกับระบบจัดการไฟล์ ไม่สามารถอัปโหลดไฟล์ได้");
}
return this.setStatus(HttpStatus.NO_CONTENT);
}
}

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,212 @@
import { AppDataSource } from "../database/data-source";
import { CreateMeeting, Meeting } from "../entities/Meeting";
import {
Body,
Delete,
Get,
Path,
Post,
Put,
Response,
Route,
SuccessResponse,
Tags,
Query,
Request,
Security,
} from "tsoa";
import HttpStatusCode from "../interfaces/http-status";
import HttpSuccess from "../interfaces/http-success";
import HttpError from "../interfaces/http-error";
import { RequestWithUser } from "../middlewares/user";
import permission from "../interfaces/permission";
import { setLogDataDiff } from "../interfaces/utils";
import { Brackets } from "typeorm";
@Route("api/v1/evaluation/meeting")
@Tags("meeting")
@Security("bearerAuth")
@Response(
HttpStatusCode.INTERNAL_SERVER_ERROR,
"เกิดข้อผิดพลาด ไม่สามารถแสดงรายการได้ กรุณาลองใหม่ในภายหลัง",
)
@SuccessResponse(HttpStatusCode.OK, "สำเร็จ")
export class MeetingController {
private meetingRepository = AppDataSource.getRepository(Meeting);
/**
* API
*
* @summary EV4_006 - (ADMIN)
*
*/
@Get()
async all(
@Request() request: RequestWithUser,
@Query("page") page: number = 1,
@Query("pageSize") pageSize: number = 10,
@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}%`,
},
);
}),
)
.orderBy("meeting.createdAt", "DESC")
.skip((page - 1) * pageSize)
.take(pageSize)
.getMany();
return new HttpSuccess(meetings);
}
@Get("admin")
async allAdmin(
@Request() request: RequestWithUser,
@Query("page") page: number = 1,
@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}%`,
},
);
}),
)
.orderBy("meeting.createdAt", "DESC")
.skip((page - 1) * pageSize)
.take(pageSize)
.getMany();
return new HttpSuccess(meetings);
}
/**
* API
*
* @summary EV4_007 - (ADMIN)
*
*/
@Get("{id}")
async one(@Path() id: string, @Request() request: RequestWithUser) {
let _workflow = await new permission().Workflow(request, id, "SYS_EVA_INFO");
if (_workflow == false) await new permission().PermissionGet(request, "SYS_EVA_INFO");
const meeting = await this.meetingRepository.findOne({ where: { id } });
if (!meeting) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found.");
}
return new HttpSuccess(meeting);
}
/**
* API
*
* @summary EV4_008 - (ADMIN)
*
*/
@Post()
async save(@Body() requestBody: CreateMeeting, @Request() request: RequestWithUser) {
await new permission().PermissionCreate(request, "SYS_EVA_INFO");
const meeting = Object.assign(new Meeting(), requestBody);
meeting.createdUserId = request.user.sub;
meeting.createdFullName = request.user.name;
meeting.createdAt = new Date();
meeting.lastUpdateUserId = request.user.sub;
meeting.lastUpdateFullName = request.user.name;
meeting.lastUpdatedAt = new Date();
const before = null;
await this.meetingRepository.save(meeting, { data: request });
setLogDataDiff(request, { before, after: meeting });
return new HttpSuccess();
}
/**
* API
*
* @summary EV4_009 - (ADMIN)
*
*/
@Put("{id}")
async update(@Path() id: string, @Body() u: CreateMeeting, @Request() request: RequestWithUser) {
await new permission().PermissionUpdate(request, "SYS_EVA_INFO");
let meeting = await this.meetingRepository.findOneBy({ id });
if (!meeting) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found.");
}
const before = structuredClone(meeting);
meeting.lastUpdateUserId = request.user.sub;
meeting.lastUpdateFullName = request.user.name;
meeting.lastUpdatedAt = new Date();
this.meetingRepository.merge(meeting, u);
await this.meetingRepository.save(meeting, { data: request });
setLogDataDiff(request, { before, after: meeting });
return new HttpSuccess();
}
/**
* API
*
* @summary EV4_010 - (ADMIN)
*
*/
@Delete("{id}")
async remove(id: string, @Request() request: RequestWithUser) {
await new permission().PermissionDelete(request, "SYS_EVA_INFO");
let meeting = await this.meetingRepository.findOneBy({ id });
if (!meeting) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found.");
}
await this.meetingRepository.remove(meeting, { data: request });
return new HttpSuccess();
}
}

View file

@ -0,0 +1,370 @@
import { AppDataSource } from "../database/data-source";
import {
Body,
Example,
Get,
Path,
Post,
Put,
Request,
Response,
Route,
Security,
SuccessResponse,
Tags,
Delete,
} from "tsoa";
import HttpStatusCode from "../interfaces/http-status";
import { Evaluation } from "../entities/Evaluation";
import HttpSuccess from "../interfaces/http-success";
import { EvaluationLogs } from "../entities/EvaluationLogs";
import HttpError from "../interfaces/http-error";
import { Education } from "../entities/Education";
import { Certificate } from "../entities/Certificate";
import { Salary } from "../entities/Salary";
import { Training } from "../entities/Training";
import { Assessment } from "../entities/Assessment";
import { Director } from "../entities/Director";
import { Meeting } from "../entities/Meeting";
import { Brackets } from "typeorm";
import CallAPI from "../interfaces/call-api";
import { RequestWithUser } from "../middlewares/user";
import Extension from "../interfaces/extension";
import { Not } from "typeorm"
@Route("api/v1/evaluation/report")
@Tags("report")
@Security("bearerAuth")
@Response(
HttpStatusCode.INTERNAL_SERVER_ERROR,
"เกิดข้อผิดพลาด ไม่สามารถทำรายการได้ กรุณาลองใหม่ในภายหลัง",
)
@SuccessResponse(HttpStatusCode.OK, "สำเร็จ")
export class ReoportController {
private evaluationRepository = AppDataSource.getRepository(Evaluation);
private evaluationLogsRepository = AppDataSource.getRepository(EvaluationLogs);
private educationRepository = AppDataSource.getRepository(Education);
private certificateRepository = AppDataSource.getRepository(Certificate);
private salaryRepository = AppDataSource.getRepository(Salary);
private trainingRepository = AppDataSource.getRepository(Training);
private assessmentRepository = AppDataSource.getRepository(Assessment);
private directorRepository = AppDataSource.getRepository(Director);
private meetingRepository = AppDataSource.getRepository(Meeting);
/**
* Report
*
* @summary Report (ADMIN & USER)
*
* @param {string} id id
*/
@Get("check-spec-report/{id}")
async checkSpecGetReport(@Request() request: RequestWithUser, @Path() id: string) {
const evaluation = await AppDataSource.getRepository(Evaluation)
.createQueryBuilder("evaluation")
.leftJoin("evaluation.education", "education")
.leftJoin("evaluation.certificate", "certificate")
.leftJoin("evaluation.salaries", "salaries")
.leftJoin("evaluation.training", "training")
.leftJoin("evaluation.assessment", "assessment")
.where("evaluation.id = :id", { id })
.select([
"evaluation.id",
"evaluation.userId",
"evaluation.subject",
"evaluation.isEducationalQft",
"evaluation.isGovermantServiceHtr",
"evaluation.isOperatingExp",
"evaluation.isMinPeriodOfTenure",
"evaluation.isHaveSpecificQft",
"evaluation.isHaveProLicense",
"evaluation.isHaveMinPeriodOrHoldPos",
"evaluation.type",
"evaluation.prefix",
"evaluation.fullName",
"evaluation.position",
"evaluation.posNo",
"evaluation.oc",
"evaluation.salary",
"evaluation.positionLevel",
"evaluation.birthDate",
"evaluation.govAge",
"evaluation.experience",
"education.educationLevel",
"education.institute",
"education.isDate",
"education.startDate",
"education.endDate",
"education.finishDate",
"education.isEducation",
"education.degree",
"education.field",
"education.fundName",
"education.gpa",
"education.country",
"education.other",
"education.duration",
"education.durationYear",
"certificate.certificateType",
"certificate.issuer",
"certificate.certificateNo",
"certificate.issueDate",
"certificate.expireDate",
"salaries.date",
"salaries.amount",
"salaries.positionSalaryAmount",
"salaries.mouthSalaryAmount",
"salaries.position",
"salaries.posNo",
"salaries.salaryClass",
"salaries.salaryRef",
"salaries.refCommandNo",
"salaries.refCommandDate",
"salaries.salaryStatus",
"training.name",
"training.topic",
"training.startDate",
"training.endDate",
"training.yearly",
"training.place",
"training.duration",
"training.department",
"training.numberOrder",
"training.dateOrder",
"assessment.date",
"assessment.point1Total",
"assessment.point1",
"assessment.point2Total",
"assessment.point2",
"assessment.pointSumTotal",
"assessment.pointSum",
])
.getOne();
if (!evaluation) {
return "ไม่พบข้อมูล";
}
let root: any
let dateStart: any
let dateRetireLaw: any
let org: any
let commanderFullname: any
let commanderPosition: any
let commanderRootName: any
let commanderOrg: any
let commanderAboveFullname: any
let commanderAbovePosition: any
let commanderAboveRootName: any
let commanderAboveOrg: any
if (!evaluation.userId) {
return "ไม่พบข้อมูลผู้ขอประเมิน";
}
await new CallAPI()
.GetData(request, `/org/profile/keycloak/commander/${evaluation.userId}`)
.then(async (x) => {
root = x.root,
dateStart = x.dateStart,
dateRetireLaw = x.dateRetireLaw,
org = x.org,
commanderFullname = x.commanderFullname,
commanderPosition = x.commanderPosition,
commanderRootName = x.commanderRootName,
commanderOrg = x.commanderOrg,
commanderAboveFullname = x.commanderAboveFullname,
commanderAbovePosition = x.commanderAbovePosition,
commanderAboveRootName = x.commanderAboveRootName,
commanderAboveOrg = x.commanderAboveOrg
})
.catch();
const evaluationOld = await this.evaluationRepository.find({
where: {
id: Not(id),
userId: evaluation.userId,
step: "DONE"
}
});
let subjectOld = evaluationOld.length > 0
? evaluationOld.map(x => x.subject).join(", ")
: "ไม่มี"
let thaiYear:number = new Date().getFullYear()+543
let years = {
lastTwoYear: Extension.ToThaiNumber((thaiYear-2).toString()),
lastOneYear: Extension.ToThaiNumber((thaiYear-1).toString()),
currentYear: Extension.ToThaiNumber(thaiYear.toString()),
}
const dataEvaluation = {
isEducationalQft: evaluation.isEducationalQft,
isGovermantServiceHtr: evaluation.isGovermantServiceHtr,
isOperatingExp: evaluation.isOperatingExp,
isMinPeriodOfTenure: evaluation.isMinPeriodOfTenure,
isHaveSpecificQft: evaluation.isHaveSpecificQft,
isHaveProLicense: evaluation.isHaveProLicense,
isHaveMinPeriodOrHoldPos: evaluation.isHaveMinPeriodOrHoldPos,
type: evaluation.type,
prefix: evaluation.prefix,
fullName: evaluation.prefix && evaluation.fullName ? `${evaluation.prefix}${evaluation.fullName}` : "-",
position: evaluation.position ? evaluation.position : "-",
posNo: evaluation.posNo ? Extension.ToThaiNumber(evaluation.posNo) : "-",
oc: evaluation.oc ? evaluation.oc : "-",
org: org ? org : "-", //สังกัด
root: root ? root : "-", //หน่วยงาน
salary: evaluation.salary ? Extension.ToThaiNumber(evaluation.salary) : "-",
positionLevel: evaluation.positionLevel ? evaluation.positionLevel : "-",
birthDate: evaluation.birthDate != null && evaluation.birthDate != ""
? Extension.ToThaiNumber(Extension.ToThaiShortDate_noPrefix(new Date(evaluation.birthDate)))
: "-",
govAge: evaluation.govAge != null
? Extension.ToThaiNumber(evaluation.govAge)
: "-",
experience: evaluation.experience ? evaluation.experience : "-",
dateStart: dateStart
? Extension.ToThaiNumber(Extension.ToThaiShortDate(new Date(dateStart)))
: "-",
dateRetireLaw: dateRetireLaw
? Extension.ToThaiNumber(Extension.ToThaiShortDate(new Date(dateRetireLaw)))
: "-",
subject: evaluation.subject != null ? evaluation.subject : "-",
subjectOld: subjectOld,
educations: evaluation.education.length > 0
? evaluation.education.map((education) => ({
educationLevel: education.educationLevel
? Extension.ToThaiNumber(education.educationLevel)
: "-",
institute: education.institute
? Extension.ToThaiNumber(education.institute)
: "-",
finishYear: education.finishDate
? Extension.ToThaiNumber((Extension.ToThaiYear(education.finishDate.getFullYear())).toString())
: "-",
isDate: education.isDate,
startDate: education.startDate,
endDate: education.endDate,
finishDate: education.finishDate
? Extension.ToThaiNumber(Extension.ToThaiShortDate(education.finishDate).toString())
: "-",
isEducation: education.isEducation,
degree: education.degree
? Extension.ToThaiNumber(education.degree)
: "-",
field: education.field
? Extension.ToThaiNumber(education.field)
: "-",
fundName: education.fundName,
gpa: education.gpa,
country: education.country,
other: education.other,
duration: education.duration,
durationYear: education.durationYear,
}))
: [{
educationLevel: "-",
institute: "-",
finishYear: "-",
finishDate: "-",
degree: "-",
field: "-"
}],
certificates: evaluation.certificate.length > 0
? evaluation.certificate.map((certificate) => ({
certificateType: certificate.certificateType
? Extension.ToThaiNumber(certificate.certificateType)
: "-",
issuer: certificate.issuer
? Extension.ToThaiNumber(certificate.issuer)
: "-",
certificateNo: certificate.certificateNo
? Extension.ToThaiNumber(certificate.certificateNo)
: "-",
issueDate: certificate.issueDate,
expireDate: certificate.expireDate,
}))
: [{
certificateType: "-",
issuer: "-",
certificateNo: "-",
issueDate: "-",
expireDate: "-",
}],
salaries: evaluation.salaries.length > 0
? evaluation.salaries.map((salaries) => ({
date: salaries.date
? Extension.ToThaiNumber(Extension.ToThaiShortDate_noPrefix(salaries.date))
: "-",
amount: salaries.amount
? Extension.ToThaiNumber(salaries.amount.toLocaleString())
: "-",
position: salaries.position
? Extension.ToThaiNumber(salaries.position)
: "-",
positionSalaryAmount: salaries.positionSalaryAmount,
mouthSalaryAmount: salaries.mouthSalaryAmount,
posNo: salaries.posNo,
salaryClass: salaries.salaryClass,
salaryRef: salaries.salaryRef,
refCommandNo: salaries.refCommandNo,
refCommandDate: salaries.refCommandDate,
salaryStatus: salaries.salaryStatus,
}))
: [{
date: "-",
amount: "-",
position: "-",
}],
trainings: evaluation.training.length > 0
? evaluation.training.map((training) => ({
name: training.name
? Extension.ToThaiNumber(training.name)
: "-",
topic: training.topic
? Extension.ToThaiNumber(training.topic)
: "-",
startDate: training.startDate
? Extension.ToThaiNumber(Extension.ToThaiShortDate_noPrefix(training.startDate))
: "-",
endDate: training.endDate
? Extension.ToThaiNumber(Extension.ToThaiShortDate_noPrefix(training.endDate))
: "-",
yearly: training.yearly
? Extension.ToThaiNumber(training.yearly.toString())
: "-",
place: training.place,
duration: training.duration,
department: training.department,
numberOrder: training.numberOrder,
dateOrder: training.dateOrder,
}))
: [{
name: "-",
topic: "-",
yearly: "-",
}],
assessments: evaluation.assessment.map((assessment) => ({
date: assessment.date,
point1Total: assessment.point1Total,
point1: assessment.point1,
point2Total: assessment.point2Total,
point2: assessment.point2,
pointSumTotal: assessment.pointSumTotal,
pointSum: assessment.pointSum,
})),
commanderFullname: commanderFullname ? commanderFullname : "-",
commanderPosition: commanderPosition ? commanderPosition : "-",
commanderRootName: commanderRootName ? commanderRootName : "-",
commanderOrg: commanderOrg ? commanderOrg : "-",
commanderAboveFullname: commanderAboveFullname ? commanderAboveFullname : "-",
commanderAbovePosition: commanderAbovePosition ? commanderAbovePosition : "-",
commanderAboveRootName: commanderAboveRootName ? commanderAboveRootName : "-",
commanderAboveOrg: commanderAboveOrg ? commanderAboveOrg : "-",
years: years
};
if (!dataEvaluation) {
return "ไม่พบข้อมูล";
}
return new HttpSuccess(dataEvaluation);
}
}

View file

@ -0,0 +1,65 @@
import "dotenv/config";
import "reflect-metadata";
import { DataSource, LogLevel, LogMessage } from "typeorm";
import { Logger } from "typeorm";
import { QueryRunner } from "typeorm/browser";
import { RequestWithUser } from "../middlewares/user";
import { addLogSequence } from "../interfaces/utils";
export class MyCustomLogger implements Logger {
log(level: "log" | "info" | "warn", message: any, queryRunner?: QueryRunner) {}
logQuery(query: string, parameters?: any[], queryRunner?: QueryRunner): void {
const req = queryRunner?.data as RequestWithUser;
if (req?.app?.locals.logData?.sequence) {
addLogSequence(req, {
action: "database",
status: "success",
description: "Query Data.",
query: [
"Query: " + query + (parameters ? " - Parameters:" + JSON.stringify(parameters) : ""),
],
});
}
// const req = queryRunner?.data as RequestWithUser | undefined;
// const logData = req?.app?.locals.logData?.sequence?.at(-1);
// if (logData && !logData.query) logData.query = [];
// if (logData) logData.query.push(
// "Query: " + query + (parameters ? (" - Parameters:" + JSON.stringify(parameters)) : '')
// );
}
logMigration(message: string, queryRunner?: QueryRunner) {}
logQueryError(
error: string | Error,
query: string,
parameters?: any[],
queryRunner?: QueryRunner,
) {}
logQuerySlow(time: number, query: string, parameters?: any[], queryRunner?: QueryRunner) {}
logSchemaBuild(message: string, queryRunner?: QueryRunner) {}
}
export const AppDataSource = new DataSource({
type: "mysql",
database: process.env.DB_NAME,
host: process.env.DB_HOST,
port: +(process.env.DB_PORT || 3306),
username: process.env.DB_USERNAME,
password: process.env.DB_PASSWORD,
connectorPackage: "mysql2",
synchronize: false,
logging: ["query", "error"],
entities:
process.env.NODE_ENV !== "production"
? ["src/entities/**/*.ts"]
: ["dist/entities/**/*{.ts,.js}"],
migrations:
process.env.NODE_ENV !== "production"
? ["src/migration/**/*.ts"]
: ["dist/migration/**/*{.ts,.js}"],
subscribers: [],
logger: new MyCustomLogger(),
});

View file

@ -0,0 +1,40 @@
import { Entity, Column, ManyToOne, JoinColumn, OneToOne } from "typeorm";
import { EntityBase } from "./base/Base";
import { Evaluation } from "./Evaluation";
@Entity("assessment")
export class Assessment extends EntityBase {
@Column({
comment: "Id การทำรายการระบบประเมิน",
length: 40,
default: "00000000-0000-0000-0000-000000000000",
})
evaluationId: string;
@Column({ nullable: true, type: "datetime", comment: "วันที่ได้รับ" })
date: Date;
@Column({ nullable: true, type: "double precision", comment: "ส่วนที่1 (คะแนน)" })
point1Total: number;
@Column({ nullable: true, type: "double precision", comment: "ผลประเมินส่วนที่2 (คะแนน)" })
point1: number;
@Column({ nullable: true, type: "double precision", comment: "ส่วนที่2 (คะแนน)" })
point2Total: number;
@Column({ nullable: true, type: "double precision", comment: "ผลประเมินส่วนที่2 (คะแนน)" })
point2: number;
@Column({ nullable: true, type: "double precision", comment: "ผลรวม (คะแนน)" })
pointSumTotal: number;
@Column({ nullable: true, type: "double precision", comment: "ผลประเมินรวม (คะแนน)" })
pointSum: number;
@ManyToOne(() => Evaluation, (Evaluation) => Evaluation.assessment)
@JoinColumn({ name: "evaluationId" })
evaluation: Evaluation;
}
export type UpdateAssessment = Partial<Assessment>;

View file

@ -0,0 +1,37 @@
import { Entity, Column, ManyToOne, JoinColumn, OneToOne } from "typeorm";
import { EntityBase } from "./base/Base";
import { Evaluation } from "./Evaluation";
@Entity("certificate")
export class Certificate extends EntityBase {
@Column({
comment: "Id การทำรายการระบบประเมิน",
length: 40,
default: "00000000-0000-0000-0000-000000000000",
})
evaluationId: string;
@Column({ nullable: true, comment: "ชื่อสถานะการประเมิน" })
statictep: string;
@Column({ nullable: true, comment: "ชื่อใบอนุญาต" })
certificateType: string;
@Column({ nullable: true, comment: "หน่วยงานผู้ออกใบอนุญาต" })
issuer: string;
@Column({ nullable: true, comment: "เลขที่ใบอนุญาต" })
certificateNo: string;
@Column({ nullable: true, type: "datetime", comment: "วันที่ออกใบอนุญาต" })
issueDate: Date;
@Column({ nullable: true, type: "datetime", comment: "วันที่หมดอายุ" })
expireDate: Date;
@ManyToOne(() => Evaluation, (Evaluation) => Evaluation.certificate)
@JoinColumn({ name: "evaluationId" })
evaluation: Evaluation;
}
export type UpdateCertificate = Partial<Certificate>;

51
src/entities/Director.ts Normal file
View file

@ -0,0 +1,51 @@
import {
Entity,
Column,
ManyToMany,
} from "typeorm";
import { EntityBase } from "./base/Base";
import { Evaluation } from "./Evaluation";
@Entity("director")
export class Director extends EntityBase {
@Column({ nullable: true, comment: "คำนำหน้าชื่อ" })
prefix: string;
@Column({ nullable: true, comment: "ชื่อ" })
firstName: string;
@Column({ nullable: true, comment: "นามสกุล" })
lastName: string;
@Column({ nullable: true, comment: "เบอร์โทรศัพท์" })
phone: string;
@Column({ nullable: true, comment: "อีเมล" })
email: string;
@Column({ nullable: true, comment: "ตำแหน่ง" })
position: string;
@ManyToMany(() => Evaluation, (evaluation) => evaluation.directors)
evaluations: Evaluation[];
}
export class CreateDirector {
@Column()
prefix: string;
@Column()
firstName: string;
@Column()
lastName: string;
@Column()
phone: string;
@Column()
email: string;
@Column()
position: string;
}
export type UpdateDirector = Partial<Director>;

64
src/entities/Education.ts Normal file
View file

@ -0,0 +1,64 @@
import { Entity, Column, ManyToOne, JoinColumn, OneToOne } from "typeorm";
import { EntityBase } from "./base/Base";
import { Evaluation } from "./Evaluation";
@Entity("education")
export class Education extends EntityBase {
@Column({
comment: "Id การทำรายการระบบประเมิน",
length: 40,
default: "00000000-0000-0000-0000-000000000000",
})
evaluationId: string;
@Column({ nullable: true, comment: "ระดับศึกษา" })
educationLevel: string;
@Column({ nullable: true, comment: "สถานศึกษา" })
institute: string;
@Column({ nullable: true, comment: "ประเภทช่วงเวลาการศึกษา" })
isDate: boolean;
@Column({ nullable: true, type: "datetime", comment: "ตั้งแต่" })
startDate: Date;
@Column({ nullable: true, type: "datetime", comment: "EndDate" })
endDate: Date;
@Column({ nullable: true, type: "datetime", comment: "วันที่สำเร็จการศึกษา" })
finishDate: Date;
@Column({ nullable: true, comment: "เป็นวุฒิศึกษาในตำแหน่ง" })
isEducation: boolean;
@Column({ nullable: true, comment: "วุฒิการศึกษา" })
degree: string;
@Column({ nullable: true, comment: "สาขาวิชา/ทาง" })
field: string;
@Column({ nullable: true, comment: "ทุน" })
fundName: string;
@Column({ nullable: true, comment: "เกรดเฉลี่ย" })
gpa: string;
@Column({ nullable: true, comment: "ประเทศ" })
country: string;
@Column({ nullable: true, comment: "ข้อมูลการติดต่อ" })
other: string;
@Column({ nullable: true, comment: "ระยะเวลา" })
duration: string;
@Column({ nullable: true, comment: "ระยะเวลาหลักสูตร" })
durationYear: string;
@ManyToOne(() => Evaluation, (Evaluation) => Evaluation.education)
@JoinColumn({ name: "evaluationId" })
evaluation: Evaluation;
}
export type UpdateEducation = Partial<Education>;

476
src/entities/Evaluation.ts Normal file
View file

@ -0,0 +1,476 @@
import { Entity, Column, OneToMany, ManyToMany, JoinTable } from "typeorm";
import { EntityBase } from "./base/Base";
import { EvaluationLogs } from "./EvaluationLogs";
import { Education } from "./Education";
import { Certificate } from "./Certificate";
import { Salary } from "./Salary";
import { Training } from "./Training";
import { Assessment } from "./Assessment";
import { Director } from "./Director";
import { Meeting } from "./Meeting";
@Entity("evaluation")
export class Evaluation extends EntityBase {
@Column({
comment: "Id ชื่อผู้ใช้งาน",
length: 40,
default: "00000000-0000-0000-0000-000000000000",
})
userId: string;
@Column({ nullable: true, comment: "รหัสบัตรประชาชน", length: 13 })
citizenId: string;
@Column({ nullable: true, comment: "คำนำหน้า" })
prefix: string;
@Column({ nullable: true, comment: "ชื่อ นามสกุล" })
fullName: string;
@Column({ nullable: true, comment: "ตำแหน่ง" })
position: string;
@Column({ nullable: true, comment: "สังกัด" })
oc: string;
@Column({
nullable: true,
comment: "root",
length: 255,
default: null,
})
rootId: string;
@Column({
nullable: true,
comment: "child1",
length: 255,
default: null,
})
child1Id: string;
@Column({
nullable: true,
comment: "child2",
length: 255,
default: null,
})
child2Id: string;
@Column({
nullable: true,
comment: "child3",
length: 255,
default: null,
})
child3Id: string;
@Column({
nullable: true,
comment: "child4",
length: 255,
default: null,
})
child4Id: string;
@Column({ nullable: true, comment: "เงินเดือนปัจจุบัน" })
salary: string;
@Column({ nullable: true, comment: "ระดับปัจจุบัน" })
positionLevel: string;
@Column({ nullable: true, comment: "ตำแหน่งเลขที่" })
posNo: string;
@Column({ nullable: true, comment: "วันเดือนปีเกิด" })
birthDate: string;
@Column({ nullable: true, comment: "อายุราชการ" })
govAge: string;
@Column({ nullable: true, comment: "ประเภทแบบประเมิน" })
type: string;
@Column({ nullable: true, comment: "ชื่อสถานะการประเมิน" })
step: string;
@Column({ comment: "มีคุณวุฒิการศึกษา", default: false })
isEducationalQft: boolean;
@Column({ comment: "มีประวัติการรับราชการ", default: false })
isGovermantServiceHtr: boolean;
@Column({ comment: "มีประสบการณ์ในการปฏิบัติงาน", default: false })
isOperatingExp: boolean;
@Column({
comment: "มีระยะเวลาขั้นต่ำในการดำรงตำแหน่งในสายงานที่ขอเข้ารับการคัดเลือก",
default: false,
})
isMinPeriodOfTenure: boolean;
@Column({
comment: "มีคุณสมบัติตรงตามคุณสมบัติเฉพาะสำหรับตำแหน่งที่กำหนด ในมาตราฐานกำหนดตำแหน่ง",
default: false,
})
isHaveSpecificQft: boolean;
@Column({
comment:
"มีใบอนุญาตประกอบวิชาชีพของสายงานต่างๆ และ/หรือ คุณวุฒิเพิ่มเติมครบถ้วนตามที่ ก.ก. กำหนด (แพทย์พยาบาล วิศวกรโยธา สถาปนิก ฯลฯ)",
default: false,
})
isHaveProLicense: boolean;
@Column({
comment:
"มีระยะเวลาขั้นต่ำในการดำรงตำแหน่งหรือเคยดำรงตำแหน่งในสายงานที่จะคัดเลือกตามคุณวุฒิของบุคคลและระดับตำแหน่งที่จะคัดเลือก",
default: false,
})
isHaveMinPeriodOrHoldPos: boolean;
@Column({ nullable: true, comment: "เหตุผล" })
reason: string;
@Column({ nullable: true, comment: "ประสบการณ์ในการปฏิบัติงาน" })
experience: string;
@Column({ nullable: true, comment: "ชื่อ-นามสกุล ผู้บังคับบัญชาชั้นต้น" })
commanderFullname: string;
@Column({ nullable: true, comment: "ตำแหน่ง ผู้บังคับบัญชาชั้นต้น" })
commanderPosition: string;
@Column({ nullable: true, comment: "ชื่อ-นามสกุล ผู้บังคับบัญชาเหนือขึ้นไป 1 ระดับ" })
commanderAboveFullname: string;
@Column({ nullable: true, comment: "ตำแหน่ง ผู้บังคับบัญชาเหนือขึ้นไป 1 ระดับ" })
commanderAbovePosition: string;
@Column({ nullable: true, comment: "ชื่อ-นามสกุล ผู้บังคับบัญชาชั้นต้น (จัดเตรียมเอกสารเล่ม 2)" })
commanderFullnameDoc2: string;
@Column({ nullable: true, comment: "ตำแหน่ง ผู้บังคับบัญชาชั้นต้น (จัดเตรียมเอกสารเล่ม 2)" })
commanderPositionDoc2: string;
@Column({
nullable: true,
comment: "ชื่อ-นามสกุล ผู้บังคับบัญชาเหนือขึ้นไป 1 ระดับ (จัดเตรียมเอกสารเล่ม 2)",
})
commanderAboveFullnameDoc2: string;
@Column({
nullable: true,
comment: "ตำแหน่ง ผู้บังคับบัญชาเหนือขึ้นไป 1 ระดับ (จัดเตรียมเอกสารเล่ม 2)",
})
commanderAbovePositionDoc2: string;
@Column({ nullable: true, comment: "วันที่ประกาศบนเว็บไซต์" })
dateAnnounce: Date;
@Column({ nullable: true, comment: "วันที่จัดเตรียมเอกสารเล่ม 2" })
datePrepareDoc2: Date;
@Column({ nullable: true, comment: "ชื่อเจ้าของผลงาน" })
author: string;
@Column({ nullable: true, comment: "ชื่อผลงาน" })
subject: string;
@Column({ nullable: true, comment: "ชื่อเจ้าของผลงาน2" })
authorDoc2: string;
@Column({ nullable: true, comment: "ชื่อผลงาน2" })
subjectDoc2: string;
@Column({ nullable: true, comment: "ตำแหน่งที่ได้รับมอบหมาย" })
assignedPosition: string;
@OneToMany(() => EvaluationLogs, (evaluationLogs) => evaluationLogs.evaluation)
evaluationLogs: EvaluationLogs[];
@OneToMany(() => Education, (education) => education.evaluation)
education: Education[];
@OneToMany(() => Certificate, (certificate) => certificate.evaluation)
certificate: Certificate[];
@OneToMany(() => Salary, (salary) => salary.evaluation)
salaries: Salary[];
@OneToMany(() => Training, (training) => training.evaluation)
training: Training[];
@OneToMany(() => Assessment, (assessment) => assessment.evaluation)
assessment: Assessment[];
@ManyToMany(() => Director, (director) => director.evaluations)
@JoinTable()
directors: Director[];
@ManyToMany(() => Meeting, (meeting) => meeting.evaluations)
@JoinTable()
meetings: Meeting[];
}
export class CreateEvaluation {
@Column()
userId?: string;
@Column()
citizenId?: string;
@Column()
prefix?: string;
@Column()
fullName: string;
@Column()
position?: string | null;
@Column()
oc?: string | null;
@Column()
salary?: string | null;
@Column()
positionLevel?: string | null;
@Column()
posNo?: string | null;
@Column()
birthDate?: string | null;
@Column()
govAge?: string | null;
@Column()
type?: string | null;
@Column()
step?: string | null;
@Column()
isEducationalQft: boolean; //ReqField
@Column()
isGovermantServiceHtr: boolean; //ReqField
@Column()
isOperatingExp: boolean; //ReqField
@Column()
isMinPeriodOfTenure: boolean; //ReqField
@Column()
isHaveSpecificQft: boolean; //ReqField
@Column()
isHaveProLicense: boolean; //ReqField
@Column()
isHaveMinPeriodOrHoldPos: boolean; //ReqField
@Column()
reason?: string | null;
@Column()
educations?: CreateEducation[];
@Column()
certificates?: CreateCertificate[];
@Column()
salaries?: CreateSalary[];
@Column()
trainings?: CreateTraining[];
@Column()
assessments?: CreateAssessment[];
}
export class CreateEducation {
@Column()
educationLevel?: string | null;
@Column()
institute?: string | null;
@Column()
isDate?: boolean | null;
@Column()
startDate?: Date | null;
@Column()
endDate?: Date | null;
@Column()
finishDate?: Date | null;
@Column()
isEducation?: boolean | null;
@Column()
degree?: string | null;
@Column()
field?: string | null;
@Column()
fundName?: string | null;
@Column()
gpa?: string | null;
@Column()
country?: string | null;
@Column()
other?: string | null;
@Column()
duration?: string | null;
@Column()
durationYear?: string | null;
}
export class CreateCertificate {
@Column()
step?: string | null;
@Column()
certificateType?: string | null;
@Column()
issuer?: string | null;
@Column()
certificateNo?: string | null;
@Column()
issueDate?: Date | null;
@Column()
expireDate?: Date | null;
}
export class CreateSalary {
@Column()
step?: string | null;
@Column()
date?: Date | null;
@Column()
amount?: number | null;
@Column()
positionSalaryAmount?: number | null;
@Column()
mouthSalaryAmount?: number | null;
@Column()
position?: string | null;
@Column()
posNo?: string | null;
@Column()
salaryClass?: string | null;
@Column()
salaryRef?: string | null;
@Column()
refCommandNo?: string | null;
@Column()
refCommandDate?: Date | null;
@Column()
salaryStatus?: string | null;
}
export class CreateTraining {
@Column()
name?: string | null;
@Column()
topic?: string | null;
@Column()
startDate?: Date | null;
@Column()
endDate?: Date | null;
@Column()
yearly?: number | null;
@Column()
place?: string | null;
@Column()
duration?: string | null;
@Column()
department?: string | null;
@Column()
numberOrder?: string | null;
@Column()
dateOrder?: Date | null;
}
export class CreateAssessment {
@Column()
date?: Date | null;
@Column()
point1Total?: number | null;
@Column()
point1?: number | null;
@Column()
point2Total?: number | null;
@Column()
point2?: number | null;
@Column()
pointSumTotal?: number | null;
@Column()
pointSum?: number | null;
}
export class CreateEvaluationExpertise {
@Column()
author?: string | null;
@Column()
subject?: string | null;
@Column()
commanderFullname?: string | null;
@Column()
commanderPosition?: string | null;
@Column()
commanderAboveFullname?: string | null;
@Column()
commanderAbovePosition?: string | null;
@Column()
oc?: string | null;
}
export type UpdateEvaluation = Partial<Evaluation>;

View file

@ -0,0 +1,22 @@
import { Entity, Column, ManyToOne, JoinColumn } from "typeorm";
import { EntityBase } from "./base/Base";
import { Evaluation } from "./Evaluation";
@Entity("evaluationlogs")
export class EvaluationLogs extends EntityBase {
@Column({
comment: "Id การทำรายการระบบประเมิน",
length: 40,
default: "00000000-0000-0000-0000-000000000000",
})
evaluationId: string;
@Column({ comment: "ชื่อสถานะการประเมิน", default: "string" })
step: string;
@ManyToOne(() => Evaluation, (Evaluation) => Evaluation.evaluationLogs)
@JoinColumn({ name: "evaluationId" })
evaluation: Evaluation;
}
export type UpdateEvaluationLogs = Partial<EvaluationLogs>;

51
src/entities/Meeting.ts Normal file
View file

@ -0,0 +1,51 @@
import {
Entity,
Column,
ManyToMany,
} from "typeorm";
import { EntityBase } from "./base/Base";
import { Evaluation } from "./Evaluation";
@Entity("meeting")
export class Meeting extends EntityBase {
@Column({ nullable: true, comment: "ชื่อการประชุม" })
title: string;
@Column({ nullable: true, comment: "ครั้งที่" })
round: string;
@Column({ nullable: true, comment: "วันเวลาเริ่มในการประชุม" })
dateStart: Date;
@Column({ nullable: true, comment: "วันเวลาสิ้นสุดในการประชุม" })
dateEnd: Date;
@Column({ nullable: true, comment: "ผลการพิจารณาของคณะกรรมการประเมินผลงานแต่ละคณะ" })
result: string;
@Column({ nullable: true, comment: "ระยะเวลาในการแก้ไขผลงาน" })
duration: string;
@ManyToMany(() => Evaluation, (evaluation) => evaluation.meetings)
evaluations: Evaluation[];
}
export class CreateMeeting {
@Column()
title: string;
@Column()
round: string;
@Column()
dateStart: Date;
@Column()
dateEnd: Date;
@Column()
result: string;
@Column()
duration: string;
}
export type UpdateMeeting = Partial<Meeting>;

52
src/entities/Salary.ts Normal file
View file

@ -0,0 +1,52 @@
import { Entity, Column, ManyToOne, JoinColumn, OneToOne } from "typeorm";
import { EntityBase } from "./base/Base";
import { Evaluation } from "./Evaluation";
@Entity("salary")
export class Salary extends EntityBase {
@Column({
comment: "Id การทำรายการระบบประเมิน",
length: 40,
default: "00000000-0000-0000-0000-000000000000",
})
evaluationId: string;
@Column({ nullable: true, type: "datetime", comment: "วัน เดือน ปี รับตำแหน่ง" })
date: Date;
@Column({ nullable: true, type: "double precision", comment: "เงินเดือน" })
amount: number;
@Column({ nullable: true, type: "double precision", comment: "เงินประจำตำแหน่ง" })
positionSalaryAmount: number;
@Column({ nullable: true, type: "double precision", comment: "เงินค่าตอบแทนรายเดือน" })
mouthSalaryAmount: number;
@Column({ nullable: true, comment: "ตำแหน่ง" })
position: string;
@Column({ nullable: true, comment: "เลขที่ตำแหน่ง" })
posNo: string;
@Column({ nullable: true, comment: "ตำแหน่ง (รายละเอียด)" })
salaryClass: string;
@Column({ nullable: true, comment: "เอกสารอ้างอิง" })
salaryRef: string;
@Column({ nullable: true, comment: "เอกสารอ้างอิง (เลขที่คำสั่ง)" })
refCommandNo: string;
@Column({ nullable: true, type: "datetime", comment: "เอกสารอ้างอิง (ลงวันที่)" })
refCommandDate: Date;
@Column({ nullable: true, comment: "ประเภทตำแหน่งกรณีพิเศษ" })
salaryStatus: string;
@ManyToOne(() => Evaluation, (Evaluation) => Evaluation.salaries)
@JoinColumn({ name: "evaluationId" })
evaluation: Evaluation;
}
export type UpdateSalary = Partial<Salary>;

49
src/entities/Training.ts Normal file
View file

@ -0,0 +1,49 @@
import { Entity, Column, ManyToOne, JoinColumn, OneToOne } from "typeorm";
import { EntityBase } from "./base/Base";
import { Evaluation } from "./Evaluation";
@Entity("training")
export class Training extends EntityBase {
@Column({
comment: "Id การทำรายการระบบประเมิน",
length: 40,
default: "00000000-0000-0000-0000-000000000000",
})
evaluationId: string;
@Column({ nullable: true, comment: "ชื่อโครงการ/หลักสูตรการฝึกอบรม" })
name: string;
@Column({ nullable: true, comment: "หัวข้อการฝึกอบรม/ดูงาน" })
topic: string;
@Column({ nullable: true, type: "datetime", comment: "วันเริ่มต้นการฝึกอบรม/ดูงาน" })
startDate: Date;
@Column({ nullable: true, type: "datetime", comment: "วันสิ้นสุดการฝึกอบรม/ดูงาน" })
endDate: Date;
@Column({ nullable: true, comment: "ปีที่อบรม (พ.ศ.)" })
yearly: number;
@Column({ nullable: true, comment: "สถานที่ฝึกอบรม/ดูงาน" })
place: string;
@Column({ nullable: true, comment: "รวมระยะเวลาในการฝึกอบรม/ดูงาน" })
duration: string;
@Column({ nullable: true, comment: "หน่วยงานที่รับผิดชอบจัดการฝึกอบรม/ดูงาน" })
department: string;
@Column({ nullable: true, comment: "เลขที่คำสั่ง/เลขที่หนังสืออนุมัติ" })
numberOrder: string;
@Column({ nullable: true, type: "datetime", comment: "คำสั่งลงวันที่/หนังสืออนุมัติลงวันที่" })
dateOrder: Date;
@ManyToOne(() => Evaluation, (Evaluation) => Evaluation.training)
@JoinColumn({ name: "evaluationId" })
evaluation: Evaluation;
}
export type UpdateTraining = Partial<Training>;

39
src/entities/base/Base.ts Normal file
View file

@ -0,0 +1,39 @@
import {
Entity,
PrimaryGeneratedColumn,
Column,
CreateDateColumn,
UpdateDateColumn,
} from "typeorm";
@Entity()
export class EntityBase {
@PrimaryGeneratedColumn("uuid")
id: string;
@CreateDateColumn({ comment: "สร้างข้อมูลเมื่อ" })
createdAt: Date;
@Column({
comment: "User Id ที่สร้างข้อมูล",
length: 40,
default: "00000000-0000-0000-0000-000000000000",
})
createdUserId: String;
@UpdateDateColumn({ comment: "แก้ไขข้อมูลล่าสุดเมื่อ" })
lastUpdatedAt: Date;
@Column({
comment: "User Id ที่แก้ไขข้อมูล",
length: 40,
default: "00000000-0000-0000-0000-000000000000",
})
lastUpdateUserId: String;
@Column({ comment: "ชื่อ User ที่สร้างข้อมูล", length: 200, default: "string" })
createdFullName: String;
@Column({ comment: "ชื่อ User ที่แก้ไขข้อมูลล่าสุด", length: 200, default: "string" })
lastUpdateFullName: String;
}

View file

@ -0,0 +1,84 @@
import { Path } from "tsoa";
import axios from "axios";
import { addLogSequence } from "./utils";
class CallAPI {
//Get
public async GetData(request: any, @Path() path: any, log = true) {
const token = "Bearer " + request.headers.authorization.replace("Bearer ", "");
const url = process.env.API_URL + path;
try {
const response = await axios.get(url, {
headers: {
Authorization: `${token}`,
"Content-Type": "application/json",
api_key: process.env.API_KEY,
},
});
if(log) addLogSequence(request, {
action: "request",
status: "success",
description: "connected",
request: {
method: "GET",
url: url,
response: JSON.stringify(response.data.result),
},
});
return response.data.result;
} catch (error) {
if(log) addLogSequence(request, {
action: "request",
status: "error",
description: "unconnected",
request: {
method: "GET",
url: url,
response: JSON.stringify(error),
},
});
throw error;
}
}
//Post
public async PostData(request: any, @Path() path: any, sendData: any) {
const token = "Bearer " + request.headers.authorization.replace("Bearer ", "");
const url = process.env.API_URL + path;
try {
const response = await axios.post(url, sendData, {
headers: {
Authorization: `${token}`,
"Content-Type": "application/json",
api_key: process.env.API_KEY,
},
});
addLogSequence(request, {
action: "request",
status: "success",
description: "connected",
request: {
method: "POST",
url: url,
payload: JSON.stringify(sendData),
response: JSON.stringify(response.data.result),
},
});
return response.data.result;
} catch (error) {
addLogSequence(request, {
action: "request",
status: "error",
description: "unconnected",
request: {
method: "POST",
url: url,
payload: JSON.stringify(sendData),
response: JSON.stringify(error),
},
});
throw error;
}
}
}
export default CallAPI;

152
src/interfaces/extension.ts Normal file
View file

@ -0,0 +1,152 @@
class Extension {
public static ToThaiMonth(value: number) {
switch (value) {
case 1:
return "มกราคม";
case 2:
return "กุมภาพันธ์";
case 3:
return "มีนาคม";
case 4:
return "เมษายน";
case 5:
return "พฤษภาคม";
case 6:
return "มิถุนายน";
case 7:
return "กรกฎาคม";
case 8:
return "สิงหาคม";
case 9:
return "กันยายน";
case 10:
return "ตุลาคม";
case 11:
return "พฤศจิกายน";
case 12:
return "ธันวาคม";
default:
return "";
}
}
public static ToThaiShortMonth(value: number) {
switch (value) {
case 1:
return "ม.ค.";
case 2:
return "ก.พ.";
case 3:
return "มี.ค.";
case 4:
return "เม.ย.";
case 5:
return "พ.ค.";
case 6:
return "มิ.ย.";
case 7:
return "ก.ค.";
case 8:
return "ส.ค.";
case 9:
return "ก.ย.";
case 10:
return "ต.ค.";
case 11:
return "พ.ย.";
case 12:
return "ธ.ค.";
default:
return "";
}
}
public static ToThaiYear(value: number) {
if (value < 2400) return value + 543;
else return value;
}
public static ToCeYear(value: number) {
if (value >= 2400) return value - 543;
else return value;
}
public static ToThaiNumber(value: string) {
let arabicNumbers = "0123456789";
let thaiNumbers = "๐๑๒๓๔๕๖๗๘๙";
let result = "";
for (let digit of value) {
let index = arabicNumbers.indexOf(digit);
if (index >= 0) {
result += thaiNumbers[index];
} else {
result += digit;
}
}
return result;
}
public static ToThaiFullDate(value: Date) {
let yy = value.getFullYear() < 2400 ? value.getFullYear() + 543 : value.getFullYear();
return (
"วันที่ " +
value.getDate() +
" เดือน " +
Extension.ToThaiMonth(value.getMonth() + 1) +
" พ.ศ. " +
yy
);
}
public static ToThaiFullDate2(value: Date) {
let yy = value.getFullYear() < 2400 ? value.getFullYear() + 543 : value.getFullYear();
return value.getDate() + " " + Extension.ToThaiMonth(value.getMonth() + 1) + " " + yy;
}
public static ToThaiFullDate3(value: Date) {
let yy = value.getFullYear() < 2400 ? value.getFullYear() + 543 : value.getFullYear();
return value.getDate() + " เดือน " + Extension.ToThaiMonth(value.getMonth() + 1) + " พ.ศ. " + yy;
}
public static ToThaiShortDate(value: Date) {
let yy = value.getFullYear() < 2400 ? value.getFullYear() + 543 : value.getFullYear();
return (
"วันที่ " +
value.getDate() +
" " +
Extension.ToThaiShortMonth(value.getMonth() + 1) +
" " +
yy.toString().slice(-2)
);
}
public static ToThaiShortDate_noPrefix(value: Date) {
let yy = value.getFullYear() < 2400 ? value.getFullYear() + 543 : value.getFullYear();
return (
value.getDate() +
" " +
Extension.ToThaiShortMonth(value.getMonth() + 1) +
" " +
yy.toString().slice(-2)
);
}
public static ToThaiShortDate_monthYear(value: Date) {
let yy = value.getFullYear() < 2400 ? value.getFullYear() + 543 : value.getFullYear();
return (
value.getDate() + " เดือน " + Extension.ToThaiMonth(value.getMonth() + 1) + " พ.ศ. " + yy
);
}
public static sumObjectValues(array: any, propertyName: any) {
let sum = 0;
for (let i = 0; i < array.length; i++) {
if (array[i][propertyName] !== undefined) {
sum += array[i][propertyName];
}
}
return sum;
}
}
export default Extension;

View file

@ -0,0 +1,19 @@
import HttpStatus from "./http-status";
class HttpError extends Error {
/**
* HTTP Status Code
*/
status: HttpStatus;
message: string;
constructor(status: HttpStatus, message: string) {
super(message);
this.name = "HttpError";
this.status = status;
this.message = message;
}
}
export default HttpError;

View file

@ -0,0 +1,380 @@
/**
* Hypertext Transfer Protocol (HTTP) response status codes.
* @see {@link https://en.wikipedia.org/wiki/List_of_HTTP_status_codes}
*/
enum HttpStatus {
/**
* The server has received the request headers and the client should proceed to send the request body
* (in the case of a request for which a body needs to be sent; for example, a POST request).
* Sending a large request body to a server after a request has been rejected for inappropriate headers would be inefficient.
* To have a server check the request's headers, a client must send Expect: 100-continue as a header in its initial request
* and receive a 100 Continue status code in response before sending the body. The response 417 Expectation Failed indicates the request should not be continued.
*/
CONTINUE = 100,
/**
* The requester has asked the server to switch protocols and the server has agreed to do so.
*/
SWITCHING_PROTOCOLS = 101,
/**
* A WebDAV request may contain many sub-requests involving file operations, requiring a long time to complete the request.
* This code indicates that the server has received and is processing the request, but no response is available yet.
* This prevents the client from timing out and assuming the request was lost.
*/
PROCESSING = 102,
/**
* Standard response for successful HTTP requests.
* The actual response will depend on the request method used.
* In a GET request, the response will contain an entity corresponding to the requested resource.
* In a POST request, the response will contain an entity describing or containing the result of the action.
*/
OK = 200,
/**
* The request has been fulfilled, resulting in the creation of a new resource.
*/
CREATED = 201,
/**
* The request has been accepted for processing, but the processing has not been completed.
* The request might or might not be eventually acted upon, and may be disallowed when processing occurs.
*/
ACCEPTED = 202,
/**
* SINCE HTTP/1.1
* The server is a transforming proxy that received a 200 OK from its origin,
* but is returning a modified version of the origin's response.
*/
NON_AUTHORITATIVE_INFORMATION = 203,
/**
* The server successfully processed the request and is not returning any content.
*/
NO_CONTENT = 204,
/**
* The server successfully processed the request, but is not returning any content.
* Unlike a 204 response, this response requires that the requester reset the document view.
*/
RESET_CONTENT = 205,
/**
* The server is delivering only part of the resource (byte serving) due to a range header sent by the client.
* The range header is used by HTTP clients to enable resuming of interrupted downloads,
* or split a download into multiple simultaneous streams.
*/
PARTIAL_CONTENT = 206,
/**
* The message body that follows is an XML message and can contain a number of separate response codes,
* depending on how many sub-requests were made.
*/
MULTI_STATUS = 207,
/**
* The members of a DAV binding have already been enumerated in a preceding part of the (multistatus) response,
* and are not being included again.
*/
ALREADY_REPORTED = 208,
/**
* The server has fulfilled a request for the resource,
* and the response is a representation of the result of one or more instance-manipulations applied to the current instance.
*/
IM_USED = 226,
/**
* Indicates multiple options for the resource from which the client may choose (via agent-driven content negotiation).
* For example, this code could be used to present multiple video format options,
* to list files with different filename extensions, or to suggest word-sense disambiguation.
*/
MULTIPLE_CHOICES = 300,
/**
* This and all future requests should be directed to the given URI.
*/
MOVED_PERMANENTLY = 301,
/**
* This is an example of industry practice contradicting the standard.
* The HTTP/1.0 specification (RFC 1945) required the client to perform a temporary redirect
* (the original describing phrase was "Moved Temporarily"), but popular browsers implemented 302
* with the functionality of a 303 See Other. Therefore, HTTP/1.1 added status codes 303 and 307
* to distinguish between the two behaviours. However, some Web applications and frameworks
* use the 302 status code as if it were the 303.
*/
FOUND = 302,
/**
* SINCE HTTP/1.1
* The response to the request can be found under another URI using a GET method.
* When received in response to a POST (or PUT/DELETE), the client should presume that
* the server has received the data and should issue a redirect with a separate GET message.
*/
SEE_OTHER = 303,
/**
* Indicates that the resource has not been modified since the version specified by the request headers If-Modified-Since or If-None-Match.
* In such case, there is no need to retransmit the resource since the client still has a previously-downloaded copy.
*/
NOT_MODIFIED = 304,
/**
* SINCE HTTP/1.1
* The requested resource is available only through a proxy, the address for which is provided in the response.
* Many HTTP clients (such as Mozilla and Internet Explorer) do not correctly handle responses with this status code, primarily for security reasons.
*/
USE_PROXY = 305,
/**
* No longer used. Originally meant "Subsequent requests should use the specified proxy."
*/
SWITCH_PROXY = 306,
/**
* SINCE HTTP/1.1
* In this case, the request should be repeated with another URI; however, future requests should still use the original URI.
* In contrast to how 302 was historically implemented, the request method is not allowed to be changed when reissuing the original request.
* For example, a POST request should be repeated using another POST request.
*/
TEMPORARY_REDIRECT = 307,
/**
* The request and all future requests should be repeated using another URI.
* 307 and 308 parallel the behaviors of 302 and 301, but do not allow the HTTP method to change.
* So, for example, submitting a form to a permanently redirected resource may continue smoothly.
*/
PERMANENT_REDIRECT = 308,
/**
* The server cannot or will not process the request due to an apparent client error
* (e.g., malformed request syntax, too large size, invalid request message framing, or deceptive request routing).
*/
BAD_REQUEST = 400,
/**
* Similar to 403 Forbidden, but specifically for use when authentication is required and has failed or has not yet
* been provided. The response must include a WWW-Authenticate header field containing a challenge applicable to the
* requested resource. See Basic access authentication and Digest access authentication. 401 semantically means
* "unauthenticated",i.e. the user does not have the necessary credentials.
*/
UNAUTHORIZED = 401,
/**
* Reserved for future use. The original intention was that this code might be used as part of some form of digital
* cash or micro payment scheme, but that has not happened, and this code is not usually used.
* Google Developers API uses this status if a particular developer has exceeded the daily limit on requests.
*/
PAYMENT_REQUIRED = 402,
/**
* The request was valid, but the server is refusing action.
* The user might not have the necessary permissions for a resource.
*/
FORBIDDEN = 403,
/**
* The requested resource could not be found but may be available in the future.
* Subsequent requests by the client are permissible.
*/
NOT_FOUND = 404,
/**
* A request method is not supported for the requested resource;
* for example, a GET request on a form that requires data to be presented via POST, or a PUT request on a read-only resource.
*/
METHOD_NOT_ALLOWED = 405,
/**
* The requested resource is capable of generating only content not acceptable according to the Accept headers sent in the request.
*/
NOT_ACCEPTABLE = 406,
/**
* The client must first authenticate itself with the proxy.
*/
PROXY_AUTHENTICATION_REQUIRED = 407,
/**
* The server timed out waiting for the request.
* According to HTTP specifications:
* "The client did not produce a request within the time that the server was prepared to wait. The client MAY repeat the request without modifications at any later time."
*/
REQUEST_TIMEOUT = 408,
/**
* Indicates that the request could not be processed because of conflict in the request,
* such as an edit conflict between multiple simultaneous updates.
*/
CONFLICT = 409,
/**
* Indicates that the resource requested is no longer available and will not be available again.
* This should be used when a resource has been intentionally removed and the resource should be purged.
* Upon receiving a 410 status code, the client should not request the resource in the future.
* Clients such as search engines should remove the resource from their indices.
* Most use cases do not require clients and search engines to purge the resource, and a "404 Not Found" may be used instead.
*/
GONE = 410,
/**
* The request did not specify the length of its content, which is required by the requested resource.
*/
LENGTH_REQUIRED = 411,
/**
* The server does not meet one of the preconditions that the requester put on the request.
*/
PRECONDITION_FAILED = 412,
/**
* The request is larger than the server is willing or able to process. Previously called "Request Entity Too Large".
*/
PAYLOAD_TOO_LARGE = 413,
/**
* The URI provided was too long for the server to process. Often the result of too much data being encoded as a query-string of a GET request,
* in which case it should be converted to a POST request.
* Called "Request-URI Too Long" previously.
*/
URI_TOO_LONG = 414,
/**
* The request entity has a media type which the server or resource does not support.
* For example, the client uploads an image as image/svg+xml, but the server requires that images use a different format.
*/
UNSUPPORTED_MEDIA_TYPE = 415,
/**
* The client has asked for a portion of the file (byte serving), but the server cannot supply that portion.
* For example, if the client asked for a part of the file that lies beyond the end of the file.
* Called "Requested Range Not Satisfiable" previously.
*/
RANGE_NOT_SATISFIABLE = 416,
/**
* The server cannot meet the requirements of the Expect request-header field.
*/
EXPECTATION_FAILED = 417,
/**
* This code was defined in 1998 as one of the traditional IETF April Fools' jokes, in RFC 2324, Hyper Text Coffee Pot Control Protocol,
* and is not expected to be implemented by actual HTTP servers. The RFC specifies this code should be returned by
* teapots requested to brew coffee. This HTTP status is used as an Easter egg in some websites, including Google.com.
*/
I_AM_A_TEAPOT = 418,
/**
* The request was directed at a server that is not able to produce a response (for example because a connection reuse).
*/
MISDIRECTED_REQUEST = 421,
/**
* The request was well-formed but was unable to be followed due to semantic errors.
*/
UNPROCESSABLE_ENTITY = 422,
/**
* The resource that is being accessed is locked.
*/
LOCKED = 423,
/**
* The request failed due to failure of a previous request (e.g., a PROPPATCH).
*/
FAILED_DEPENDENCY = 424,
/**
* The client should switch to a different protocol such as TLS/1.0, given in the Upgrade header field.
*/
UPGRADE_REQUIRED = 426,
/**
* The origin server requires the request to be conditional.
* Intended to prevent "the 'lost update' problem, where a client
* GETs a resource's state, modifies it, and PUTs it back to the server,
* when meanwhile a third party has modified the state on the server, leading to a conflict."
*/
PRECONDITION_REQUIRED = 428,
/**
* The user has sent too many requests in a given amount of time. Intended for use with rate-limiting schemes.
*/
TOO_MANY_REQUESTS = 429,
/**
* The server is unwilling to process the request because either an individual header field,
* or all the header fields collectively, are too large.
*/
REQUEST_HEADER_FIELDS_TOO_LARGE = 431,
/**
* A server operator has received a legal demand to deny access to a resource or to a set of resources
* that includes the requested resource. The code 451 was chosen as a reference to the novel Fahrenheit 451.
*/
UNAVAILABLE_FOR_LEGAL_REASONS = 451,
/**
* A generic error message, given when an unexpected condition was encountered and no more specific message is suitable.
*/
INTERNAL_SERVER_ERROR = 500,
/**
* The server either does not recognize the request method, or it lacks the ability to fulfill the request.
* Usually this implies future availability (e.g., a new feature of a web-service API).
*/
NOT_IMPLEMENTED = 501,
/**
* The server was acting as a gateway or proxy and received an invalid response from the upstream server.
*/
BAD_GATEWAY = 502,
/**
* The server is currently unavailable (because it is overloaded or down for maintenance).
* Generally, this is a temporary state.
*/
SERVICE_UNAVAILABLE = 503,
/**
* The server was acting as a gateway or proxy and did not receive a timely response from the upstream server.
*/
GATEWAY_TIMEOUT = 504,
/**
* The server does not support the HTTP protocol version used in the request
*/
HTTP_VERSION_NOT_SUPPORTED = 505,
/**
* Transparent content negotiation for the request results in a circular reference.
*/
VARIANT_ALSO_NEGOTIATES = 506,
/**
* The server is unable to store the representation needed to complete the request.
*/
INSUFFICIENT_STORAGE = 507,
/**
* The server detected an infinite loop while processing the request.
*/
LOOP_DETECTED = 508,
/**
* Further extensions to the request are required for the server to fulfill it.
*/
NOT_EXTENDED = 510,
/**
* The client needs to authenticate to gain network access.
* Intended for use by intercepting proxies used to control access to the network (e.g., "captive portals" used
* to require agreement to Terms of Service before granting full Internet access via a Wi-Fi hotspot).
*/
NETWORK_AUTHENTICATION_REQUIRED = 511,
}
export default HttpStatus;

View file

@ -0,0 +1,19 @@
import { RequestWithUser } from "../middlewares/user";
import HttpStatus from "./http-status";
import { addLogSequence } from "./utils";
class HttpSuccess {
/**
* HTTP Status Code
*/
status: HttpStatus;
message: string;
result?: any;
constructor(result?: any) {
this.status = HttpStatus.OK;
this.message = "สำเร็จ";
this.result = result;
}
}
export default HttpSuccess;

View file

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

View file

@ -0,0 +1,39 @@
export interface StorageFolder {
/**
* @prop Full path to this folder. It is used as key as there are no files or directories at the same location.
*/
pathname: string;
/**
* @prop Directory / Folder name.
*/
name: string;
createdAt: string | Date;
createdBy: string | Date;
}
export interface StorageFile {
/**
* @prop Full path to this folder. It is used as key as there are no files or directories at the same location.
*/
pathname: string;
fileName: string;
fileSize: number;
fileType: string;
title: string;
description: string;
author: string;
category: string[];
keyword: string[];
metadata: Record<string, unknown>;
path: string;
upload: boolean;
updatedAt: string | Date;
updatedBy: string;
createdAt: string | Date;
createdBy: string;
}

37
src/interfaces/utils.ts Normal file
View file

@ -0,0 +1,37 @@
import { RequestWithUser } from "../middlewares/user";
export type DataDiff = {
before: any;
after: any;
};
export type LogSequence = {
action: string;
status: "success" | "error";
description: string;
query?: any;
request?: {
method?: "GET" | "POST" | "PUT" | "DELETE" | "PATCH";
url?: string;
payload?: string;
response?: string;
};
};
export function setLogDataDiff(req: RequestWithUser, data: DataDiff) {
req.app.locals.logData.dataDiff = {
before: JSON.stringify(data.before),
after: JSON.stringify(data.after),
};
}
export function addLogSequence(req: RequestWithUser, data: LogSequence) {
if (!req?.app?.locals?.logData?.sequence) {
req.app.locals.logData.sequence = [];
}
req.app.locals.logData.sequence = req.app.locals.logData.sequence.concat(data);
}
export function editLogSequence(req: RequestWithUser, index: number, data: LogSequence) {
req.app.locals.logData.sequence[index] = data;
}

View file

@ -0,0 +1,14 @@
import { MigrationInterface, QueryRunner } from "typeorm";
export class Start1707895706666 implements MigrationInterface {
name = 'Start1707895706666'
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`CREATE TABLE \`entity_base\` (\`id\` varchar(36) NOT NULL, \`createdAt\` datetime(6) NOT NULL COMMENT 'สร้างข้อมูลเมื่อ' DEFAULT CURRENT_TIMESTAMP(6), \`createdUserId\` varchar(40) NOT NULL COMMENT 'User Id ที่สร้างข้อมูล' DEFAULT '00000000-0000-0000-0000-000000000000', \`lastUpdatedAt\` datetime(6) NOT NULL COMMENT 'แก้ไขข้อมูลล่าสุดเมื่อ' DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6), \`lastUpdateUserId\` varchar(40) NOT NULL COMMENT 'User Id ที่แก้ไขข้อมูล' DEFAULT '00000000-0000-0000-0000-000000000000', \`createdFullName\` varchar(200) NOT NULL COMMENT 'ชื่อ User ที่สร้างข้อมูล' DEFAULT 'string', \`lastUpdateFullName\` varchar(200) NOT NULL COMMENT 'ชื่อ User ที่แก้ไขข้อมูลล่าสุด' DEFAULT 'string', PRIMARY KEY (\`id\`)) ENGINE=InnoDB`);
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`DROP TABLE \`entity_base\``);
}
}

88
src/middlewares/auth.ts Normal file
View file

@ -0,0 +1,88 @@
import * as express from "express";
import { createDecoder, createVerifier } from "fast-jwt";
import HttpError from "../interfaces/http-error";
import HttpStatus from "../interfaces/http-status";
import { addLogSequence } from "../interfaces/utils";
import { RequestWithUser } from "./user";
if (!process.env.AUTH_PUBLIC_KEY && !process.env.AUTH_REALM_URL) {
throw new Error("Require keycloak AUTH_PUBLIC_KEY or AUTH_REALM_URL.");
}
if (process.env.AUTH_PUBLIC_KEY && process.env.AUTH_REALM_URL && !process.env.AUTH_PREFERRED_MODE) {
throw new Error(
"AUTH_PREFFERRED must be specified if AUTH_PUBLIC_KEY and AUTH_REALM_URL is provided.",
);
}
const jwtVerify = createVerifier({
key: async () => {
return `-----BEGIN PUBLIC KEY-----\n${process.env.AUTH_PUBLIC_KEY}\n-----END PUBLIC KEY-----`;
},
});
const jwtDecode = createDecoder();
export async function expressAuthentication(
request: RequestWithUser,
securityName: string,
_scopes?: string[],
) {
if (process.env.NODE_ENV !== "production" && process.env.AUTH_BYPASS) {
return { preferred_username: "bypassed" };
}
if (securityName !== "bearerAuth") throw new Error("ไม่ทราบวิธีการยืนยันตัวตน");
const token = request.headers["authorization"]?.includes("Bearer ")
? request.headers["authorization"].split(" ")[1]
: request.headers["authorization"];
if (!token) throw new HttpError(HttpStatus.UNAUTHORIZED, "ไม่พบข้อมูลสำหรับยืนยันตัวตน");
let payload: Record<string, any> = {};
switch (process.env.AUTH_PREFERRED_MODE) {
case "online":
payload = await verifyOnline(token);
break;
case "offline":
payload = await verifyOffline(token);
break;
default:
if (process.env.AUTH_REALM_URL) payload = await verifyOnline(token);
if (process.env.AUTH_PUBLIC_KEY) payload = await verifyOffline(token);
break;
}
if (!request.app.locals.logData) {
request.app.locals.logData = {};
}
// addLogSequence(request, {
// action: "database",
// status: "success",
// description: "Query Data.",
// });
request.app.locals.logData.userId = payload.sub;
request.app.locals.logData.userName = payload.name;
request.app.locals.logData.user = payload.preferred_username;
return payload;
}
async function verifyOffline(token: string) {
const payload = await jwtVerify(token).catch((_) => null);
if (!payload) throw new HttpError(HttpStatus.UNAUTHORIZED, "ไม่สามารถยืนยันตัวตนได้");
return payload;
}
async function verifyOnline(token: string) {
const res = await fetch(`${process.env.AUTH_REALM_URL}/protocol/openid-connect/userinfo`, {
headers: { authorization: `Bearer ${token}` },
}).catch((e) => console.error(e));
if (!res) throw new Error("ไม่สามารถเข้าถึงระบบยืนยันตัวตน");
if (!res.ok) throw new HttpError(HttpStatus.UNAUTHORIZED, "ไม่สามารถยืนยันตัวตนได้");
return await jwtDecode(token);
}

36
src/middlewares/error.ts Normal file
View file

@ -0,0 +1,36 @@
import { NextFunction, Request, Response } from "express";
import HttpError from "../interfaces/http-error";
import HttpStatus from "../interfaces/http-status";
import { ValidateError } from "tsoa";
function error(error: Error, _req: Request, res: Response, _next: NextFunction) {
const logData = _req.app.locals.logData.sequence?.at(-1);
if (logData) {
logData.status = "error";
logData.description = error.message;
}
if (error instanceof HttpError) {
return res.status(error.status).json({
status: error.status,
message: error.message,
});
}
if (error instanceof ValidateError) {
return res.status(error.status).json({
status: HttpStatus.UNPROCESSABLE_ENTITY,
message: "Validation error(s).",
detail: error.fields,
});
}
console.error("Exception Caught:" + error);
return res.status(HttpStatus.INTERNAL_SERVER_ERROR).json({
status: HttpStatus.INTERNAL_SERVER_ERROR,
message: error.message,
});
}
export default error;

80
src/middlewares/logs.ts Normal file
View file

@ -0,0 +1,80 @@
import { NextFunction, Request, Response } from "express";
import { Client } from "@elastic/elasticsearch";
import permission from "../interfaces/permission";
if (!process.env.ELASTICSEARCH_INDEX) {
throw new Error("Require ELASTICSEARCH_INDEX to store log.");
}
const ELASTICSEARCH_INDEX = process.env.ELASTICSEARCH_INDEX;
const LOG_LEVEL_MAP: Record<string, number> = {
debug: 4,
info: 3,
warning: 2,
error: 1,
none: 0,
};
const elasticsearch = new Client({
node: `${process.env.ELASTICSEARCH_PROTOCOL}://${process.env.ELASTICSEARCH_HOST}:${process.env.ELASTICSEARCH_PORT}`,
});
async function logMiddleware(req: Request, res: Response, next: NextFunction) {
if (!req.url.startsWith("/api/")) return next();
let data: any;
const originalJson = res.json;
res.json = function (v: any) {
data = v;
return originalJson.call(this, v);
};
const timestamp = new Date().toISOString();
const start = performance.now();
req.app.locals.logData = {};
res.on("finish", async () => {
if (!req.url.startsWith("/api/")) return;
const level = LOG_LEVEL_MAP[process.env.LOG_LEVEL ?? "debug"] || 4;
if (level === 1 && res.statusCode < 500) return;
if (level === 2 && res.statusCode < 400) return;
if (level === 3 && res.statusCode < 200) return;
let token: any;
token = req.headers['authorization']
const rootId = await new permission().checkOrg(token,req.app.locals.logData.userId);
const obj = {
logType: res.statusCode >= 500 ? "error" : res.statusCode >= 400 ? "warning" : "info",
ip: req.ip,
rootId: rootId?rootId.orgRootId:null,
systemName: "evaluation",
startTimeStamp: timestamp,
endTimeStamp: new Date().toISOString(),
processTime: performance.now() - start,
host: req.hostname,
method: req.method,
endpoint: req.url,
responseCode: String(res.statusCode === 304 ? 200 : res.statusCode),
responseDescription: data?.message,
input: (level === 4 && JSON.stringify(req.body, null, 2)) || undefined,
output: (level === 4 && JSON.stringify(data, null, 2)) || undefined,
...req.app.locals.logData,
};
elasticsearch.index({
index: ELASTICSEARCH_INDEX,
document: obj,
});
});
return next();
}
export default logMiddleware;

13
src/middlewares/user.ts Normal file
View file

@ -0,0 +1,13 @@
import type { Request } from "express";
export type RequestWithUser = Request & {
user: {
sub: string;
name: string;
given_name: string;
familiy_name: string;
preferred_username: string;
email: string;
role: string[];
};
};

File diff suppressed because one or more lines are too long

View file

@ -0,0 +1,61 @@
import { MigrationInterface, QueryRunner } from "typeorm";
export class UpdateTableEvaluateAddDatePrepareDoc231703317318791 implements MigrationInterface {
name = "UpdateTableEvaluateAddDatePrepareDoc231703317318791";
public async up(queryRunner: QueryRunner): Promise<void> {
// await queryRunner.query(`CREATE TABLE \`entity_base\` (\`id\` varchar(36) NOT NULL, \`createdAt\` datetime(6) NOT NULL COMMENT 'สร้างข้อมูลเมื่อ' DEFAULT CURRENT_TIMESTAMP(6), \`createdUserId\` varchar(40) NOT NULL COMMENT 'User Id ที่สร้างข้อมูล' DEFAULT '00000000-0000-0000-0000-000000000000', \`lastUpdatedAt\` datetime(6) NOT NULL COMMENT 'แก้ไขข้อมูลล่าสุดเมื่อ' DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6), \`lastUpdateUserId\` varchar(40) NOT NULL COMMENT 'User Id ที่แก้ไขข้อมูล' DEFAULT '00000000-0000-0000-0000-000000000000', \`createdFullName\` varchar(200) NOT NULL COMMENT 'ชื่อ User ที่สร้างข้อมูล' DEFAULT 'string', \`lastUpdateFullName\` varchar(200) NOT NULL COMMENT 'ชื่อ User ที่แก้ไขข้อมูลล่าสุด' DEFAULT 'string', PRIMARY KEY (\`id\`)) ENGINE=InnoDB`);
await queryRunner.query(
`ALTER TABLE \`evaluation\` CHANGE \`commanderFullname\` \`commanderFullname\` varchar(255) NOT NULL COMMENT 'ชื่อ-นามสกุล ผู้บังคับบัญชาชั้นต้น' DEFAULT ''`,
);
await queryRunner.query(
`ALTER TABLE \`evaluation\` CHANGE \`commanderPosition\` \`commanderPosition\` varchar(255) NOT NULL COMMENT 'ตำแหน่ง ผู้บังคับบัญชาชั้นต้น' DEFAULT ''`,
);
await queryRunner.query(
`ALTER TABLE \`evaluation\` CHANGE \`commanderAboveFullname\` \`commanderAboveFullname\` varchar(255) NOT NULL COMMENT 'ชื่อ-นามสกุล ผู้บังคับบัญชาเหนือขึ้นไป 1 ระดับ' DEFAULT ''`,
);
await queryRunner.query(
`ALTER TABLE \`evaluation\` CHANGE \`commanderAbovePosition\` \`commanderAbovePosition\` varchar(255) NOT NULL COMMENT 'ตำแหน่ง ผู้บังคับบัญชาเหนือขึ้นไป 1 ระดับ' DEFAULT ''`,
);
await queryRunner.query(
`ALTER TABLE \`evaluation\` CHANGE \`commanderFullnameDoc2\` \`commanderFullnameDoc2\` varchar(255) NOT NULL COMMENT 'ชื่อ-นามสกุล ผู้บังคับบัญชาชั้นต้น (จัดเตรียมเอกสารเล่ม 2)' DEFAULT ''`,
);
await queryRunner.query(
`ALTER TABLE \`evaluation\` CHANGE \`commanderPositionDoc2\` \`commanderPositionDoc2\` varchar(255) NOT NULL COMMENT 'ตำแหน่ง ผู้บังคับบัญชาชั้นต้น (จัดเตรียมเอกสารเล่ม 2)' DEFAULT ''`,
);
await queryRunner.query(
`ALTER TABLE \`evaluation\` CHANGE \`commanderAboveFullnameDoc2\` \`commanderAboveFullnameDoc2\` varchar(255) NOT NULL COMMENT 'ชื่อ-นามสกุล ผู้บังคับบัญชาเหนือขึ้นไป 1 ระดับ (จัดเตรียมเอกสารเล่ม 2)' DEFAULT ''`,
);
await queryRunner.query(
`ALTER TABLE \`evaluation\` CHANGE \`commanderAbovePositionDoc2\` \`commanderAbovePositionDoc2\` varchar(255) NOT NULL COMMENT 'ตำแหน่ง ผู้บังคับบัญชาเหนือขึ้นไป 1 ระดับ (จัดเตรียมเอกสารเล่ม 2)' DEFAULT ''`,
);
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`ALTER TABLE \`evaluation\` CHANGE \`commanderAbovePositionDoc2\` \`commanderAbovePositionDoc2\` varchar(255) NOT NULL COMMENT 'ตำแหน่ง ผู้บังคับบัญชาเหนือขึ้นไป 1 ระดับ (จัดเตรียมเอกสารเล่ม 2)' DEFAULT 'string'`,
);
await queryRunner.query(
`ALTER TABLE \`evaluation\` CHANGE \`commanderAboveFullnameDoc2\` \`commanderAboveFullnameDoc2\` varchar(255) NOT NULL COMMENT 'ชื่อ-นามสกุล ผู้บังคับบัญชาเหนือขึ้นไป 1 ระดับ (จัดเตรียมเอกสารเล่ม 2)' DEFAULT 'string'`,
);
await queryRunner.query(
`ALTER TABLE \`evaluation\` CHANGE \`commanderPositionDoc2\` \`commanderPositionDoc2\` varchar(255) NOT NULL COMMENT 'ตำแหน่ง ผู้บังคับบัญชาชั้นต้น (จัดเตรียมเอกสารเล่ม 2)' DEFAULT 'string'`,
);
await queryRunner.query(
`ALTER TABLE \`evaluation\` CHANGE \`commanderFullnameDoc2\` \`commanderFullnameDoc2\` varchar(255) NOT NULL COMMENT 'ชื่อ-นามสกุล ผู้บังคับบัญชาชั้นต้น (จัดเตรียมเอกสารเล่ม 2)' DEFAULT 'string'`,
);
await queryRunner.query(
`ALTER TABLE \`evaluation\` CHANGE \`commanderAbovePosition\` \`commanderAbovePosition\` varchar(255) NOT NULL COMMENT 'ตำแหน่ง ผู้บังคับบัญชาเหนือขึ้นไป 1 ระดับ' DEFAULT 'string'`,
);
await queryRunner.query(
`ALTER TABLE \`evaluation\` CHANGE \`commanderAboveFullname\` \`commanderAboveFullname\` varchar(255) NOT NULL COMMENT 'ชื่อ-นามสกุล ผู้บังคับบัญชาเหนือขึ้นไป 1 ระดับ' DEFAULT 'string'`,
);
await queryRunner.query(
`ALTER TABLE \`evaluation\` CHANGE \`commanderPosition\` \`commanderPosition\` varchar(255) NOT NULL COMMENT 'ตำแหน่ง ผู้บังคับบัญชาชั้นต้น' DEFAULT 'string'`,
);
await queryRunner.query(
`ALTER TABLE \`evaluation\` CHANGE \`commanderFullname\` \`commanderFullname\` varchar(255) NOT NULL COMMENT 'ชื่อ-นามสกุล ผู้บังคับบัญชาชั้นต้น' DEFAULT 'string'`,
);
// await queryRunner.query(`DROP TABLE \`entity_base\``);
}
}

View file

@ -0,0 +1,145 @@
import { MigrationInterface, QueryRunner } from "typeorm";
export class UpdateTableEvaluateAddDatePrepareDoc241703317358364 implements MigrationInterface {
name = "UpdateTableEvaluateAddDatePrepareDoc241703317358364";
public async up(queryRunner: QueryRunner): Promise<void> {
// await queryRunner.query(`CREATE TABLE \`entity_base\` (\`id\` varchar(36) NOT NULL, \`createdAt\` datetime(6) NOT NULL COMMENT 'สร้างข้อมูลเมื่อ' DEFAULT CURRENT_TIMESTAMP(6), \`createdUserId\` varchar(40) NOT NULL COMMENT 'User Id ที่สร้างข้อมูล' DEFAULT '00000000-0000-0000-0000-000000000000', \`lastUpdatedAt\` datetime(6) NOT NULL COMMENT 'แก้ไขข้อมูลล่าสุดเมื่อ' DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6), \`lastUpdateUserId\` varchar(40) NOT NULL COMMENT 'User Id ที่แก้ไขข้อมูล' DEFAULT '00000000-0000-0000-0000-000000000000', \`createdFullName\` varchar(200) NOT NULL COMMENT 'ชื่อ User ที่สร้างข้อมูล' DEFAULT 'string', \`lastUpdateFullName\` varchar(200) NOT NULL COMMENT 'ชื่อ User ที่แก้ไขข้อมูลล่าสุด' DEFAULT 'string', PRIMARY KEY (\`id\`)) ENGINE=InnoDB`);
await queryRunner.query(
`ALTER TABLE \`evaluation\` CHANGE \`citizenId\` \`citizenId\` varchar(13) NOT NULL COMMENT 'รหัสบัตรประชาชน' DEFAULT ''`,
);
await queryRunner.query(
`ALTER TABLE \`evaluation\` CHANGE \`prefix\` \`prefix\` varchar(255) NOT NULL COMMENT 'คำนำหน้า' DEFAULT ''`,
);
await queryRunner.query(
`ALTER TABLE \`evaluation\` CHANGE \`fullName\` \`fullName\` varchar(255) NOT NULL COMMENT 'ชื่อ นามสกุล' DEFAULT ''`,
);
await queryRunner.query(
`ALTER TABLE \`evaluation\` CHANGE \`position\` \`position\` varchar(255) NOT NULL COMMENT 'ตำแหน่ง' DEFAULT ''`,
);
await queryRunner.query(
`ALTER TABLE \`evaluation\` CHANGE \`oc\` \`oc\` varchar(255) NOT NULL COMMENT 'สังกัด' DEFAULT ''`,
);
await queryRunner.query(
`ALTER TABLE \`evaluation\` CHANGE \`salary\` \`salary\` varchar(255) NOT NULL COMMENT 'เงินเดือนปัจจุบัน' DEFAULT ''`,
);
await queryRunner.query(
`ALTER TABLE \`evaluation\` CHANGE \`positionLevel\` \`positionLevel\` varchar(255) NOT NULL COMMENT 'ระดับปัจจุบัน' DEFAULT ''`,
);
await queryRunner.query(
`ALTER TABLE \`evaluation\` CHANGE \`posNo\` \`posNo\` varchar(255) NOT NULL COMMENT 'ตำแหน่งเลขที่' DEFAULT ''`,
);
await queryRunner.query(
`ALTER TABLE \`evaluation\` CHANGE \`birthDate\` \`birthDate\` varchar(255) NOT NULL COMMENT 'วันเดือนปีเกิด' DEFAULT ''`,
);
await queryRunner.query(
`ALTER TABLE \`evaluation\` CHANGE \`govAge\` \`govAge\` varchar(255) NOT NULL COMMENT 'อายุราชการ' DEFAULT ''`,
);
await queryRunner.query(
`ALTER TABLE \`evaluation\` CHANGE \`type\` \`type\` varchar(255) NOT NULL COMMENT 'ประเภทแบบประเมิน' DEFAULT ''`,
);
await queryRunner.query(
`ALTER TABLE \`evaluation\` CHANGE \`step\` \`step\` varchar(255) NOT NULL COMMENT 'ชื่อสถานะการประเมิน' DEFAULT ''`,
);
await queryRunner.query(
`ALTER TABLE \`evaluation\` CHANGE \`reason\` \`reason\` varchar(255) NOT NULL COMMENT 'เหตุผล' DEFAULT ''`,
);
await queryRunner.query(
`ALTER TABLE \`evaluation\` CHANGE \`experience\` \`experience\` varchar(255) NOT NULL COMMENT 'ประสบการณ์ในการปฏิบัติงาน' DEFAULT ''`,
);
await queryRunner.query(
`ALTER TABLE \`evaluation\` CHANGE \`commanderFullname\` \`commanderFullname\` varchar(255) NOT NULL COMMENT 'ชื่อ-นามสกุล ผู้บังคับบัญชาชั้นต้น' DEFAULT ''`,
);
await queryRunner.query(
`ALTER TABLE \`evaluation\` CHANGE \`commanderPosition\` \`commanderPosition\` varchar(255) NOT NULL COMMENT 'ตำแหน่ง ผู้บังคับบัญชาชั้นต้น' DEFAULT ''`,
);
await queryRunner.query(
`ALTER TABLE \`evaluation\` CHANGE \`commanderAboveFullname\` \`commanderAboveFullname\` varchar(255) NOT NULL COMMENT 'ชื่อ-นามสกุล ผู้บังคับบัญชาเหนือขึ้นไป 1 ระดับ' DEFAULT ''`,
);
await queryRunner.query(
`ALTER TABLE \`evaluation\` CHANGE \`commanderAbovePosition\` \`commanderAbovePosition\` varchar(255) NOT NULL COMMENT 'ตำแหน่ง ผู้บังคับบัญชาเหนือขึ้นไป 1 ระดับ' DEFAULT ''`,
);
await queryRunner.query(
`ALTER TABLE \`evaluation\` CHANGE \`commanderFullnameDoc2\` \`commanderFullnameDoc2\` varchar(255) NOT NULL COMMENT 'ชื่อ-นามสกุล ผู้บังคับบัญชาชั้นต้น (จัดเตรียมเอกสารเล่ม 2)' DEFAULT ''`,
);
await queryRunner.query(
`ALTER TABLE \`evaluation\` CHANGE \`commanderPositionDoc2\` \`commanderPositionDoc2\` varchar(255) NOT NULL COMMENT 'ตำแหน่ง ผู้บังคับบัญชาชั้นต้น (จัดเตรียมเอกสารเล่ม 2)' DEFAULT ''`,
);
await queryRunner.query(
`ALTER TABLE \`evaluation\` CHANGE \`commanderAboveFullnameDoc2\` \`commanderAboveFullnameDoc2\` varchar(255) NOT NULL COMMENT 'ชื่อ-นามสกุล ผู้บังคับบัญชาเหนือขึ้นไป 1 ระดับ (จัดเตรียมเอกสารเล่ม 2)' DEFAULT ''`,
);
await queryRunner.query(
`ALTER TABLE \`evaluation\` CHANGE \`commanderAbovePositionDoc2\` \`commanderAbovePositionDoc2\` varchar(255) NOT NULL COMMENT 'ตำแหน่ง ผู้บังคับบัญชาเหนือขึ้นไป 1 ระดับ (จัดเตรียมเอกสารเล่ม 2)' DEFAULT ''`,
);
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`ALTER TABLE \`evaluation\` CHANGE \`commanderAbovePositionDoc2\` \`commanderAbovePositionDoc2\` varchar(255) NOT NULL COMMENT 'ตำแหน่ง ผู้บังคับบัญชาเหนือขึ้นไป 1 ระดับ (จัดเตรียมเอกสารเล่ม 2)' DEFAULT 'string'`,
);
await queryRunner.query(
`ALTER TABLE \`evaluation\` CHANGE \`commanderAboveFullnameDoc2\` \`commanderAboveFullnameDoc2\` varchar(255) NOT NULL COMMENT 'ชื่อ-นามสกุล ผู้บังคับบัญชาเหนือขึ้นไป 1 ระดับ (จัดเตรียมเอกสารเล่ม 2)' DEFAULT 'string'`,
);
await queryRunner.query(
`ALTER TABLE \`evaluation\` CHANGE \`commanderPositionDoc2\` \`commanderPositionDoc2\` varchar(255) NOT NULL COMMENT 'ตำแหน่ง ผู้บังคับบัญชาชั้นต้น (จัดเตรียมเอกสารเล่ม 2)' DEFAULT 'string'`,
);
await queryRunner.query(
`ALTER TABLE \`evaluation\` CHANGE \`commanderFullnameDoc2\` \`commanderFullnameDoc2\` varchar(255) NOT NULL COMMENT 'ชื่อ-นามสกุล ผู้บังคับบัญชาชั้นต้น (จัดเตรียมเอกสารเล่ม 2)' DEFAULT 'string'`,
);
await queryRunner.query(
`ALTER TABLE \`evaluation\` CHANGE \`commanderAbovePosition\` \`commanderAbovePosition\` varchar(255) NOT NULL COMMENT 'ตำแหน่ง ผู้บังคับบัญชาเหนือขึ้นไป 1 ระดับ' DEFAULT 'string'`,
);
await queryRunner.query(
`ALTER TABLE \`evaluation\` CHANGE \`commanderAboveFullname\` \`commanderAboveFullname\` varchar(255) NOT NULL COMMENT 'ชื่อ-นามสกุล ผู้บังคับบัญชาเหนือขึ้นไป 1 ระดับ' DEFAULT 'string'`,
);
await queryRunner.query(
`ALTER TABLE \`evaluation\` CHANGE \`commanderPosition\` \`commanderPosition\` varchar(255) NOT NULL COMMENT 'ตำแหน่ง ผู้บังคับบัญชาชั้นต้น' DEFAULT 'string'`,
);
await queryRunner.query(
`ALTER TABLE \`evaluation\` CHANGE \`commanderFullname\` \`commanderFullname\` varchar(255) NOT NULL COMMENT 'ชื่อ-นามสกุล ผู้บังคับบัญชาชั้นต้น' DEFAULT 'string'`,
);
await queryRunner.query(
`ALTER TABLE \`evaluation\` CHANGE \`experience\` \`experience\` varchar(255) NOT NULL COMMENT 'ประสบการณ์ในการปฏิบัติงาน' DEFAULT 'string'`,
);
await queryRunner.query(
`ALTER TABLE \`evaluation\` CHANGE \`reason\` \`reason\` varchar(255) NOT NULL COMMENT 'เหตุผล' DEFAULT 'string'`,
);
await queryRunner.query(
`ALTER TABLE \`evaluation\` CHANGE \`step\` \`step\` varchar(255) NOT NULL COMMENT 'ชื่อสถานะการประเมิน' DEFAULT 'string'`,
);
await queryRunner.query(
`ALTER TABLE \`evaluation\` CHANGE \`type\` \`type\` varchar(255) NOT NULL COMMENT 'ประเภทแบบประเมิน' DEFAULT 'string'`,
);
await queryRunner.query(
`ALTER TABLE \`evaluation\` CHANGE \`govAge\` \`govAge\` varchar(255) NOT NULL COMMENT 'อายุราชการ' DEFAULT 'string'`,
);
await queryRunner.query(
`ALTER TABLE \`evaluation\` CHANGE \`birthDate\` \`birthDate\` varchar(255) NOT NULL COMMENT 'วันเดือนปีเกิด' DEFAULT 'string'`,
);
await queryRunner.query(
`ALTER TABLE \`evaluation\` CHANGE \`posNo\` \`posNo\` varchar(255) NOT NULL COMMENT 'ตำแหน่งเลขที่' DEFAULT 'string'`,
);
await queryRunner.query(
`ALTER TABLE \`evaluation\` CHANGE \`positionLevel\` \`positionLevel\` varchar(255) NOT NULL COMMENT 'ระดับปัจจุบัน' DEFAULT 'string'`,
);
await queryRunner.query(
`ALTER TABLE \`evaluation\` CHANGE \`salary\` \`salary\` varchar(255) NOT NULL COMMENT 'เงินเดือนปัจจุบัน' DEFAULT 'string'`,
);
await queryRunner.query(
`ALTER TABLE \`evaluation\` CHANGE \`oc\` \`oc\` varchar(255) NOT NULL COMMENT 'สังกัด' DEFAULT 'string'`,
);
await queryRunner.query(
`ALTER TABLE \`evaluation\` CHANGE \`position\` \`position\` varchar(255) NOT NULL COMMENT 'ตำแหน่ง' DEFAULT 'string'`,
);
await queryRunner.query(
`ALTER TABLE \`evaluation\` CHANGE \`fullName\` \`fullName\` varchar(255) NOT NULL COMMENT 'ชื่อ นามสกุล' DEFAULT 'string'`,
);
await queryRunner.query(
`ALTER TABLE \`evaluation\` CHANGE \`prefix\` \`prefix\` varchar(255) NOT NULL COMMENT 'คำนำหน้า' DEFAULT 'string'`,
);
await queryRunner.query(
`ALTER TABLE \`evaluation\` CHANGE \`citizenId\` \`citizenId\` varchar(13) NOT NULL COMMENT 'รหัสบัตรประชาชน' DEFAULT 'string'`,
);
// await queryRunner.query(`DROP TABLE \`entity_base\``);
}
}

View file

@ -0,0 +1,56 @@
import { MigrationInterface, QueryRunner } from "typeorm";
export class UpdateTableEvaluateNullType1703326121795 implements MigrationInterface {
name = 'UpdateTableEvaluateNullType1703326121795'
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE \`evaluation\` CHANGE \`citizenId\` \`citizenId\` varchar(13) NULL COMMENT 'รหัสบัตรประชาชน'`);
await queryRunner.query(`ALTER TABLE \`evaluation\` CHANGE \`prefix\` \`prefix\` varchar(255) NULL COMMENT 'คำนำหน้า'`);
await queryRunner.query(`ALTER TABLE \`evaluation\` CHANGE \`fullName\` \`fullName\` varchar(255) NULL COMMENT 'ชื่อ นามสกุล'`);
await queryRunner.query(`ALTER TABLE \`evaluation\` CHANGE \`position\` \`position\` varchar(255) NULL COMMENT 'ตำแหน่ง'`);
await queryRunner.query(`ALTER TABLE \`evaluation\` CHANGE \`oc\` \`oc\` varchar(255) NULL COMMENT 'สังกัด'`);
await queryRunner.query(`ALTER TABLE \`evaluation\` CHANGE \`salary\` \`salary\` varchar(255) NULL COMMENT 'เงินเดือนปัจจุบัน'`);
await queryRunner.query(`ALTER TABLE \`evaluation\` CHANGE \`positionLevel\` \`positionLevel\` varchar(255) NULL COMMENT 'ระดับปัจจุบัน'`);
await queryRunner.query(`ALTER TABLE \`evaluation\` CHANGE \`posNo\` \`posNo\` varchar(255) NULL COMMENT 'ตำแหน่งเลขที่'`);
await queryRunner.query(`ALTER TABLE \`evaluation\` CHANGE \`birthDate\` \`birthDate\` varchar(255) NULL COMMENT 'วันเดือนปีเกิด'`);
await queryRunner.query(`ALTER TABLE \`evaluation\` CHANGE \`govAge\` \`govAge\` varchar(255) NULL COMMENT 'อายุราชการ'`);
await queryRunner.query(`ALTER TABLE \`evaluation\` CHANGE \`type\` \`type\` varchar(255) NULL COMMENT 'ประเภทแบบประเมิน'`);
await queryRunner.query(`ALTER TABLE \`evaluation\` CHANGE \`step\` \`step\` varchar(255) NULL COMMENT 'ชื่อสถานะการประเมิน'`);
await queryRunner.query(`ALTER TABLE \`evaluation\` CHANGE \`reason\` \`reason\` varchar(255) NULL COMMENT 'เหตุผล'`);
await queryRunner.query(`ALTER TABLE \`evaluation\` CHANGE \`experience\` \`experience\` varchar(255) NULL COMMENT 'ประสบการณ์ในการปฏิบัติงาน'`);
await queryRunner.query(`ALTER TABLE \`evaluation\` CHANGE \`commanderFullname\` \`commanderFullname\` varchar(255) NULL COMMENT 'ชื่อ-นามสกุล ผู้บังคับบัญชาชั้นต้น'`);
await queryRunner.query(`ALTER TABLE \`evaluation\` CHANGE \`commanderPosition\` \`commanderPosition\` varchar(255) NULL COMMENT 'ตำแหน่ง ผู้บังคับบัญชาชั้นต้น'`);
await queryRunner.query(`ALTER TABLE \`evaluation\` CHANGE \`commanderAboveFullname\` \`commanderAboveFullname\` varchar(255) NULL COMMENT 'ชื่อ-นามสกุล ผู้บังคับบัญชาเหนือขึ้นไป 1 ระดับ'`);
await queryRunner.query(`ALTER TABLE \`evaluation\` CHANGE \`commanderAbovePosition\` \`commanderAbovePosition\` varchar(255) NULL COMMENT 'ตำแหน่ง ผู้บังคับบัญชาเหนือขึ้นไป 1 ระดับ'`);
await queryRunner.query(`ALTER TABLE \`evaluation\` CHANGE \`commanderFullnameDoc2\` \`commanderFullnameDoc2\` varchar(255) NULL COMMENT 'ชื่อ-นามสกุล ผู้บังคับบัญชาชั้นต้น (จัดเตรียมเอกสารเล่ม 2)'`);
await queryRunner.query(`ALTER TABLE \`evaluation\` CHANGE \`commanderPositionDoc2\` \`commanderPositionDoc2\` varchar(255) NULL COMMENT 'ตำแหน่ง ผู้บังคับบัญชาชั้นต้น (จัดเตรียมเอกสารเล่ม 2)'`);
await queryRunner.query(`ALTER TABLE \`evaluation\` CHANGE \`commanderAboveFullnameDoc2\` \`commanderAboveFullnameDoc2\` varchar(255) NULL COMMENT 'ชื่อ-นามสกุล ผู้บังคับบัญชาเหนือขึ้นไป 1 ระดับ (จัดเตรียมเอกสารเล่ม 2)'`);
await queryRunner.query(`ALTER TABLE \`evaluation\` CHANGE \`commanderAbovePositionDoc2\` \`commanderAbovePositionDoc2\` varchar(255) NULL COMMENT 'ตำแหน่ง ผู้บังคับบัญชาเหนือขึ้นไป 1 ระดับ (จัดเตรียมเอกสารเล่ม 2)'`);
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE \`evaluation\` CHANGE \`commanderAbovePositionDoc2\` \`commanderAbovePositionDoc2\` varchar(255) NOT NULL COMMENT 'ตำแหน่ง ผู้บังคับบัญชาเหนือขึ้นไป 1 ระดับ (จัดเตรียมเอกสารเล่ม 2)' DEFAULT ''`);
await queryRunner.query(`ALTER TABLE \`evaluation\` CHANGE \`commanderAboveFullnameDoc2\` \`commanderAboveFullnameDoc2\` varchar(255) NOT NULL COMMENT 'ชื่อ-นามสกุล ผู้บังคับบัญชาเหนือขึ้นไป 1 ระดับ (จัดเตรียมเอกสารเล่ม 2)' DEFAULT ''`);
await queryRunner.query(`ALTER TABLE \`evaluation\` CHANGE \`commanderPositionDoc2\` \`commanderPositionDoc2\` varchar(255) NOT NULL COMMENT 'ตำแหน่ง ผู้บังคับบัญชาชั้นต้น (จัดเตรียมเอกสารเล่ม 2)' DEFAULT ''`);
await queryRunner.query(`ALTER TABLE \`evaluation\` CHANGE \`commanderFullnameDoc2\` \`commanderFullnameDoc2\` varchar(255) NOT NULL COMMENT 'ชื่อ-นามสกุล ผู้บังคับบัญชาชั้นต้น (จัดเตรียมเอกสารเล่ม 2)' DEFAULT ''`);
await queryRunner.query(`ALTER TABLE \`evaluation\` CHANGE \`commanderAbovePosition\` \`commanderAbovePosition\` varchar(255) NOT NULL COMMENT 'ตำแหน่ง ผู้บังคับบัญชาเหนือขึ้นไป 1 ระดับ' DEFAULT ''`);
await queryRunner.query(`ALTER TABLE \`evaluation\` CHANGE \`commanderAboveFullname\` \`commanderAboveFullname\` varchar(255) NOT NULL COMMENT 'ชื่อ-นามสกุล ผู้บังคับบัญชาเหนือขึ้นไป 1 ระดับ' DEFAULT ''`);
await queryRunner.query(`ALTER TABLE \`evaluation\` CHANGE \`commanderPosition\` \`commanderPosition\` varchar(255) NOT NULL COMMENT 'ตำแหน่ง ผู้บังคับบัญชาชั้นต้น' DEFAULT ''`);
await queryRunner.query(`ALTER TABLE \`evaluation\` CHANGE \`commanderFullname\` \`commanderFullname\` varchar(255) NOT NULL COMMENT 'ชื่อ-นามสกุล ผู้บังคับบัญชาชั้นต้น' DEFAULT ''`);
await queryRunner.query(`ALTER TABLE \`evaluation\` CHANGE \`experience\` \`experience\` varchar(255) NOT NULL COMMENT 'ประสบการณ์ในการปฏิบัติงาน' DEFAULT ''`);
await queryRunner.query(`ALTER TABLE \`evaluation\` CHANGE \`reason\` \`reason\` varchar(255) NOT NULL COMMENT 'เหตุผล' DEFAULT ''`);
await queryRunner.query(`ALTER TABLE \`evaluation\` CHANGE \`step\` \`step\` varchar(255) NOT NULL COMMENT 'ชื่อสถานะการประเมิน' DEFAULT ''`);
await queryRunner.query(`ALTER TABLE \`evaluation\` CHANGE \`type\` \`type\` varchar(255) NOT NULL COMMENT 'ประเภทแบบประเมิน' DEFAULT ''`);
await queryRunner.query(`ALTER TABLE \`evaluation\` CHANGE \`govAge\` \`govAge\` varchar(255) NOT NULL COMMENT 'อายุราชการ' DEFAULT ''`);
await queryRunner.query(`ALTER TABLE \`evaluation\` CHANGE \`birthDate\` \`birthDate\` varchar(255) NOT NULL COMMENT 'วันเดือนปีเกิด' DEFAULT ''`);
await queryRunner.query(`ALTER TABLE \`evaluation\` CHANGE \`posNo\` \`posNo\` varchar(255) NOT NULL COMMENT 'ตำแหน่งเลขที่' DEFAULT ''`);
await queryRunner.query(`ALTER TABLE \`evaluation\` CHANGE \`positionLevel\` \`positionLevel\` varchar(255) NOT NULL COMMENT 'ระดับปัจจุบัน' DEFAULT ''`);
await queryRunner.query(`ALTER TABLE \`evaluation\` CHANGE \`salary\` \`salary\` varchar(255) NOT NULL COMMENT 'เงินเดือนปัจจุบัน' DEFAULT ''`);
await queryRunner.query(`ALTER TABLE \`evaluation\` CHANGE \`oc\` \`oc\` varchar(255) NOT NULL COMMENT 'สังกัด' DEFAULT ''`);
await queryRunner.query(`ALTER TABLE \`evaluation\` CHANGE \`position\` \`position\` varchar(255) NOT NULL COMMENT 'ตำแหน่ง' DEFAULT ''`);
await queryRunner.query(`ALTER TABLE \`evaluation\` CHANGE \`fullName\` \`fullName\` varchar(255) NOT NULL COMMENT 'ชื่อ นามสกุล' DEFAULT ''`);
await queryRunner.query(`ALTER TABLE \`evaluation\` CHANGE \`prefix\` \`prefix\` varchar(255) NOT NULL COMMENT 'คำนำหน้า' DEFAULT ''`);
await queryRunner.query(`ALTER TABLE \`evaluation\` CHANGE \`citizenId\` \`citizenId\` varchar(13) NOT NULL COMMENT 'รหัสบัตรประชาชน' DEFAULT ''`);
}
}

View file

@ -0,0 +1,154 @@
import { MigrationInterface, QueryRunner } from "typeorm";
export class UpdateTableEvaluateNullType11703326303281 implements MigrationInterface {
name = 'UpdateTableEvaluateNullType11703326303281'
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE \`education\` CHANGE \`educationLevel\` \`educationLevel\` varchar(255) NULL COMMENT 'ระดับศึกษา'`);
await queryRunner.query(`ALTER TABLE \`education\` CHANGE \`institute\` \`institute\` varchar(255) NULL COMMENT 'สถานศึกษา'`);
await queryRunner.query(`ALTER TABLE \`education\` CHANGE \`isDate\` \`isDate\` tinyint NULL COMMENT 'ประเภทช่วงเวลาการศึกษา'`);
await queryRunner.query(`ALTER TABLE \`education\` CHANGE \`startDate\` \`startDate\` datetime NULL COMMENT 'ตั้งแต่'`);
await queryRunner.query(`ALTER TABLE \`education\` CHANGE \`endDate\` \`endDate\` datetime NULL COMMENT 'EndDate'`);
await queryRunner.query(`ALTER TABLE \`education\` CHANGE \`finishDate\` \`finishDate\` datetime NULL COMMENT 'วันที่สำเร็จการศึกษา'`);
await queryRunner.query(`ALTER TABLE \`education\` CHANGE \`isEducation\` \`isEducation\` tinyint NULL COMMENT 'เป็นวุฒิศึกษาในตำแหน่ง'`);
await queryRunner.query(`ALTER TABLE \`education\` CHANGE \`degree\` \`degree\` varchar(255) NULL COMMENT 'วุฒิการศึกษา'`);
await queryRunner.query(`ALTER TABLE \`education\` CHANGE \`field\` \`field\` varchar(255) NULL COMMENT 'สาขาวิชา/ทาง'`);
await queryRunner.query(`ALTER TABLE \`education\` CHANGE \`fundName\` \`fundName\` varchar(255) NULL COMMENT 'ทุน'`);
await queryRunner.query(`ALTER TABLE \`education\` CHANGE \`gpa\` \`gpa\` varchar(255) NULL COMMENT 'เกรดเฉลี่ย'`);
await queryRunner.query(`ALTER TABLE \`education\` CHANGE \`country\` \`country\` varchar(255) NULL COMMENT 'ประเทศ'`);
await queryRunner.query(`ALTER TABLE \`education\` CHANGE \`other\` \`other\` varchar(255) NULL COMMENT 'ข้อมูลการติดต่อ'`);
await queryRunner.query(`ALTER TABLE \`education\` CHANGE \`duration\` \`duration\` varchar(255) NULL COMMENT 'ระยะเวลา'`);
await queryRunner.query(`ALTER TABLE \`education\` CHANGE \`durationYear\` \`durationYear\` varchar(255) NULL COMMENT 'ระยะเวลาหลักสูตร'`);
await queryRunner.query(`ALTER TABLE \`certificate\` CHANGE \`statictep\` \`statictep\` varchar(255) NULL COMMENT 'ชื่อสถานะการประเมิน'`);
await queryRunner.query(`ALTER TABLE \`certificate\` CHANGE \`certificateType\` \`certificateType\` varchar(255) NULL COMMENT 'ชื่อใบอนุญาต'`);
await queryRunner.query(`ALTER TABLE \`certificate\` CHANGE \`issuer\` \`issuer\` varchar(255) NULL COMMENT 'หน่วยงานผู้ออกใบอนุญาต'`);
await queryRunner.query(`ALTER TABLE \`certificate\` CHANGE \`certificateNo\` \`certificateNo\` varchar(255) NULL COMMENT 'เลขที่ใบอนุญาต'`);
await queryRunner.query(`ALTER TABLE \`certificate\` CHANGE \`issueDate\` \`issueDate\` datetime NULL COMMENT 'วันที่ออกใบอนุญาต'`);
await queryRunner.query(`ALTER TABLE \`certificate\` CHANGE \`expireDate\` \`expireDate\` datetime NULL COMMENT 'วันที่หมดอายุ'`);
await queryRunner.query(`ALTER TABLE \`salary\` CHANGE \`date\` \`date\` datetime NULL COMMENT 'วัน เดือน ปี รับตำแหน่ง'`);
await queryRunner.query(`ALTER TABLE \`salary\` CHANGE \`amount\` \`amount\` double NULL COMMENT 'เงินเดือน'`);
await queryRunner.query(`ALTER TABLE \`salary\` CHANGE \`positionSalaryAmount\` \`positionSalaryAmount\` double NULL COMMENT 'เงินประจำตำแหน่ง'`);
await queryRunner.query(`ALTER TABLE \`salary\` CHANGE \`mouthSalaryAmount\` \`mouthSalaryAmount\` double NULL COMMENT 'เงินค่าตอบแทนรายเดือน'`);
await queryRunner.query(`ALTER TABLE \`salary\` CHANGE \`position\` \`position\` varchar(255) NULL COMMENT 'ตำแหน่ง'`);
await queryRunner.query(`ALTER TABLE \`salary\` CHANGE \`posNo\` \`posNo\` varchar(255) NULL COMMENT 'เลขที่ตำแหน่ง'`);
await queryRunner.query(`ALTER TABLE \`salary\` CHANGE \`salaryClass\` \`salaryClass\` varchar(255) NULL COMMENT 'ตำแหน่ง (รายละเอียด)'`);
await queryRunner.query(`ALTER TABLE \`salary\` CHANGE \`salaryRef\` \`salaryRef\` varchar(255) NULL COMMENT 'เอกสารอ้างอิง'`);
await queryRunner.query(`ALTER TABLE \`salary\` CHANGE \`refCommandNo\` \`refCommandNo\` varchar(255) NULL COMMENT 'เอกสารอ้างอิง (เลขที่คำสั่ง)'`);
await queryRunner.query(`ALTER TABLE \`salary\` CHANGE \`refCommandDate\` \`refCommandDate\` datetime NULL COMMENT 'เอกสารอ้างอิง (ลงวันที่)'`);
await queryRunner.query(`ALTER TABLE \`salary\` CHANGE \`salaryStatus\` \`salaryStatus\` varchar(255) NULL COMMENT 'ประเภทตำแหน่งกรณีพิเศษ'`);
await queryRunner.query(`ALTER TABLE \`training\` CHANGE \`name\` \`name\` varchar(255) NULL COMMENT 'ชื่อโครงการ/หลักสูตรการฝึกอบรม'`);
await queryRunner.query(`ALTER TABLE \`training\` CHANGE \`topic\` \`topic\` varchar(255) NULL COMMENT 'หัวข้อการฝึกอบรม/ดูงาน'`);
await queryRunner.query(`ALTER TABLE \`training\` CHANGE \`startDate\` \`startDate\` datetime NULL COMMENT 'วันเริ่มต้นการฝึกอบรม/ดูงาน'`);
await queryRunner.query(`ALTER TABLE \`training\` CHANGE \`endDate\` \`endDate\` datetime NULL COMMENT 'วันสิ้นสุดการฝึกอบรม/ดูงาน'`);
await queryRunner.query(`ALTER TABLE \`training\` CHANGE \`yearly\` \`yearly\` int NULL COMMENT 'ปีที่อบรม (พ.ศ.)'`);
await queryRunner.query(`ALTER TABLE \`training\` CHANGE \`place\` \`place\` varchar(255) NULL COMMENT 'สถานที่ฝึกอบรม/ดูงาน'`);
await queryRunner.query(`ALTER TABLE \`training\` CHANGE \`duration\` \`duration\` varchar(255) NULL COMMENT 'รวมระยะเวลาในการฝึกอบรม/ดูงาน'`);
await queryRunner.query(`ALTER TABLE \`training\` CHANGE \`department\` \`department\` varchar(255) NULL COMMENT 'หน่วยงานที่รับผิดชอบจัดการฝึกอบรม/ดูงาน'`);
await queryRunner.query(`ALTER TABLE \`training\` CHANGE \`numberOrder\` \`numberOrder\` varchar(255) NULL COMMENT 'เลขที่คำสั่ง/เลขที่หนังสืออนุมัติ'`);
await queryRunner.query(`ALTER TABLE \`training\` CHANGE \`dateOrder\` \`dateOrder\` datetime NULL COMMENT 'คำสั่งลงวันที่/หนังสืออนุมัติลงวันที่'`);
await queryRunner.query(`ALTER TABLE \`evaluation\` CHANGE \`citizenId\` \`citizenId\` varchar(13) NULL COMMENT 'รหัสบัตรประชาชน'`);
await queryRunner.query(`ALTER TABLE \`evaluation\` CHANGE \`prefix\` \`prefix\` varchar(255) NULL COMMENT 'คำนำหน้า'`);
await queryRunner.query(`ALTER TABLE \`evaluation\` CHANGE \`fullName\` \`fullName\` varchar(255) NULL COMMENT 'ชื่อ นามสกุล'`);
await queryRunner.query(`ALTER TABLE \`evaluation\` CHANGE \`position\` \`position\` varchar(255) NULL COMMENT 'ตำแหน่ง'`);
await queryRunner.query(`ALTER TABLE \`evaluation\` CHANGE \`oc\` \`oc\` varchar(255) NULL COMMENT 'สังกัด'`);
await queryRunner.query(`ALTER TABLE \`evaluation\` CHANGE \`salary\` \`salary\` varchar(255) NULL COMMENT 'เงินเดือนปัจจุบัน'`);
await queryRunner.query(`ALTER TABLE \`evaluation\` CHANGE \`positionLevel\` \`positionLevel\` varchar(255) NULL COMMENT 'ระดับปัจจุบัน'`);
await queryRunner.query(`ALTER TABLE \`evaluation\` CHANGE \`posNo\` \`posNo\` varchar(255) NULL COMMENT 'ตำแหน่งเลขที่'`);
await queryRunner.query(`ALTER TABLE \`evaluation\` CHANGE \`birthDate\` \`birthDate\` varchar(255) NULL COMMENT 'วันเดือนปีเกิด'`);
await queryRunner.query(`ALTER TABLE \`evaluation\` CHANGE \`govAge\` \`govAge\` varchar(255) NULL COMMENT 'อายุราชการ'`);
await queryRunner.query(`ALTER TABLE \`evaluation\` CHANGE \`type\` \`type\` varchar(255) NULL COMMENT 'ประเภทแบบประเมิน'`);
await queryRunner.query(`ALTER TABLE \`evaluation\` CHANGE \`step\` \`step\` varchar(255) NULL COMMENT 'ชื่อสถานะการประเมิน'`);
await queryRunner.query(`ALTER TABLE \`evaluation\` CHANGE \`reason\` \`reason\` varchar(255) NULL COMMENT 'เหตุผล'`);
await queryRunner.query(`ALTER TABLE \`evaluation\` CHANGE \`experience\` \`experience\` varchar(255) NULL COMMENT 'ประสบการณ์ในการปฏิบัติงาน'`);
await queryRunner.query(`ALTER TABLE \`evaluation\` CHANGE \`commanderFullname\` \`commanderFullname\` varchar(255) NULL COMMENT 'ชื่อ-นามสกุล ผู้บังคับบัญชาชั้นต้น'`);
await queryRunner.query(`ALTER TABLE \`evaluation\` CHANGE \`commanderPosition\` \`commanderPosition\` varchar(255) NULL COMMENT 'ตำแหน่ง ผู้บังคับบัญชาชั้นต้น'`);
await queryRunner.query(`ALTER TABLE \`evaluation\` CHANGE \`commanderAboveFullname\` \`commanderAboveFullname\` varchar(255) NULL COMMENT 'ชื่อ-นามสกุล ผู้บังคับบัญชาเหนือขึ้นไป 1 ระดับ'`);
await queryRunner.query(`ALTER TABLE \`evaluation\` CHANGE \`commanderAbovePosition\` \`commanderAbovePosition\` varchar(255) NULL COMMENT 'ตำแหน่ง ผู้บังคับบัญชาเหนือขึ้นไป 1 ระดับ'`);
await queryRunner.query(`ALTER TABLE \`evaluation\` CHANGE \`commanderFullnameDoc2\` \`commanderFullnameDoc2\` varchar(255) NULL COMMENT 'ชื่อ-นามสกุล ผู้บังคับบัญชาชั้นต้น (จัดเตรียมเอกสารเล่ม 2)'`);
await queryRunner.query(`ALTER TABLE \`evaluation\` CHANGE \`commanderPositionDoc2\` \`commanderPositionDoc2\` varchar(255) NULL COMMENT 'ตำแหน่ง ผู้บังคับบัญชาชั้นต้น (จัดเตรียมเอกสารเล่ม 2)'`);
await queryRunner.query(`ALTER TABLE \`evaluation\` CHANGE \`commanderAboveFullnameDoc2\` \`commanderAboveFullnameDoc2\` varchar(255) NULL COMMENT 'ชื่อ-นามสกุล ผู้บังคับบัญชาเหนือขึ้นไป 1 ระดับ (จัดเตรียมเอกสารเล่ม 2)'`);
await queryRunner.query(`ALTER TABLE \`evaluation\` CHANGE \`commanderAbovePositionDoc2\` \`commanderAbovePositionDoc2\` varchar(255) NULL COMMENT 'ตำแหน่ง ผู้บังคับบัญชาเหนือขึ้นไป 1 ระดับ (จัดเตรียมเอกสารเล่ม 2)'`);
await queryRunner.query(`ALTER TABLE \`assessment\` CHANGE \`date\` \`date\` datetime NULL COMMENT 'วันที่ได้รับ'`);
await queryRunner.query(`ALTER TABLE \`assessment\` CHANGE \`point1Total\` \`point1Total\` double NULL COMMENT 'ส่วนที่1 (คะแนน)'`);
await queryRunner.query(`ALTER TABLE \`assessment\` CHANGE \`point1\` \`point1\` double NULL COMMENT 'ผลประเมินส่วนที่2 (คะแนน)'`);
await queryRunner.query(`ALTER TABLE \`assessment\` CHANGE \`point2Total\` \`point2Total\` double NULL COMMENT 'ส่วนที่2 (คะแนน)'`);
await queryRunner.query(`ALTER TABLE \`assessment\` CHANGE \`point2\` \`point2\` double NULL COMMENT 'ผลประเมินส่วนที่2 (คะแนน)'`);
await queryRunner.query(`ALTER TABLE \`assessment\` CHANGE \`pointSumTotal\` \`pointSumTotal\` double NULL COMMENT 'ผลรวม (คะแนน)'`);
await queryRunner.query(`ALTER TABLE \`assessment\` CHANGE \`pointSum\` \`pointSum\` double NULL COMMENT 'ผลประเมินรวม (คะแนน)'`);
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE \`assessment\` CHANGE \`pointSum\` \`pointSum\` double NOT NULL COMMENT 'ผลประเมินรวม (คะแนน)' DEFAULT '0'`);
await queryRunner.query(`ALTER TABLE \`assessment\` CHANGE \`pointSumTotal\` \`pointSumTotal\` double NOT NULL COMMENT 'ผลรวม (คะแนน)' DEFAULT '0'`);
await queryRunner.query(`ALTER TABLE \`assessment\` CHANGE \`point2\` \`point2\` double NOT NULL COMMENT 'ผลประเมินส่วนที่2 (คะแนน)' DEFAULT '0'`);
await queryRunner.query(`ALTER TABLE \`assessment\` CHANGE \`point2Total\` \`point2Total\` double NOT NULL COMMENT 'ส่วนที่2 (คะแนน)' DEFAULT '0'`);
await queryRunner.query(`ALTER TABLE \`assessment\` CHANGE \`point1\` \`point1\` double NOT NULL COMMENT 'ผลประเมินส่วนที่2 (คะแนน)' DEFAULT '0'`);
await queryRunner.query(`ALTER TABLE \`assessment\` CHANGE \`point1Total\` \`point1Total\` double NOT NULL COMMENT 'ส่วนที่1 (คะแนน)' DEFAULT '0'`);
await queryRunner.query(`ALTER TABLE \`assessment\` CHANGE \`date\` \`date\` datetime NOT NULL COMMENT 'วันที่ได้รับ'`);
await queryRunner.query(`ALTER TABLE \`evaluation\` CHANGE \`commanderAbovePositionDoc2\` \`commanderAbovePositionDoc2\` varchar(255) NOT NULL COMMENT 'ตำแหน่ง ผู้บังคับบัญชาเหนือขึ้นไป 1 ระดับ (จัดเตรียมเอกสารเล่ม 2)' DEFAULT ''`);
await queryRunner.query(`ALTER TABLE \`evaluation\` CHANGE \`commanderAboveFullnameDoc2\` \`commanderAboveFullnameDoc2\` varchar(255) NOT NULL COMMENT 'ชื่อ-นามสกุล ผู้บังคับบัญชาเหนือขึ้นไป 1 ระดับ (จัดเตรียมเอกสารเล่ม 2)' DEFAULT ''`);
await queryRunner.query(`ALTER TABLE \`evaluation\` CHANGE \`commanderPositionDoc2\` \`commanderPositionDoc2\` varchar(255) NOT NULL COMMENT 'ตำแหน่ง ผู้บังคับบัญชาชั้นต้น (จัดเตรียมเอกสารเล่ม 2)' DEFAULT ''`);
await queryRunner.query(`ALTER TABLE \`evaluation\` CHANGE \`commanderFullnameDoc2\` \`commanderFullnameDoc2\` varchar(255) NOT NULL COMMENT 'ชื่อ-นามสกุล ผู้บังคับบัญชาชั้นต้น (จัดเตรียมเอกสารเล่ม 2)' DEFAULT ''`);
await queryRunner.query(`ALTER TABLE \`evaluation\` CHANGE \`commanderAbovePosition\` \`commanderAbovePosition\` varchar(255) NOT NULL COMMENT 'ตำแหน่ง ผู้บังคับบัญชาเหนือขึ้นไป 1 ระดับ' DEFAULT ''`);
await queryRunner.query(`ALTER TABLE \`evaluation\` CHANGE \`commanderAboveFullname\` \`commanderAboveFullname\` varchar(255) NOT NULL COMMENT 'ชื่อ-นามสกุล ผู้บังคับบัญชาเหนือขึ้นไป 1 ระดับ' DEFAULT ''`);
await queryRunner.query(`ALTER TABLE \`evaluation\` CHANGE \`commanderPosition\` \`commanderPosition\` varchar(255) NOT NULL COMMENT 'ตำแหน่ง ผู้บังคับบัญชาชั้นต้น' DEFAULT ''`);
await queryRunner.query(`ALTER TABLE \`evaluation\` CHANGE \`commanderFullname\` \`commanderFullname\` varchar(255) NOT NULL COMMENT 'ชื่อ-นามสกุล ผู้บังคับบัญชาชั้นต้น' DEFAULT ''`);
await queryRunner.query(`ALTER TABLE \`evaluation\` CHANGE \`experience\` \`experience\` varchar(255) NOT NULL COMMENT 'ประสบการณ์ในการปฏิบัติงาน' DEFAULT ''`);
await queryRunner.query(`ALTER TABLE \`evaluation\` CHANGE \`reason\` \`reason\` varchar(255) NOT NULL COMMENT 'เหตุผล' DEFAULT ''`);
await queryRunner.query(`ALTER TABLE \`evaluation\` CHANGE \`step\` \`step\` varchar(255) NOT NULL COMMENT 'ชื่อสถานะการประเมิน' DEFAULT ''`);
await queryRunner.query(`ALTER TABLE \`evaluation\` CHANGE \`type\` \`type\` varchar(255) NOT NULL COMMENT 'ประเภทแบบประเมิน' DEFAULT ''`);
await queryRunner.query(`ALTER TABLE \`evaluation\` CHANGE \`govAge\` \`govAge\` varchar(255) NOT NULL COMMENT 'อายุราชการ' DEFAULT ''`);
await queryRunner.query(`ALTER TABLE \`evaluation\` CHANGE \`birthDate\` \`birthDate\` varchar(255) NOT NULL COMMENT 'วันเดือนปีเกิด' DEFAULT ''`);
await queryRunner.query(`ALTER TABLE \`evaluation\` CHANGE \`posNo\` \`posNo\` varchar(255) NOT NULL COMMENT 'ตำแหน่งเลขที่' DEFAULT ''`);
await queryRunner.query(`ALTER TABLE \`evaluation\` CHANGE \`positionLevel\` \`positionLevel\` varchar(255) NOT NULL COMMENT 'ระดับปัจจุบัน' DEFAULT ''`);
await queryRunner.query(`ALTER TABLE \`evaluation\` CHANGE \`salary\` \`salary\` varchar(255) NOT NULL COMMENT 'เงินเดือนปัจจุบัน' DEFAULT ''`);
await queryRunner.query(`ALTER TABLE \`evaluation\` CHANGE \`oc\` \`oc\` varchar(255) NOT NULL COMMENT 'สังกัด' DEFAULT ''`);
await queryRunner.query(`ALTER TABLE \`evaluation\` CHANGE \`position\` \`position\` varchar(255) NOT NULL COMMENT 'ตำแหน่ง' DEFAULT ''`);
await queryRunner.query(`ALTER TABLE \`evaluation\` CHANGE \`fullName\` \`fullName\` varchar(255) NOT NULL COMMENT 'ชื่อ นามสกุล' DEFAULT ''`);
await queryRunner.query(`ALTER TABLE \`evaluation\` CHANGE \`prefix\` \`prefix\` varchar(255) NOT NULL COMMENT 'คำนำหน้า' DEFAULT ''`);
await queryRunner.query(`ALTER TABLE \`evaluation\` CHANGE \`citizenId\` \`citizenId\` varchar(13) NOT NULL COMMENT 'รหัสบัตรประชาชน' DEFAULT ''`);
await queryRunner.query(`ALTER TABLE \`training\` CHANGE \`dateOrder\` \`dateOrder\` datetime NOT NULL COMMENT 'คำสั่งลงวันที่/หนังสืออนุมัติลงวันที่'`);
await queryRunner.query(`ALTER TABLE \`training\` CHANGE \`numberOrder\` \`numberOrder\` varchar(255) NOT NULL COMMENT 'เลขที่คำสั่ง/เลขที่หนังสืออนุมัติ' DEFAULT 'string'`);
await queryRunner.query(`ALTER TABLE \`training\` CHANGE \`department\` \`department\` varchar(255) NOT NULL COMMENT 'หน่วยงานที่รับผิดชอบจัดการฝึกอบรม/ดูงาน' DEFAULT 'string'`);
await queryRunner.query(`ALTER TABLE \`training\` CHANGE \`duration\` \`duration\` varchar(255) NOT NULL COMMENT 'รวมระยะเวลาในการฝึกอบรม/ดูงาน' DEFAULT 'string'`);
await queryRunner.query(`ALTER TABLE \`training\` CHANGE \`place\` \`place\` varchar(255) NOT NULL COMMENT 'สถานที่ฝึกอบรม/ดูงาน' DEFAULT 'string'`);
await queryRunner.query(`ALTER TABLE \`training\` CHANGE \`yearly\` \`yearly\` int NOT NULL COMMENT 'ปีที่อบรม (พ.ศ.)'`);
await queryRunner.query(`ALTER TABLE \`training\` CHANGE \`endDate\` \`endDate\` datetime NOT NULL COMMENT 'วันสิ้นสุดการฝึกอบรม/ดูงาน'`);
await queryRunner.query(`ALTER TABLE \`training\` CHANGE \`startDate\` \`startDate\` datetime NOT NULL COMMENT 'วันเริ่มต้นการฝึกอบรม/ดูงาน'`);
await queryRunner.query(`ALTER TABLE \`training\` CHANGE \`topic\` \`topic\` varchar(255) NOT NULL COMMENT 'หัวข้อการฝึกอบรม/ดูงาน' DEFAULT 'string'`);
await queryRunner.query(`ALTER TABLE \`training\` CHANGE \`name\` \`name\` varchar(255) NOT NULL COMMENT 'ชื่อโครงการ/หลักสูตรการฝึกอบรม' DEFAULT 'string'`);
await queryRunner.query(`ALTER TABLE \`salary\` CHANGE \`salaryStatus\` \`salaryStatus\` varchar(255) NOT NULL COMMENT 'ประเภทตำแหน่งกรณีพิเศษ' DEFAULT 'string'`);
await queryRunner.query(`ALTER TABLE \`salary\` CHANGE \`refCommandDate\` \`refCommandDate\` datetime NOT NULL COMMENT 'เอกสารอ้างอิง (ลงวันที่)'`);
await queryRunner.query(`ALTER TABLE \`salary\` CHANGE \`refCommandNo\` \`refCommandNo\` varchar(255) NOT NULL COMMENT 'เอกสารอ้างอิง (เลขที่คำสั่ง)' DEFAULT 'string'`);
await queryRunner.query(`ALTER TABLE \`salary\` CHANGE \`salaryRef\` \`salaryRef\` varchar(255) NOT NULL COMMENT 'เอกสารอ้างอิง' DEFAULT 'string'`);
await queryRunner.query(`ALTER TABLE \`salary\` CHANGE \`salaryClass\` \`salaryClass\` varchar(255) NOT NULL COMMENT 'ตำแหน่ง (รายละเอียด)' DEFAULT 'string'`);
await queryRunner.query(`ALTER TABLE \`salary\` CHANGE \`posNo\` \`posNo\` varchar(255) NOT NULL COMMENT 'เลขที่ตำแหน่ง' DEFAULT 'string'`);
await queryRunner.query(`ALTER TABLE \`salary\` CHANGE \`position\` \`position\` varchar(255) NOT NULL COMMENT 'ตำแหน่ง' DEFAULT 'string'`);
await queryRunner.query(`ALTER TABLE \`salary\` CHANGE \`mouthSalaryAmount\` \`mouthSalaryAmount\` double NOT NULL COMMENT 'เงินค่าตอบแทนรายเดือน' DEFAULT '0'`);
await queryRunner.query(`ALTER TABLE \`salary\` CHANGE \`positionSalaryAmount\` \`positionSalaryAmount\` double NOT NULL COMMENT 'เงินประจำตำแหน่ง' DEFAULT '0'`);
await queryRunner.query(`ALTER TABLE \`salary\` CHANGE \`amount\` \`amount\` double NOT NULL COMMENT 'เงินเดือน' DEFAULT '0'`);
await queryRunner.query(`ALTER TABLE \`salary\` CHANGE \`date\` \`date\` datetime NOT NULL COMMENT 'วัน เดือน ปี รับตำแหน่ง'`);
await queryRunner.query(`ALTER TABLE \`certificate\` CHANGE \`expireDate\` \`expireDate\` datetime NOT NULL COMMENT 'วันที่หมดอายุ'`);
await queryRunner.query(`ALTER TABLE \`certificate\` CHANGE \`issueDate\` \`issueDate\` datetime NOT NULL COMMENT 'วันที่ออกใบอนุญาต'`);
await queryRunner.query(`ALTER TABLE \`certificate\` CHANGE \`certificateNo\` \`certificateNo\` varchar(255) NOT NULL COMMENT 'เลขที่ใบอนุญาต' DEFAULT 'string'`);
await queryRunner.query(`ALTER TABLE \`certificate\` CHANGE \`issuer\` \`issuer\` varchar(255) NOT NULL COMMENT 'หน่วยงานผู้ออกใบอนุญาต' DEFAULT 'string'`);
await queryRunner.query(`ALTER TABLE \`certificate\` CHANGE \`certificateType\` \`certificateType\` varchar(255) NOT NULL COMMENT 'ชื่อใบอนุญาต' DEFAULT 'string'`);
await queryRunner.query(`ALTER TABLE \`certificate\` CHANGE \`statictep\` \`statictep\` varchar(255) NOT NULL COMMENT 'ชื่อสถานะการประเมิน' DEFAULT 'string'`);
await queryRunner.query(`ALTER TABLE \`education\` CHANGE \`durationYear\` \`durationYear\` varchar(255) NOT NULL COMMENT 'ระยะเวลาหลักสูตร' DEFAULT 'string'`);
await queryRunner.query(`ALTER TABLE \`education\` CHANGE \`duration\` \`duration\` varchar(255) NOT NULL COMMENT 'ระยะเวลา' DEFAULT 'string'`);
await queryRunner.query(`ALTER TABLE \`education\` CHANGE \`other\` \`other\` varchar(255) NOT NULL COMMENT 'ข้อมูลการติดต่อ' DEFAULT 'string'`);
await queryRunner.query(`ALTER TABLE \`education\` CHANGE \`country\` \`country\` varchar(255) NOT NULL COMMENT 'ประเทศ' DEFAULT 'string'`);
await queryRunner.query(`ALTER TABLE \`education\` CHANGE \`gpa\` \`gpa\` varchar(255) NOT NULL COMMENT 'เกรดเฉลี่ย' DEFAULT 'string'`);
await queryRunner.query(`ALTER TABLE \`education\` CHANGE \`fundName\` \`fundName\` varchar(255) NOT NULL COMMENT 'ทุน' DEFAULT 'string'`);
await queryRunner.query(`ALTER TABLE \`education\` CHANGE \`field\` \`field\` varchar(255) NOT NULL COMMENT 'สาขาวิชา/ทาง' DEFAULT 'string'`);
await queryRunner.query(`ALTER TABLE \`education\` CHANGE \`degree\` \`degree\` varchar(255) NOT NULL COMMENT 'วุฒิการศึกษา' DEFAULT 'string'`);
await queryRunner.query(`ALTER TABLE \`education\` CHANGE \`isEducation\` \`isEducation\` tinyint NOT NULL COMMENT 'เป็นวุฒิศึกษาในตำแหน่ง' DEFAULT '0'`);
await queryRunner.query(`ALTER TABLE \`education\` CHANGE \`finishDate\` \`finishDate\` datetime NOT NULL COMMENT 'วันที่สำเร็จการศึกษา'`);
await queryRunner.query(`ALTER TABLE \`education\` CHANGE \`endDate\` \`endDate\` datetime NOT NULL COMMENT 'EndDate'`);
await queryRunner.query(`ALTER TABLE \`education\` CHANGE \`startDate\` \`startDate\` datetime NOT NULL COMMENT 'ตั้งแต่'`);
await queryRunner.query(`ALTER TABLE \`education\` CHANGE \`isDate\` \`isDate\` tinyint NOT NULL COMMENT 'ประเภทช่วงเวลาการศึกษา' DEFAULT '0'`);
await queryRunner.query(`ALTER TABLE \`education\` CHANGE \`institute\` \`institute\` varchar(255) NOT NULL COMMENT 'สถานศึกษา' DEFAULT 'string'`);
await queryRunner.query(`ALTER TABLE \`education\` CHANGE \`educationLevel\` \`educationLevel\` varchar(255) NOT NULL COMMENT 'ระดับศึกษา' DEFAULT 'string'`);
}
}

View file

@ -0,0 +1,22 @@
import { MigrationInterface, QueryRunner } from "typeorm";
export class UpdateTableEvaluateAddAuthor1704279787037 implements MigrationInterface {
name = 'UpdateTableEvaluateAddAuthor1704279787037'
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE \`evaluation\` ADD \`author\` varchar(255) NULL COMMENT 'ชื่อเจ้าของผลงาน'`);
await queryRunner.query(`ALTER TABLE \`evaluation\` ADD \`subject\` varchar(255) NULL COMMENT 'ชื่อผลงาน'`);
await queryRunner.query(`ALTER TABLE \`evaluation\` ADD \`authorDoc2\` varchar(255) NULL COMMENT 'ชื่อเจ้าของผลงาน2'`);
await queryRunner.query(`ALTER TABLE \`evaluation\` ADD \`subjectDoc2\` varchar(255) NULL COMMENT 'ชื่อผลงาน2'`);
await queryRunner.query(`ALTER TABLE \`evaluation\` ADD \`assignedPosition\` varchar(255) NULL COMMENT 'ตำแหน่งที่ได้รับมอบหมาย'`);
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE \`evaluation\` DROP COLUMN \`assignedPosition\``);
await queryRunner.query(`ALTER TABLE \`evaluation\` DROP COLUMN \`subjectDoc2\``);
await queryRunner.query(`ALTER TABLE \`evaluation\` DROP COLUMN \`authorDoc2\``);
await queryRunner.query(`ALTER TABLE \`evaluation\` DROP COLUMN \`subject\``);
await queryRunner.query(`ALTER TABLE \`evaluation\` DROP COLUMN \`author\``);
}
}

View file

@ -0,0 +1,18 @@
import { MigrationInterface, QueryRunner } from "typeorm";
export class UpdateTableEvaluateTittleToTitle1706070949738 implements MigrationInterface {
name = 'UpdateTableEvaluateTittleToTitle1706070949738'
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE \`meeting\` CHANGE \`tittle\` \`title\` varchar(255) NULL COMMENT 'ชื่อการประชุม'`);
await queryRunner.query(`ALTER TABLE \`meeting\` DROP COLUMN \`title\``);
await queryRunner.query(`ALTER TABLE \`meeting\` ADD \`title\` varchar(255) NULL COMMENT 'ชื่อการประชุม'`);
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE \`meeting\` DROP COLUMN \`title\``);
await queryRunner.query(`ALTER TABLE \`meeting\` ADD \`title\` varchar(255) NULL COMMENT 'ชื่อการประชุม'`);
await queryRunner.query(`ALTER TABLE \`meeting\` CHANGE \`title\` \`tittle\` varchar(255) NULL COMMENT 'ชื่อการประชุม'`);
}
}

View file

@ -0,0 +1,22 @@
import { MigrationInterface, QueryRunner } from "typeorm";
export class UpdateTableEvaAddRoot1730874813739 implements MigrationInterface {
name = 'UpdateTableEvaAddRoot1730874813739'
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE \`evaluation\` ADD \`rootId\` varchar(255) NULL COMMENT 'root'`);
await queryRunner.query(`ALTER TABLE \`evaluation\` ADD \`child1Id\` varchar(255) NULL COMMENT 'child1'`);
await queryRunner.query(`ALTER TABLE \`evaluation\` ADD \`child2Id\` varchar(255) NULL COMMENT 'child2'`);
await queryRunner.query(`ALTER TABLE \`evaluation\` ADD \`child3Id\` varchar(255) NULL COMMENT 'child3'`);
await queryRunner.query(`ALTER TABLE \`evaluation\` ADD \`child4Id\` varchar(255) NULL COMMENT 'child4'`);
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE \`evaluation\` DROP COLUMN \`child4Id\``);
await queryRunner.query(`ALTER TABLE \`evaluation\` DROP COLUMN \`child3Id\``);
await queryRunner.query(`ALTER TABLE \`evaluation\` DROP COLUMN \`child2Id\``);
await queryRunner.query(`ALTER TABLE \`evaluation\` DROP COLUMN \`child1Id\``);
await queryRunner.query(`ALTER TABLE \`evaluation\` DROP COLUMN \`rootId\``);
}
}

53
src/services/README.md Normal file
View file

@ -0,0 +1,53 @@
# External Service Library
## Storage
- สำหรับจัดเก็บไฟล์เท่านั้น หากต้องการเพิ่มข้อมูลเสริมอาจเก็บไว้ใน description ในรูปแบบของ String โดยอาจใช้ `JSON.stringify` ในการแปลงตัวแปรให้อยู่ในรูป String หรือเก็บแยกคนละส่วน
- เมื่อร้องขอการอัปโหลดไฟล์จำเป็นจะต้องทราบนามสกุล และ/หรือ ประเภทของไฟล์ด้วย สามารถใช้ [mime](https://www.npmjs.com/package/mime) ช่วยในการระบุได้จากชื่อโดยทราบจากการดึงข้อมูลของไฟล์ที่เลือกไว้ รวมถึง ประเภท เช่นกัน
### Storage - Upload File ผ่าน PresignedURL
```ts
// file เป็น file ที่เลือกจาก input ประเภท file
await axios
.put(res.data.uploadUrl, file, {
// ระบบ MinIO ใช้ในการระบุ ประเภทไฟล์ (จำเป็นสำหรับดาวน์โหลด) สามารถดึงจาก File ที่เก็บในตัวแปรที่เลือกไว้ในฟอร์มได้
headers: { "Content-Type": file?.type },
onUploadProgress: (e) => console.log(e),
})
.catch((e) => console.error(e));
```
### Storage - Download File ผ่าน PresignedURL
ข้อมูลที่ API ให้มาเมื่อต้องการดาวน์โหลดจะมีข้อมูลทั้งหมดของไฟล์ รวมถึงลิงก์สำหรับดาวน์โหลดไฟล์ ซึ่งสามารถใช้ในการระบุประเภทไฟล์ที่ใช้ในการดาวน์โหลดได้
หากชื่อไฟล์ที่มีในระบบ ไม่มีการระบุนามสกุลไฟล์ไว้ อาจจำเป็นต้องใช้ Library อย่าง [mime](https://www.npmjs.com/package/mime) ในการระบุนามสกุลไฟล์และเพิ่มเข้าไปตามท้ายของ ชื่อไฟล์
และหากไม่มีการระบุประเภทไฟล์ เช่น mimeType ก็จะไม่สามารถรู้ได้ว่าไฟล์เป็นไฟล์อะไร
```ts
await axios
.get(res.data.downloadUrl, {
method: "GET",
responseType: "blob",
headers: {
"Content-Type": "application/json",
Accept: res.data.fileType, // ถ้ามีการระบุเมื่ออัปโหลด
},
})
.then((r) => {
const a = document.createElement("a");
a.href = window.URL.createObjectURL(r.data);
a.download = res.data.fileName;
// a.download = res.data.fileName + `.${mime.getExtension(res.data.fileType)}`
a.click();
});
```
### Storage - Waiting File Upload
เมื่ออัปโหลดเสร็จอาจต้องการอไฟล์ที่อัปโหลดเข้าระบบแล้ว เพื่อนำมาทำอะไรบางอย่างเช่น PDF Preview
อาจจำเป็นต้องใช้ SocketIO ช่วยเนื่องจากระบบนี้ออกแบบให้รับโหลดได้สูง และยังมีการดึงข้อมูลภายใน File มาทำ index การค้นหา
ทำให้เกิดความหน่วยเวลาหลังอัปโหลดเล็กน้อยจากการที่รอ ElasticSearch ทำการ Refresh Index ซึ่งเกิดขึ้น ทุกๆ 1 วินาที ซึ่งเมื่ออัปโหลดแล้วอาจต้องรอรอบในการ Refresh Index
ซึ่งแม้จะเป็นไฟล์ขนาดเล็ก ก็สามารถเกิดความหน่วงของเวลา 1 วินาทีหลังอัปโหลดได้ ขึ้นอยู่กับ จังหวะ ที่อัปโหลดไฟล์
ตัวอย่างโค้ด อาจเพิ่มในภายหลัง

16
src/services/callApi.ts Normal file
View file

@ -0,0 +1,16 @@
import { getToken } from "./storage";
const API_URL = process.env.API_URL;
export async function sendNoti(sendData: any, token: any) {
const res = await fetch(`${API_URL}/placement/noti/keycloak`, {
method: "POST",
headers: {
Authorization: `${token}`,
"Content-Type": "application/json",
},
body: JSON.stringify(sendData),
}).catch((e) => console.error(e));
if (!res || !res.ok) {
return Boolean(console.error(res ? await res.json() : res));
}
return true;
}

265
src/services/storage.ts Normal file
View file

@ -0,0 +1,265 @@
import { DecodedJwt } from "fast-jwt";
import HttpError from "../interfaces/http-error";
import HttpStatus from "../interfaces/http-status";
import { StorageFile, StorageFolder } from "../interfaces/storage-fs";
import { jwtDecode } from "../utils/jwt";
if (!process.env.STORAGE_URL) {
throw new Error("Requires STORAGE_URL env variable.");
}
if (!process.env.STORAGE_REALM_URL && !process.env.STORAGE_SECRET) {
throw new Error("Requires STORAGE_REALM_URL and STORAGE_SECRET env variable.");
}
export type FileProps = Partial<
Pick<StorageFile, "title" | "description" | "author" | "keyword" | "category">
> & {
metadata?: { [key: string]: unknown };
};
const STORAGE_URL = process.env.STORAGE_URL;
const STORAGE_REALM_URL = process.env.STORAGE_REALM_URL;
const STORAGE_SECRET: any = process.env.STORAGE_SECRET;
let token: string | null = null;
let decoded: DecodedJwt | null = null;
/**
* Check if token is expired or will expire in 30 seconds
* @returns true if expire or can't get exp, false otherwise
*/
export function expireCheck(token: string, beforeExpire: number = 30) {
decoded = jwtDecode(token);
if (decoded && decoded.payload.exp) {
return Date.now() / 1000 >= decoded.payload.exp - beforeExpire;
}
return true;
}
/**
* Get token from id service if needed
*/
export async function getToken() {
if (!token || expireCheck(token)) {
const body = new URLSearchParams();
body.append("client_id", "ext-api");
body.append("client_secret", STORAGE_SECRET);
body.append("grant_type", "client_credentials");
const res = await fetch(`${STORAGE_REALM_URL}/protocol/openid-connect/token`, {
method: "POST",
body: body,
}).catch((e) => console.error(e));
if (!res) return;
const data = await res.json();
if (data && data.access_token) {
token = data.access_token;
}
}
return token;
}
/**
* @param path - Path that new folder will live
* @param name - Name of the folder to create
* @param recursive - Will create parent automatically
*/
export async function createFolder(path: string[], name: string, recursive: boolean = false) {
if (recursive && path.length > 0) {
await createFolder(path.slice(0, -1), path[path.length - 1], true);
}
const res = await fetch(`${STORAGE_URL}/storage/folder`, {
method: "POST",
headers: {
Authorization: `Bearer ${await getToken()}`,
"Content-Type": "application/json",
},
body: JSON.stringify({ path, name }),
}).catch((e) => console.error(e));
if (!res || !res.ok) {
return Boolean(console.error(res ? await res.json() : res));
}
return true;
}
/**
* @param path - Path that new file will live
* @param file - Name of the file to create
*/
export async function createFile(path: string[], file: string, props?: FileProps) {
const res = await fetch(`${STORAGE_URL}/storage/file`, {
method: "POST",
headers: {
Authorization: `Bearer ${await getToken()}`,
"Content-Type": "application/json",
},
body: JSON.stringify({
...props,
path,
file,
hidden: false,
}),
}).catch((e) => console.error(e));
if (!res || !res.ok) {
return Boolean(console.error(res ? await res.json() : res));
}
return (await res.json()) as StorageFile & { uploadUrl: string };
}
export async function list(operation: "file" | "folder", path: string[]) {
const res = await fetch(`${STORAGE_URL}/storage/list`, {
method: "POST",
headers: {
Authorization: `Bearer ${await getToken()}`,
"Content-Type": "application/json",
},
body: JSON.stringify({ operation, path, hidden: false }),
}).catch((e) => console.error(e));
if (!res || !res.ok) {
if (res && res.status === HttpStatus.NOT_FOUND) {
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบแฟ้ม/ไฟล์ในระบบ");
}
return Boolean(console.error(res ? await res.json() : res));
}
return (await res.json()) as StorageFile & { uploadUrl: string };
}
export async function listFolder(path: string[]) {
return (await list("folder", path)) as StorageFolder[] | boolean;
}
export async function listFile(path: string[]) {
return (await list("file", path)) as StorageFile[] | boolean;
}
export async function updateFile(path: string[], file: string, metadata: FileProps) {
const res = await fetch(`${STORAGE_URL}/storage/file`, {
method: "PUT",
headers: {
Authorization: `Bearer ${await getToken()}`,
"Content-Type": "application/json",
},
body: JSON.stringify({
from: { path, file },
...metadata,
upload: false,
}),
}).catch((e) => console.error(e));
if (!res || !res.ok) {
if (res && res.status === HttpStatus.NOT_FOUND) {
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบไฟล์ในระบบ");
}
return Boolean(console.error(res ? await res.json() : res));
}
return Boolean(res);
}
export async function deleteFolder(path: string[], name: string) {
const res = await fetch(`${STORAGE_URL}/storage/folder`, {
method: "DELETE",
headers: {
Authorization: `Bearer ${await getToken()}`,
"Content-Type": "application/json",
},
body: JSON.stringify({ path: [...path, name] }),
}).catch((e) => console.error(e));
if (!res || !res.ok) {
return Boolean(console.error(res ? await res.json() : res));
}
return true;
}
export async function deleteFile(path: string[], file: string) {
const res = await fetch(`${STORAGE_URL}/storage/file`, {
method: "DELETE",
headers: {
Authorization: `Bearer ${await getToken()}`,
"Content-Type": "application/json",
},
body: JSON.stringify({ path, file }),
}).catch((e) => console.error(e));
if (!res || !res.ok) {
return Boolean(console.error(res ? await res.json() : res));
}
return true;
}
export async function downloadFile(path: string[], file: string) {
const res = await fetch(`${STORAGE_URL}/storage/file/download`, {
method: "POST",
headers: {
Authorization: `Bearer ${await getToken()}`,
"Content-Type": "application/json",
},
body: JSON.stringify({ path, file }),
}).catch((e) => console.error(e));
if (!res || !res.ok) {
if (res && res.status === HttpStatus.NOT_FOUND) {
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบไฟล์ในระบบ");
}
return Boolean(console.error(res ? await res.json() : res));
}
return (await res.json()) as StorageFile & { downloadUrl: string };
}
export function getUserInfoFromRequest(request: { user: { sub: string; name: string } }): {
sub: string;
name: string;
} {
const { sub, name } = request.user;
return { sub, name };
}
export function ConvertToThaiStep(val: string) {
switch (val) {
case "CHECK_SPEC":
return "ตรวจสอบคุณสมบัติด้วยตนเอง";
case "PREPARE_DOC_V1":
return "จัดเตรียมเอกสารเล่ม 1";
case "CHECK_DOC_V1":
return "ตรวจสอบความถูกต้องของเอกสารเล่ม 1";
case "WAIT_CHECK_DOC_V1":
return "รอตรวจสอบคุณสมบัติ 1";
case "ANNOUNCE_WEB":
return "ประกาศบนเว็บไซต์";
case "PREPARE_DOC_V2":
return "จัดเตรียมเอกสารเล่ม 2";
case "CHECK_DOC_V2":
return "รอพิจารณาผลการประเมิน 2";
case "WAIT_CHECK_DOC_V2":
return "ตรวจสอบความถูกต้องของเอกสารเล่ม 2";
case "DONE":
return "เสร็จสิ้น";
default:
return null;
}
}
export function ConvertToThaiType(val: string) {
switch (val) {
case "EXPERT":
return "ชำนาญการ";
case "SPECIAL_EXPERT":
return "ชำนาญการพิเศษ";
case "EXPERTISE":
return "เชี่ยวชาญ";
default:
return null;
}
}

76
src/utils/auth.ts Normal file
View file

@ -0,0 +1,76 @@
import * as express from "express";
import { createDecoder, createVerifier } from "fast-jwt";
import HttpError from "../interfaces/http-error";
import HttpStatusCode from "../interfaces/http-status";
if (!process.env.PUBLIC_KEY && !process.env.REALM_URL) {
throw new Error("Requires PUBLIC_KEY or REALM_URL");
}
if (process.env.PUBLIC_KEY && process.env.REALM_URL && !process.env.PREFERRED_AUTH) {
throw new Error(
"PREFERRED_AUTH must be specified when both REALM_URL and PUBLIC_KEY are provided.",
);
}
const jwtVerify = createVerifier({
key: async () => {
return `-----BEGIN PUBLIC KEY-----\n${process.env.PUBLIC_KEY}\n-----END PUBLIC KEY-----`;
},
});
const jwtDecode = createDecoder();
export async function expressAuthentication(
request: express.Request,
securityName: string,
scopes?: string[],
) {
if (process.env.AUTH_BYPASS) return { preferred_username: "bypassed" };
if (securityName !== "bearerAuth") throw new Error("Unknown authentication method.");
const token = request.headers["authorization"]?.includes("Bearer ")
? request.headers["authorization"].split(" ")[1]
: request.headers["authorization"];
if (!token) throw new HttpError(HttpStatusCode.UNAUTHORIZED, "กรุณาเข้าสู่ระบบก่อนใช้งาน!");
let payload: Record<string, any> = {};
switch (process.env.PREFERRED_AUTH) {
case "online":
payload = await verifyOnline(token);
break;
case "offline":
payload = await verifyOffline(token);
break;
default:
if (process.env.REALM_URL) payload = await verifyOnline(token);
if (process.env.PUBLIC_KEY) payload = await verifyOffline(token);
break;
}
if (scopes && scopes.length > 0 && scopes.every((v) => !payload.role.includes(v))) {
throw new HttpError(HttpStatusCode.FORBIDDEN, "You are not allowed to perform this action.");
}
return payload;
}
async function verifyOffline(token: string) {
const payload = await jwtVerify(token).catch((_) => null);
if (!payload) throw new HttpError(HttpStatusCode.UNAUTHORIZED, "Invalid token provided.");
return payload;
}
async function verifyOnline(token: string) {
const res = await fetch(`${process.env.REALM_URL}/protocol/openid-connect/userinfo`, {
headers: { authorization: `Bearer ${token}` },
}).catch((e) => console.error(e));
if (!res) throw new Error("Cannot connect to auth service.");
if (!res.ok) throw new HttpError(HttpStatusCode.UNAUTHORIZED, "Invalid token provided.");
return await jwtDecode(token);
}

5
src/utils/jwt.ts Normal file
View file

@ -0,0 +1,5 @@
import { createDecoder } from "fast-jwt";
const jwtDecode = createDecoder({ complete: true });
export { jwtDecode };

266
static/index.html Normal file
View file

@ -0,0 +1,266 @@
<!--
~ Copyright 2016 Red Hat, Inc. and/or its affiliates
~ and other contributors as indicated by the @author tags.
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->
<html>
<head>
<script src="./keycloak.js"></script>
</head>
<body>
<div>
<button onclick="keycloak.login()">Login</button>
<button onclick="keycloak.login({ action: 'UPDATE_PASSWORD' })">
Update Password
</button>
<button onclick="keycloak.logout()">Logout</button>
<button onclick="keycloak.register()">Register</button>
<button onclick="keycloak.accountManagement()">Account</button>
<button onclick="refreshToken(9999)">Refresh Token</button>
<button onclick="refreshToken(30)">
Refresh Token (if <30s validity)
</button>
<button onclick="loadProfile()">Get Profile</button>
<button onclick="updateProfile()">Update profile</button>
<button onclick="loadUserInfo()">Get User Info</button>
<button onclick="output(keycloak.tokenParsed)">Show Token</button>
<button onclick="output(keycloak.refreshTokenParsed)">
Show Refresh Token
</button>
<button onclick="output(keycloak.idTokenParsed)">Show ID Token</button>
<button onclick="showExpires()">Show Expires</button>
<button onclick="output(keycloak)">Show Details</button>
<button onclick="output(keycloak.createLoginUrl())">
Show Login URL
</button>
<button onclick="output(keycloak.createLogoutUrl())">
Show Logout URL
</button>
<button onclick="output(keycloak.createRegisterUrl())">
Show Register URL
</button>
<button onclick="output(keycloak.createAccountUrl())">
Show Account URL
</button>
</div>
<h2>Result</h2>
<pre
style="
background-color: #ddd;
border: 1px solid #ccc;
padding: 10px;
word-wrap: break-word;
white-space: pre-wrap;
"
id="output"
></pre>
<h2>Events</h2>
<pre
style="
background-color: #ddd;
border: 1px solid #ccc;
padding: 10px;
word-wrap: break-word;
white-space: pre-wrap;
"
id="events"
></pre>
<script>
function loadProfile() {
keycloak
.loadUserProfile()
.success(function (profile) {
output(profile);
})
.error(function () {
output("Failed to load profile");
});
}
function updateProfile() {
var url = keycloak.createAccountUrl().split("?")[0];
var req = new XMLHttpRequest();
req.open("POST", url, true);
req.setRequestHeader("Accept", "application/json");
req.setRequestHeader("Content-Type", "application/json");
req.setRequestHeader("Authorization", "bearer " + keycloak.token);
req.onreadystatechange = function () {
if (req.readyState == 4) {
if (req.status == 200) {
output("Success");
} else {
output("Failed");
}
}
};
req.send(
'{"email":"myemail@foo.bar","firstName":"test","lastName":"bar"}'
);
}
function loadUserInfo() {
keycloak
.loadUserInfo()
.success(function (userInfo) {
output(userInfo);
})
.error(function () {
output("Failed to load user info");
});
}
function refreshToken(minValidity) {
keycloak
.updateToken(minValidity)
.then(function (refreshed) {
if (refreshed) {
output(keycloak.tokenParsed);
} else {
output(
"Token not refreshed, valid for " +
Math.round(
keycloak.tokenParsed.exp +
keycloak.timeSkew -
new Date().getTime() / 1000
) +
" seconds"
);
}
})
.catch(function () {
output("Failed to refresh token");
});
}
function showExpires() {
if (!keycloak.tokenParsed) {
output("Not authenticated");
return;
}
var o =
"Token Expires:\t\t" +
new Date(
(keycloak.tokenParsed.exp + keycloak.timeSkew) * 1000
).toLocaleString() +
"\n";
o +=
"Token Expires in:\t" +
Math.round(
keycloak.tokenParsed.exp +
keycloak.timeSkew -
new Date().getTime() / 1000
) +
" seconds\n";
if (keycloak.refreshTokenParsed) {
o +=
"Refresh Token Expires:\t" +
new Date(
(keycloak.refreshTokenParsed.exp + keycloak.timeSkew) * 1000
).toLocaleString() +
"\n";
o +=
"Refresh Expires in:\t" +
Math.round(
keycloak.refreshTokenParsed.exp +
keycloak.timeSkew -
new Date().getTime() / 1000
) +
" seconds";
}
output(o);
}
function output(data) {
if (typeof data === "object") {
data = JSON.stringify(data, null, " ");
}
document.getElementById("output").innerHTML = data;
}
function event(event) {
var e = document.getElementById("events").innerHTML;
document.getElementById("events").innerHTML =
new Date().toLocaleString() + "\t" + event + "\n" + e;
}
var keycloak = Keycloak();
keycloak.onAuthSuccess = function () {
event("Auth Success");
};
keycloak.onAuthError = function (errorData) {
event("Auth Error: " + JSON.stringify(errorData));
};
keycloak.onAuthRefreshSuccess = function () {
event("Auth Refresh Success");
};
keycloak.onAuthRefreshError = function () {
event("Auth Refresh Error");
};
keycloak.onAuthLogout = function () {
event("Auth Logout");
};
keycloak.onTokenExpired = function () {
event("Access token expired.");
};
keycloak.onActionUpdate = function (status) {
switch (status) {
case "success":
event("Action completed successfully");
break;
case "cancelled":
event("Action cancelled by user");
break;
case "error":
event("Action failed");
break;
}
};
// Flow can be changed to 'implicit' or 'hybrid', but then client must enable implicit flow in admin console too
var initOptions = {
responseMode: "fragment",
flow: "standard",
};
keycloak
.init(initOptions)
.then(function (authenticated) {
output(
"Init Success (" +
(authenticated ? "Authenticated" : "Not Authenticated") +
")"
);
})
.catch(function () {
output("Init Error");
});
</script>
</body>
</html>

2952
static/keycloak.js Normal file

File diff suppressed because it is too large Load diff

9
static/keycloak.json Normal file
View file

@ -0,0 +1,9 @@
{
"realm": "bma-ehr",
"auth-server-url": "https://id.frappet.synology.me",
"ssl-required": "external",
"resource": "bma-ehr",
"public-client": true,
"client_secret": "tF0huP4MylOSMVZEohwPMI8DDttW66A7",
"realm-public-key":"MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAvYg0ZJvH6HgNOzyPp7PCvY3bJwD9WdsNn6gZbuvIfqJQZ8iSH1t0p3fgODO/fqwcj9UFeh1bVFOSjuW+JpnPehROqzt81KNl9zLLNXoN4LimReQHaMM3dU7DCbRylgVCouIDvObyjg8G+Cy5lZvFKWym/DPwGVpSdbvDZJ83qxq2dp7GJXS8PhOvA+MB1K009/jW5pBTUwNArLjoFccr+gIYIiOJDg2rYyIF3fDkwyWkuxr6xRt10+BRJytselwy/18kbDuJxVPaapdgTXI6wLzx7HWcDk30n5EvhJEumnIPpRst8gucqNYmB4MH+vsyoxV5WLuO3qmVRzFbtAppRQIDAQAB"
}

18
tsconfig.json Normal file
View file

@ -0,0 +1,18 @@
{
"compilerOptions": {
"incremental": true,
"outDir": "dist",
"lib": ["ESNext", "DOM", "DOM.Iterable"],
"target": "ESNext",
"module": "NodeNext",
"moduleResolution": "NodeNext",
"strictPropertyInitialization": false,
"strict": true,
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"resolveJsonModule": true,
"skipLibCheck": true
}
}

38
tsoa.json Normal file
View file

@ -0,0 +1,38 @@
{
"entryFile": "src/app.ts",
"noImplicitAdditionalProperties": "throw-on-extras",
"controllerPathGlobs": ["src/controllers/*Controller.ts"],
"spec": {
"outputDirectory": "src",
"specVersion": 3,
"spec": {
"info": {
"title": "bma-ehr-evaluation - API",
"version": "0.0.1",
"description": "ระบบการประเมินบุคคล (evaluation: DV)",
"license": {
"name": "by Frappet",
"url": "https://frappet.com"
}
},
"basePath": "/"
},
"securityDefinitions": {
"bearerAuth": {
"type": "apiKey",
"name": "Authorization",
"description": "Keycloak Bearer Token",
"in": "header"
}
},
"tags": [
{
"name": "Test", "description": "สำหรับทดสอบ"
}
]
},
"routes": {
"routesDir": "src/",
"authenticationModule": "src/middlewares/auth.ts"
}
}