Merge branch 'develop' into adiDev
This commit is contained in:
commit
83eeb0d468
10 changed files with 1202 additions and 1009 deletions
61
.github/workflows/release.yaml
vendored
61
.github/workflows/release.yaml
vendored
|
|
@ -1,5 +1,5 @@
|
||||||
name: release-test
|
name: release
|
||||||
run-name: release-test ${{ github.actor }}
|
run-name: release ${{ github.actor }}
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
tags:
|
tags:
|
||||||
|
|
@ -7,14 +7,13 @@ on:
|
||||||
workflow_dispatch:
|
workflow_dispatch:
|
||||||
env:
|
env:
|
||||||
REGISTRY: docker.frappet.com
|
REGISTRY: docker.frappet.com
|
||||||
# IMAGE_NAME: ehr/bma-ehr-node-service
|
|
||||||
IMAGE_NAME: ehr/bma-ehr-probation
|
IMAGE_NAME: ehr/bma-ehr-probation
|
||||||
DEPLOY_HOST: frappet.com
|
DEPLOY_HOST: frappet.com
|
||||||
# COMPOSE_PATH: /home/frappet/docker/bma-ehr
|
|
||||||
COMPOSE_PATH: /home/frappet/docker/bma/bma-ehr-probation
|
COMPOSE_PATH: /home/frappet/docker/bma/bma-ehr-probation
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
# act workflow_dispatch -W .github/workflows/release.yaml --input IMAGE_VER=test-v1 -s DOCKER_USER=sorawit -s DOCKER_PASS=P@ssword -s SSH_PASSWORD=P@ssw0rd
|
# act workflow_dispatch -W .github/workflows/release.yaml --input IMAGE_VER=test-v1 -s DOCKER_USER=sorawit -s DOCKER_PASS=P@ssword -s SSH_PASSWORD=P@ssw0rd
|
||||||
release-test:
|
release:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v3
|
||||||
|
|
@ -53,6 +52,7 @@ jobs:
|
||||||
with:
|
with:
|
||||||
context: .
|
context: .
|
||||||
platforms: linux/amd64
|
platforms: linux/amd64
|
||||||
|
file: docker/Dockerfile
|
||||||
push: true
|
push: true
|
||||||
tags: ${{env.REGISTRY}}/${{env.IMAGE_NAME}}:${{ steps.gen_ver.outputs.image_ver }},${{env.REGISTRY}}/${{env.IMAGE_NAME}}:latest
|
tags: ${{env.REGISTRY}}/${{env.IMAGE_NAME}}:${{ steps.gen_ver.outputs.image_ver }},${{env.REGISTRY}}/${{env.IMAGE_NAME}}:latest
|
||||||
- name: Remote Deployment
|
- name: Remote Deployment
|
||||||
|
|
@ -67,21 +67,40 @@ jobs:
|
||||||
docker compose pull
|
docker compose pull
|
||||||
docker compose up -d
|
docker compose up -d
|
||||||
echo "${{ steps.gen_ver.outputs.image_ver }}"> success
|
echo "${{ steps.gen_ver.outputs.image_ver }}"> success
|
||||||
- uses: snow-actions/line-notify@v1.1.0
|
- name: Notify Discord Success
|
||||||
if: success()
|
if: success()
|
||||||
with:
|
run: |
|
||||||
access_token: ${{ secrets.TOKEN_LINE }}
|
curl -H "Content-Type: application/json" \
|
||||||
message: |
|
-X POST \
|
||||||
-Success✅✅✅
|
-d '{
|
||||||
Image: ${{env.IMAGE_NAME}}
|
"embeds": [{
|
||||||
Version: ${{ steps.gen_ver.outputs.IMAGE_VER }}
|
"title": "✅ Deployment Success!",
|
||||||
By: ${{github.actor}}
|
"description": "**Details:**\n- Image: `${{env.IMAGE_NAME}}`\n- Version: `${{ steps.gen_ver.outputs.image_ver }}`\n- Deployed by: `${{github.actor}}`",
|
||||||
- uses: snow-actions/line-notify@v1.1.0
|
"color": 3066993,
|
||||||
|
"footer": {
|
||||||
|
"text": "Release Notification",
|
||||||
|
"icon_url": "https://example.com/success-icon.png"
|
||||||
|
},
|
||||||
|
"timestamp": "'$(date -u +%Y-%m-%dT%H:%M:%SZ)'"
|
||||||
|
}]
|
||||||
|
}' \
|
||||||
|
${{ secrets.DISCORD_WEBHOOK }}
|
||||||
|
|
||||||
|
- name: Notify Discord Failure
|
||||||
if: failure()
|
if: failure()
|
||||||
with:
|
run: |
|
||||||
access_token: ${{ secrets.TOKEN_LINE }}
|
curl -H "Content-Type: application/json" \
|
||||||
message: |
|
-X POST \
|
||||||
-Failure❌❌❌
|
-d '{
|
||||||
Image: ${{env.IMAGE_NAME}}
|
"embeds": [{
|
||||||
Version: ${{ steps.gen_ver.outputs.IMAGE_VER }}
|
"title": "❌ Deployment Failed!",
|
||||||
By: ${{github.actor}}
|
"description": "**Details:**\n- Image: `${{env.IMAGE_NAME}}`\n- Version: `${{ steps.gen_ver.outputs.image_ver }}`\n- Attempted by: `${{github.actor}}`",
|
||||||
|
"color": 15158332,
|
||||||
|
"footer": {
|
||||||
|
"text": "Release Notification",
|
||||||
|
"icon_url": "https://example.com/failure-icon.png"
|
||||||
|
},
|
||||||
|
"timestamp": "'$(date -u +%Y-%m-%dT%H:%M:%SZ)'"
|
||||||
|
}]
|
||||||
|
}' \
|
||||||
|
${{ secrets.DISCORD_WEBHOOK }}
|
||||||
|
|
|
||||||
35
Dockerfile
35
Dockerfile
|
|
@ -1,35 +0,0 @@
|
||||||
FROM node:18-alpine as builder
|
|
||||||
|
|
||||||
# Create app directory
|
|
||||||
WORKDIR /app
|
|
||||||
|
|
||||||
# Install app dependencies
|
|
||||||
COPY package*.json ./
|
|
||||||
|
|
||||||
RUN npm ci
|
|
||||||
|
|
||||||
COPY . .
|
|
||||||
|
|
||||||
RUN npm run build
|
|
||||||
|
|
||||||
FROM node:18-alpine
|
|
||||||
|
|
||||||
ENV NODE_ENV production
|
|
||||||
USER node
|
|
||||||
|
|
||||||
# Create app directory
|
|
||||||
WORKDIR /app
|
|
||||||
|
|
||||||
# Install app dependencies
|
|
||||||
COPY package*.json ./
|
|
||||||
# COPY .env ./
|
|
||||||
|
|
||||||
RUN npm ci --production
|
|
||||||
|
|
||||||
COPY --from=builder /app/dist ./dist
|
|
||||||
|
|
||||||
# COPY entrypoint.sh /usr/local/bin/entrypoint.sh
|
|
||||||
# RUN chmod u+x /usr/local/bin/entrypoint.sh
|
|
||||||
|
|
||||||
# ENTRYPOINT ["/usr/local/bin/entrypoint.sh"]
|
|
||||||
CMD [ "node", "dist/app.js" ]
|
|
||||||
34
docker/Dockerfile
Normal file
34
docker/Dockerfile
Normal 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" ]
|
||||||
|
|
@ -1,40 +1,22 @@
|
||||||
import {
|
import { Controller, Route, Security, Tags, Body, Request, SuccessResponse, Response, Get, Put, Post, Path, Delete, Query } from "tsoa"
|
||||||
Controller,
|
import { setLogDataDiff } from "../interfaces/utils"
|
||||||
Route,
|
|
||||||
Security,
|
|
||||||
Tags,
|
|
||||||
Body,
|
|
||||||
Request,
|
|
||||||
SuccessResponse,
|
|
||||||
Response,
|
|
||||||
Get,
|
|
||||||
Put,
|
|
||||||
Post,
|
|
||||||
Path,
|
|
||||||
Delete,
|
|
||||||
Query,
|
|
||||||
} from "tsoa";
|
|
||||||
import { setLogDataDiff } from "../interfaces/utils";
|
|
||||||
|
|
||||||
import { AppDataSource } from "../database/data-source";
|
import { AppDataSource } from "../database/data-source"
|
||||||
import HttpSuccess from "../interfaces/http-success";
|
import HttpSuccess from "../interfaces/http-success"
|
||||||
import HttpStatusCode from "../interfaces/http-status";
|
import HttpStatusCode from "../interfaces/http-status"
|
||||||
import HttpError from "../interfaces/http-error";
|
import HttpError from "../interfaces/http-error"
|
||||||
import permission from "../interfaces/permission";
|
import permission from "../interfaces/permission"
|
||||||
import { RequestWithUser } from "../middlewares/user";
|
import { RequestWithUser } from "../middlewares/user"
|
||||||
import { Appoint, CreateAppoint, Person, UpdateAppoint } from "../entities/Appoint";
|
import { Appoint, CreateAppoint, Person, UpdateAppoint } from "../entities/Appoint"
|
||||||
import { AppointDirector } from "../entities/AppointDirector";
|
import { AppointDirector } from "../entities/AppointDirector"
|
||||||
|
|
||||||
@Route("api/v1/probation/appoint")
|
@Route("api/v1/probation/appoint")
|
||||||
@Tags("Appoint Director")
|
@Tags("Appoint Director")
|
||||||
@Security("bearerAuth")
|
@Security("bearerAuth")
|
||||||
@Response(
|
@Response(HttpStatusCode.INTERNAL_SERVER_ERROR, "เกิดข้อผิดพลาด ไม่สามารถแสดงรายการได้ กรุณาลองใหม่ในภายหลัง")
|
||||||
HttpStatusCode.INTERNAL_SERVER_ERROR,
|
|
||||||
"เกิดข้อผิดพลาด ไม่สามารถแสดงรายการได้ กรุณาลองใหม่ในภายหลัง",
|
|
||||||
)
|
|
||||||
export class AppointController extends Controller {
|
export class AppointController extends Controller {
|
||||||
private appointRepository = AppDataSource.getRepository(Appoint);
|
private appointRepository = AppDataSource.getRepository(Appoint)
|
||||||
private appointDirectorRepository = AppDataSource.getRepository(AppointDirector);
|
private appointDirectorRepository = AppDataSource.getRepository(AppointDirector)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* API รายการแต่งตั้งคณะกรรมการฯ ทดลองงาน
|
* API รายการแต่งตั้งคณะกรรมการฯ ทดลองงาน
|
||||||
|
|
@ -43,43 +25,38 @@ export class AppointController extends Controller {
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@Get("")
|
@Get("")
|
||||||
async GetList(
|
async GetList(@Query() keyword: string = "", @Query("page") page: number = 1, @Query("pageSize") pageSize: number = 10, @Request() request: RequestWithUser) {
|
||||||
@Query() keyword: string = "",
|
await new permission().PermissionList(request, "SYS_PROBATION")
|
||||||
@Query("page") page: number = 1,
|
const _data = await new permission().PermissionOrgList(request, "SYS_PROBATION")
|
||||||
@Query("pageSize") pageSize: number = 10,
|
|
||||||
@Request() request: RequestWithUser,
|
|
||||||
) {
|
|
||||||
await new permission().PermissionList(request, "SYS_PROBATION");
|
|
||||||
const _data = await new permission().PermissionOrgList(request, "SYS_PROBATION");
|
|
||||||
|
|
||||||
const conditions: any = {};
|
const conditions: any = {}
|
||||||
|
|
||||||
if (_data.root != undefined && _data.root != null && _data.root[0] != null) {
|
if (_data.root != undefined && _data.root != null && _data.root[0] != null) {
|
||||||
conditions.root = _data.root;
|
conditions.root = _data.root
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_data.child1 != undefined && _data.child1 != null && _data.child1[0] != null) {
|
if (_data.child1 != undefined && _data.child1 != null && _data.child1[0] != null) {
|
||||||
conditions.child1 = _data.child1;
|
conditions.child1 = _data.child1
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_data.child2 != undefined && _data.child2 != null && _data.child2[0] != null) {
|
if (_data.child2 != undefined && _data.child2 != null && _data.child2[0] != null) {
|
||||||
conditions.child2 = _data.child2;
|
conditions.child2 = _data.child2
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_data.child3 != undefined && _data.child3 != null && _data.child3[0] != null) {
|
if (_data.child3 != undefined && _data.child3 != null && _data.child3[0] != null) {
|
||||||
conditions.child3 = _data.child3;
|
conditions.child3 = _data.child3
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_data.child4 != undefined && _data.child4 != null && _data.child4[0] != null) {
|
if (_data.child4 != undefined && _data.child4 != null && _data.child4[0] != null) {
|
||||||
conditions.child4 = _data.child4;
|
conditions.child4 = _data.child4
|
||||||
}
|
}
|
||||||
|
|
||||||
const appoint = await this.appointRepository.find({
|
const appoint = await this.appointRepository.find({
|
||||||
relations: ["personal"],
|
relations: ["personal"],
|
||||||
where: { personal: conditions },
|
where: { personal: conditions },
|
||||||
});
|
})
|
||||||
|
|
||||||
return new HttpSuccess(appoint);
|
return new HttpSuccess(appoint)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -93,9 +70,9 @@ export class AppointController extends Controller {
|
||||||
const appoint = await this.appointRepository.find({
|
const appoint = await this.appointRepository.find({
|
||||||
relations: ["directors"],
|
relations: ["directors"],
|
||||||
where: { profileId: id, status: "DONE" },
|
where: { profileId: id, status: "DONE" },
|
||||||
});
|
})
|
||||||
|
|
||||||
return new HttpSuccess(appoint);
|
return new HttpSuccess(appoint)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -106,19 +83,19 @@ export class AppointController extends Controller {
|
||||||
*/
|
*/
|
||||||
@Post("")
|
@Post("")
|
||||||
async Create(@Request() request: RequestWithUser, @Body() requestBody: CreateAppoint) {
|
async Create(@Request() request: RequestWithUser, @Body() requestBody: CreateAppoint) {
|
||||||
await new permission().PermissionCreate(request, "SYS_PROBATION");
|
await new permission().PermissionCreate(request, "SYS_PROBATION")
|
||||||
|
|
||||||
const data: any = {
|
const data: any = {
|
||||||
topic: requestBody.topic,
|
topic: requestBody.topic,
|
||||||
profileId: requestBody.profileId,
|
profileId: requestBody.profileId,
|
||||||
createdUserId: request.user.sub,
|
createdUserId: request.user.sub,
|
||||||
createdFullName: request.user.name,
|
createdFullName: request.user.name,
|
||||||
};
|
}
|
||||||
const before = null;
|
const before = null
|
||||||
const appoint = await this.appointRepository.save(data, { data: request });
|
const appoint = await this.appointRepository.save(data, { data: request })
|
||||||
setLogDataDiff(request, { before, after: appoint });
|
setLogDataDiff(request, { before, after: appoint })
|
||||||
|
|
||||||
return new HttpSuccess(appoint.id);
|
return new HttpSuccess(appoint.id)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -129,16 +106,16 @@ export class AppointController extends Controller {
|
||||||
*/
|
*/
|
||||||
@Get("{id}")
|
@Get("{id}")
|
||||||
async GetById(@Request() request: RequestWithUser, @Path() id: string) {
|
async GetById(@Request() request: RequestWithUser, @Path() id: string) {
|
||||||
let _workflow = await new permission().Workflow(request, id, "SYS_PROBATION");
|
let _workflow = await new permission().Workflow(request, id, "SYS_PROBATION")
|
||||||
if (_workflow == false) await new permission().PermissionGet(request, "SYS_PROBATION");
|
if (_workflow == false) await new permission().PermissionGet(request, "SYS_PROBATION")
|
||||||
|
|
||||||
const appoint = await this.appointRepository.findOne({
|
const appoint = await this.appointRepository.findOne({
|
||||||
select: ["id", "topic", "status", "profileId"],
|
select: ["id", "topic", "status", "profileId"],
|
||||||
where: { id },
|
where: { id },
|
||||||
relations: ["directors"],
|
relations: ["directors"],
|
||||||
});
|
})
|
||||||
|
|
||||||
return new HttpSuccess(appoint);
|
return new HttpSuccess(appoint)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -148,40 +125,35 @@ export class AppointController extends Controller {
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@Put("{id}")
|
@Put("{id}")
|
||||||
async Update(
|
async Update(@Request() request: RequestWithUser, @Body() requestBody: UpdateAppoint, @Path() id: string) {
|
||||||
@Request() request: RequestWithUser,
|
await new permission().PermissionUpdate(request, "SYS_PROBATION")
|
||||||
@Body() requestBody: UpdateAppoint,
|
|
||||||
@Path() id: string,
|
|
||||||
) {
|
|
||||||
await new permission().PermissionUpdate(request, "SYS_PROBATION");
|
|
||||||
|
|
||||||
const appoint: any = await this.appointRepository.findOne({ where: { id } });
|
const appoint: any = await this.appointRepository.findOne({ where: { id } })
|
||||||
|
|
||||||
if (!appoint) {
|
if (!appoint) {
|
||||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลการแต่งตั้งคณะกรรมการฯ");
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลการแต่งตั้งคณะกรรมการฯ")
|
||||||
}
|
}
|
||||||
|
|
||||||
const before = appoint;
|
const before = appoint
|
||||||
|
|
||||||
appoint.topic = requestBody.topic;
|
appoint.topic = requestBody.topic
|
||||||
appoint.updateUserId = request.user.sub;
|
appoint.updateUserId = request.user.sub
|
||||||
appoint.updateFullName = request.user.name;
|
appoint.updateFullName = request.user.name
|
||||||
|
await this.appointDirectorRepository.delete({ appointId: id })
|
||||||
await this.appointDirectorRepository.delete({ appointId: id });
|
const directors: any = await requestBody.persons.map((x: Person) => ({
|
||||||
const directors = await requestBody.persons.map((x: Person) => ({
|
|
||||||
...x,
|
...x,
|
||||||
appointId: id,
|
appointId: id,
|
||||||
createdUserId: request.user.sub,
|
createdUserId: request.user.sub,
|
||||||
createdFullName: request.user.name,
|
createdFullName: request.user.name,
|
||||||
updateUserId: request.user.sub,
|
updateUserId: request.user.sub,
|
||||||
updateFullName: request.user.name,
|
updateFullName: request.user.name,
|
||||||
}));
|
}))
|
||||||
await this.appointDirectorRepository.save(directors);
|
await this.appointDirectorRepository.save(directors)
|
||||||
|
|
||||||
await this.appointRepository.save(appoint, { data: request });
|
await this.appointRepository.save(appoint, { data: request })
|
||||||
setLogDataDiff(request, { before, after: appoint });
|
setLogDataDiff(request, { before, after: appoint })
|
||||||
|
|
||||||
return new HttpSuccess();
|
return new HttpSuccess()
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -192,13 +164,13 @@ export class AppointController extends Controller {
|
||||||
*/
|
*/
|
||||||
@Delete("{id}")
|
@Delete("{id}")
|
||||||
public async deleteRole(@Path() id: string, @Request() request: RequestWithUser) {
|
public async deleteRole(@Path() id: string, @Request() request: RequestWithUser) {
|
||||||
await new permission().PermissionDelete(request, "SYS_PROBATION");
|
await new permission().PermissionDelete(request, "SYS_PROBATION")
|
||||||
|
|
||||||
await this.appointDirectorRepository.delete({ appointId: id });
|
await this.appointDirectorRepository.delete({ appointId: id })
|
||||||
|
|
||||||
const result = await this.appointRepository.delete({ id });
|
const result = await this.appointRepository.delete({ id })
|
||||||
if (!result) throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
|
if (!result) throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล")
|
||||||
|
|
||||||
return new HttpSuccess();
|
return new HttpSuccess()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,40 +1,59 @@
|
||||||
import { Controller, Post, Put, Route, Security, Tags, Body, Request, SuccessResponse, Response, Get, Query } from "tsoa"
|
import {
|
||||||
import { AppDataSource } from "../database/data-source"
|
Controller,
|
||||||
import HttpSuccess from "../interfaces/http-success"
|
Post,
|
||||||
import HttpStatusCode from "../interfaces/http-status"
|
Put,
|
||||||
import HttpError from "../interfaces/http-error"
|
Route,
|
||||||
import { RequestWithUser } from "../middlewares/user"
|
Security,
|
||||||
import { findEndDate, setLogDataDiff } from "../interfaces/utils"
|
Tags,
|
||||||
import { Personal } from "../entities/Personal"
|
Body,
|
||||||
import permission from "../interfaces/permission"
|
Request,
|
||||||
import { Assign, CreateAssign } from "../entities/Assign"
|
SuccessResponse,
|
||||||
import { AssignDirector, CreateAssignDirector } from "../entities/AssignDirector"
|
Response,
|
||||||
import { AssignJob, CreateAssignJob } from "../entities/AssignJob"
|
Get,
|
||||||
import { AssignKnowledge, CreateAssignKnowledge } from "../entities/AssignKnowledge"
|
Query,
|
||||||
import { AssignLaw, CreateAssignLaw } from "../entities/AssignLaw"
|
} from "tsoa";
|
||||||
import { AssignSkill, CreateAssignSkill } from "../entities/AssignSkill"
|
import { AppDataSource } from "../database/data-source";
|
||||||
import { AssignCompetency, CreateAssignCompetency } from "../entities/AssignCompetency"
|
import HttpSuccess from "../interfaces/http-success";
|
||||||
import { AssignCompetencyGroup, CreateAssignCompetencyGroup } from "../entities/AssignCompetencyGroup"
|
import HttpStatusCode from "../interfaces/http-status";
|
||||||
import { AssignOutput, CreateAssignOutput } from "../entities/AssignOutput"
|
import HttpError from "../interfaces/http-error";
|
||||||
import { Law } from "../entities/Law"
|
import { RequestWithUser } from "../middlewares/user";
|
||||||
import CallAPI from "../interfaces/call-api"
|
import { findEndDate, setLogDataDiff } from "../interfaces/utils";
|
||||||
|
import { Personal } from "../entities/Personal";
|
||||||
|
import permission from "../interfaces/permission";
|
||||||
|
import { Assign, CreateAssign } from "../entities/Assign";
|
||||||
|
import { AssignDirector, CreateAssignDirector } from "../entities/AssignDirector";
|
||||||
|
import { AssignJob, CreateAssignJob } from "../entities/AssignJob";
|
||||||
|
import { AssignKnowledge, CreateAssignKnowledge } from "../entities/AssignKnowledge";
|
||||||
|
import { AssignLaw, CreateAssignLaw } from "../entities/AssignLaw";
|
||||||
|
import { AssignSkill, CreateAssignSkill } from "../entities/AssignSkill";
|
||||||
|
import { AssignCompetency, CreateAssignCompetency } from "../entities/AssignCompetency";
|
||||||
|
import {
|
||||||
|
AssignCompetencyGroup,
|
||||||
|
CreateAssignCompetencyGroup,
|
||||||
|
} from "../entities/AssignCompetencyGroup";
|
||||||
|
import { AssignOutput, CreateAssignOutput } from "../entities/AssignOutput";
|
||||||
|
import { Law } from "../entities/Law";
|
||||||
|
import CallAPI from "../interfaces/call-api";
|
||||||
|
|
||||||
@Route("api/v1/probation/assign")
|
@Route("api/v1/probation/assign")
|
||||||
@Tags("ฟอร์มมอบหมายงาน")
|
@Tags("ฟอร์มมอบหมายงาน")
|
||||||
@Security("bearerAuth")
|
@Security("bearerAuth")
|
||||||
@Response(HttpStatusCode.INTERNAL_SERVER_ERROR, "เกิดข้อผิดพลาด ไม่สามารถแสดงรายการได้ กรุณาลองใหม่ในภายหลัง")
|
@Response(
|
||||||
|
HttpStatusCode.INTERNAL_SERVER_ERROR,
|
||||||
|
"เกิดข้อผิดพลาด ไม่สามารถแสดงรายการได้ กรุณาลองใหม่ในภายหลัง",
|
||||||
|
)
|
||||||
export class AssignController extends Controller {
|
export class AssignController extends Controller {
|
||||||
private assignRepository = AppDataSource.getRepository(Assign)
|
private assignRepository = AppDataSource.getRepository(Assign);
|
||||||
private personalRepository = AppDataSource.getRepository(Personal)
|
private personalRepository = AppDataSource.getRepository(Personal);
|
||||||
private assignDirectorRepository = AppDataSource.getRepository(AssignDirector)
|
private assignDirectorRepository = AppDataSource.getRepository(AssignDirector);
|
||||||
private assignJobRepository = AppDataSource.getRepository(AssignJob)
|
private assignJobRepository = AppDataSource.getRepository(AssignJob);
|
||||||
private assignKnowledgeRepository = AppDataSource.getRepository(AssignKnowledge)
|
private assignKnowledgeRepository = AppDataSource.getRepository(AssignKnowledge);
|
||||||
private assignLawRepository = AppDataSource.getRepository(AssignLaw)
|
private assignLawRepository = AppDataSource.getRepository(AssignLaw);
|
||||||
private assignSkillRepository = AppDataSource.getRepository(AssignSkill)
|
private assignSkillRepository = AppDataSource.getRepository(AssignSkill);
|
||||||
private assignCompetencyRepository = AppDataSource.getRepository(AssignCompetency)
|
private assignCompetencyRepository = AppDataSource.getRepository(AssignCompetency);
|
||||||
private assignCompetencyGroupRepository = AppDataSource.getRepository(AssignCompetencyGroup)
|
private assignCompetencyGroupRepository = AppDataSource.getRepository(AssignCompetencyGroup);
|
||||||
private assignOutputRepository = AppDataSource.getRepository(AssignOutput)
|
private assignOutputRepository = AppDataSource.getRepository(AssignOutput);
|
||||||
private lawsRepository = AppDataSource.getRepository(Law)
|
private lawsRepository = AppDataSource.getRepository(Law);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* API เพิ่มข้อมูลการมอบหมายงาน
|
* API เพิ่มข้อมูลการมอบหมายงาน
|
||||||
|
|
@ -44,15 +63,15 @@ export class AssignController extends Controller {
|
||||||
*/
|
*/
|
||||||
@Post("")
|
@Post("")
|
||||||
async AddAssign(@Request() request: RequestWithUser, @Body() requestBody: CreateAssign) {
|
async AddAssign(@Request() request: RequestWithUser, @Body() requestBody: CreateAssign) {
|
||||||
await new permission().PermissionUpdate(request, "SYS_PROBATION")
|
await new permission().PermissionUpdate(request, "SYS_PROBATION");
|
||||||
const person = await this.personalRepository.findOne({
|
const person = await this.personalRepository.findOne({
|
||||||
where: {
|
where: {
|
||||||
personal_id: requestBody.personalId,
|
personal_id: requestBody.personalId,
|
||||||
},
|
},
|
||||||
})
|
});
|
||||||
|
|
||||||
if (!person) {
|
if (!person) {
|
||||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลบุคคล")
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลบุคคล");
|
||||||
}
|
}
|
||||||
|
|
||||||
const roundNo = await this.assignRepository.count({
|
const roundNo = await this.assignRepository.count({
|
||||||
|
|
@ -60,7 +79,7 @@ export class AssignController extends Controller {
|
||||||
active: 1,
|
active: 1,
|
||||||
personal_id: requestBody.personalId,
|
personal_id: requestBody.personalId,
|
||||||
},
|
},
|
||||||
})
|
});
|
||||||
|
|
||||||
const data: any = {
|
const data: any = {
|
||||||
...requestBody,
|
...requestBody,
|
||||||
|
|
@ -70,10 +89,10 @@ export class AssignController extends Controller {
|
||||||
createdFullName: request.user.name,
|
createdFullName: request.user.name,
|
||||||
updateUserId: request.user.sub,
|
updateUserId: request.user.sub,
|
||||||
updateFullName: request.user.name,
|
updateFullName: request.user.name,
|
||||||
}
|
};
|
||||||
const before = null
|
const before = null;
|
||||||
const assign = await this.assignRepository.save(data, { data: request })
|
const assign = await this.assignRepository.save(data, { data: request });
|
||||||
setLogDataDiff(request, { before, after: data })
|
setLogDataDiff(request, { before, after: data });
|
||||||
|
|
||||||
const jobs = await requestBody.assign_jobs.map((x: CreateAssignJob, index: number) => ({
|
const jobs = await requestBody.assign_jobs.map((x: CreateAssignJob, index: number) => ({
|
||||||
...x,
|
...x,
|
||||||
|
|
@ -83,11 +102,12 @@ export class AssignController extends Controller {
|
||||||
createdFullName: request.user.name,
|
createdFullName: request.user.name,
|
||||||
updateUserId: request.user.sub,
|
updateUserId: request.user.sub,
|
||||||
updateFullName: request.user.name,
|
updateFullName: request.user.name,
|
||||||
}))
|
}));
|
||||||
await this.assignJobRepository.save(jobs, { data: request })
|
await this.assignJobRepository.save(jobs, { data: request });
|
||||||
setLogDataDiff(request, { before, after: jobs })
|
setLogDataDiff(request, { before, after: jobs });
|
||||||
|
|
||||||
const knowledges = await requestBody.assign_knowledges.map((x: CreateAssignKnowledge, index: number) => ({
|
const knowledges = await requestBody.assign_knowledges.map(
|
||||||
|
(x: CreateAssignKnowledge, index: number) => ({
|
||||||
knowledge_level: x.level,
|
knowledge_level: x.level,
|
||||||
knowledge_id: x.id,
|
knowledge_id: x.id,
|
||||||
assign_id: assign.id,
|
assign_id: assign.id,
|
||||||
|
|
@ -95,9 +115,10 @@ export class AssignController extends Controller {
|
||||||
createdFullName: request.user.name,
|
createdFullName: request.user.name,
|
||||||
updateUserId: request.user.sub,
|
updateUserId: request.user.sub,
|
||||||
updateFullName: request.user.name,
|
updateFullName: request.user.name,
|
||||||
}))
|
}),
|
||||||
await this.assignKnowledgeRepository.save(knowledges, { data: request })
|
);
|
||||||
setLogDataDiff(request, { before, after: knowledges })
|
await this.assignKnowledgeRepository.save(knowledges, { data: request });
|
||||||
|
setLogDataDiff(request, { before, after: knowledges });
|
||||||
|
|
||||||
const laws = await requestBody.assign_law.map((x: CreateAssignLaw, index: number) => ({
|
const laws = await requestBody.assign_law.map((x: CreateAssignLaw, index: number) => ({
|
||||||
ordering: index + 1,
|
ordering: index + 1,
|
||||||
|
|
@ -107,9 +128,9 @@ export class AssignController extends Controller {
|
||||||
createdFullName: request.user.name,
|
createdFullName: request.user.name,
|
||||||
updateUserId: request.user.sub,
|
updateUserId: request.user.sub,
|
||||||
updateFullName: request.user.name,
|
updateFullName: request.user.name,
|
||||||
}))
|
}));
|
||||||
await this.assignLawRepository.save(laws, { data: request })
|
await this.assignLawRepository.save(laws, { data: request });
|
||||||
setLogDataDiff(request, { before, after: laws })
|
setLogDataDiff(request, { before, after: laws });
|
||||||
|
|
||||||
const skills = await requestBody.assign_skill.map((x: CreateAssignSkill, index: number) => ({
|
const skills = await requestBody.assign_skill.map((x: CreateAssignSkill, index: number) => ({
|
||||||
skill_id: index + 1,
|
skill_id: index + 1,
|
||||||
|
|
@ -119,11 +140,12 @@ export class AssignController extends Controller {
|
||||||
createdFullName: request.user.name,
|
createdFullName: request.user.name,
|
||||||
updateUserId: request.user.sub,
|
updateUserId: request.user.sub,
|
||||||
updateFullName: request.user.name,
|
updateFullName: request.user.name,
|
||||||
}))
|
}));
|
||||||
await this.assignSkillRepository.save(skills, { data: request })
|
await this.assignSkillRepository.save(skills, { data: request });
|
||||||
setLogDataDiff(request, { before, after: skills })
|
setLogDataDiff(request, { before, after: skills });
|
||||||
|
|
||||||
const competencise = await requestBody.assign_competency.map((x: CreateAssignCompetency, index: number) => ({
|
const competencise = await requestBody.assign_competency.map(
|
||||||
|
(x: CreateAssignCompetency, index: number) => ({
|
||||||
competency_id: x.id,
|
competency_id: x.id,
|
||||||
competency_level: x.level,
|
competency_level: x.level,
|
||||||
competency_name: x.name,
|
competency_name: x.name,
|
||||||
|
|
@ -133,11 +155,13 @@ export class AssignController extends Controller {
|
||||||
createdFullName: request.user.name,
|
createdFullName: request.user.name,
|
||||||
updateUserId: request.user.sub,
|
updateUserId: request.user.sub,
|
||||||
updateFullName: request.user.name,
|
updateFullName: request.user.name,
|
||||||
}))
|
}),
|
||||||
await this.assignCompetencyRepository.save(competencise, { data: request })
|
);
|
||||||
setLogDataDiff(request, { before, after: competencise })
|
await this.assignCompetencyRepository.save(competencise, { data: request });
|
||||||
|
setLogDataDiff(request, { before, after: competencise });
|
||||||
|
|
||||||
const competencyGroups = await requestBody.assign_competency_group.map((x: CreateAssignCompetencyGroup, index: number) => ({
|
const competencyGroups = await requestBody.assign_competency_group.map(
|
||||||
|
(x: CreateAssignCompetencyGroup, index: number) => ({
|
||||||
competency_group_id: x.id,
|
competency_group_id: x.id,
|
||||||
competency_group_level: x.level,
|
competency_group_level: x.level,
|
||||||
competency_group_name: x.name,
|
competency_group_name: x.name,
|
||||||
|
|
@ -147,13 +171,15 @@ export class AssignController extends Controller {
|
||||||
createdFullName: request.user.name,
|
createdFullName: request.user.name,
|
||||||
updateUserId: request.user.sub,
|
updateUserId: request.user.sub,
|
||||||
updateFullName: request.user.name,
|
updateFullName: request.user.name,
|
||||||
}))
|
}),
|
||||||
|
);
|
||||||
await this.assignCompetencyGroupRepository.save(competencyGroups, {
|
await this.assignCompetencyGroupRepository.save(competencyGroups, {
|
||||||
data: request,
|
data: request,
|
||||||
})
|
});
|
||||||
setLogDataDiff(request, { before, after: competencyGroups })
|
setLogDataDiff(request, { before, after: competencyGroups });
|
||||||
|
|
||||||
const outputs = await requestBody.assign_outputs.map((x: CreateAssignOutput, index: number) => ({
|
const outputs = await requestBody.assign_outputs.map(
|
||||||
|
(x: CreateAssignOutput, index: number) => ({
|
||||||
...x,
|
...x,
|
||||||
id: index + 1,
|
id: index + 1,
|
||||||
assign_id: assign.id,
|
assign_id: assign.id,
|
||||||
|
|
@ -161,11 +187,13 @@ export class AssignController extends Controller {
|
||||||
createdFullName: request.user.name,
|
createdFullName: request.user.name,
|
||||||
updateUserId: request.user.sub,
|
updateUserId: request.user.sub,
|
||||||
updateFullName: request.user.name,
|
updateFullName: request.user.name,
|
||||||
}))
|
}),
|
||||||
await this.assignOutputRepository.save(outputs, { data: request })
|
);
|
||||||
setLogDataDiff(request, { before, after: outputs })
|
await this.assignOutputRepository.save(outputs, { data: request });
|
||||||
|
setLogDataDiff(request, { before, after: outputs });
|
||||||
|
|
||||||
const directors = await requestBody.assign_director.map((x: CreateAssignDirector, index: number) => ({
|
const directors = await requestBody.assign_director.map(
|
||||||
|
(x: CreateAssignDirector, index: number) => ({
|
||||||
...x,
|
...x,
|
||||||
assign_id: assign.id,
|
assign_id: assign.id,
|
||||||
fullname: x.name,
|
fullname: x.name,
|
||||||
|
|
@ -174,11 +202,12 @@ export class AssignController extends Controller {
|
||||||
createdFullName: request.user.name,
|
createdFullName: request.user.name,
|
||||||
updateUserId: request.user.sub,
|
updateUserId: request.user.sub,
|
||||||
updateFullName: request.user.name,
|
updateFullName: request.user.name,
|
||||||
}))
|
}),
|
||||||
await this.assignDirectorRepository.save(directors, { data: request })
|
);
|
||||||
setLogDataDiff(request, { before, after: directors })
|
await this.assignDirectorRepository.save(directors, { data: request });
|
||||||
|
setLogDataDiff(request, { before, after: directors });
|
||||||
|
|
||||||
return new HttpSuccess()
|
return new HttpSuccess();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -188,26 +217,30 @@ export class AssignController extends Controller {
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@Put("")
|
@Put("")
|
||||||
async EditAssign(@Query() assign_id: string, @Request() request: RequestWithUser, @Body() requestBody: CreateAssign) {
|
async EditAssign(
|
||||||
await new permission().PermissionUpdate(request, "SYS_PROBATION")
|
@Query() assign_id: string,
|
||||||
|
@Request() request: RequestWithUser,
|
||||||
|
@Body() requestBody: CreateAssign,
|
||||||
|
) {
|
||||||
|
await new permission().PermissionUpdate(request, "SYS_PROBATION");
|
||||||
|
|
||||||
const assign = await this.assignRepository.findOne({
|
const assign = await this.assignRepository.findOne({
|
||||||
where: { id: assign_id },
|
where: { id: assign_id },
|
||||||
})
|
});
|
||||||
let before = assign
|
let before = assign;
|
||||||
|
|
||||||
if (!assign) {
|
if (!assign) {
|
||||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลแบบมอบหมายงาน")
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลแบบมอบหมายงาน");
|
||||||
}
|
}
|
||||||
|
|
||||||
const person = await this.personalRepository.findOne({
|
const person = await this.personalRepository.findOne({
|
||||||
where: {
|
where: {
|
||||||
personal_id: requestBody.personalId,
|
personal_id: requestBody.personalId,
|
||||||
},
|
},
|
||||||
})
|
});
|
||||||
|
|
||||||
if (!person) {
|
if (!person) {
|
||||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลบุคคล")
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลบุคคล");
|
||||||
}
|
}
|
||||||
|
|
||||||
const data: any = {
|
const data: any = {
|
||||||
|
|
@ -215,9 +248,9 @@ export class AssignController extends Controller {
|
||||||
id: assign_id,
|
id: assign_id,
|
||||||
updateUserId: request.user.sub,
|
updateUserId: request.user.sub,
|
||||||
updateFullName: request.user.name,
|
updateFullName: request.user.name,
|
||||||
}
|
};
|
||||||
|
|
||||||
await this.assignJobRepository.delete({ assign_id })
|
await this.assignJobRepository.delete({ assign_id });
|
||||||
const jobs = await requestBody.assign_jobs.map((x: CreateAssignJob, index: number) => ({
|
const jobs = await requestBody.assign_jobs.map((x: CreateAssignJob, index: number) => ({
|
||||||
...x,
|
...x,
|
||||||
id: index + 1,
|
id: index + 1,
|
||||||
|
|
@ -226,11 +259,12 @@ export class AssignController extends Controller {
|
||||||
createdFullName: request.user.name,
|
createdFullName: request.user.name,
|
||||||
updateUserId: request.user.sub,
|
updateUserId: request.user.sub,
|
||||||
updateFullName: request.user.name,
|
updateFullName: request.user.name,
|
||||||
}))
|
}));
|
||||||
await this.assignJobRepository.save(jobs)
|
await this.assignJobRepository.save(jobs);
|
||||||
|
|
||||||
await this.assignKnowledgeRepository.delete({ assign_id })
|
await this.assignKnowledgeRepository.delete({ assign_id });
|
||||||
const knowledges = await requestBody.assign_knowledges.map((x: CreateAssignKnowledge, index: number) => ({
|
const knowledges = await requestBody.assign_knowledges.map(
|
||||||
|
(x: CreateAssignKnowledge, index: number) => ({
|
||||||
knowledge_level: x.level,
|
knowledge_level: x.level,
|
||||||
knowledge_id: x.id,
|
knowledge_id: x.id,
|
||||||
assign_id: assign.id,
|
assign_id: assign.id,
|
||||||
|
|
@ -238,10 +272,11 @@ export class AssignController extends Controller {
|
||||||
createdFullName: request.user.name,
|
createdFullName: request.user.name,
|
||||||
updateUserId: request.user.sub,
|
updateUserId: request.user.sub,
|
||||||
updateFullName: request.user.name,
|
updateFullName: request.user.name,
|
||||||
}))
|
}),
|
||||||
await this.assignKnowledgeRepository.save(knowledges)
|
);
|
||||||
|
await this.assignKnowledgeRepository.save(knowledges);
|
||||||
|
|
||||||
await this.assignLawRepository.delete({ assign_id })
|
await this.assignLawRepository.delete({ assign_id });
|
||||||
const laws = await requestBody.assign_law.map((x: CreateAssignLaw, index: number) => ({
|
const laws = await requestBody.assign_law.map((x: CreateAssignLaw, index: number) => ({
|
||||||
ordering: index + 1,
|
ordering: index + 1,
|
||||||
law_id: x.id,
|
law_id: x.id,
|
||||||
|
|
@ -250,10 +285,10 @@ export class AssignController extends Controller {
|
||||||
createdFullName: request.user.name,
|
createdFullName: request.user.name,
|
||||||
updateUserId: request.user.sub,
|
updateUserId: request.user.sub,
|
||||||
updateFullName: request.user.name,
|
updateFullName: request.user.name,
|
||||||
}))
|
}));
|
||||||
await this.assignLawRepository.save(laws)
|
await this.assignLawRepository.save(laws);
|
||||||
|
|
||||||
await this.assignSkillRepository.delete({ assign_id })
|
await this.assignSkillRepository.delete({ assign_id });
|
||||||
const skills = await requestBody.assign_skill.map((x: CreateAssignSkill, index: number) => ({
|
const skills = await requestBody.assign_skill.map((x: CreateAssignSkill, index: number) => ({
|
||||||
skill_id: index + 1,
|
skill_id: index + 1,
|
||||||
skill_level: x.level,
|
skill_level: x.level,
|
||||||
|
|
@ -262,11 +297,12 @@ export class AssignController extends Controller {
|
||||||
createdFullName: request.user.name,
|
createdFullName: request.user.name,
|
||||||
updateUserId: request.user.sub,
|
updateUserId: request.user.sub,
|
||||||
updateFullName: request.user.name,
|
updateFullName: request.user.name,
|
||||||
}))
|
}));
|
||||||
await this.assignSkillRepository.save(skills)
|
await this.assignSkillRepository.save(skills);
|
||||||
|
|
||||||
await this.assignCompetencyRepository.delete({ assign_id })
|
await this.assignCompetencyRepository.delete({ assign_id });
|
||||||
const competencise = await requestBody.assign_competency.map((x: CreateAssignCompetency, index: number) => ({
|
const competencise = await requestBody.assign_competency.map(
|
||||||
|
(x: CreateAssignCompetency, index: number) => ({
|
||||||
competency_id: x.id,
|
competency_id: x.id,
|
||||||
competency_level: x.level,
|
competency_level: x.level,
|
||||||
competency_name: x.name,
|
competency_name: x.name,
|
||||||
|
|
@ -276,11 +312,13 @@ export class AssignController extends Controller {
|
||||||
createdFullName: request.user.name,
|
createdFullName: request.user.name,
|
||||||
updateUserId: request.user.sub,
|
updateUserId: request.user.sub,
|
||||||
updateFullName: request.user.name,
|
updateFullName: request.user.name,
|
||||||
}))
|
}),
|
||||||
await this.assignCompetencyRepository.save(competencise)
|
);
|
||||||
|
await this.assignCompetencyRepository.save(competencise);
|
||||||
|
|
||||||
await this.assignCompetencyGroupRepository.delete({ assign_id })
|
await this.assignCompetencyGroupRepository.delete({ assign_id });
|
||||||
const competencyGroups = await requestBody.assign_competency_group.map((x: CreateAssignCompetencyGroup, index: number) => ({
|
const competencyGroups = await requestBody.assign_competency_group.map(
|
||||||
|
(x: CreateAssignCompetencyGroup, index: number) => ({
|
||||||
competency_group_id: x.id,
|
competency_group_id: x.id,
|
||||||
competency_group_level: x.level,
|
competency_group_level: x.level,
|
||||||
competency_group_name: x.name,
|
competency_group_name: x.name,
|
||||||
|
|
@ -290,11 +328,13 @@ export class AssignController extends Controller {
|
||||||
createdFullName: request.user.name,
|
createdFullName: request.user.name,
|
||||||
updateUserId: request.user.sub,
|
updateUserId: request.user.sub,
|
||||||
updateFullName: request.user.name,
|
updateFullName: request.user.name,
|
||||||
}))
|
}),
|
||||||
await this.assignCompetencyGroupRepository.save(competencyGroups)
|
);
|
||||||
|
await this.assignCompetencyGroupRepository.save(competencyGroups);
|
||||||
|
|
||||||
await this.assignOutputRepository.delete({ assign_id })
|
await this.assignOutputRepository.delete({ assign_id });
|
||||||
const outputs = await requestBody.assign_outputs.map((x: CreateAssignOutput, index: number) => ({
|
const outputs = await requestBody.assign_outputs.map(
|
||||||
|
(x: CreateAssignOutput, index: number) => ({
|
||||||
...x,
|
...x,
|
||||||
id: index + 1,
|
id: index + 1,
|
||||||
assign_id: assign.id,
|
assign_id: assign.id,
|
||||||
|
|
@ -302,11 +342,13 @@ export class AssignController extends Controller {
|
||||||
createdFullName: request.user.name,
|
createdFullName: request.user.name,
|
||||||
updateUserId: request.user.sub,
|
updateUserId: request.user.sub,
|
||||||
updateFullName: request.user.name,
|
updateFullName: request.user.name,
|
||||||
}))
|
}),
|
||||||
await this.assignOutputRepository.save(outputs)
|
);
|
||||||
|
await this.assignOutputRepository.save(outputs);
|
||||||
|
|
||||||
await this.assignDirectorRepository.delete({ assign_id })
|
await this.assignDirectorRepository.delete({ assign_id });
|
||||||
const directors = await requestBody.assign_director.map((x: CreateAssignDirector, index: number) => ({
|
const directors = await requestBody.assign_director.map(
|
||||||
|
(x: CreateAssignDirector, index: number) => ({
|
||||||
...x,
|
...x,
|
||||||
assign_id: assign.id,
|
assign_id: assign.id,
|
||||||
fullname: x.name,
|
fullname: x.name,
|
||||||
|
|
@ -315,18 +357,19 @@ export class AssignController extends Controller {
|
||||||
createdFullName: request.user.name,
|
createdFullName: request.user.name,
|
||||||
updateUserId: request.user.sub,
|
updateUserId: request.user.sub,
|
||||||
updateFullName: request.user.name,
|
updateFullName: request.user.name,
|
||||||
}))
|
}),
|
||||||
await this.assignDirectorRepository.save(directors)
|
);
|
||||||
|
await this.assignDirectorRepository.save(directors);
|
||||||
|
|
||||||
await this.assignRepository.save(data, { data: request })
|
await this.assignRepository.save(data, { data: request });
|
||||||
setLogDataDiff(request, { before, after: data })
|
setLogDataDiff(request, { before, after: data });
|
||||||
|
|
||||||
// #noted cronjob
|
// #noted cronjob
|
||||||
// แจ้งผู้ดูแลและผู้บังคับบัญชาเข้ามาบันทึกผลทุก 2 เดือน
|
// แจ้งผู้ดูแลและผู้บังคับบัญชาเข้ามาบันทึกผลทุก 2 เดือน
|
||||||
const dateSaveForm = await findEndDate(2, requestBody.date_start)
|
const dateSaveForm = await findEndDate(2, requestBody.date_start);
|
||||||
requestBody.assign_director
|
requestBody.assign_director
|
||||||
.filter(x => x.role == "mentor" || x.role == "commander")
|
.filter((x) => x.role == "mentor" || x.role == "commander")
|
||||||
.map(async director => {
|
.map(async (director) => {
|
||||||
await new CallAPI()
|
await new CallAPI()
|
||||||
.PostData(request, "/placement/noti", {
|
.PostData(request, "/placement/noti", {
|
||||||
subject: `ถึงกำหนดบันทึกผลการทดลองปฏิบัติหน้าที่ราชการครั้งที่ 1 ${requestBody.fullname}`,
|
subject: `ถึงกำหนดบันทึกผลการทดลองปฏิบัติหน้าที่ราชการครั้งที่ 1 ${requestBody.fullname}`,
|
||||||
|
|
@ -337,16 +380,16 @@ export class AssignController extends Controller {
|
||||||
isSendInbox: true,
|
isSendInbox: true,
|
||||||
receiveDate: dateSaveForm,
|
receiveDate: dateSaveForm,
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch((error) => {
|
||||||
console.error("Error calling API:", error)
|
console.error("Error calling API:", error);
|
||||||
})
|
});
|
||||||
})
|
});
|
||||||
|
|
||||||
// แจ้งผู้บังคับบัญชา และคณะกรรมการเข้ามาประเมินทุก 3 เดือน
|
// แจ้งผู้บังคับบัญชา และคณะกรรมการเข้ามาประเมินทุก 3 เดือน
|
||||||
const dateEvaluate = await findEndDate(3, requestBody.date_start)
|
const dateEvaluate = await findEndDate(3, requestBody.date_start);
|
||||||
requestBody.assign_director
|
requestBody.assign_director
|
||||||
.filter(x => x.role == "commander" || x.role == "chairman")
|
.filter((x) => x.role == "commander" || x.role == "chairman")
|
||||||
.map(async director => {
|
.map(async (director) => {
|
||||||
await new CallAPI()
|
await new CallAPI()
|
||||||
.PostData(request, "/placement/noti", {
|
.PostData(request, "/placement/noti", {
|
||||||
subject: `ถึงกำหนดประเมินผลการทดลองปฏิบัติหน้าที่ราชการครั้งที่ 1 ${requestBody.fullname}`,
|
subject: `ถึงกำหนดประเมินผลการทดลองปฏิบัติหน้าที่ราชการครั้งที่ 1 ${requestBody.fullname}`,
|
||||||
|
|
@ -357,16 +400,16 @@ export class AssignController extends Controller {
|
||||||
isSendInbox: true,
|
isSendInbox: true,
|
||||||
receiveDate: dateEvaluate,
|
receiveDate: dateEvaluate,
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch((error) => {
|
||||||
console.error("Error calling API:", error)
|
console.error("Error calling API:", error);
|
||||||
})
|
});
|
||||||
})
|
});
|
||||||
|
|
||||||
// แจ้งประธาน 6 เดือน
|
// แจ้งประธาน 6 เดือน
|
||||||
const dateResult = await findEndDate(6, requestBody.date_start)
|
const dateResult = await findEndDate(6, requestBody.date_start);
|
||||||
requestBody.assign_director
|
requestBody.assign_director
|
||||||
.filter(x => x.role == "chairman")
|
.filter((x) => x.role == "chairman")
|
||||||
.map(async director => {
|
.map(async (director) => {
|
||||||
await new CallAPI()
|
await new CallAPI()
|
||||||
.PostData(request, "/placement/noti", {
|
.PostData(request, "/placement/noti", {
|
||||||
subject: `ถึงกำหนดรายงานการประเมินผลการทดลองปฏิบัติหน้าที่ราชการ ${requestBody.fullname}`,
|
subject: `ถึงกำหนดรายงานการประเมินผลการทดลองปฏิบัติหน้าที่ราชการ ${requestBody.fullname}`,
|
||||||
|
|
@ -378,12 +421,12 @@ export class AssignController extends Controller {
|
||||||
// isSendNotification: true
|
// isSendNotification: true
|
||||||
receiveDate: dateResult,
|
receiveDate: dateResult,
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch((error) => {
|
||||||
console.error("Error calling API:", error)
|
console.error("Error calling API:", error);
|
||||||
})
|
});
|
||||||
})
|
});
|
||||||
|
|
||||||
return new HttpSuccess()
|
return new HttpSuccess();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -394,51 +437,104 @@ export class AssignController extends Controller {
|
||||||
*/
|
*/
|
||||||
@Get("assign-list")
|
@Get("assign-list")
|
||||||
async ListPersonal(@Request() request: RequestWithUser, @Query() personal_id: string) {
|
async ListPersonal(@Request() request: RequestWithUser, @Query() personal_id: string) {
|
||||||
let _workflow = await new permission().Workflow(request, personal_id, "SYS_PROBATION")
|
let _workflow = await new permission().Workflow(request, personal_id, "SYS_PROBATION");
|
||||||
if (_workflow == false) await new permission().PermissionGet(request, "SYS_PROBATION")
|
if (_workflow == false) await new permission().PermissionGet(request, "SYS_PROBATION");
|
||||||
const lists = await this.assignRepository.find({
|
const lists = await this.assignRepository.find({
|
||||||
select: ["id", "round_no", "date_start", "date_finish"],
|
select: ["id", "round_no", "date_start", "date_finish"],
|
||||||
where: { personal_id },
|
where: { personal_id },
|
||||||
order: { round_no: "ASC" },
|
order: { round_no: "ASC" },
|
||||||
})
|
});
|
||||||
|
|
||||||
let result: any = []
|
let result: any = [];
|
||||||
|
|
||||||
await Promise.all(
|
await Promise.all(
|
||||||
lists.map(async item => {
|
lists.map(async (item) => {
|
||||||
const director = await this.assignDirectorRepository.find({
|
const director = await this.assignDirectorRepository.find({
|
||||||
where: { assign_id: item.id },
|
where: { assign_id: item.id },
|
||||||
order: { ordering: "ASC" },
|
order: { ordering: "ASC" },
|
||||||
})
|
});
|
||||||
|
|
||||||
let mentors = ""
|
let mentors = "";
|
||||||
const mentorList = await director.filter(x => x.role == "mentor")
|
const mentorList = await director.filter((x) => x.role == "mentor");
|
||||||
if (mentorList.length > 0) {
|
if (mentorList.length > 0) {
|
||||||
for (let index = 0; index < mentorList.length; index++) {
|
for (let index = 0; index < mentorList.length; index++) {
|
||||||
const e = await mentorList[index]
|
const e = await mentorList[index];
|
||||||
mentors += e.fullname
|
mentors += e.fullname;
|
||||||
if (index < mentorList.length - 1) {
|
if (index < mentorList.length - 1) {
|
||||||
mentors += ", "
|
mentors += ", ";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const commanderData = await (director.find(x => x.role == "commander") ?? null)
|
const commanderData = await (director.find((x) => x.role == "commander") ?? null);
|
||||||
const commander = commanderData ? commanderData.fullname : null
|
const commander = commanderData ? commanderData.fullname : null;
|
||||||
|
|
||||||
const chairmanData = await (director.find(x => x.role == "chairman") ?? null)
|
const chairmanData = await (director.find((x) => x.role == "chairman") ?? null);
|
||||||
const chairman = chairmanData ? chairmanData.fullname : null
|
const chairman = chairmanData ? chairmanData.fullname : null;
|
||||||
|
|
||||||
await result.push({
|
await result.push({
|
||||||
...item,
|
...item,
|
||||||
mentors: mentors,
|
mentors: mentors,
|
||||||
commander: commander,
|
commander: commander,
|
||||||
chairman: chairman,
|
chairman: chairman,
|
||||||
})
|
});
|
||||||
})
|
}),
|
||||||
)
|
);
|
||||||
|
|
||||||
return new HttpSuccess(result)
|
return new HttpSuccess(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* API รายการข้อมูลการทดลองงานของผู้ใช้งาน ใช้เพื่อดูข้อมูลตอนทำ KPI
|
||||||
|
*
|
||||||
|
* @summary รายการข้อมูลการทดลองงานของผู้ใช้งาน
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
@Get("assign-user-list")
|
||||||
|
async ListPersonalUser(@Request() request: RequestWithUser, @Query() personal_id: string) {
|
||||||
|
const lists = await this.assignRepository.find({
|
||||||
|
select: ["id", "round_no", "date_start", "date_finish"],
|
||||||
|
where: { personal_id },
|
||||||
|
order: { round_no: "ASC" },
|
||||||
|
});
|
||||||
|
|
||||||
|
let result: any = [];
|
||||||
|
|
||||||
|
await Promise.all(
|
||||||
|
lists.map(async (item) => {
|
||||||
|
const director = await this.assignDirectorRepository.find({
|
||||||
|
where: { assign_id: item.id },
|
||||||
|
order: { ordering: "ASC" },
|
||||||
|
});
|
||||||
|
|
||||||
|
let mentors = "";
|
||||||
|
const mentorList = await director.filter((x) => x.role == "mentor");
|
||||||
|
if (mentorList.length > 0) {
|
||||||
|
for (let index = 0; index < mentorList.length; index++) {
|
||||||
|
const e = await mentorList[index];
|
||||||
|
mentors += e.fullname;
|
||||||
|
if (index < mentorList.length - 1) {
|
||||||
|
mentors += ", ";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const commanderData = await (director.find((x) => x.role == "commander") ?? null);
|
||||||
|
const commander = commanderData ? commanderData.fullname : null;
|
||||||
|
|
||||||
|
const chairmanData = await (director.find((x) => x.role == "chairman") ?? null);
|
||||||
|
const chairman = chairmanData ? chairmanData.fullname : null;
|
||||||
|
|
||||||
|
await result.push({
|
||||||
|
...item,
|
||||||
|
mentors: mentors,
|
||||||
|
commander: commander,
|
||||||
|
chairman: chairman,
|
||||||
|
});
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
|
||||||
|
return new HttpSuccess(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -449,8 +545,8 @@ export class AssignController extends Controller {
|
||||||
*/
|
*/
|
||||||
@Get("")
|
@Get("")
|
||||||
async GetAssign(@Query() assign_id: string, @Request() request: RequestWithUser) {
|
async GetAssign(@Query() assign_id: string, @Request() request: RequestWithUser) {
|
||||||
let _workflow = await new permission().Workflow(request, assign_id, "SYS_PROBATION")
|
let _workflow = await new permission().Workflow(request, assign_id, "SYS_PROBATION");
|
||||||
if (_workflow == false) await new permission().PermissionGet(request, "SYS_PROBATION")
|
if (_workflow == false) await new permission().PermissionGet(request, "SYS_PROBATION");
|
||||||
|
|
||||||
const assign = await this.assignRepository.findOne({
|
const assign = await this.assignRepository.findOne({
|
||||||
select: [
|
select: [
|
||||||
|
|
@ -467,24 +563,34 @@ export class AssignController extends Controller {
|
||||||
"active",
|
"active",
|
||||||
"createdAt",
|
"createdAt",
|
||||||
"updatedAt",
|
"updatedAt",
|
||||||
"reportPersonId"
|
"reportPersonId",
|
||||||
],
|
],
|
||||||
where: { id: assign_id },
|
where: { id: assign_id },
|
||||||
})
|
});
|
||||||
|
|
||||||
if (!assign) {
|
if (!assign) {
|
||||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลแบบมอบหมายงาน")
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลแบบมอบหมายงาน");
|
||||||
}
|
}
|
||||||
|
|
||||||
const profileData = await this.personalRepository.findOne({
|
const profileData = await this.personalRepository.findOne({
|
||||||
select: ["personal_id", "prefixName", "firstName", "lastName", "positionName", "positionLevelName", "positionLineName", "orgRootName", "organization"],
|
select: [
|
||||||
|
"personal_id",
|
||||||
|
"prefixName",
|
||||||
|
"firstName",
|
||||||
|
"lastName",
|
||||||
|
"positionName",
|
||||||
|
"positionLevelName",
|
||||||
|
"positionLineName",
|
||||||
|
"orgRootName",
|
||||||
|
"organization",
|
||||||
|
],
|
||||||
where: {
|
where: {
|
||||||
personal_id: assign.personal_id,
|
personal_id: assign.personal_id,
|
||||||
},
|
},
|
||||||
})
|
});
|
||||||
|
|
||||||
if (!profileData) {
|
if (!profileData) {
|
||||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลบุคคล")
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลบุคคล");
|
||||||
}
|
}
|
||||||
|
|
||||||
const profile = {
|
const profile = {
|
||||||
|
|
@ -494,18 +600,18 @@ export class AssignController extends Controller {
|
||||||
Department: "-",
|
Department: "-",
|
||||||
OrganizationOrganization: profileData.orgRootName,
|
OrganizationOrganization: profileData.orgRootName,
|
||||||
Oc: profileData.organization,
|
Oc: profileData.organization,
|
||||||
}
|
};
|
||||||
|
|
||||||
const jobs = await this.assignJobRepository.find({
|
const jobs = await this.assignJobRepository.find({
|
||||||
select: ["id", "activity_desc", "goal_desc"],
|
select: ["id", "activity_desc", "goal_desc"],
|
||||||
where: { assign_id },
|
where: { assign_id },
|
||||||
})
|
});
|
||||||
|
|
||||||
const knowledgeData = await this.assignKnowledgeRepository.find({
|
const knowledgeData = await this.assignKnowledgeRepository.find({
|
||||||
relations: ["knowledge"],
|
relations: ["knowledge"],
|
||||||
where: { assign_id },
|
where: { assign_id },
|
||||||
})
|
});
|
||||||
const knowledges = await knowledgeData.map(x => ({
|
const knowledges = await knowledgeData.map((x) => ({
|
||||||
id: x.knowledge_id,
|
id: x.knowledge_id,
|
||||||
level: x.knowledge_level,
|
level: x.knowledge_level,
|
||||||
title: x.knowledge.title,
|
title: x.knowledge.title,
|
||||||
|
|
@ -521,34 +627,34 @@ export class AssignController extends Controller {
|
||||||
: x.knowledge_level == 5
|
: x.knowledge_level == 5
|
||||||
? x.knowledge.level5
|
? x.knowledge.level5
|
||||||
: "",
|
: "",
|
||||||
}))
|
}));
|
||||||
|
|
||||||
const lawData = await this.lawsRepository.find({
|
const lawData = await this.lawsRepository.find({
|
||||||
where: { active: 1 },
|
where: { active: 1 },
|
||||||
})
|
});
|
||||||
|
|
||||||
const laws = await Promise.all(
|
const laws = await Promise.all(
|
||||||
lawData.map(async x => {
|
lawData.map(async (x) => {
|
||||||
const assignLaw = await this.assignLawRepository.countBy({
|
const assignLaw = await this.assignLawRepository.countBy({
|
||||||
assign_id: assign_id,
|
assign_id: assign_id,
|
||||||
law_id: x.id,
|
law_id: x.id,
|
||||||
})
|
});
|
||||||
|
|
||||||
return {
|
return {
|
||||||
id: x.id,
|
id: x.id,
|
||||||
selected: assignLaw > 0 ? 1 : 0,
|
selected: assignLaw > 0 ? 1 : 0,
|
||||||
description: x.description,
|
description: x.description,
|
||||||
status_select: x.status_select,
|
status_select: x.status_select,
|
||||||
}
|
};
|
||||||
})
|
}),
|
||||||
)
|
);
|
||||||
|
|
||||||
const skillsData = await this.assignSkillRepository.find({
|
const skillsData = await this.assignSkillRepository.find({
|
||||||
relations: ["skill"],
|
relations: ["skill"],
|
||||||
where: { assign_id },
|
where: { assign_id },
|
||||||
})
|
});
|
||||||
|
|
||||||
const skills = await skillsData.map(x => ({
|
const skills = await skillsData.map((x) => ({
|
||||||
id: x.skill_id,
|
id: x.skill_id,
|
||||||
level: x.skill_level,
|
level: x.skill_level,
|
||||||
title: x.skill.title,
|
title: x.skill.title,
|
||||||
|
|
@ -564,74 +670,90 @@ export class AssignController extends Controller {
|
||||||
: x.skill_level == 5
|
: x.skill_level == 5
|
||||||
? x.skill.level5
|
? x.skill.level5
|
||||||
: "",
|
: "",
|
||||||
}))
|
}));
|
||||||
|
|
||||||
const competencyData = await this.assignCompetencyRepository.find({
|
const competencyData = await this.assignCompetencyRepository.find({
|
||||||
select: ["competency_id", "competency_level", "competency_name", "competency_description"],
|
select: ["competency_id", "competency_level", "competency_name", "competency_description"],
|
||||||
where: { assign_id },
|
where: { assign_id },
|
||||||
})
|
});
|
||||||
|
|
||||||
const competencys = await competencyData.map(x => ({
|
const competencys = await competencyData.map((x) => ({
|
||||||
id: x.competency_id,
|
id: x.competency_id,
|
||||||
level: x.competency_level,
|
level: x.competency_level,
|
||||||
name: x.competency_name,
|
name: x.competency_name,
|
||||||
description: x.competency_description,
|
description: x.competency_description,
|
||||||
}))
|
}));
|
||||||
|
|
||||||
const competencyGroupData = await this.assignCompetencyGroupRepository.find({
|
const competencyGroupData = await this.assignCompetencyGroupRepository.find({
|
||||||
select: ["competency_group_id", "competency_group_level", "competency_group_name", "competency_group_description"],
|
select: [
|
||||||
|
"competency_group_id",
|
||||||
|
"competency_group_level",
|
||||||
|
"competency_group_name",
|
||||||
|
"competency_group_description",
|
||||||
|
],
|
||||||
where: { assign_id },
|
where: { assign_id },
|
||||||
})
|
});
|
||||||
const competency_groups = await competencyGroupData.map(x => ({
|
const competency_groups = await competencyGroupData.map((x) => ({
|
||||||
id: x.competency_group_id,
|
id: x.competency_group_id,
|
||||||
level: x.competency_group_level,
|
level: x.competency_group_level,
|
||||||
name: x.competency_group_name,
|
name: x.competency_group_name,
|
||||||
description: x.competency_group_description,
|
description: x.competency_group_description,
|
||||||
}))
|
}));
|
||||||
|
|
||||||
const outputs = await this.assignOutputRepository.find({
|
const outputs = await this.assignOutputRepository.find({
|
||||||
select: ["id", "output_desc", "indicator_desc"],
|
select: ["id", "output_desc", "indicator_desc"],
|
||||||
where: { assign_id },
|
where: { assign_id },
|
||||||
})
|
});
|
||||||
|
|
||||||
const director = await this.assignDirectorRepository.find({
|
const director = await this.assignDirectorRepository.find({
|
||||||
where: { assign_id },
|
where: { assign_id },
|
||||||
order: { ordering: "ASC" },
|
order: { ordering: "ASC" },
|
||||||
})
|
});
|
||||||
|
|
||||||
let mentors = []
|
let mentors = [];
|
||||||
const mentorList = await director.filter(x => x.role == "mentor")
|
const mentorList = await director.filter((x) => x.role == "mentor");
|
||||||
if (mentorList.length > 0) {
|
if (mentorList.length > 0) {
|
||||||
for (let index = 0; index < mentorList.length; index++) {
|
for (let index = 0; index < mentorList.length; index++) {
|
||||||
const e = await mentorList[index]
|
const e = await mentorList[index];
|
||||||
mentors.push({
|
mentors.push({
|
||||||
...e,
|
...e,
|
||||||
name: e.fullname,
|
name: e.fullname,
|
||||||
label: e.fullname + " " + (e.position ? `(${e.position}, ${e.posType}: ${e.posLevel})` : ""),
|
label:
|
||||||
|
e.fullname + " " + (e.position ? `(${e.position}, ${e.posType}: ${e.posLevel})` : ""),
|
||||||
Position: e.position, // report
|
Position: e.position, // report
|
||||||
})
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const commanderData = await (director.find(x => x.role == "commander") ?? null)
|
const commanderData = await (director.find((x) => x.role == "commander") ?? null);
|
||||||
const commander = await (commanderData
|
const commander = await (commanderData
|
||||||
? {
|
? {
|
||||||
...commanderData,
|
...commanderData,
|
||||||
name: commanderData.fullname,
|
name: commanderData.fullname,
|
||||||
label: commanderData.fullname + " " + (commanderData.position ? `(${commanderData.position}, ${commanderData.posType}: ${commanderData.posLevel})` : ""),
|
label:
|
||||||
|
commanderData.fullname +
|
||||||
|
" " +
|
||||||
|
(commanderData.position
|
||||||
|
? `(${commanderData.position}, ${commanderData.posType}: ${commanderData.posLevel})`
|
||||||
|
: ""),
|
||||||
Position: commanderData.position, // report
|
Position: commanderData.position, // report
|
||||||
}
|
}
|
||||||
: null)
|
: null);
|
||||||
|
|
||||||
const chairmanData = await (director.find(x => x.role == "chairman") ?? null)
|
const chairmanData = await (director.find((x) => x.role == "chairman") ?? null);
|
||||||
const chairman = await (chairmanData
|
const chairman = await (chairmanData
|
||||||
? {
|
? {
|
||||||
...chairmanData,
|
...chairmanData,
|
||||||
name: chairmanData.fullname,
|
name: chairmanData.fullname,
|
||||||
label: chairmanData.fullname + " " + (chairmanData.position ? `(${chairmanData.position}, ${chairmanData.posType}: ${chairmanData.posLevel})` : ""),
|
label:
|
||||||
|
chairmanData.fullname +
|
||||||
|
" " +
|
||||||
|
(chairmanData.position
|
||||||
|
? `(${chairmanData.position}, ${chairmanData.posType}: ${chairmanData.posLevel})`
|
||||||
|
: ""),
|
||||||
Position: chairmanData.position, // report
|
Position: chairmanData.position, // report
|
||||||
}
|
}
|
||||||
: null)
|
: null);
|
||||||
|
|
||||||
return new HttpSuccess({
|
return new HttpSuccess({
|
||||||
assign,
|
assign,
|
||||||
|
|
@ -646,6 +768,6 @@ export class AssignController extends Controller {
|
||||||
mentors,
|
mentors,
|
||||||
commander,
|
commander,
|
||||||
chairman,
|
chairman,
|
||||||
})
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,7 @@ import { setLogDataDiff } from "../interfaces/utils";
|
||||||
import { Personal, PostPersonal } from "../entities/Personal";
|
import { Personal, PostPersonal } from "../entities/Personal";
|
||||||
import permission from "../interfaces/permission";
|
import permission from "../interfaces/permission";
|
||||||
import { Assign } from "../entities/Assign";
|
import { Assign } from "../entities/Assign";
|
||||||
|
import { Brackets } from "typeorm";
|
||||||
|
|
||||||
@Route("api/v1/probation/personal")
|
@Route("api/v1/probation/personal")
|
||||||
@Tags("Personal")
|
@Tags("Personal")
|
||||||
|
|
@ -101,6 +102,7 @@ export class PersonalController extends Controller {
|
||||||
@Get("list")
|
@Get("list")
|
||||||
async ListPersonal(
|
async ListPersonal(
|
||||||
@Query() status: string = "",
|
@Query() status: string = "",
|
||||||
|
@Query() keyword: string = "",
|
||||||
@Query("page") page: number = 1,
|
@Query("page") page: number = 1,
|
||||||
@Query("pageSize") pageSize: number = 10,
|
@Query("pageSize") pageSize: number = 10,
|
||||||
@Request() request: RequestWithUser,
|
@Request() request: RequestWithUser,
|
||||||
|
|
@ -133,12 +135,39 @@ export class PersonalController extends Controller {
|
||||||
conditions.child4 = _data.child4;
|
conditions.child4 = _data.child4;
|
||||||
}
|
}
|
||||||
|
|
||||||
const [lists, total] = await this.personalRepository.findAndCount({
|
const searchKeyword = await (keyword ? keyword.trim() : null);
|
||||||
order: { createdAt: "DESC" },
|
|
||||||
where: conditions,
|
const [lists, total] = await AppDataSource.getRepository(Personal)
|
||||||
skip: (page - 1) * pageSize,
|
.createQueryBuilder("personal")
|
||||||
take: pageSize,
|
.where(conditions)
|
||||||
|
.andWhere(
|
||||||
|
new Brackets((qb) => {
|
||||||
|
qb.orWhere(
|
||||||
|
searchKeyword
|
||||||
|
? `CONCAT(prefixName, firstName," ",lastName) like '%${keyword}%'`
|
||||||
|
: "1=1",
|
||||||
|
{
|
||||||
|
keyword: `%${searchKeyword}%`,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
qb.orWhere(searchKeyword ? `positionName like '%${keyword}%'` : "1=1", {
|
||||||
|
keyword: `%${searchKeyword}%`,
|
||||||
});
|
});
|
||||||
|
qb.orWhere(searchKeyword ? `positionLevelName like '%${keyword}%'` : "1=1", {
|
||||||
|
keyword: `%${searchKeyword}%`,
|
||||||
|
});
|
||||||
|
qb.orWhere(searchKeyword ? `organization like '%${keyword}%'` : "1=1", {
|
||||||
|
keyword: `%${searchKeyword}%`,
|
||||||
|
});
|
||||||
|
qb.orWhere(searchKeyword ? `order_number like '%${keyword}%'` : "1=1", {
|
||||||
|
keyword: `%${searchKeyword}%`,
|
||||||
|
});
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
.orderBy("updatedAt", "DESC")
|
||||||
|
.skip((page - 1) * pageSize)
|
||||||
|
.take(pageSize)
|
||||||
|
.getManyAndCount();
|
||||||
|
|
||||||
if (!lists) {
|
if (!lists) {
|
||||||
throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, "ไม่สามารถแสดงข้อมูลได้");
|
throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, "ไม่สามารถแสดงข้อมูลได้");
|
||||||
|
|
@ -146,32 +175,54 @@ export class PersonalController extends Controller {
|
||||||
|
|
||||||
let result: any = [];
|
let result: any = [];
|
||||||
|
|
||||||
await Promise.all(
|
for (let i = 0; i < lists.length; i++) {
|
||||||
lists.map(async (item, index) => {
|
|
||||||
const probation_no = await this.assignRepository.count({
|
const probation_no = await this.assignRepository.count({
|
||||||
where: {
|
where: { personal_id: lists[i].personal_id },
|
||||||
personal_id: item.personal_id,
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
|
|
||||||
await result.push({
|
await result.push({
|
||||||
personal_id: item.personal_id,
|
personal_id: lists[i].personal_id,
|
||||||
ordering: index + 1,
|
ordering: i + 1,
|
||||||
name: item.prefixName + item.firstName + " " + item.lastName,
|
name: lists[i].prefixName + lists[i].firstName + " " + lists[i].lastName,
|
||||||
idcard: item.idcard,
|
prefixName: lists[i].prefixName,
|
||||||
prefixName: item.prefixName,
|
firstName: lists[i].firstName,
|
||||||
firstName: item.firstName,
|
lastName: lists[i].lastName,
|
||||||
lastName: item.lastName,
|
idcard: lists[i].idcard,
|
||||||
position_line: item.positionName,
|
position_line: lists[i].positionName,
|
||||||
position_level: item.positionLevelName,
|
position_level: lists[i].positionLevelName,
|
||||||
position_type: item.positionTypeName,
|
position_type: lists[i].positionTypeName,
|
||||||
organization: item.organization,
|
organization: lists[i].organization,
|
||||||
probation_no: probation_no,
|
probation_no: probation_no,
|
||||||
order_number: item.order_number,
|
order_number: lists[i].order_number,
|
||||||
probation_status: item.probation_status,
|
probation_status: lists[i].probation_status,
|
||||||
});
|
});
|
||||||
}),
|
}
|
||||||
);
|
// await Promise.all(
|
||||||
|
// lists.map(async (item, index) => {
|
||||||
|
// const probation_no = await this.assignRepository.count({
|
||||||
|
// where: {
|
||||||
|
// personal_id: item.personal_id,
|
||||||
|
// },
|
||||||
|
// });
|
||||||
|
|
||||||
|
// await result.push({
|
||||||
|
// personal_id: item.personal_id,
|
||||||
|
// ordering: index + 1,
|
||||||
|
// name: item.prefixName + item.firstName + " " + item.lastName,
|
||||||
|
// idcard: item.idcard,
|
||||||
|
// // prefixName: item.prefixName,
|
||||||
|
// // firstName: item.firstName,
|
||||||
|
// // lastName: item.lastName,
|
||||||
|
// position_line: item.positionName,
|
||||||
|
// position_level: item.positionLevelName,
|
||||||
|
// position_type: item.positionTypeName,
|
||||||
|
// organization: item.organization,
|
||||||
|
// probation_no: probation_no,
|
||||||
|
// order_number: item.order_number,
|
||||||
|
// probation_status: item.probation_status,
|
||||||
|
// });
|
||||||
|
// }),
|
||||||
|
// );
|
||||||
|
|
||||||
return new HttpSuccess({ data: result, total: total });
|
return new HttpSuccess({ data: result, total: total });
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -52,13 +52,13 @@ export class CreateAppoint {
|
||||||
|
|
||||||
export type Person = {
|
export type Person = {
|
||||||
profileId: string
|
profileId: string
|
||||||
name: string
|
name: string | null
|
||||||
position: string
|
position?: string | null
|
||||||
positionType: string
|
positionType?: string | null
|
||||||
positionLevel: string
|
positionLevel?: string | null
|
||||||
role: string
|
role: string | null
|
||||||
posNo: string
|
posNo?: string | null
|
||||||
actFullName: string
|
actFullName?: string | null
|
||||||
}
|
}
|
||||||
|
|
||||||
export class UpdateAppoint {
|
export class UpdateAppoint {
|
||||||
|
|
|
||||||
|
|
@ -1,24 +1,12 @@
|
||||||
import {
|
import { Path } from "tsoa"
|
||||||
Controller,
|
import axios from "axios"
|
||||||
Request,
|
import { addLogSequence } from "./utils"
|
||||||
Get,
|
|
||||||
Post,
|
|
||||||
Put,
|
|
||||||
Delete,
|
|
||||||
Patch,
|
|
||||||
Route,
|
|
||||||
Security,
|
|
||||||
Tags,
|
|
||||||
Path,
|
|
||||||
} from "tsoa";
|
|
||||||
import axios from "axios";
|
|
||||||
import { addLogSequence } from "./utils";
|
|
||||||
|
|
||||||
class CallAPI {
|
class CallAPI {
|
||||||
//Get
|
//Get
|
||||||
public async GetData(request: any, @Path() path: any) {
|
public async GetData(request: any, @Path() path: any, log = true) {
|
||||||
const token = request.headers.authorization;
|
const token = "Bearer " + request.headers.authorization.replace("Bearer ", "")
|
||||||
const url = process.env.API_URL + path;
|
const url = process.env.API_URL + path
|
||||||
try {
|
try {
|
||||||
const response = await axios.get(url, {
|
const response = await axios.get(url, {
|
||||||
headers: {
|
headers: {
|
||||||
|
|
@ -26,7 +14,8 @@ class CallAPI {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
api_key: process.env.API_KEY,
|
api_key: process.env.API_KEY,
|
||||||
},
|
},
|
||||||
});
|
})
|
||||||
|
if (log)
|
||||||
addLogSequence(request, {
|
addLogSequence(request, {
|
||||||
action: "request",
|
action: "request",
|
||||||
status: "success",
|
status: "success",
|
||||||
|
|
@ -36,9 +25,10 @@ class CallAPI {
|
||||||
url: url,
|
url: url,
|
||||||
response: JSON.stringify(response.data.result),
|
response: JSON.stringify(response.data.result),
|
||||||
},
|
},
|
||||||
});
|
})
|
||||||
return response.data.result;
|
return response.data.result
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
if (log)
|
||||||
addLogSequence(request, {
|
addLogSequence(request, {
|
||||||
action: "request",
|
action: "request",
|
||||||
status: "error",
|
status: "error",
|
||||||
|
|
@ -48,14 +38,14 @@ class CallAPI {
|
||||||
url: url,
|
url: url,
|
||||||
response: JSON.stringify(error),
|
response: JSON.stringify(error),
|
||||||
},
|
},
|
||||||
});
|
})
|
||||||
throw error;
|
throw error
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//Post
|
//Post
|
||||||
public async PostData(request: any, @Path() path: any, sendData: any) {
|
public async PostData(request: any, @Path() path: any, sendData: any) {
|
||||||
const token = request.headers.authorization;
|
const token = "Bearer " + request.headers.authorization.replace("Bearer ", "")
|
||||||
const url = process.env.API_URL + path;
|
const url = process.env.API_URL + path
|
||||||
try {
|
try {
|
||||||
const response = await axios.post(url, sendData, {
|
const response = await axios.post(url, sendData, {
|
||||||
headers: {
|
headers: {
|
||||||
|
|
@ -63,7 +53,7 @@ class CallAPI {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
api_key: process.env.API_KEY,
|
api_key: process.env.API_KEY,
|
||||||
},
|
},
|
||||||
});
|
})
|
||||||
addLogSequence(request, {
|
addLogSequence(request, {
|
||||||
action: "request",
|
action: "request",
|
||||||
status: "success",
|
status: "success",
|
||||||
|
|
@ -74,8 +64,8 @@ class CallAPI {
|
||||||
payload: JSON.stringify(sendData),
|
payload: JSON.stringify(sendData),
|
||||||
response: JSON.stringify(response.data.result),
|
response: JSON.stringify(response.data.result),
|
||||||
},
|
},
|
||||||
});
|
})
|
||||||
return response.data.result;
|
return response.data.result
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
addLogSequence(request, {
|
addLogSequence(request, {
|
||||||
action: "request",
|
action: "request",
|
||||||
|
|
@ -87,10 +77,10 @@ class CallAPI {
|
||||||
payload: JSON.stringify(sendData),
|
payload: JSON.stringify(sendData),
|
||||||
response: JSON.stringify(error),
|
response: JSON.stringify(error),
|
||||||
},
|
},
|
||||||
});
|
})
|
||||||
throw error;
|
throw error
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default CallAPI;
|
export default CallAPI
|
||||||
|
|
|
||||||
|
|
@ -3,8 +3,11 @@ import { RequestWithUser } from "../middlewares/user"
|
||||||
import CallAPI from "./call-api"
|
import CallAPI from "./call-api"
|
||||||
import HttpError from "./http-error"
|
import HttpError from "./http-error"
|
||||||
import HttpStatus from "./http-status"
|
import HttpStatus from "./http-status"
|
||||||
|
import { promisify } from "util"
|
||||||
|
|
||||||
class CheckAuth {
|
class CheckAuth {
|
||||||
|
private redis = require("redis")
|
||||||
|
|
||||||
public async Permission(req: RequestWithUser, system: string, action: string) {
|
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) {
|
if (req.headers.hasOwnProperty("api_key") && req.headers["api_key"] && req.headers["api_key"] == process.env.API_KEY) {
|
||||||
return null
|
return null
|
||||||
|
|
@ -155,6 +158,41 @@ class CheckAuth {
|
||||||
return false
|
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 {
|
||||||
|
if (!keycloakId) throw "Error calling API No KeycloakId"
|
||||||
|
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) {
|
public async PermissionCreate(req: RequestWithUser, system: string) {
|
||||||
return await this.Permission(req, system, "CREATE")
|
return await this.Permission(req, system, "CREATE")
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,12 @@
|
||||||
import { NextFunction, Request, Response } from "express";
|
import { NextFunction, Request, Response } from "express"
|
||||||
import { Client } from "@elastic/elasticsearch";
|
import { Client } from "@elastic/elasticsearch"
|
||||||
|
import permission from "../interfaces/permission"
|
||||||
|
|
||||||
if (!process.env.ELASTICSEARCH_INDEX) {
|
if (!process.env.ELASTICSEARCH_INDEX) {
|
||||||
throw new Error("Require ELASTICSEARCH_INDEX to store log.");
|
throw new Error("Require ELASTICSEARCH_INDEX to store log.")
|
||||||
}
|
}
|
||||||
|
|
||||||
const ELASTICSEARCH_INDEX = process.env.ELASTICSEARCH_INDEX;
|
const ELASTICSEARCH_INDEX = process.env.ELASTICSEARCH_INDEX
|
||||||
|
|
||||||
const LOG_LEVEL_MAP: Record<string, number> = {
|
const LOG_LEVEL_MAP: Record<string, number> = {
|
||||||
debug: 4,
|
debug: 4,
|
||||||
|
|
@ -13,46 +14,47 @@ const LOG_LEVEL_MAP: Record<string, number> = {
|
||||||
warning: 2,
|
warning: 2,
|
||||||
error: 1,
|
error: 1,
|
||||||
none: 0,
|
none: 0,
|
||||||
};
|
}
|
||||||
|
|
||||||
const elasticsearch = new Client({
|
const elasticsearch = new Client({
|
||||||
node: `${process.env.ELASTICSEARCH_PROTOCOL}://${process.env.ELASTICSEARCH_HOST}:${process.env.ELASTICSEARCH_PORT}`,
|
node: `${process.env.ELASTICSEARCH_PROTOCOL}://${process.env.ELASTICSEARCH_HOST}:${process.env.ELASTICSEARCH_PORT}`,
|
||||||
});
|
})
|
||||||
|
|
||||||
async function logMiddleware(req: Request, res: Response, next: NextFunction) {
|
async function logMiddleware(req: Request, res: Response, next: NextFunction) {
|
||||||
if (!req.url.startsWith("/api/")) return next();
|
if (!req.url.startsWith("/api/")) return next()
|
||||||
|
|
||||||
let data: any;
|
let data: any
|
||||||
|
|
||||||
const originalJson = res.json;
|
const originalJson = res.json
|
||||||
|
|
||||||
res.json = function (v: any) {
|
res.json = function (v: any) {
|
||||||
data = v;
|
data = v
|
||||||
return originalJson.call(this, v);
|
return originalJson.call(this, v)
|
||||||
};
|
}
|
||||||
|
|
||||||
const timestamp = new Date().toISOString();
|
const timestamp = new Date().toISOString()
|
||||||
const start = performance.now();
|
const start = performance.now()
|
||||||
|
|
||||||
req.app.locals.logData = {};
|
req.app.locals.logData = {}
|
||||||
|
|
||||||
res.on("finish", () => {
|
res.on("finish", async () => {
|
||||||
if (!req.url.startsWith("/api/")) return;
|
if (!req.url.startsWith("/api/")) return
|
||||||
|
|
||||||
const level = LOG_LEVEL_MAP[process.env.LOG_LEVEL ?? "debug"] || 4;
|
const level = LOG_LEVEL_MAP[process.env.LOG_LEVEL ?? "debug"] || 4
|
||||||
|
|
||||||
if (level === 1 && res.statusCode < 500) return;
|
if (level === 1 && res.statusCode < 500) return
|
||||||
if (level === 2 && res.statusCode < 400) return;
|
if (level === 2 && res.statusCode < 400) return
|
||||||
if (level === 3 && res.statusCode < 200) 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 = {
|
const obj = {
|
||||||
logType:
|
logType: res.statusCode >= 500 ? "error" : res.statusCode >= 400 ? "warning" : "info",
|
||||||
res.statusCode >= 500
|
|
||||||
? "error"
|
|
||||||
: res.statusCode >= 400
|
|
||||||
? "warning"
|
|
||||||
: "info",
|
|
||||||
ip: req.ip,
|
ip: req.ip,
|
||||||
|
rootId: rootId ? rootId.orgRootId : null,
|
||||||
systemName: "probation",
|
systemName: "probation",
|
||||||
startTimeStamp: timestamp,
|
startTimeStamp: timestamp,
|
||||||
endTimeStamp: new Date().toISOString(),
|
endTimeStamp: new Date().toISOString(),
|
||||||
|
|
@ -65,15 +67,15 @@ async function logMiddleware(req: Request, res: Response, next: NextFunction) {
|
||||||
input: (level === 4 && JSON.stringify(req.body, null, 2)) || undefined,
|
input: (level === 4 && JSON.stringify(req.body, null, 2)) || undefined,
|
||||||
output: (level === 4 && JSON.stringify(data, null, 2)) || undefined,
|
output: (level === 4 && JSON.stringify(data, null, 2)) || undefined,
|
||||||
...req.app.locals.logData,
|
...req.app.locals.logData,
|
||||||
};
|
}
|
||||||
|
|
||||||
elasticsearch.index({
|
elasticsearch.index({
|
||||||
index: ELASTICSEARCH_INDEX,
|
index: ELASTICSEARCH_INDEX,
|
||||||
document: obj,
|
document: obj,
|
||||||
});
|
})
|
||||||
});
|
})
|
||||||
|
|
||||||
return next();
|
return next()
|
||||||
}
|
}
|
||||||
|
|
||||||
export default logMiddleware;
|
export default logMiddleware
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue