From 9da7f47cf64cf91a7ff52b0cdc5543cdbf73ee31 Mon Sep 17 00:00:00 2001 From: Bright Date: Tue, 2 Apr 2024 17:53:45 +0700 Subject: [PATCH 001/250] crud development --- src/controllers/DevelopmentController.ts | 171 ++++++++++++++++++ src/entities/Development.ts | 34 ++++ src/interfaces/call-api.ts | 51 ++++++ src/interfaces/extension.ts | 81 +++++++++ src/interfaces/storage-fs.ts | 39 ++++ .../1712050402784-add_table_development.ts | 14 ++ tsoa.json | 3 + 7 files changed, 393 insertions(+) create mode 100644 src/controllers/DevelopmentController.ts create mode 100644 src/entities/Development.ts create mode 100644 src/interfaces/call-api.ts create mode 100644 src/interfaces/extension.ts create mode 100644 src/interfaces/storage-fs.ts create mode 100644 src/migration/1712050402784-add_table_development.ts diff --git a/src/controllers/DevelopmentController.ts b/src/controllers/DevelopmentController.ts new file mode 100644 index 0000000..baaada6 --- /dev/null +++ b/src/controllers/DevelopmentController.ts @@ -0,0 +1,171 @@ +import { + Controller, + Get, + Post, + Put, + Delete, + Route, + Security, + Tags, + Body, + Path, + Request, + Query, + Example +} from "tsoa"; +import { AppDataSource } from "../database/data-source"; +import { In, Not, MoreThan, Brackets, Like, MoreThanOrEqual, } from "typeorm"; +import HttpSuccess from "../interfaces/http-success"; +import HttpError from "../interfaces/http-error"; +import HttpStatusCode from "../interfaces/http-status"; +import { Development, CreateDevelopment, UpdateDevelopment } from "../entities/Development"; + +@Route("api/v1/development/main") +@Tags("Development") +@Security("bearerAuth") +export class DevelopmentController extends Controller { + private developmentRepository = AppDataSource.getRepository(Development); + + /** + * API เพิ่มโครงการ/หลักสูตรการฝึกอบรม + * + * @summary DEV_001 - เพิ่มโครงการ/หลักสูตรการฝึกอบรม#1 + * + */ + @Post() + @Example({ + name: "", + year: 2024, + }) + async CreateDevelopment( + @Body() requestBody: CreateDevelopment, + @Request() request: { user: Record }, + ) { + const development = Object.assign(new Development(), requestBody); + if (!development) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล"); + } + const chk_name = await this.developmentRepository.find({ + where: { + name: requestBody.name, + year: requestBody.year + }, + }); + if (chk_name.length > 0) { + throw new HttpError( + HttpStatusCode.NOT_FOUND, + "โครงการ/หลักสูตรการฝึกอบรม: " + requestBody.name + " ปีงบประมาณ: " + requestBody.year + " มีอยู่ในระบบแล้ว", + ); + } + development.createdUserId = request.user.sub; + development.createdFullName = request.user.name; + development.lastUpdateUserId = request.user.sub; + development.lastUpdateFullName = request.user.name; + await this.developmentRepository.save(development); + return new HttpSuccess(development.id); + } + + /** + * API แก้ไขโครงการ/หลักสูตรการฝึกอบรม + * + * @summary DEV_002 - แก้ไขโครงการ/หลักสูตรการฝึกอบรม #2 + * + * @param {string} id Id โครงการ + */ + @Put("{id}") + async UpdateDevelopment( + @Path() id: string, + @Body() requestBody: UpdateDevelopment, + @Request() request: { user: Record }, + ) { + const development = await this.developmentRepository.findOne({ where: { id } }); + if (!development) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงการ/หลักสูตรการฝึกอบรมนี้"); + } + const chk_name = await this.developmentRepository.find({ + where: { + name: requestBody.name, + year: requestBody.year, + id: Not(id) + }, + }); + if (chk_name.length > 0) { + throw new HttpError( + HttpStatusCode.NOT_FOUND, + "โครงการ/หลักสูตรการฝึกอบรม: " + requestBody.name + " ปีงบประมาณ: " + requestBody.year + " มีอยู่ในระบบแล้ว", + ); + } + development.lastUpdateUserId = request.user.sub; + development.lastUpdateFullName = request.user.name; + this.developmentRepository.merge(development, requestBody); + await this.developmentRepository.save(development); + return new HttpSuccess(development.id); + } + + /** + * API ลบโครงการ/หลักสูตรการฝึกอบรม + * + * @summary DEV_003 - ลบโครงการ/หลักสูตรการฝึกอบรม #3 + * + * @param {string} id Id โครงการ + */ + @Delete("{id}") + async DeleteDevelopment(@Path() id: string) { + const delDevelopment = await this.developmentRepository.findOne({ where: { id } }); + if (!delDevelopment) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงการ/หลักสูตรการฝึกอบรมนี้"); + } + await this.developmentRepository.remove(delDevelopment); + return new HttpSuccess(); + } + + /** + * API รายการโครงการ/หลักสูตรการฝึกอบรม + * + * @summary DEV_004 - รายการโครงการ/หลักสูตรการฝึกอบรม #4 + * + */ + @Get() + async GetDevelopmentLists( + @Query("page") page: number = 1, + @Query("pageSize") pageSize: number = 10, + @Query("keyword") keyword?: string, + @Query("year") year: number = 2024, + ) { + const [development, total] = await AppDataSource.getRepository(Development) + .createQueryBuilder("development") + .andWhere(year != 0 ? "development.year LIKE :year" : "1=1", { year: `${year}` }) + .orWhere("development.name LIKE :keyword", { keyword: `${keyword}` }) + .select([ + "development.id", + "development.name", + "development.year", + ]) + .orderBy("development.year", "DESC") + .skip((page - 1) * pageSize) + .take(pageSize) + .getManyAndCount(); + + return new HttpSuccess({ data: development, total }); + } + + /** + * API รายละเอียดโครงการ/หลักสูตรการฝึกอบรม + * + * @summary DEV_005 - รายละเอียดโครงการ/หลักสูตรการฝึกอบรม #5 + * + * @param {string} id Id โครงการ + */ + @Get("{id}") + async GetDevelopemtById(@Path() id: string) { + const getDevelopment = await this.developmentRepository.findOne({ + select: ["id", "name", "year"], + where: { id: id }, + }); + if (!getDevelopment) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงการ/หลักสูตรการฝึกอบรมนี้"); + } + return new HttpSuccess(getDevelopment); + } + +} diff --git a/src/entities/Development.ts b/src/entities/Development.ts new file mode 100644 index 0000000..ca5c2b9 --- /dev/null +++ b/src/entities/Development.ts @@ -0,0 +1,34 @@ +import { Entity, Column, ManyToOne, JoinColumn, OneToOne, OneToMany } from "typeorm"; +import { EntityBase } from "./base/Base"; + +@Entity("development") +export class Development extends EntityBase { + @Column({ + comment: "ชื่อโครงการ/กิจกรรม/หลักสูตร", + length: 255, + }) + name: string; + + @Column({ + nullable: true, + comment: "ปีงบประมาณ", + }) + year: number; + +} + +export class CreateDevelopment { + @Column() + name: string; + + @Column() + year: number; +} + +export class UpdateDevelopment { + @Column() + name: string; + + @Column() + year: number; +} diff --git a/src/interfaces/call-api.ts b/src/interfaces/call-api.ts new file mode 100644 index 0000000..8608230 --- /dev/null +++ b/src/interfaces/call-api.ts @@ -0,0 +1,51 @@ +import { + Controller, + Request, + Get, + Post, + Put, + Delete, + Patch, + Route, + Security, + Tags, + Path, +} from "tsoa"; +import axios from "axios"; + +class CallAPI { + //Get + public async GetData(request: any, @Path() path: any) { + const token = request.headers.authorization; + const url = process.env.API + path; + try { + const response = await axios.get(url, { + headers: { + Authorization: `Bearer ${token}`, + "Content-Type": "application/json", + }, + }); + return response.data.result; + } catch (error) { + throw error; + } + } + //Post + public async PostData(request: any, @Path() path: any, sendData: any) { + const token = request.headers.authorization; + const url = process.env.API + path; + try { + const response = await axios.post(url, sendData, { + headers: { + Authorization: `Bearer ${token}`, + "Content-Type": "application/json", + }, + }); + return response.data.result; + } catch (error) { + throw error; + } + } +} + +export default CallAPI; diff --git a/src/interfaces/extension.ts b/src/interfaces/extension.ts new file mode 100644 index 0000000..1355587 --- /dev/null +++ b/src/interfaces/extension.ts @@ -0,0 +1,81 @@ +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 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 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; diff --git a/src/interfaces/storage-fs.ts b/src/interfaces/storage-fs.ts new file mode 100644 index 0000000..63d0769 --- /dev/null +++ b/src/interfaces/storage-fs.ts @@ -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; + + path: string; + upload: boolean; + + updatedAt: string | Date; + updatedBy: string; + createdAt: string | Date; + createdBy: string; +} diff --git a/src/migration/1712050402784-add_table_development.ts b/src/migration/1712050402784-add_table_development.ts new file mode 100644 index 0000000..35b2cf5 --- /dev/null +++ b/src/migration/1712050402784-add_table_development.ts @@ -0,0 +1,14 @@ +import { MigrationInterface, QueryRunner } from "typeorm"; + +export class AddTableDevelopment1712050402784 implements MigrationInterface { + name = 'AddTableDevelopment1712050402784' + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(`CREATE TABLE \`development\` (\`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', \`name\` varchar(255) NOT NULL COMMENT 'ชื่อโครงการ/กิจกรรม/หลักสูตร', \`year\` int NULL COMMENT 'ปีงบประมาณ', PRIMARY KEY (\`id\`)) ENGINE=InnoDB`); + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(`DROP TABLE \`development\``); + } + +} diff --git a/tsoa.json b/tsoa.json index 5bbc1e5..ff48c69 100644 --- a/tsoa.json +++ b/tsoa.json @@ -28,6 +28,9 @@ "tags": [ { "name": "Test", "description": "สำหรับทดสอบ" + }, + { + "name": "Development", "description": "ชื่อโครงการ/กิจกรรม/หลักสูตร" } ] }, From c2af2a3b08b1bd9f0a8f642096b0824a3c96d7c3 Mon Sep 17 00:00:00 2001 From: Kittapath Date: Wed, 3 Apr 2024 00:55:40 +0700 Subject: [PATCH 002/250] =?UTF-8?q?api=20=E0=B8=8A=E0=B8=B7=E0=B9=88?= =?UTF-8?q?=E0=B8=AD=E0=B9=82=E0=B8=84=E0=B8=A3=E0=B8=87=E0=B8=81=E0=B8=B2?= =?UTF-8?q?=E0=B8=A3/=E0=B8=81=E0=B8=B4=E0=B8=88=E0=B8=81=E0=B8=A3?= =?UTF-8?q?=E0=B8=A3=E0=B8=A1/=E0=B8=AB=E0=B8=A5=E0=B8=B1=E0=B8=81?= =?UTF-8?q?=E0=B8=AA=E0=B8=B9=E0=B8=95=E0=B8=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/release.yaml | 17 +- package-lock.json | 72 +++ package.json | 1 + src/controllers/DevelopmentController.ts | 298 +++++++++-- .../DevelopmentHistoryController.ts | 178 +++++++ src/entities/ActualGoal.ts | 95 ++++ src/entities/ActualPeople.ts | 40 ++ src/entities/Development.ts | 465 +++++++++++++++++- src/entities/DevelopmentHistory.ts | 154 ++++++ src/entities/EmployeePosLevel.ts | 61 +++ src/entities/EmployeePosType.ts | 43 ++ src/entities/PlannedGoal.ts | 95 ++++ src/entities/PlannedPeople.ts | 40 ++ src/entities/PosLevel.ts | 74 +++ src/entities/PosType.ts | 47 ++ src/entities/Province.ts | 27 + .../1712060108057-add_table_development.ts | 128 +++++ ...2076616416-add_table_developmentHistory.ts | 22 + ...078526676-add_table_developmentHistory1.ts | 16 + tsoa.json | 3 + 20 files changed, 1819 insertions(+), 57 deletions(-) create mode 100644 src/controllers/DevelopmentHistoryController.ts create mode 100644 src/entities/ActualGoal.ts create mode 100644 src/entities/ActualPeople.ts create mode 100644 src/entities/DevelopmentHistory.ts create mode 100644 src/entities/EmployeePosLevel.ts create mode 100644 src/entities/EmployeePosType.ts create mode 100644 src/entities/PlannedGoal.ts create mode 100644 src/entities/PlannedPeople.ts create mode 100644 src/entities/PosLevel.ts create mode 100644 src/entities/PosType.ts create mode 100644 src/entities/Province.ts create mode 100644 src/migration/1712060108057-add_table_development.ts create mode 100644 src/migration/1712076616416-add_table_developmentHistory.ts create mode 100644 src/migration/1712078526676-add_table_developmentHistory1.ts diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 59bae3b..c358c91 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -7,9 +7,9 @@ on: workflow_dispatch: env: REGISTRY: docker.frappet.com - IMAGE_NAME: ehr/bma-ehr-org-service - DEPLOY_HOST: 192.168.1.80 - COMPOSE_PATH: /home/frappet/docker/bma-ehr + IMAGE_NAME: ehr/bma-ehr-development-service + DEPLOY_HOST: 49.0.91.80 + COMPOSE_PATH: /home/frappet/docker/bma/bma-ehr-development 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 release-test: @@ -59,11 +59,11 @@ jobs: host: ${{env.DEPLOY_HOST}} username: frappet password: ${{ secrets.SSH_PASSWORD }} - port: 22 + port: 10102 script: | cd "${{env.COMPOSE_PATH}}" - docker-compose pull - docker-compose up -d + 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() @@ -73,7 +73,7 @@ jobs: -Success✅✅✅ Image: ${{env.IMAGE_NAME}} Version: ${{ steps.gen_ver.outputs.IMAGE_VER }} - By: ${{secrets.DOCKER_USER}} + By: ${{github.actor}} - uses: snow-actions/line-notify@v1.1.0 if: failure() with: @@ -82,4 +82,5 @@ jobs: -Failure❌❌❌ Image: ${{env.IMAGE_NAME}} Version: ${{ steps.gen_ver.outputs.IMAGE_VER }} - By: ${{secrets.DOCKER_USER}} + By: ${{github.actor}} + diff --git a/package-lock.json b/package-lock.json index 303f4cb..3fd41e0 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10,6 +10,7 @@ "license": "ISC", "dependencies": { "@tsoa/runtime": "^6.0.0", + "axios": "^1.6.8", "cors": "^2.8.5", "dotenv": "^16.3.1", "express": "^4.18.2", @@ -520,6 +521,11 @@ "resolved": "https://registry.npmjs.org/async/-/async-0.2.10.tgz", "integrity": "sha512-eAkdoKxU6/LkKDBzLpT+t6Ff5EtfSF4wx1WfJiPEEV7WNLnDaRXk0oVysiEPm262roaachGexwUv94WhSgN5TQ==" }, + "node_modules/asynckit": { + "version": "0.4.0", + "resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz", + "integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==" + }, "node_modules/available-typed-arrays": { "version": "1.0.5", "resolved": "https://registry.npmjs.org/available-typed-arrays/-/available-typed-arrays-1.0.5.tgz", @@ -531,6 +537,16 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/axios": { + "version": "1.6.8", + "resolved": "https://registry.npmjs.org/axios/-/axios-1.6.8.tgz", + "integrity": "sha512-v/ZHtJDU39mDpyBoFVkETcd/uNdxrWRrg3bKpOKzXFA6Bvqopts6ALSMU3y6ijYxbw2B+wPrIv46egTzJXCLGQ==", + "dependencies": { + "follow-redirects": "^1.15.6", + "form-data": "^4.0.0", + "proxy-from-env": "^1.1.0" + } + }, "node_modules/balanced-match": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz", @@ -967,6 +983,17 @@ "resolved": "https://registry.npmjs.org/colors-console/-/colors-console-1.0.3.tgz", "integrity": "sha512-Q31K32UwadWqAxs+Iu46gNm4HJqUwrTJT2zen5NnhkKE5w7uqeZQZiuODUOxM/zOtHfiUTkia0io6zbN/VcCUQ==" }, + "node_modules/combined-stream": { + "version": "1.0.8", + "resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz", + "integrity": "sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==", + "dependencies": { + "delayed-stream": "~1.0.0" + }, + "engines": { + "node": ">= 0.8" + } + }, "node_modules/commander": { "version": "2.20.3", "resolved": "https://registry.npmjs.org/commander/-/commander-2.20.3.tgz", @@ -1112,6 +1139,14 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/delayed-stream": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz", + "integrity": "sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ==", + "engines": { + "node": ">=0.4.0" + } + }, "node_modules/denque": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/denque/-/denque-2.1.0.tgz", @@ -1497,6 +1532,25 @@ "node": ">= 0.8" } }, + "node_modules/follow-redirects": { + "version": "1.15.6", + "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.6.tgz", + "integrity": "sha512-wWN62YITEaOpSK584EZXJafH1AGpO8RVgElfkuXbTOrPX4fIfOyEpW/CsiNd8JdYrAoOvafRTOEnvsO++qCqFA==", + "funding": [ + { + "type": "individual", + "url": "https://github.com/sponsors/RubenVerborgh" + } + ], + "engines": { + "node": ">=4.0" + }, + "peerDependenciesMeta": { + "debug": { + "optional": true + } + } + }, "node_modules/for-each": { "version": "0.3.3", "resolved": "https://registry.npmjs.org/for-each/-/for-each-0.3.3.tgz", @@ -1520,6 +1574,19 @@ "url": "https://github.com/sponsors/isaacs" } }, + "node_modules/form-data": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.0.tgz", + "integrity": "sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww==", + "dependencies": { + "asynckit": "^0.4.0", + "combined-stream": "^1.0.8", + "mime-types": "^2.1.12" + }, + "engines": { + "node": ">= 6" + } + }, "node_modules/forwarded": { "version": "0.2.0", "resolved": "https://registry.npmjs.org/forwarded/-/forwarded-0.2.0.tgz", @@ -3067,6 +3134,11 @@ "node": ">= 0.10" } }, + "node_modules/proxy-from-env": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/proxy-from-env/-/proxy-from-env-1.1.0.tgz", + "integrity": "sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg==" + }, "node_modules/pstree.remy": { "version": "1.1.8", "resolved": "https://registry.npmjs.org/pstree.remy/-/pstree.remy-1.1.8.tgz", diff --git a/package.json b/package.json index f5a8240..b530886 100644 --- a/package.json +++ b/package.json @@ -28,6 +28,7 @@ }, "dependencies": { "@tsoa/runtime": "^6.0.0", + "axios": "^1.6.8", "cors": "^2.8.5", "dotenv": "^16.3.1", "express": "^4.18.2", diff --git a/src/controllers/DevelopmentController.ts b/src/controllers/DevelopmentController.ts index baaada6..451a952 100644 --- a/src/controllers/DevelopmentController.ts +++ b/src/controllers/DevelopmentController.ts @@ -11,20 +11,34 @@ import { Path, Request, Query, - Example + Example, } from "tsoa"; import { AppDataSource } from "../database/data-source"; -import { In, Not, MoreThan, Brackets, Like, MoreThanOrEqual, } from "typeorm"; +import { Not } from "typeorm"; import HttpSuccess from "../interfaces/http-success"; import HttpError from "../interfaces/http-error"; import HttpStatusCode from "../interfaces/http-status"; import { Development, CreateDevelopment, UpdateDevelopment } from "../entities/Development"; +import { ActualPeople } from "../entities/ActualPeople"; +import { PlannedPeople } from "../entities/PlannedPeople"; +import { ActualGoal } from "../entities/ActualGoal"; +import { PlannedGoal } from "../entities/PlannedGoal"; +import { Province } from "../entities/Province"; +import { PosType } from "../entities/PosType"; +import { PosLevel } from "../entities/PosLevel"; @Route("api/v1/development/main") @Tags("Development") @Security("bearerAuth") export class DevelopmentController extends Controller { private developmentRepository = AppDataSource.getRepository(Development); + private actualPeopleRepository = AppDataSource.getRepository(ActualPeople); + private plannedPeopleRepository = AppDataSource.getRepository(PlannedPeople); + private actualGoalRepository = AppDataSource.getRepository(ActualGoal); + private plannedGoalRepository = AppDataSource.getRepository(PlannedGoal); + private provinceRepository = AppDataSource.getRepository(Province); + private posTypeRepository = AppDataSource.getRepository(PosType); + private posLevelRepository = AppDataSource.getRepository(PosLevel); /** * API เพิ่มโครงการ/หลักสูตรการฝึกอบรม @@ -33,35 +47,127 @@ export class DevelopmentController extends Controller { * */ @Post() - @Example({ - name: "", - year: 2024, - }) async CreateDevelopment( @Body() requestBody: CreateDevelopment, @Request() request: { user: Record }, ) { - const development = Object.assign(new Development(), requestBody); - if (!development) { - throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล"); - } const chk_name = await this.developmentRepository.find({ - where: { - name: requestBody.name, - year: requestBody.year + where: { + projectName: requestBody.projectName, + year: requestBody.year, }, }); if (chk_name.length > 0) { throw new HttpError( - HttpStatusCode.NOT_FOUND, - "โครงการ/หลักสูตรการฝึกอบรม: " + requestBody.name + " ปีงบประมาณ: " + requestBody.year + " มีอยู่ในระบบแล้ว", + HttpStatusCode.NOT_FOUND, + "โครงการ/หลักสูตรการฝึกอบรม: " + + requestBody.projectName + + " ปีงบประมาณ: " + + requestBody.year + + " มีอยู่ในระบบแล้ว", ); } + + if (requestBody.provinceId != null) { + const checkId = await this.provinceRepository.findOne({ + where: { id: requestBody.provinceId }, + }); + if (!checkId) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลจังหวัดสถานที่ดำเนินการ"); + } + } + if (requestBody.provinceActualId != null) { + const checkId = await this.provinceRepository.findOne({ + where: { id: requestBody.provinceActualId }, + }); + if (!checkId) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลจังหวัดข้อมูลด้านวิชาการ"); + } + } + + const development = Object.assign(new Development(), requestBody); + development.createdUserId = request.user.sub; development.createdFullName = request.user.name; development.lastUpdateUserId = request.user.sub; development.lastUpdateFullName = request.user.name; await this.developmentRepository.save(development); + await Promise.all( + requestBody.actualPeoples.map(async (x) => { + const data = Object.assign(new ActualPeople(), x); + data.createdUserId = request.user.sub; + data.createdFullName = request.user.name; + data.lastUpdateUserId = request.user.sub; + data.lastUpdateFullName = request.user.name; + data.developmentActualPeopleId = development.id; + await this.actualPeopleRepository.save(data); + }), + ); + await Promise.all( + requestBody.plannedPeoples.map(async (x) => { + const data = Object.assign(new PlannedPeople(), x); + data.createdUserId = request.user.sub; + data.createdFullName = request.user.name; + data.lastUpdateUserId = request.user.sub; + data.lastUpdateFullName = request.user.name; + data.developmentPlannedPeopleId = development.id; + await this.plannedPeopleRepository.save(data); + }), + ); + await Promise.all( + requestBody.actualGoals.map(async (x) => { + if (x.posTypeActualId != null) { + const checkId = await this.posTypeRepository.findOne({ + where: { id: x.posTypeActualId }, + }); + if (!checkId) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลประเภทตำแหน่ง"); + } + } + if (x.posLevelActualId != null) { + const checkId = await this.posLevelRepository.findOne({ + where: { id: x.posLevelActualId }, + }); + if (!checkId) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลระดับตำแหน่ง"); + } + } + const data = Object.assign(new ActualGoal(), x); + data.createdUserId = request.user.sub; + data.createdFullName = request.user.name; + data.lastUpdateUserId = request.user.sub; + data.lastUpdateFullName = request.user.name; + data.developmentActualGoalId = development.id; + await this.actualGoalRepository.save(data); + }), + ); + await Promise.all( + requestBody.plannedGoals.map(async (x) => { + if (x.posTypePlannedId != null) { + const checkId = await this.posTypeRepository.findOne({ + where: { id: x.posTypePlannedId }, + }); + if (!checkId) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลประเภทตำแหน่ง"); + } + } + if (x.posLevelPlannedId != null) { + const checkId = await this.posLevelRepository.findOne({ + where: { id: x.posLevelPlannedId }, + }); + if (!checkId) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลระดับตำแหน่ง"); + } + } + const data = Object.assign(new PlannedGoal(), x); + data.createdUserId = request.user.sub; + data.createdFullName = request.user.name; + data.lastUpdateUserId = request.user.sub; + data.lastUpdateFullName = request.user.name; + data.developmentPlannedGoalId = development.id; + await this.plannedGoalRepository.save(data); + }), + ); return new HttpSuccess(development.id); } @@ -78,27 +184,135 @@ export class DevelopmentController extends Controller { @Body() requestBody: UpdateDevelopment, @Request() request: { user: Record }, ) { - const development = await this.developmentRepository.findOne({ where: { id } }); + const development = await this.developmentRepository.findOne({ + where: { id }, + relations: { + developmentActualPeoples: true, + developmentPlannedPeoples: true, + developmentActualGoals: true, + developmentPlannedGoals: true, + }, + }); if (!development) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงการ/หลักสูตรการฝึกอบรมนี้"); } + if (requestBody.provinceId != null) { + const checkId = await this.provinceRepository.findOne({ + where: { id: requestBody.provinceId }, + }); + if (!checkId) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลจังหวัดสถานที่ดำเนินการ"); + } + } + if (requestBody.provinceActualId != null) { + const checkId = await this.provinceRepository.findOne({ + where: { id: requestBody.provinceActualId }, + }); + if (!checkId) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลจังหวัดข้อมูลด้านวิชาการ"); + } + } const chk_name = await this.developmentRepository.find({ - where: { - name: requestBody.name, + where: { + projectName: requestBody.projectName, year: requestBody.year, - id: Not(id) + id: Not(id), }, }); if (chk_name.length > 0) { throw new HttpError( - HttpStatusCode.NOT_FOUND, - "โครงการ/หลักสูตรการฝึกอบรม: " + requestBody.name + " ปีงบประมาณ: " + requestBody.year + " มีอยู่ในระบบแล้ว", + HttpStatusCode.NOT_FOUND, + "โครงการ/หลักสูตรการฝึกอบรม: " + + requestBody.projectName + + " ปีงบประมาณ: " + + requestBody.year + + " มีอยู่ในระบบแล้ว", ); } + Object.assign(development, requestBody); development.lastUpdateUserId = request.user.sub; development.lastUpdateFullName = request.user.name; - this.developmentRepository.merge(development, requestBody); await this.developmentRepository.save(development); + await this.actualPeopleRepository.remove(development.developmentActualPeoples); + await this.plannedPeopleRepository.remove(development.developmentPlannedPeoples); + await this.actualGoalRepository.remove(development.developmentActualGoals); + await this.plannedGoalRepository.remove(development.developmentPlannedGoals); + await Promise.all( + requestBody.actualPeoples.map(async (x) => { + const data = Object.assign(new ActualPeople(), x); + data.createdUserId = request.user.sub; + data.createdFullName = request.user.name; + data.lastUpdateUserId = request.user.sub; + data.lastUpdateFullName = request.user.name; + data.developmentActualPeopleId = development.id; + await this.actualPeopleRepository.save(data); + }), + ); + await Promise.all( + requestBody.plannedPeoples.map(async (x) => { + const data = Object.assign(new PlannedPeople(), x); + data.createdUserId = request.user.sub; + data.createdFullName = request.user.name; + data.lastUpdateUserId = request.user.sub; + data.lastUpdateFullName = request.user.name; + data.developmentPlannedPeopleId = development.id; + await this.plannedPeopleRepository.save(data); + }), + ); + await Promise.all( + requestBody.actualGoals.map(async (x) => { + if (x.posTypeActualId != null) { + const checkId = await this.posTypeRepository.findOne({ + where: { id: x.posTypeActualId }, + }); + if (!checkId) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลประเภทตำแหน่ง"); + } + } + if (x.posLevelActualId != null) { + const checkId = await this.posLevelRepository.findOne({ + where: { id: x.posLevelActualId }, + }); + if (!checkId) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลระดับตำแหน่ง"); + } + } + const data = Object.assign(new ActualGoal(), x); + data.createdUserId = request.user.sub; + data.createdFullName = request.user.name; + data.lastUpdateUserId = request.user.sub; + data.lastUpdateFullName = request.user.name; + data.developmentActualGoalId = development.id; + await this.actualGoalRepository.save(data); + }), + ); + await Promise.all( + requestBody.plannedGoals.map(async (x) => { + if (x.posTypePlannedId != null) { + const checkId = await this.posTypeRepository.findOne({ + where: { id: x.posTypePlannedId }, + }); + if (!checkId) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลประเภทตำแหน่ง"); + } + } + if (x.posLevelPlannedId != null) { + const checkId = await this.posLevelRepository.findOne({ + where: { id: x.posLevelPlannedId }, + }); + if (!checkId) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลระดับตำแหน่ง"); + } + } + const data = Object.assign(new PlannedGoal(), x); + data.createdUserId = request.user.sub; + data.createdFullName = request.user.name; + data.lastUpdateUserId = request.user.sub; + data.lastUpdateFullName = request.user.name; + data.developmentPlannedGoalId = development.id; + await this.plannedGoalRepository.save(data); + }), + ); return new HttpSuccess(development.id); } @@ -111,11 +325,24 @@ export class DevelopmentController extends Controller { */ @Delete("{id}") async DeleteDevelopment(@Path() id: string) { - const delDevelopment = await this.developmentRepository.findOne({ where: { id } }); - if (!delDevelopment) { + const development = await this.developmentRepository.findOne({ + where: { id }, + relations: { + developmentActualPeoples: true, + developmentPlannedPeoples: true, + developmentActualGoals: true, + developmentPlannedGoals: true, + }, + }); + if (!development) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงการ/หลักสูตรการฝึกอบรมนี้"); } - await this.developmentRepository.remove(delDevelopment); + + await this.actualPeopleRepository.remove(development.developmentActualPeoples); + await this.plannedPeopleRepository.remove(development.developmentPlannedPeoples); + await this.actualGoalRepository.remove(development.developmentActualGoals); + await this.plannedGoalRepository.remove(development.developmentPlannedGoals); + await this.developmentRepository.remove(development); return new HttpSuccess(); } @@ -130,18 +357,15 @@ export class DevelopmentController extends Controller { @Query("page") page: number = 1, @Query("pageSize") pageSize: number = 10, @Query("keyword") keyword?: string, - @Query("year") year: number = 2024, + @Query("year") year?: number, ) { const [development, total] = await AppDataSource.getRepository(Development) .createQueryBuilder("development") - .andWhere(year != 0 ? "development.year LIKE :year" : "1=1", { year: `${year}` }) - .orWhere("development.name LIKE :keyword", { keyword: `${keyword}` }) - .select([ - "development.id", - "development.name", - "development.year", - ]) + .andWhere(year == null ? "development.year LIKE :year" : "1=1", { year: `${year}` }) + .orWhere("development.projectName LIKE :keyword", { keyword: `${keyword}` }) + .select(["development.id", "development.projectName", "development.year"]) .orderBy("development.year", "DESC") + .orderBy("development.createdAt", "DESC") .skip((page - 1) * pageSize) .take(pageSize) .getManyAndCount(); @@ -159,13 +383,17 @@ export class DevelopmentController extends Controller { @Get("{id}") async GetDevelopemtById(@Path() id: string) { const getDevelopment = await this.developmentRepository.findOne({ - select: ["id", "name", "year"], where: { id: id }, + relations: { + developmentActualPeoples: true, + developmentPlannedPeoples: true, + developmentActualGoals: true, + developmentPlannedGoals: true, + }, }); if (!getDevelopment) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงการ/หลักสูตรการฝึกอบรมนี้"); } return new HttpSuccess(getDevelopment); } - } diff --git a/src/controllers/DevelopmentHistoryController.ts b/src/controllers/DevelopmentHistoryController.ts new file mode 100644 index 0000000..283ac8d --- /dev/null +++ b/src/controllers/DevelopmentHistoryController.ts @@ -0,0 +1,178 @@ +import { + Controller, + Get, + Post, + Put, + Delete, + Route, + Security, + Tags, + Body, + Path, + Request, + Query, +} from "tsoa"; +import { AppDataSource } from "../database/data-source"; +import { Not } from "typeorm"; +import HttpSuccess from "../interfaces/http-success"; +import HttpError from "../interfaces/http-error"; +import HttpStatusCode from "../interfaces/http-status"; +import { Development } from "../entities/Development"; +import { + CreateDevelopmentHistory, + DevelopmentHistory, + UpdateDevelopmentHistory, +} from "../entities/DevelopmentHistory"; + +@Route("api/v1/development/history") +@Tags("DevelopmentHistory") +@Security("bearerAuth") +export class DevelopmentHistoryController extends Controller { + private developmentHistoryRepository = AppDataSource.getRepository(DevelopmentHistory); + private developmentRepository = AppDataSource.getRepository(Development); + + /** + * API เพิ่มประวัติการฝึกอบรม/ดูงาน + * + * @summary DEV_006 - เพิ่มประวัติการฝึกอบรม/ดูงาน#6 + * + */ + @Post() + async CreateDevelopmentHistory( + @Body() requestBody: CreateDevelopmentHistory, + @Request() request: { user: Record }, + ) { + const chk_name = await this.developmentHistoryRepository.find({ + where: { + citizenId: requestBody.citizenId, + developmentId: requestBody.developmentId, + }, + }); + if (chk_name.length > 0) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ประวัติการฝึกอบรม/ดูงาน มีอยู่ในระบบแล้ว"); + } + + const checkId = await this.developmentRepository.findOne({ + where: { id: requestBody.developmentId }, + }); + if (!checkId) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงการ/หลักสูตรการฝึกอบรม"); + } + + const development = Object.assign(new DevelopmentHistory(), requestBody); + + development.createdUserId = request.user.sub; + development.createdFullName = request.user.name; + development.lastUpdateUserId = request.user.sub; + development.lastUpdateFullName = request.user.name; + await this.developmentHistoryRepository.save(development); + return new HttpSuccess(development.id); + } + + /** + * API แก้ไขประวัติการฝึกอบรม/ดูงาน + * + * @summary DEV_007 - แก้ไขประวัติการฝึกอบรม/ดูงาน #7 + * + * @param {string} id Id โครงการ + */ + @Put("{id}") + async UpdateDevelopmentHistory( + @Path() id: string, + @Body() requestBody: UpdateDevelopmentHistory, + @Request() request: { user: Record }, + ) { + const development = await this.developmentHistoryRepository.findOne({ + where: { id }, + }); + if (!development) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลประวัติการฝึกอบรม/ดูงานนี้"); + } + const chk_name = await this.developmentHistoryRepository.find({ + where: { + citizenId: requestBody.citizenId, + developmentId: requestBody.developmentId, + id: Not(id), + }, + }); + if (chk_name.length > 0) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ประวัติการฝึกอบรม/ดูงาน มีอยู่ในระบบแล้ว"); + } + const checkId = await this.developmentRepository.findOne({ + where: { id: requestBody.developmentId }, + }); + if (!checkId) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงการ/หลักสูตรการฝึกอบรม"); + } + Object.assign(development, requestBody); + development.lastUpdateUserId = request.user.sub; + development.lastUpdateFullName = request.user.name; + await this.developmentHistoryRepository.save(development); + return new HttpSuccess(development.id); + } + + /** + * API ลบประวัติการฝึกอบรม/ดูงาน + * + * @summary DEV_008 - ลบประวัติการฝึกอบรม/ดูงาน #8 + * + * @param {string} id Id โครงการ + */ + @Delete("{id}") + async DeleteDevelopmentHistory(@Path() id: string) { + const development = await this.developmentHistoryRepository.findOne({ + where: { id }, + }); + if (!development) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลประวัติการฝึกอบรม/ดูงานนี้"); + } + + await this.developmentHistoryRepository.remove(development); + return new HttpSuccess(); + } + + /** + * API รายการประวัติการฝึกอบรม/ดูงาน + * + * @summary DEV_009 - รายการประวัติการฝึกอบรม/ดูงาน #9 + * + */ + @Get() + async GetDevelopmentHistoryLists( + @Query("page") page: number = 1, + @Query("pageSize") pageSize: number = 10, + @Query("keyword") keyword?: string, + @Query("year") year?: number, + ) { + const [development, total] = await AppDataSource.getRepository(DevelopmentHistory) + .createQueryBuilder("developmentHistory") + // .andWhere(year == null ? "developmentHistory.year LIKE :year" : "1=1", { year: `${year}` }) + // .orWhere("developmentHistory.projectName LIKE :keyword", { keyword: `${keyword}` }) + // .select(["development.id", "development.projectName", "development.year"]) + // .orderBy("developmentHistory.year", "DESC") + .orderBy("developmentHistory.createdAt", "DESC") + .skip((page - 1) * pageSize) + .take(pageSize) + .getManyAndCount(); + + return new HttpSuccess({ data: development, total }); + } + + /** + * API รายละเอียดประวัติการฝึกอบรม/ดูงาน + * + * @summary DEV_010 - รายละเอียดประวัติการฝึกอบรม/ดูงาน #10 + * + * @param {string} id Id โครงการ + */ + @Get("{id}") + async GetDevelopemtHistoryById(@Path() id: string) { + const getDevelopment = await this.developmentHistoryRepository.findOne({ + where: { id: id }, + }); + if (!getDevelopment) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลประวัติการฝึกอบรม/ดูงานนี้"); + } + return new HttpSuccess(getDevelopment); + } +} diff --git a/src/entities/ActualGoal.ts b/src/entities/ActualGoal.ts new file mode 100644 index 0000000..cbe85aa --- /dev/null +++ b/src/entities/ActualGoal.ts @@ -0,0 +1,95 @@ +import { Entity, Column, ManyToOne, JoinColumn } from "typeorm"; +import { EntityBase } from "./base/Base"; +import { Development } from "./Development"; +import { PosLevel } from "./PosLevel"; +import { PosType } from "./PosType"; + +@Entity("actualGoal") +export class ActualGoal extends EntityBase { + @Column({ + nullable: true, + comment: "กลุ่มเป้าหมาย", + default: null, + }) + groupTarget: string; + + @Column({ + nullable: true, + comment: "กลุ่มเป้าหมายย่อย", + default: null, + }) + groupTargetSub: string; + + @Column({ + nullable: true, + comment: "ตำแหน่ง", + default: null, + }) + position: string; + + @Column({ + nullable: true, + comment: "ประเภทตำแหน่ง", + default: null, + }) + posTypeActualId: string; + + @ManyToOne(() => PosType, (posType: PosType) => posType.actualGoals) + @JoinColumn({ name: "posTypeActualId" }) + posTypeActual: PosType; + + @Column({ + nullable: true, + comment: "ระดับตำแหน่ง", + default: null, + }) + posLevelActualId: string; + + @ManyToOne(() => PosLevel, (posLevel: PosLevel) => posLevel.actualGoals) + @JoinColumn({ name: "posLevelActualId" }) + posLevelActual: PosLevel; + + @Column({ + nullable: true, + comment: "ประเภท(กลุ่มอาชีพ คุณสมบัติ)", + default: null, + }) + type: string; + + @Column({ + nullable: true, + comment: "จำนวน(คน)", + default: null, + }) + amount: number; + + @Column({ + nullable: true, + comment: "id โครงการ", + default: null, + }) + developmentActualGoalId: string; + + @ManyToOne(() => Development, (development: Development) => development.developmentActualGoals) + @JoinColumn({ name: "developmentActualGoalId" }) + developmentActualGoal: Development; +} + +export class CreateActualGoal { + @Column() + groupTarget: string | null; + @Column() + groupTargetSub: string | null; + @Column() + position: string | null; + @Column() + posTypeActualId: string | null; + @Column() + posLevelActualId: string | null; + @Column() + type: string | null; + @Column() + amount: number | null; +} + +export type UpdateActualGoal = Partial; diff --git a/src/entities/ActualPeople.ts b/src/entities/ActualPeople.ts new file mode 100644 index 0000000..8050810 --- /dev/null +++ b/src/entities/ActualPeople.ts @@ -0,0 +1,40 @@ +import { Entity, Column, ManyToOne, JoinColumn } from "typeorm"; +import { EntityBase } from "./base/Base"; +import { Development } from "./Development"; + +@Entity("actualPeople") +export class ActualPeople extends EntityBase { + @Column({ + nullable: true, + comment: "ผู้เกี่ยวข้อง", + default: null, + }) + groupTarget: string; + + @Column({ + nullable: true, + comment: "จำนวน(คน)", + default: null, + }) + amount: number; + + @Column({ + nullable: true, + comment: "id โครงการ", + default: null, + }) + developmentActualPeopleId: string; + + @ManyToOne(() => Development, (development: Development) => development.developmentActualPeoples) + @JoinColumn({ name: "developmentActualPeopleId" }) + developmentActualPeople: Development; +} + +export class CreateActualPeople { + @Column() + groupTarget: string | null; + @Column() + amount: number | null; +} + +export type UpdateActualPeople = Partial; diff --git a/src/entities/Development.ts b/src/entities/Development.ts index ca5c2b9..a3d5368 100644 --- a/src/entities/Development.ts +++ b/src/entities/Development.ts @@ -1,34 +1,471 @@ -import { Entity, Column, ManyToOne, JoinColumn, OneToOne, OneToMany } from "typeorm"; +import { Entity, Column, ManyToOne, JoinColumn, OneToOne, OneToMany, Double } from "typeorm"; import { EntityBase } from "./base/Base"; +import { Province } from "./Province"; +import { ActualPeople, CreateActualPeople } from "./ActualPeople"; +import { CreatePlannedPeople, PlannedPeople } from "./PlannedPeople"; +import { ActualGoal, CreateActualGoal } from "./ActualGoal"; +import { CreatePlannedGoal, PlannedGoal } from "./PlannedGoal"; +import { DevelopmentHistory } from "./DevelopmentHistory"; @Entity("development") export class Development extends EntityBase { - @Column({ - comment: "ชื่อโครงการ/กิจกรรม/หลักสูตร", - length: 255, - }) - name: string; - @Column({ nullable: true, comment: "ปีงบประมาณ", }) year: number; -} + @Column({ + comment: "ชื่อโครงการ/กิจกรรม/หลักสูตร", + length: 255, + }) + projectName: string; + @Column({ + nullable: true, + comment: "หลักการและเหตุผล", + default: null, + }) + reason: string; + + @Column({ + nullable: true, + comment: "วัตถุประสงค์", + default: null, + }) + objective: string; + + @Column({ + nullable: true, + comment: "ประเภทตัวชี้วัด", + default: null, + }) + metricType: string; + + @Column({ + nullable: true, + comment: "ตัวชี้วัด", + default: null, + }) + indicators: string; + + @Column({ + nullable: true, + comment: "เป้าหมาย", + default: null, + }) + target: string; + + @Column({ + nullable: true, + comment: "วิธีการคำนวณ/เครื่องมือ", + default: null, + }) + calculation: string; + + @Column({ + nullable: true, + comment: "ระยะเวลาวัดผล", + default: null, + }) + measuRement: string; + + @Column({ + nullable: true, + comment: "ผลการดำเนิน", + default: null, + }) + results: string; + + @Column({ + nullable: true, + comment: "ปัญหาอุปสรรค", + default: null, + }) + obstacles: string; + + @Column({ + nullable: true, + comment: "ข้อเสนอเเนะ", + default: null, + }) + suggestions: string; + + @Column({ + nullable: true, + comment: "ประเภทโครงการ", + default: null, + }) + project: string; + + @Column({ + comment: "ผ่านการพิจาณา ได้รับการจัดสรรงบประมาณตามข้อบัญญัติ", + default: false, + }) + isPassAllocate: boolean; + + @Column({ + comment: + "ผ่านการพิจารณา ไม่ได้รับการจัดสรรงบประมาณตามข้อบัญญัติ แต่ได้รับการจัดสรรเงินนอกงบประมาณ", + default: false, + }) + isPassNoAllocate: boolean; + + @Column({ + comment: "ไม่ผ่านการพิจารณา แต่ได้รับการจัดสรรเงินนอกงบประมาณ", + default: false, + }) + isNoPass: boolean; + + @Column({ + comment: "แต่ได้รับการจัดสรรงบประมาณตามข้อบัญญัติ", + default: false, + }) + isBudget: boolean; + + @Column({ + comment: "แต่ได้รับการจัดสรรเงินนอกงบประมาณ", + default: false, + }) + isOutBudget: boolean; + + @Column({ + nullable: true, + type: "datetime", + comment: "วันที่เริ่มต้น", + default: null, + }) + dateStart: Date; + + @Column({ + nullable: true, + type: "datetime", + comment: "วันที่สิ้นสุด", + default: null, + }) + dateEnd: Date; + + @Column({ + nullable: true, + comment: "รวมระยะเวลา (วัน)", + default: null, + }) + totalDate: number; + + @Column({ + nullable: true, + comment: "ที่อยู่", + default: null, + }) + address: string; + + @Column({ + nullable: true, + comment: "จังหวัด", + default: null, + }) + provinceId: string; + + @ManyToOne(() => Province, (province: Province) => province.developments) + @JoinColumn({ name: "provinceId" }) + province: Province; + + @Column({ + nullable: true, + comment: "ประเภทงบประมาณ", + default: null, + }) + budget: string; + + @Column({ + nullable: true, + comment: "จํานวนงบประมาณที่ขอรับการจัดสรรฯ", + default: 0, + type: "double", + }) + accept: Double; + + @Column({ + nullable: true, + comment: "จํานวนงบประมาณที่ได้รับการจัดสรรฯ", + default: 0, + type: "double", + }) + receive: Double; + + @Column({ + nullable: true, + comment: "จํานวนงบประมาณที่ได้รับอนุมัติ", + default: 0, + type: "double", + }) + approved: Double; + + @Column({ + nullable: true, + comment: "จํานวนงบประมาณที่จ่ายจริง", + default: 0, + type: "double", + }) + budgetPay: Double; + + @Column({ + nullable: true, + comment: "ประเด็นความเสี่ยง", + default: null, + }) + issues: string; + + @Column({ + nullable: true, + comment: "โอกาสที่จะเกิด", + default: null, + }) + chance: string; + + @Column({ + nullable: true, + comment: "ผลกระทบจากการเกิด", + default: null, + }) + effects: string; + + @Column({ + nullable: true, + comment: "ระดับความเสี่ยง", + default: null, + }) + riskLevel: string; + + @Column({ + nullable: true, + comment: "เเนวทางการบริหารความเสี่ยง", + default: null, + }) + riskManagement: string; + + @Column({ + nullable: true, + comment: "ประโยชน์ที่คาดว่าจะได้รับ", + default: null, + }) + expect: string; + + @Column({ + nullable: true, + comment: "หัวข้อ/ประเด็นการฝึกอบรม ศึกษาดูงาน", + default: null, + }) + topicAcademic: string; + + @Column({ + nullable: true, + comment: "สถานที่ฝึกอบรม ศึกษาดูงาน", + default: null, + }) + addressAcademic: string; + + @Column({ + nullable: true, + comment: "จังหวัด(ข้อมูลวิชาการ)", + default: null, + }) + provinceActualId: string; + + @ManyToOne(() => Province, (province: Province) => province.developmentActuals) + @JoinColumn({ name: "provinceActualId" }) + provinceActual: Province; + + @OneToMany( + () => ActualPeople, + (actualPeople: ActualPeople) => actualPeople.developmentActualPeople, + ) + developmentActualPeoples: ActualPeople[]; + + @OneToMany( + () => PlannedPeople, + (plannedPeople: PlannedPeople) => plannedPeople.developmentPlannedPeople, + ) + developmentPlannedPeoples: PlannedPeople[]; + + @OneToMany(() => ActualGoal, (actualGoal: ActualGoal) => actualGoal.developmentActualGoal) + developmentActualGoals: ActualGoal[]; + + @OneToMany(() => PlannedGoal, (plannedGoal: PlannedGoal) => plannedGoal.developmentPlannedGoal) + developmentPlannedGoals: PlannedGoal[]; + + @OneToMany( + () => DevelopmentHistory, + (developmentHistory: DevelopmentHistory) => developmentHistory.development, + ) + developmentHistorys: DevelopmentHistory[]; +} export class CreateDevelopment { - @Column() - name: string; - @Column() year: number; + @Column() + projectName: string; + @Column() + reason: string | null; + @Column() + objective: string | null; + @Column() + metricType: string | null; + @Column() + indicators: string | null; + @Column() + target: string | null; + @Column() + calculation: string | null; + @Column() + measuRement: string | null; + @Column() + results: string | null; + @Column() + obstacles: string | null; + @Column() + suggestions: string | null; + @Column() + project: string | null; + @Column() + isPassAllocate: boolean; + @Column() + isPassNoAllocate: boolean; + @Column() + isNoPass: boolean; + @Column() + isBudget: boolean; + @Column() + isOutBudget: boolean; + @Column() + dateStart: Date | null; + @Column() + dateEnd: Date | null; + @Column() + totalDate: number | null; + @Column() + address: string | null; + @Column() + provinceId: string | null; + @Column() + budget: string | null; + @Column() + accept: Double | null; + @Column() + receive: Double | null; + @Column() + approved: Double | null; + @Column() + budgetPay: Double | null; + @Column() + issues: string | null; + @Column() + chance: string | null; + @Column() + effects: string | null; + @Column() + riskLevel: string | null; + @Column() + riskManagement: string | null; + @Column() + expect: string | null; + @Column() + topicAcademic: string | null; + @Column() + addressAcademic: string | null; + @Column() + provinceActualId: string | null; + @Column() + actualPeoples: CreateActualPeople[]; + @Column() + plannedPeoples: CreatePlannedPeople[]; + @Column() + actualGoals: CreateActualGoal[]; + @Column() + plannedGoals: CreatePlannedGoal[]; } export class UpdateDevelopment { - @Column() - name: string; - @Column() year: number; + @Column() + projectName: string; + @Column() + reason: string | null; + @Column() + objective: string | null; + @Column() + metricType: string | null; + @Column() + indicators: string | null; + @Column() + target: string | null; + @Column() + calculation: string | null; + @Column() + measuRement: string | null; + @Column() + results: string | null; + @Column() + obstacles: string | null; + @Column() + suggestions: string | null; + @Column() + project: string | null; + @Column() + isPassAllocate: boolean; + @Column() + isPassNoAllocate: boolean; + @Column() + isNoPass: boolean; + @Column() + isBudget: boolean; + @Column() + isOutBudget: boolean; + @Column() + dateStart: Date | null; + @Column() + dateEnd: Date | null; + @Column() + totalDate: number | null; + @Column() + address: string | null; + @Column() + provinceId: string | null; + @Column() + budget: string | null; + @Column() + accept: Double | null; + @Column() + receive: Double | null; + @Column() + approved: Double | null; + @Column() + budgetPay: Double | null; + @Column() + issues: string | null; + @Column() + chance: string | null; + @Column() + effects: string | null; + @Column() + riskLevel: string | null; + @Column() + riskManagement: string | null; + @Column() + expect: string | null; + @Column() + topicAcademic: string | null; + @Column() + addressAcademic: string | null; + @Column() + provinceActualId: string | null; + @Column() + actualPeoples: CreateActualPeople[]; + @Column() + plannedPeoples: CreatePlannedPeople[]; + @Column() + actualGoals: CreateActualGoal[]; + @Column() + plannedGoals: CreatePlannedGoal[]; } diff --git a/src/entities/DevelopmentHistory.ts b/src/entities/DevelopmentHistory.ts new file mode 100644 index 0000000..ca34e4f --- /dev/null +++ b/src/entities/DevelopmentHistory.ts @@ -0,0 +1,154 @@ +import { Entity, Column, ManyToOne, JoinColumn } from "typeorm"; +import { EntityBase } from "./base/Base"; +import { PosLevel } from "./PosLevel"; +import { PosType } from "./PosType"; +import { Development } from "./Development"; + +@Entity("developmentHistory") +export class DevelopmentHistory extends EntityBase { + @Column({ + nullable: true, + comment: "ยศ", + length: 40, + default: null, + }) + rank: string; + + @Column({ + nullable: true, + comment: "คำนำหน้าชื่อ", + length: 40, + default: null, + }) + prefix: string; + + @Column({ + nullable: true, + comment: "ชื่อ", + length: 255, + default: null, + }) + firstName: string; + + @Column({ + nullable: true, + comment: "นามสกุล", + length: 255, + default: null, + }) + lastName: string; + + @Column({ + nullable: true, + comment: "เลขประจำตัวประชาชน", + default: null, + length: 13, + }) + citizenId: string; + + @Column({ + nullable: true, + comment: "ตำแหน่ง", + default: null, + length: 255, + }) + position: string; + + @Column({ + nullable: true, + length: 40, + comment: "ไอดีระดับตำแหน่ง", + }) + posLevelId: string | null; + + @ManyToOne(() => PosLevel, (posLevel) => posLevel.developmentHistorys) + @JoinColumn({ name: "posLevelId" }) + posLevel: PosLevel; + + @Column({ + nullable: true, + length: 40, + comment: "ไอดีประเภทตำแหน่ง", + }) + posTypeId: string | null; + + @ManyToOne(() => PosType, (posType) => posType.developmentHistorys) + @JoinColumn({ name: "posTypeId" }) + posType: PosType; + + @Column({ + nullable: true, + comment: "โครงการ/หลักสูตรการฝึกอบรม", + default: null, + }) + developmentId: string; + + @ManyToOne(() => Development, (development: Development) => development.developmentHistorys) + @JoinColumn({ name: "developmentId" }) + development: Development; + + @Column({ + nullable: true, + comment: "เลขที่คำสั่ง/เลขที่หนังสืออนุมัติ", + default: null, + length: 255, + }) + order: string; + + @Column({ + nullable: true, + comment: "คำสั่งลงวันที่/หนังสืออนุมัติลงวันที่", + default: null, + length: 255, + }) + dateOrder: string; +} +export class CreateDevelopmentHistory { + @Column() + rank: string | null; + @Column() + prefix: string | null; + @Column() + firstName: string | null; + @Column() + lastName: string | null; + @Column() + citizenId: string; + @Column() + position: string | null; + @Column() + posLevelId: string | null; + @Column() + posTypeId: string | null; + @Column() + developmentId: string; + @Column() + order: string | null; + @Column() + dateOrder: string | null; +} + +export class UpdateDevelopmentHistory { + @Column() + rank: string | null; + @Column() + prefix: string | null; + @Column() + firstName: string | null; + @Column() + lastName: string | null; + @Column() + citizenId: string; + @Column() + position: string | null; + @Column() + posLevelId: string | null; + @Column() + posTypeId: string | null; + @Column() + developmentId: string; + @Column() + order: string | null; + @Column() + dateOrder: string | null; +} diff --git a/src/entities/EmployeePosLevel.ts b/src/entities/EmployeePosLevel.ts new file mode 100644 index 0000000..c84e309 --- /dev/null +++ b/src/entities/EmployeePosLevel.ts @@ -0,0 +1,61 @@ +import { Entity, Column, ManyToOne, JoinColumn } from "typeorm"; +import { EntityBase } from "./base/Base"; +import { EmployeePosType } from "./EmployeePosType"; + +enum EmployeePosLevelAuthoritys { + HEAD = "HEAD", + DEPUTY = "DEPUTY", + GOVERNOR = "GOVERNOR", +} +@Entity("employeePosLevel") +export class EmployeePosLevel extends EntityBase { + @Column({ + comment: "ชื่อระดับชั้นงาน", + type: "int", + }) + posLevelName: number; + + @Column({ + comment: "ระดับของระดับชั้นงาน", + type: "int", + }) + posLevelRank: number; + + @Column({ + nullable: true, + comment: + "ผู้มีอำนาจสั่งบรรจุของระดับนี้ head = หัวหน้าหน่วยงาน , deputy = ปลัด , governor = ผู้ว่าฯ", + type: "enum", + enum: EmployeePosLevelAuthoritys, + default: null, + }) + posLevelAuthority: EmployeePosLevelAuthoritys; + + @Column({ + length: 40, + comment: "คีย์นอก(FK)ของตาราง employeePosType", + }) + posTypeId: string; + + @ManyToOne(() => EmployeePosType, (posType: EmployeePosType) => posType.posLevels) + @JoinColumn({ name: "posTypeId" }) + posType: EmployeePosType; +} + +export class CreateEmployeePosLevel { + @Column() + posLevelName: number; + + @Column() + posLevelRank: number; + + @Column() + posLevelAuthority: string; + + @Column("uuid") + posTypeId: string; +} + +export type UpdateEmployeePosLevel = Partial & { + posLevelAuthority: EmployeePosLevelAuthoritys; +}; diff --git a/src/entities/EmployeePosType.ts b/src/entities/EmployeePosType.ts new file mode 100644 index 0000000..99b1cdb --- /dev/null +++ b/src/entities/EmployeePosType.ts @@ -0,0 +1,43 @@ +import { Entity, Column, OneToMany } from "typeorm"; +import { EntityBase } from "./base/Base"; +import { EmployeePosLevel } from "./EmployeePosLevel"; + +@Entity("employeePosType") +export class EmployeePosType extends EntityBase { + @Column({ + nullable: true, + comment: "ชื่อกลุ่มงาน", + length: 255, + default: null, + }) + posTypeName: string; + + @Column({ + comment: "ระดับของกลุ่มงาน", + }) + posTypeRank: number; + + @Column({ + nullable: true, + comment: "ชื่อย่อกลุ่มงาน", + length: 255, + default: null, + }) + posTypeShortName: string; + + @OneToMany(() => EmployeePosLevel, (posLevel: EmployeePosLevel) => posLevel.posType) + posLevels: EmployeePosLevel[]; +} + +export class CreateEmployeePosType { + @Column() + posTypeName: string; + + @Column() + posTypeRank: number; + + @Column() + posTypeShortName: string; +} + +export type UpdateEmployeePosType = Partial; diff --git a/src/entities/PlannedGoal.ts b/src/entities/PlannedGoal.ts new file mode 100644 index 0000000..5758ed8 --- /dev/null +++ b/src/entities/PlannedGoal.ts @@ -0,0 +1,95 @@ +import { Entity, Column, ManyToOne, JoinColumn } from "typeorm"; +import { EntityBase } from "./base/Base"; +import { Development } from "./Development"; +import { PosType } from "./PosType"; +import { PosLevel } from "./PosLevel"; + +@Entity("plannedGoal") +export class PlannedGoal extends EntityBase { + @Column({ + nullable: true, + comment: "กลุ่มเป้าหมาย", + default: null, + }) + groupTarget: string; + + @Column({ + nullable: true, + comment: "กลุ่มเป้าหมายย่อย", + default: null, + }) + groupTargetSub: string; + + @Column({ + nullable: true, + comment: "ตำแหน่ง", + default: null, + }) + position: string; + + @Column({ + nullable: true, + comment: "ประเภทตำแหน่ง", + default: null, + }) + posTypePlannedId: string; + + @ManyToOne(() => PosType, (posType: PosType) => posType.plannedGoals) + @JoinColumn({ name: "posTypePlannedId" }) + posTypePlanned: PosType; + + @Column({ + nullable: true, + comment: "ระดับตำแหน่ง", + default: null, + }) + posLevelPlannedId: string; + + @ManyToOne(() => PosLevel, (posLevel: PosLevel) => posLevel.plannedGoals) + @JoinColumn({ name: "posLevelPlannedId" }) + posLevelPlanned: PosLevel; + + @Column({ + nullable: true, + comment: "ประเภท(กลุ่มอาชีพ คุณสมบัติ)", + default: null, + }) + type: string; + + @Column({ + nullable: true, + comment: "จำนวน(คน)", + default: null, + }) + amount: number; + + @Column({ + nullable: true, + comment: "id โครงการ", + default: null, + }) + developmentPlannedGoalId: string; + + @ManyToOne(() => Development, (development: Development) => development.developmentPlannedGoals) + @JoinColumn({ name: "developmentPlannedGoalId" }) + developmentPlannedGoal: Development; +} + +export class CreatePlannedGoal { + @Column() + groupTarget: string | null; + @Column() + groupTargetSub: string | null; + @Column() + position: string | null; + @Column() + posTypePlannedId: string | null; + @Column() + posLevelPlannedId: string | null; + @Column() + type: string | null; + @Column() + amount: number | null; +} + +export type UpdatePlannedGoal = Partial; diff --git a/src/entities/PlannedPeople.ts b/src/entities/PlannedPeople.ts new file mode 100644 index 0000000..8743fd1 --- /dev/null +++ b/src/entities/PlannedPeople.ts @@ -0,0 +1,40 @@ +import { Entity, Column, ManyToOne, JoinColumn } from "typeorm"; +import { EntityBase } from "./base/Base"; +import { Development } from "./Development"; + +@Entity("plannedPeople") +export class PlannedPeople extends EntityBase { + @Column({ + nullable: true, + comment: "ผู้เกี่ยวข้อง", + default: null, + }) + groupTarget: string; + + @Column({ + nullable: true, + comment: "จำนวน(คน)", + default: null, + }) + amount: number; + + @Column({ + nullable: true, + comment: "id โครงการ", + default: null, + }) + developmentPlannedPeopleId: string; + + @ManyToOne(() => Development, (development: Development) => development.developmentPlannedPeoples) + @JoinColumn({ name: "developmentPlannedPeopleId" }) + developmentPlannedPeople: Development; +} + +export class CreatePlannedPeople { + @Column() + groupTarget: string | null; + @Column() + amount: number | null; +} + +export type UpdatePlannedPeople = Partial; diff --git a/src/entities/PosLevel.ts b/src/entities/PosLevel.ts new file mode 100644 index 0000000..cecb35f --- /dev/null +++ b/src/entities/PosLevel.ts @@ -0,0 +1,74 @@ +import { Entity, Column, ManyToOne, JoinColumn, OneToMany } from "typeorm"; +import { EntityBase } from "./base/Base"; +import { PosType } from "./PosType"; +import { ActualGoal } from "./ActualGoal"; +import { PlannedGoal } from "./PlannedGoal"; +import { DevelopmentHistory } from "./DevelopmentHistory"; + +enum PosLevelAuthority { + HEAD = "HEAD", + DEPUTY = "DEPUTY", + GOVERNOR = "GOVERNOR", +} +@Entity("posLevel") +export class PosLevel extends EntityBase { + @Column({ + nullable: true, + comment: "ชื่อระดับตำแหน่ง", + length: 255, + default: null, + }) + posLevelName: string; + + @Column({ + nullable: true, + comment: "ระดับของระดับตำแหน่ง", + default: null, + }) + posLevelRank: number; + + @Column({ + nullable: true, + comment: + "ผู้มีอำนาจสั่งบรรจุของระดับนี้ head = หัวหน้าหน่วยงาน , deputy = ปลัด , governor = ผู้ว่าฯ", + type: "enum", + enum: PosLevelAuthority, + default: null, + }) + posLevelAuthority: PosLevelAuthority; + + @Column({ + length: 40, + comment: "เป็นระดับของประเภทตำแหน่งใด", + }) + posTypeId: string; + + @ManyToOne(() => PosType, (posType: PosType) => posType.posLevels) + @JoinColumn({ name: "posTypeId" }) + posType: PosType; + + @OneToMany(() => ActualGoal, (actualGoal: ActualGoal) => actualGoal.posLevelActual) + actualGoals: ActualGoal[]; + + @OneToMany(() => PlannedGoal, (plannedGoal: PlannedGoal) => plannedGoal.posLevelPlanned) + plannedGoals: PlannedGoal[]; + + @OneToMany(() => DevelopmentHistory, (developmentHistory) => developmentHistory.posLevel) + developmentHistorys: DevelopmentHistory[]; +} + +export class CreatePosLevel { + @Column() + posLevelName: string; + + @Column() + posLevelRank: number; + + @Column() + posLevelAuthority: string; + + @Column("uuid") + posTypeId: string; +} + +export type UpdatePosLevel = Partial & { posLevelAuthority?: PosLevelAuthority }; diff --git a/src/entities/PosType.ts b/src/entities/PosType.ts new file mode 100644 index 0000000..f6a89f6 --- /dev/null +++ b/src/entities/PosType.ts @@ -0,0 +1,47 @@ +import { Entity, Column, OneToMany } from "typeorm"; +import { EntityBase } from "./base/Base"; +import { PosLevel } from "./PosLevel"; +import { ActualGoal } from "./ActualGoal"; +import { PlannedGoal } from "./PlannedGoal"; +import { DevelopmentHistory } from "./DevelopmentHistory"; + +@Entity("posType") +export class PosType extends EntityBase { + @Column({ + nullable: true, + comment: "ชื่อประเภทตำแหน่ง (ทั่วไป วิชาการ อำนวยการ บริหาร)", + length: 255, + default: null, + }) + posTypeName: string; + + @Column({ + nullable: true, + comment: + "ระดับของประเภทตำแหน่ง ไว้ใช้ระบุว่าประเภทตำแหน่งนี้อยู่ระดับสูงหรือต่ำกว่ากัน โดย 1 = ต่ำกว่า , มากกว่า 1 = สูงกว่า ทั่วไป = 1 วิชาการ = 2 อำนวยการ = 3 บริหาร = 4", + default: null, + }) + posTypeRank: number; + + @OneToMany(() => PosLevel, (posLevel: PosLevel) => posLevel.posType) + posLevels: PosLevel[]; + + @OneToMany(() => ActualGoal, (actualGoal: ActualGoal) => actualGoal.posTypeActual) + actualGoals: ActualGoal[]; + + @OneToMany(() => PlannedGoal, (plannedGoal: PlannedGoal) => plannedGoal.posTypePlanned) + plannedGoals: PlannedGoal[]; + + @OneToMany(() => DevelopmentHistory, (developmentHistory) => developmentHistory.posType) + developmentHistorys: DevelopmentHistory[]; +} + +export class CreatePosType { + @Column() + posTypeName: string; + + @Column() + posTypeRank: number; +} + +export type UpdatePosType = Partial; diff --git a/src/entities/Province.ts b/src/entities/Province.ts new file mode 100644 index 0000000..0ab83ff --- /dev/null +++ b/src/entities/Province.ts @@ -0,0 +1,27 @@ +import { Entity, Column, OneToMany } from "typeorm"; +import { EntityBase } from "./base/Base"; +import { Development } from "./Development"; + +@Entity("province") +export class Province extends EntityBase { + @Column({ + nullable: true, + comment: "จังหวัด", + length: 255, + default: null, + }) + name: string; + + @OneToMany(() => Development, (development: Development) => development.province) + developments: Development[]; + + @OneToMany(() => Development, (development: Development) => development.provinceActual) + developmentActuals: Development[]; +} + +export class CreateProvince { + @Column() + name: string; +} + +export type UpdateProvince = Partial; diff --git a/src/migration/1712060108057-add_table_development.ts b/src/migration/1712060108057-add_table_development.ts new file mode 100644 index 0000000..cdca497 --- /dev/null +++ b/src/migration/1712060108057-add_table_development.ts @@ -0,0 +1,128 @@ +import { MigrationInterface, QueryRunner } from "typeorm"; + +export class AddTableDevelopment1712060108057 implements MigrationInterface { + name = 'AddTableDevelopment1712060108057' + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(`CREATE TABLE \`actualPeople\` (\`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', \`groupTarget\` varchar(255) NULL COMMENT 'ผู้เกี่ยวข้อง', \`amount\` int NULL COMMENT 'จำนวน(คน)', \`developmentActualPeopleId\` varchar(255) NULL COMMENT 'id โครงการ', PRIMARY KEY (\`id\`)) ENGINE=InnoDB`); + await queryRunner.query(`CREATE TABLE \`plannedPeople\` (\`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', \`groupTarget\` varchar(255) NULL COMMENT 'ผู้เกี่ยวข้อง', \`amount\` int NULL COMMENT 'จำนวน(คน)', \`developmentPlannedPeopleId\` varchar(255) NULL COMMENT 'id โครงการ', PRIMARY KEY (\`id\`)) ENGINE=InnoDB`); + await queryRunner.query(`CREATE TABLE \`plannedGoal\` (\`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', \`groupTarget\` varchar(255) NULL COMMENT 'กลุ่มเป้าหมาย', \`groupTargetSub\` varchar(255) NULL COMMENT 'กลุ่มเป้าหมายย่อย', \`position\` varchar(255) NULL COMMENT 'ตำแหน่ง', \`posTypePlannedId\` varchar(255) NULL COMMENT 'ประเภทตำแหน่ง', \`posLevelPlannedId\` varchar(255) NULL COMMENT 'ระดับตำแหน่ง', \`type\` varchar(255) NULL COMMENT 'ประเภท(กลุ่มอาชีพ คุณสมบัติ)', \`amount\` int NULL COMMENT 'จำนวน(คน)', \`developmentPlannedGoalId\` varchar(255) NULL COMMENT 'id โครงการ', PRIMARY KEY (\`id\`)) ENGINE=InnoDB`); + await queryRunner.query(`CREATE TABLE \`posType\` (\`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', \`posTypeName\` varchar(255) NULL COMMENT 'ชื่อประเภทตำแหน่ง (ทั่วไป วิชาการ อำนวยการ บริหาร)', \`posTypeRank\` int NULL COMMENT 'ระดับของประเภทตำแหน่ง ไว้ใช้ระบุว่าประเภทตำแหน่งนี้อยู่ระดับสูงหรือต่ำกว่ากัน โดย 1 = ต่ำกว่า , มากกว่า 1 = สูงกว่า ทั่วไป = 1 วิชาการ = 2 อำนวยการ = 3 บริหาร = 4', PRIMARY KEY (\`id\`)) ENGINE=InnoDB`); + await queryRunner.query(`CREATE TABLE \`posLevel\` (\`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', \`posLevelName\` varchar(255) NULL COMMENT 'ชื่อระดับตำแหน่ง', \`posLevelRank\` int NULL COMMENT 'ระดับของระดับตำแหน่ง', \`posLevelAuthority\` enum ('HEAD', 'DEPUTY', 'GOVERNOR') NULL COMMENT 'ผู้มีอำนาจสั่งบรรจุของระดับนี้ head = หัวหน้าหน่วยงาน , deputy = ปลัด , governor = ผู้ว่าฯ', \`posTypeId\` varchar(40) NOT NULL COMMENT 'เป็นระดับของประเภทตำแหน่งใด', PRIMARY KEY (\`id\`)) ENGINE=InnoDB`); + await queryRunner.query(`CREATE TABLE \`actualGoal\` (\`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', \`groupTarget\` varchar(255) NULL COMMENT 'กลุ่มเป้าหมาย', \`groupTargetSub\` varchar(255) NULL COMMENT 'กลุ่มเป้าหมายย่อย', \`position\` varchar(255) NULL COMMENT 'ตำแหน่ง', \`posTypeActualId\` varchar(255) NULL COMMENT 'ประเภทตำแหน่ง', \`posLevelActualId\` varchar(255) NULL COMMENT 'ระดับตำแหน่ง', \`type\` varchar(255) NULL COMMENT 'ประเภท(กลุ่มอาชีพ คุณสมบัติ)', \`amount\` int NULL COMMENT 'จำนวน(คน)', \`developmentActualGoalId\` varchar(255) NULL COMMENT 'id โครงการ', PRIMARY KEY (\`id\`)) ENGINE=InnoDB`); + await queryRunner.query(`CREATE TABLE \`province\` (\`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', \`name\` varchar(255) NULL COMMENT 'จังหวัด', PRIMARY KEY (\`id\`)) ENGINE=InnoDB`); + await queryRunner.query(`CREATE TABLE \`employeePosType\` (\`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', \`posTypeName\` varchar(255) NULL COMMENT 'ชื่อกลุ่มงาน', \`posTypeRank\` int NOT NULL COMMENT 'ระดับของกลุ่มงาน', \`posTypeShortName\` varchar(255) NULL COMMENT 'ชื่อย่อกลุ่มงาน', PRIMARY KEY (\`id\`)) ENGINE=InnoDB`); + await queryRunner.query(`CREATE TABLE \`employeePosLevel\` (\`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', \`posLevelName\` int NOT NULL COMMENT 'ชื่อระดับชั้นงาน', \`posLevelRank\` int NOT NULL COMMENT 'ระดับของระดับชั้นงาน', \`posLevelAuthority\` enum ('HEAD', 'DEPUTY', 'GOVERNOR') NULL COMMENT 'ผู้มีอำนาจสั่งบรรจุของระดับนี้ head = หัวหน้าหน่วยงาน , deputy = ปลัด , governor = ผู้ว่าฯ', \`posTypeId\` varchar(40) NOT NULL COMMENT 'คีย์นอก(FK)ของตาราง employeePosType', PRIMARY KEY (\`id\`)) ENGINE=InnoDB`); + await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`name\``); + await queryRunner.query(`ALTER TABLE \`development\` ADD \`projectName\` varchar(255) NOT NULL COMMENT 'ชื่อโครงการ/กิจกรรม/หลักสูตร'`); + await queryRunner.query(`ALTER TABLE \`development\` ADD \`reason\` varchar(255) NULL COMMENT 'หลักการและเหตุผล'`); + await queryRunner.query(`ALTER TABLE \`development\` ADD \`objective\` varchar(255) NULL COMMENT 'วัตถุประสงค์'`); + await queryRunner.query(`ALTER TABLE \`development\` ADD \`metricType\` varchar(255) NULL COMMENT 'ประเภทตัวชี้วัด'`); + await queryRunner.query(`ALTER TABLE \`development\` ADD \`indicators\` varchar(255) NULL COMMENT 'ตัวชี้วัด'`); + await queryRunner.query(`ALTER TABLE \`development\` ADD \`target\` varchar(255) NULL COMMENT 'เป้าหมาย'`); + await queryRunner.query(`ALTER TABLE \`development\` ADD \`calculation\` varchar(255) NULL COMMENT 'วิธีการคำนวณ/เครื่องมือ'`); + await queryRunner.query(`ALTER TABLE \`development\` ADD \`measuRement\` varchar(255) NULL COMMENT 'ระยะเวลาวัดผล'`); + await queryRunner.query(`ALTER TABLE \`development\` ADD \`results\` varchar(255) NULL COMMENT 'ผลการดำเนิน'`); + await queryRunner.query(`ALTER TABLE \`development\` ADD \`obstacles\` varchar(255) NULL COMMENT 'ปัญหาอุปสรรค'`); + await queryRunner.query(`ALTER TABLE \`development\` ADD \`suggestions\` varchar(255) NULL COMMENT 'ข้อเสนอเเนะ'`); + await queryRunner.query(`ALTER TABLE \`development\` ADD \`project\` varchar(255) NULL COMMENT 'ประเภทโครงการ'`); + await queryRunner.query(`ALTER TABLE \`development\` ADD \`isPassAllocate\` tinyint NOT NULL COMMENT 'ผ่านการพิจาณา ได้รับการจัดสรรงบประมาณตามข้อบัญญัติ' DEFAULT 0`); + await queryRunner.query(`ALTER TABLE \`development\` ADD \`isPassNoAllocate\` tinyint NOT NULL COMMENT 'ผ่านการพิจารณา ไม่ได้รับการจัดสรรงบประมาณตามข้อบัญญัติ แต่ได้รับการจัดสรรเงินนอกงบประมาณ' DEFAULT 0`); + await queryRunner.query(`ALTER TABLE \`development\` ADD \`isNoPass\` tinyint NOT NULL COMMENT 'ไม่ผ่านการพิจารณา แต่ได้รับการจัดสรรเงินนอกงบประมาณ' DEFAULT 0`); + await queryRunner.query(`ALTER TABLE \`development\` ADD \`isBudget\` tinyint NOT NULL COMMENT 'แต่ได้รับการจัดสรรงบประมาณตามข้อบัญญัติ' DEFAULT 0`); + await queryRunner.query(`ALTER TABLE \`development\` ADD \`isOutBudget\` tinyint NOT NULL COMMENT 'แต่ได้รับการจัดสรรเงินนอกงบประมาณ' DEFAULT 0`); + await queryRunner.query(`ALTER TABLE \`development\` ADD \`dateStart\` datetime NULL COMMENT 'วันที่เริ่มต้น'`); + await queryRunner.query(`ALTER TABLE \`development\` ADD \`dateEnd\` datetime NULL COMMENT 'วันที่สิ้นสุด'`); + await queryRunner.query(`ALTER TABLE \`development\` ADD \`totalDate\` int NULL COMMENT 'รวมระยะเวลา (วัน)'`); + await queryRunner.query(`ALTER TABLE \`development\` ADD \`address\` varchar(255) NULL COMMENT 'ที่อยู่'`); + await queryRunner.query(`ALTER TABLE \`development\` ADD \`provinceId\` varchar(255) NULL COMMENT 'จังหวัด'`); + await queryRunner.query(`ALTER TABLE \`development\` ADD \`budget\` varchar(255) NULL COMMENT 'ประเภทงบประมาณ'`); + await queryRunner.query(`ALTER TABLE \`development\` ADD \`accept\` double NULL COMMENT 'จํานวนงบประมาณที่ขอรับการจัดสรรฯ' DEFAULT '0'`); + await queryRunner.query(`ALTER TABLE \`development\` ADD \`receive\` double NULL COMMENT 'จํานวนงบประมาณที่ได้รับการจัดสรรฯ' DEFAULT '0'`); + await queryRunner.query(`ALTER TABLE \`development\` ADD \`approved\` double NULL COMMENT 'จํานวนงบประมาณที่ได้รับอนุมัติ' DEFAULT '0'`); + await queryRunner.query(`ALTER TABLE \`development\` ADD \`budgetPay\` double NULL COMMENT 'จํานวนงบประมาณที่จ่ายจริง' DEFAULT '0'`); + await queryRunner.query(`ALTER TABLE \`development\` ADD \`issues\` varchar(255) NULL COMMENT 'ประเด็นความเสี่ยง'`); + await queryRunner.query(`ALTER TABLE \`development\` ADD \`chance\` varchar(255) NULL COMMENT 'โอกาศที่จะเกิด'`); + await queryRunner.query(`ALTER TABLE \`development\` ADD \`effects\` varchar(255) NULL COMMENT 'ผลกระทบจากการเกิด'`); + await queryRunner.query(`ALTER TABLE \`development\` ADD \`riskLevel\` varchar(255) NULL COMMENT 'ระดับความเสี่ยง'`); + await queryRunner.query(`ALTER TABLE \`development\` ADD \`riskManagement\` varchar(255) NULL COMMENT 'เเนวทางการบริหารความเสี่ยง'`); + await queryRunner.query(`ALTER TABLE \`development\` ADD \`expect\` varchar(255) NULL COMMENT 'ประโยชน์ที่คาดว่าจะได้รับ'`); + await queryRunner.query(`ALTER TABLE \`development\` ADD \`topicAcademic\` varchar(255) NULL COMMENT 'หัวข้อ/ประเด็นการฝึกอบรม ศึกษาดูงาน'`); + await queryRunner.query(`ALTER TABLE \`development\` ADD \`addressAcademic\` varchar(255) NULL COMMENT 'สถานที่ฝึกอบรม ศึกษาดูงาน'`); + await queryRunner.query(`ALTER TABLE \`development\` ADD \`provinceActualId\` varchar(255) NULL COMMENT 'จังหวัด(ข้อมูลวิชาการ)'`); + await queryRunner.query(`ALTER TABLE \`actualPeople\` ADD CONSTRAINT \`FK_f829036b60eabcca870d5e9242e\` FOREIGN KEY (\`developmentActualPeopleId\`) REFERENCES \`development\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`); + await queryRunner.query(`ALTER TABLE \`plannedPeople\` ADD CONSTRAINT \`FK_b508fdcde0693754799a9a75603\` FOREIGN KEY (\`developmentPlannedPeopleId\`) REFERENCES \`development\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`); + await queryRunner.query(`ALTER TABLE \`plannedGoal\` ADD CONSTRAINT \`FK_308d02f616b878261a3890b4d40\` FOREIGN KEY (\`posTypePlannedId\`) REFERENCES \`posType\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`); + await queryRunner.query(`ALTER TABLE \`plannedGoal\` ADD CONSTRAINT \`FK_0e6aba627301f35aa3570b44bf5\` FOREIGN KEY (\`posLevelPlannedId\`) REFERENCES \`posLevel\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`); + await queryRunner.query(`ALTER TABLE \`plannedGoal\` ADD CONSTRAINT \`FK_14f48058eff5d24c8be711ae92b\` FOREIGN KEY (\`developmentPlannedGoalId\`) REFERENCES \`development\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`); + await queryRunner.query(`ALTER TABLE \`posLevel\` ADD CONSTRAINT \`FK_66caa3d974b67a8a8b343d029b2\` FOREIGN KEY (\`posTypeId\`) REFERENCES \`posType\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`); + await queryRunner.query(`ALTER TABLE \`actualGoal\` ADD CONSTRAINT \`FK_e08e337e5ddeb4942c72393ff58\` FOREIGN KEY (\`posTypeActualId\`) REFERENCES \`posType\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`); + await queryRunner.query(`ALTER TABLE \`actualGoal\` ADD CONSTRAINT \`FK_a9a864dd06eaa25edba8be8f24c\` FOREIGN KEY (\`posLevelActualId\`) REFERENCES \`posLevel\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`); + await queryRunner.query(`ALTER TABLE \`actualGoal\` ADD CONSTRAINT \`FK_5fc0017c134049b436d20ee81b4\` FOREIGN KEY (\`developmentActualGoalId\`) REFERENCES \`development\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`); + await queryRunner.query(`ALTER TABLE \`development\` ADD CONSTRAINT \`FK_c7552b4624cc7347144be758e6e\` FOREIGN KEY (\`provinceId\`) REFERENCES \`province\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`); + await queryRunner.query(`ALTER TABLE \`development\` ADD CONSTRAINT \`FK_bdafbb824b88c3bdb73adf7f220\` FOREIGN KEY (\`provinceActualId\`) REFERENCES \`province\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`); + await queryRunner.query(`ALTER TABLE \`employeePosLevel\` ADD CONSTRAINT \`FK_7fb9ab868f3f46b44f460c984f1\` FOREIGN KEY (\`posTypeId\`) REFERENCES \`employeePosType\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`); + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`employeePosLevel\` DROP FOREIGN KEY \`FK_7fb9ab868f3f46b44f460c984f1\``); + await queryRunner.query(`ALTER TABLE \`development\` DROP FOREIGN KEY \`FK_bdafbb824b88c3bdb73adf7f220\``); + await queryRunner.query(`ALTER TABLE \`development\` DROP FOREIGN KEY \`FK_c7552b4624cc7347144be758e6e\``); + await queryRunner.query(`ALTER TABLE \`actualGoal\` DROP FOREIGN KEY \`FK_5fc0017c134049b436d20ee81b4\``); + await queryRunner.query(`ALTER TABLE \`actualGoal\` DROP FOREIGN KEY \`FK_a9a864dd06eaa25edba8be8f24c\``); + await queryRunner.query(`ALTER TABLE \`actualGoal\` DROP FOREIGN KEY \`FK_e08e337e5ddeb4942c72393ff58\``); + await queryRunner.query(`ALTER TABLE \`posLevel\` DROP FOREIGN KEY \`FK_66caa3d974b67a8a8b343d029b2\``); + await queryRunner.query(`ALTER TABLE \`plannedGoal\` DROP FOREIGN KEY \`FK_14f48058eff5d24c8be711ae92b\``); + await queryRunner.query(`ALTER TABLE \`plannedGoal\` DROP FOREIGN KEY \`FK_0e6aba627301f35aa3570b44bf5\``); + await queryRunner.query(`ALTER TABLE \`plannedGoal\` DROP FOREIGN KEY \`FK_308d02f616b878261a3890b4d40\``); + await queryRunner.query(`ALTER TABLE \`plannedPeople\` DROP FOREIGN KEY \`FK_b508fdcde0693754799a9a75603\``); + await queryRunner.query(`ALTER TABLE \`actualPeople\` DROP FOREIGN KEY \`FK_f829036b60eabcca870d5e9242e\``); + await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`provinceActualId\``); + await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`addressAcademic\``); + await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`topicAcademic\``); + await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`expect\``); + await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`riskManagement\``); + await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`riskLevel\``); + await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`effects\``); + await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`chance\``); + await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`issues\``); + await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`budgetPay\``); + await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`approved\``); + await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`receive\``); + await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`accept\``); + await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`budget\``); + await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`provinceId\``); + await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`address\``); + await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`totalDate\``); + await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`dateEnd\``); + await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`dateStart\``); + await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`isOutBudget\``); + await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`isBudget\``); + await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`isNoPass\``); + await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`isPassNoAllocate\``); + await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`isPassAllocate\``); + await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`project\``); + await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`suggestions\``); + await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`obstacles\``); + await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`results\``); + await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`measuRement\``); + await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`calculation\``); + await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`target\``); + await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`indicators\``); + await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`metricType\``); + await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`objective\``); + await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`reason\``); + await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`projectName\``); + await queryRunner.query(`ALTER TABLE \`development\` ADD \`name\` varchar(255) NOT NULL COMMENT 'ชื่อโครงการ/กิจกรรม/หลักสูตร'`); + await queryRunner.query(`DROP TABLE \`employeePosLevel\``); + await queryRunner.query(`DROP TABLE \`employeePosType\``); + await queryRunner.query(`DROP TABLE \`province\``); + await queryRunner.query(`DROP TABLE \`actualGoal\``); + await queryRunner.query(`DROP TABLE \`posLevel\``); + await queryRunner.query(`DROP TABLE \`posType\``); + await queryRunner.query(`DROP TABLE \`plannedGoal\``); + await queryRunner.query(`DROP TABLE \`plannedPeople\``); + await queryRunner.query(`DROP TABLE \`actualPeople\``); + } + +} diff --git a/src/migration/1712076616416-add_table_developmentHistory.ts b/src/migration/1712076616416-add_table_developmentHistory.ts new file mode 100644 index 0000000..1a5e76e --- /dev/null +++ b/src/migration/1712076616416-add_table_developmentHistory.ts @@ -0,0 +1,22 @@ +import { MigrationInterface, QueryRunner } from "typeorm"; + +export class AddTableDevelopmentHistory1712076616416 implements MigrationInterface { + name = 'AddTableDevelopmentHistory1712076616416' + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(`CREATE TABLE \`developmentHistory\` (\`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', \`rank\` varchar(40) NULL COMMENT 'ยศ', \`prefix\` varchar(40) NULL COMMENT 'คำนำหน้าชื่อ', \`firstName\` varchar(255) NULL COMMENT 'ชื่อ', \`lastName\` varchar(255) NULL COMMENT 'นามสกุล', \`citizenId\` varchar(13) NULL COMMENT 'เลขประจำตัวประชาชน', \`position\` varchar(255) NULL COMMENT 'ตำแหน่ง', \`posLevelId\` varchar(40) NULL COMMENT 'ไอดีระดับตำแหน่ง', \`posTypeId\` varchar(40) NULL COMMENT 'ไอดีประเภทตำแหน่ง', \`developmentId\` varchar(255) NULL COMMENT 'โครงการ/หลักสูตรการฝึกอบรม', PRIMARY KEY (\`id\`)) ENGINE=InnoDB`); + await queryRunner.query(`ALTER TABLE \`development\` CHANGE \`chance\` \`chance\` varchar(255) NULL COMMENT 'โอกาสที่จะเกิด'`); + await queryRunner.query(`ALTER TABLE \`developmentHistory\` ADD CONSTRAINT \`FK_d786f60dffba2d9a24c3bd3921b\` FOREIGN KEY (\`posLevelId\`) REFERENCES \`posLevel\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`); + await queryRunner.query(`ALTER TABLE \`developmentHistory\` ADD CONSTRAINT \`FK_d4e7a95f885bd0bd26c9ec1dba2\` FOREIGN KEY (\`posTypeId\`) REFERENCES \`posType\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`); + await queryRunner.query(`ALTER TABLE \`developmentHistory\` ADD CONSTRAINT \`FK_405574443eb92d4cdd8a88a22e6\` FOREIGN KEY (\`developmentId\`) REFERENCES \`development\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`); + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`developmentHistory\` DROP FOREIGN KEY \`FK_405574443eb92d4cdd8a88a22e6\``); + await queryRunner.query(`ALTER TABLE \`developmentHistory\` DROP FOREIGN KEY \`FK_d4e7a95f885bd0bd26c9ec1dba2\``); + await queryRunner.query(`ALTER TABLE \`developmentHistory\` DROP FOREIGN KEY \`FK_d786f60dffba2d9a24c3bd3921b\``); + await queryRunner.query(`ALTER TABLE \`development\` CHANGE \`chance\` \`chance\` varchar(255) NULL COMMENT 'โอกาศที่จะเกิด'`); + await queryRunner.query(`DROP TABLE \`developmentHistory\``); + } + +} diff --git a/src/migration/1712078526676-add_table_developmentHistory1.ts b/src/migration/1712078526676-add_table_developmentHistory1.ts new file mode 100644 index 0000000..0f832c9 --- /dev/null +++ b/src/migration/1712078526676-add_table_developmentHistory1.ts @@ -0,0 +1,16 @@ +import { MigrationInterface, QueryRunner } from "typeorm"; + +export class AddTableDevelopmentHistory11712078526676 implements MigrationInterface { + name = 'AddTableDevelopmentHistory11712078526676' + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`developmentHistory\` ADD \`order\` varchar(255) NULL COMMENT 'เลขที่คำสั่ง/เลขที่หนังสืออนุมัติ'`); + await queryRunner.query(`ALTER TABLE \`developmentHistory\` ADD \`dateOrder\` varchar(255) NULL COMMENT 'คำสั่งลงวันที่/หนังสืออนุมัติลงวันที่'`); + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`developmentHistory\` DROP COLUMN \`dateOrder\``); + await queryRunner.query(`ALTER TABLE \`developmentHistory\` DROP COLUMN \`order\``); + } + +} diff --git a/tsoa.json b/tsoa.json index ff48c69..c0d60df 100644 --- a/tsoa.json +++ b/tsoa.json @@ -31,6 +31,9 @@ }, { "name": "Development", "description": "ชื่อโครงการ/กิจกรรม/หลักสูตร" + }, + { + "name": "DevelopmentHistory", "description": "ประวัติการฝึกอบรม/ดูงาน" } ] }, From a5ee4afd0633c95326d98ed50d9d4d280f12d03d Mon Sep 17 00:00:00 2001 From: Kittapath Date: Wed, 3 Apr 2024 11:28:08 +0700 Subject: [PATCH 003/250] =?UTF-8?q?=E0=B8=9B=E0=B8=A3=E0=B8=B0=E0=B8=A7?= =?UTF-8?q?=E0=B8=B1=E0=B8=95=E0=B8=B4=E0=B9=82=E0=B8=84=E0=B8=A3=E0=B8=87?= =?UTF-8?q?=E0=B8=81=E0=B8=B2=E0=B8=A3=E0=B8=A5=E0=B8=B9=E0=B8=81=E0=B8=88?= =?UTF-8?q?=E0=B9=89=E0=B9=88=E0=B8=B2=E0=B8=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DevelopmentHistoryController.ts | 33 ++++++++++++------- src/entities/DevelopmentHistory.ts | 8 +++++ 2 files changed, 30 insertions(+), 11 deletions(-) diff --git a/src/controllers/DevelopmentHistoryController.ts b/src/controllers/DevelopmentHistoryController.ts index 283ac8d..564e9e0 100644 --- a/src/controllers/DevelopmentHistoryController.ts +++ b/src/controllers/DevelopmentHistoryController.ts @@ -37,15 +37,18 @@ export class DevelopmentHistoryController extends Controller { * @summary DEV_006 - เพิ่มประวัติการฝึกอบรม/ดูงาน#6 * */ - @Post() + @Post("{type}") async CreateDevelopmentHistory( + @Path() type: string, @Body() requestBody: CreateDevelopmentHistory, @Request() request: { user: Record }, ) { + const _type = type.trim().toUpperCase(); const chk_name = await this.developmentHistoryRepository.find({ where: { citizenId: requestBody.citizenId, developmentId: requestBody.developmentId, + type: _type, }, }); if (chk_name.length > 0) { @@ -60,7 +63,7 @@ export class DevelopmentHistoryController extends Controller { } const development = Object.assign(new DevelopmentHistory(), requestBody); - + development.type = _type; development.createdUserId = request.user.sub; development.createdFullName = request.user.name; development.lastUpdateUserId = request.user.sub; @@ -76,14 +79,16 @@ export class DevelopmentHistoryController extends Controller { * * @param {string} id Id โครงการ */ - @Put("{id}") + @Put("{type}/{id}") async UpdateDevelopmentHistory( + @Path() type: string, @Path() id: string, @Body() requestBody: UpdateDevelopmentHistory, @Request() request: { user: Record }, ) { + const _type = type.trim().toUpperCase(); const development = await this.developmentHistoryRepository.findOne({ - where: { id }, + where: { id: id, type: _type }, }); if (!development) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลประวัติการฝึกอบรม/ดูงานนี้"); @@ -92,6 +97,7 @@ export class DevelopmentHistoryController extends Controller { where: { citizenId: requestBody.citizenId, developmentId: requestBody.developmentId, + type: _type, id: Not(id), }, }); @@ -105,6 +111,7 @@ export class DevelopmentHistoryController extends Controller { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงการ/หลักสูตรการฝึกอบรม"); } Object.assign(development, requestBody); + development.type = _type; development.lastUpdateUserId = request.user.sub; development.lastUpdateFullName = request.user.name; await this.developmentHistoryRepository.save(development); @@ -118,10 +125,11 @@ export class DevelopmentHistoryController extends Controller { * * @param {string} id Id โครงการ */ - @Delete("{id}") - async DeleteDevelopmentHistory(@Path() id: string) { + @Delete("{type}/{id}") + async DeleteDevelopmentHistory(@Path() type: string, @Path() id: string) { + const _type = type.trim().toUpperCase(); const development = await this.developmentHistoryRepository.findOne({ - where: { id }, + where: { id: id, type: _type }, }); if (!development) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลประวัติการฝึกอบรม/ดูงานนี้"); @@ -137,13 +145,15 @@ export class DevelopmentHistoryController extends Controller { * @summary DEV_009 - รายการประวัติการฝึกอบรม/ดูงาน #9 * */ - @Get() + @Get("{type}") async GetDevelopmentHistoryLists( + @Path() type: string, @Query("page") page: number = 1, @Query("pageSize") pageSize: number = 10, @Query("keyword") keyword?: string, @Query("year") year?: number, ) { + const _type = type.trim().toUpperCase(); const [development, total] = await AppDataSource.getRepository(DevelopmentHistory) .createQueryBuilder("developmentHistory") // .andWhere(year == null ? "developmentHistory.year LIKE :year" : "1=1", { year: `${year}` }) @@ -165,10 +175,11 @@ export class DevelopmentHistoryController extends Controller { * * @param {string} id Id โครงการ */ - @Get("{id}") - async GetDevelopemtHistoryById(@Path() id: string) { + @Get("{type}/{id}") + async GetDevelopemtHistoryById(@Path() type: string, @Path() id: string) { + const _type = type.trim().toUpperCase(); const getDevelopment = await this.developmentHistoryRepository.findOne({ - where: { id: id }, + where: { id: id, type: _type }, }); if (!getDevelopment) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลประวัติการฝึกอบรม/ดูงานนี้"); diff --git a/src/entities/DevelopmentHistory.ts b/src/entities/DevelopmentHistory.ts index ca34e4f..306e645 100644 --- a/src/entities/DevelopmentHistory.ts +++ b/src/entities/DevelopmentHistory.ts @@ -6,6 +6,14 @@ import { Development } from "./Development"; @Entity("developmentHistory") export class DevelopmentHistory extends EntityBase { + @Column({ + nullable: true, + comment: "ประเภทราชการ", + length: 40, + default: null, + }) + type: string; + @Column({ nullable: true, comment: "ยศ", From e9732a1e52bdd6b5f928c98146524af8923d23b0 Mon Sep 17 00:00:00 2001 From: Kittapath Date: Wed, 3 Apr 2024 11:48:06 +0700 Subject: [PATCH 004/250] =?UTF-8?q?=E0=B8=9B=E0=B8=A3=E0=B8=B0=E0=B8=A7?= =?UTF-8?q?=E0=B8=B1=E0=B8=95=E0=B8=B4=E0=B8=A3=E0=B8=B2=E0=B8=8A=E0=B8=81?= =?UTF-8?q?=E0=B8=B2=E0=B8=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DevelopmentHistoryController.ts | 43 +++++++++---------- ...119650901-add_table_developmentHistory2.ts | 14 ++++++ 2 files changed, 34 insertions(+), 23 deletions(-) create mode 100644 src/migration/1712119650901-add_table_developmentHistory2.ts diff --git a/src/controllers/DevelopmentHistoryController.ts b/src/controllers/DevelopmentHistoryController.ts index 564e9e0..c9ca194 100644 --- a/src/controllers/DevelopmentHistoryController.ts +++ b/src/controllers/DevelopmentHistoryController.ts @@ -24,7 +24,7 @@ import { UpdateDevelopmentHistory, } from "../entities/DevelopmentHistory"; -@Route("api/v1/development/history") +@Route("api/v1/development/history/officer") @Tags("DevelopmentHistory") @Security("bearerAuth") export class DevelopmentHistoryController extends Controller { @@ -37,18 +37,17 @@ export class DevelopmentHistoryController extends Controller { * @summary DEV_006 - เพิ่มประวัติการฝึกอบรม/ดูงาน#6 * */ - @Post("{type}") + @Post() async CreateDevelopmentHistory( - @Path() type: string, @Body() requestBody: CreateDevelopmentHistory, @Request() request: { user: Record }, ) { - const _type = type.trim().toUpperCase(); + const type = "OFFICER"; const chk_name = await this.developmentHistoryRepository.find({ where: { citizenId: requestBody.citizenId, developmentId: requestBody.developmentId, - type: _type, + type: type, }, }); if (chk_name.length > 0) { @@ -63,7 +62,7 @@ export class DevelopmentHistoryController extends Controller { } const development = Object.assign(new DevelopmentHistory(), requestBody); - development.type = _type; + development.type = type; development.createdUserId = request.user.sub; development.createdFullName = request.user.name; development.lastUpdateUserId = request.user.sub; @@ -79,16 +78,15 @@ export class DevelopmentHistoryController extends Controller { * * @param {string} id Id โครงการ */ - @Put("{type}/{id}") + @Put("{id}") async UpdateDevelopmentHistory( - @Path() type: string, @Path() id: string, @Body() requestBody: UpdateDevelopmentHistory, @Request() request: { user: Record }, ) { - const _type = type.trim().toUpperCase(); + const type = "OFFICER"; const development = await this.developmentHistoryRepository.findOne({ - where: { id: id, type: _type }, + where: { id: id, type: type }, }); if (!development) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลประวัติการฝึกอบรม/ดูงานนี้"); @@ -97,7 +95,7 @@ export class DevelopmentHistoryController extends Controller { where: { citizenId: requestBody.citizenId, developmentId: requestBody.developmentId, - type: _type, + type: type, id: Not(id), }, }); @@ -111,7 +109,7 @@ export class DevelopmentHistoryController extends Controller { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงการ/หลักสูตรการฝึกอบรม"); } Object.assign(development, requestBody); - development.type = _type; + development.type = type; development.lastUpdateUserId = request.user.sub; development.lastUpdateFullName = request.user.name; await this.developmentHistoryRepository.save(development); @@ -125,11 +123,11 @@ export class DevelopmentHistoryController extends Controller { * * @param {string} id Id โครงการ */ - @Delete("{type}/{id}") - async DeleteDevelopmentHistory(@Path() type: string, @Path() id: string) { - const _type = type.trim().toUpperCase(); + @Delete("{id}") + async DeleteDevelopmentHistory(@Path() id: string) { + const type = "OFFICER"; const development = await this.developmentHistoryRepository.findOne({ - where: { id: id, type: _type }, + where: { id: id, type: type }, }); if (!development) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลประวัติการฝึกอบรม/ดูงานนี้"); @@ -145,15 +143,14 @@ export class DevelopmentHistoryController extends Controller { * @summary DEV_009 - รายการประวัติการฝึกอบรม/ดูงาน #9 * */ - @Get("{type}") + @Get() async GetDevelopmentHistoryLists( - @Path() type: string, @Query("page") page: number = 1, @Query("pageSize") pageSize: number = 10, @Query("keyword") keyword?: string, @Query("year") year?: number, ) { - const _type = type.trim().toUpperCase(); + const type = "OFFICER"; const [development, total] = await AppDataSource.getRepository(DevelopmentHistory) .createQueryBuilder("developmentHistory") // .andWhere(year == null ? "developmentHistory.year LIKE :year" : "1=1", { year: `${year}` }) @@ -175,11 +172,11 @@ export class DevelopmentHistoryController extends Controller { * * @param {string} id Id โครงการ */ - @Get("{type}/{id}") - async GetDevelopemtHistoryById(@Path() type: string, @Path() id: string) { - const _type = type.trim().toUpperCase(); + @Get("{id}") + async GetDevelopemtHistoryById(@Path() id: string) { + const type = "OFFICER"; const getDevelopment = await this.developmentHistoryRepository.findOne({ - where: { id: id, type: _type }, + where: { id: id, type: type }, }); if (!getDevelopment) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลประวัติการฝึกอบรม/ดูงานนี้"); diff --git a/src/migration/1712119650901-add_table_developmentHistory2.ts b/src/migration/1712119650901-add_table_developmentHistory2.ts new file mode 100644 index 0000000..c7dc6d5 --- /dev/null +++ b/src/migration/1712119650901-add_table_developmentHistory2.ts @@ -0,0 +1,14 @@ +import { MigrationInterface, QueryRunner } from "typeorm"; + +export class AddTableDevelopmentHistory21712119650901 implements MigrationInterface { + name = 'AddTableDevelopmentHistory21712119650901' + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`developmentHistory\` ADD \`type\` varchar(40) NULL COMMENT 'ประเภทราชการ'`); + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`developmentHistory\` DROP COLUMN \`type\``); + } + +} From 44022b311f5bc08dc4c8015f44cad53cb864996e Mon Sep 17 00:00:00 2001 From: Kittapath Date: Wed, 3 Apr 2024 12:07:57 +0700 Subject: [PATCH 005/250] =?UTF-8?q?=E0=B9=80=E0=B8=9E=E0=B8=B4=E0=B9=88?= =?UTF-8?q?=E0=B8=A1=E0=B8=9B=E0=B8=A3=E0=B8=B0=E0=B8=A7=E0=B8=B1=E0=B8=95?= =?UTF-8?q?=E0=B8=B4=E0=B8=A5=E0=B8=B9=E0=B8=81=E0=B8=88=E0=B9=89=E0=B8=B2?= =?UTF-8?q?=E0=B8=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DevelopmentEmployeeHistoryController.ts | 226 ++++++++++++++++++ .../DevelopmentHistoryController.ts | 38 ++- src/entities/DevelopmentHistory.ts | 24 ++ src/entities/EmployeePosLevel.ts | 6 +- src/entities/EmployeePosType.ts | 4 + ...pdate_table_developmentHistory_add_type.ts | 20 ++ 6 files changed, 316 insertions(+), 2 deletions(-) create mode 100644 src/controllers/DevelopmentEmployeeHistoryController.ts create mode 100644 src/migration/1712120794817-update_table_developmentHistory_add_type.ts diff --git a/src/controllers/DevelopmentEmployeeHistoryController.ts b/src/controllers/DevelopmentEmployeeHistoryController.ts new file mode 100644 index 0000000..4fcdb41 --- /dev/null +++ b/src/controllers/DevelopmentEmployeeHistoryController.ts @@ -0,0 +1,226 @@ +import { + Controller, + Get, + Post, + Put, + Delete, + Route, + Security, + Tags, + Body, + Path, + Request, + Query, +} from "tsoa"; +import { AppDataSource } from "../database/data-source"; +import { Not } from "typeorm"; +import HttpSuccess from "../interfaces/http-success"; +import HttpError from "../interfaces/http-error"; +import HttpStatusCode from "../interfaces/http-status"; +import { Development } from "../entities/Development"; +import { + CreateDevelopmentHistory, + DevelopmentHistory, + UpdateDevelopmentHistory, +} from "../entities/DevelopmentHistory"; +import { EmployeePosType } from "../entities/EmployeePosType"; +import { EmployeePosLevel } from "../entities/EmployeePosLevel"; + +@Route("api/v1/development/history/employee") +@Tags("DevelopmentEmployeeHistory") +@Security("bearerAuth") +export class DevelopmentHistoryController extends Controller { + private developmentHistoryRepository = AppDataSource.getRepository(DevelopmentHistory); + private developmentRepository = AppDataSource.getRepository(Development); + private posTypeRepository = AppDataSource.getRepository(EmployeePosType); + private posLevelRepository = AppDataSource.getRepository(EmployeePosLevel); + + /** + * API เพิ่มประวัติการฝึกอบรม/ดูงาน + * + * @summary DEV_006 - เพิ่มประวัติการฝึกอบรม/ดูงาน#6 + * + */ + @Post() + async CreateDevelopmentHistory( + @Body() requestBody: CreateDevelopmentHistory, + @Request() request: { user: Record }, + ) { + const type = "EMPLOYEE"; + const chk_name = await this.developmentHistoryRepository.find({ + where: { + citizenId: requestBody.citizenId, + developmentId: requestBody.developmentId, + type: type, + }, + }); + if (chk_name.length > 0) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ประวัติการฝึกอบรม/ดูงาน มีอยู่ในระบบแล้ว"); + } + + const checkId = await this.developmentRepository.findOne({ + where: { id: requestBody.developmentId }, + }); + if (!checkId) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงการ/หลักสูตรการฝึกอบรม"); + } + if (requestBody.posTypeId != null) { + const checkId = await this.posTypeRepository.findOne({ + where: { id: requestBody.posTypeId }, + }); + if (!checkId) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลประเภทตำแหน่ง"); + } + } + if (requestBody.posLevelId != null) { + const checkId = await this.posLevelRepository.findOne({ + where: { id: requestBody.posLevelId }, + }); + if (!checkId) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลระดับตำแหน่ง"); + } + } + + const development = Object.assign(new DevelopmentHistory(), requestBody); + development.type = type; + development.employeePosTypeId = requestBody.posTypeId; + development.employeePosLevelId = requestBody.posLevelId; + development.createdUserId = request.user.sub; + development.createdFullName = request.user.name; + development.lastUpdateUserId = request.user.sub; + development.lastUpdateFullName = request.user.name; + await this.developmentHistoryRepository.save(development); + return new HttpSuccess(development.id); + } + + /** + * API แก้ไขประวัติการฝึกอบรม/ดูงาน + * + * @summary DEV_007 - แก้ไขประวัติการฝึกอบรม/ดูงาน #7 + * + * @param {string} id Id โครงการ + */ + @Put("{id}") + async UpdateDevelopmentHistory( + @Path() id: string, + @Body() requestBody: UpdateDevelopmentHistory, + @Request() request: { user: Record }, + ) { + const type = "EMPLOYEE"; + const development = await this.developmentHistoryRepository.findOne({ + where: { id: id, type: type }, + }); + if (!development) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลประวัติการฝึกอบรม/ดูงานนี้"); + } + const chk_name = await this.developmentHistoryRepository.find({ + where: { + citizenId: requestBody.citizenId, + developmentId: requestBody.developmentId, + type: type, + id: Not(id), + }, + }); + if (chk_name.length > 0) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ประวัติการฝึกอบรม/ดูงาน มีอยู่ในระบบแล้ว"); + } + const checkId = await this.developmentRepository.findOne({ + where: { id: requestBody.developmentId }, + }); + if (!checkId) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงการ/หลักสูตรการฝึกอบรม"); + } + if (requestBody.posTypeId != null) { + const checkId = await this.posTypeRepository.findOne({ + where: { id: requestBody.posTypeId }, + }); + if (!checkId) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลประเภทตำแหน่ง"); + } + } + if (requestBody.posLevelId != null) { + const checkId = await this.posLevelRepository.findOne({ + where: { id: requestBody.posLevelId }, + }); + if (!checkId) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลระดับตำแหน่ง"); + } + } + Object.assign(development, requestBody); + development.type = type; + development.employeePosTypeId = requestBody.posTypeId; + development.employeePosLevelId = requestBody.posLevelId; + development.lastUpdateUserId = request.user.sub; + development.lastUpdateFullName = request.user.name; + await this.developmentHistoryRepository.save(development); + return new HttpSuccess(development.id); + } + + /** + * API ลบประวัติการฝึกอบรม/ดูงาน + * + * @summary DEV_008 - ลบประวัติการฝึกอบรม/ดูงาน #8 + * + * @param {string} id Id โครงการ + */ + @Delete("{id}") + async DeleteDevelopmentHistory(@Path() id: string) { + const type = "EMPLOYEE"; + const development = await this.developmentHistoryRepository.findOne({ + where: { id: id, type: type }, + }); + if (!development) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลประวัติการฝึกอบรม/ดูงานนี้"); + } + + await this.developmentHistoryRepository.remove(development); + return new HttpSuccess(); + } + + /** + * API รายการประวัติการฝึกอบรม/ดูงาน + * + * @summary DEV_009 - รายการประวัติการฝึกอบรม/ดูงาน #9 + * + */ + @Get() + async GetDevelopmentHistoryLists( + @Query("page") page: number = 1, + @Query("pageSize") pageSize: number = 10, + @Query("keyword") keyword?: string, + @Query("year") year?: number, + ) { + const type = "EMPLOYEE"; + const [development, total] = await AppDataSource.getRepository(DevelopmentHistory) + .createQueryBuilder("developmentHistory") + // .andWhere(year == null ? "developmentHistory.year LIKE :year" : "1=1", { year: `${year}` }) + // .orWhere("developmentHistory.projectName LIKE :keyword", { keyword: `${keyword}` }) + // .select(["development.id", "development.projectName", "development.year"]) + // .orderBy("developmentHistory.year", "DESC") + .orderBy("developmentHistory.createdAt", "DESC") + .skip((page - 1) * pageSize) + .take(pageSize) + .getManyAndCount(); + + return new HttpSuccess({ data: development, total }); + } + + /** + * API รายละเอียดประวัติการฝึกอบรม/ดูงาน + * + * @summary DEV_010 - รายละเอียดประวัติการฝึกอบรม/ดูงาน #10 + * + * @param {string} id Id โครงการ + */ + @Get("{id}") + async GetDevelopemtHistoryById(@Path() id: string) { + const type = "EMPLOYEE"; + const getDevelopment = await this.developmentHistoryRepository.findOne({ + where: { id: id, type: type }, + }); + if (!getDevelopment) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลประวัติการฝึกอบรม/ดูงานนี้"); + } + return new HttpSuccess(getDevelopment); + } +} diff --git a/src/controllers/DevelopmentHistoryController.ts b/src/controllers/DevelopmentHistoryController.ts index c9ca194..adc053b 100644 --- a/src/controllers/DevelopmentHistoryController.ts +++ b/src/controllers/DevelopmentHistoryController.ts @@ -23,13 +23,17 @@ import { DevelopmentHistory, UpdateDevelopmentHistory, } from "../entities/DevelopmentHistory"; +import { PosType } from "../entities/PosType"; +import { PosLevel } from "../entities/PosLevel"; @Route("api/v1/development/history/officer") -@Tags("DevelopmentHistory") +@Tags("DevelopmentOfficerHistory") @Security("bearerAuth") export class DevelopmentHistoryController extends Controller { private developmentHistoryRepository = AppDataSource.getRepository(DevelopmentHistory); private developmentRepository = AppDataSource.getRepository(Development); + private posTypeRepository = AppDataSource.getRepository(PosType); + private posLevelRepository = AppDataSource.getRepository(PosLevel); /** * API เพิ่มประวัติการฝึกอบรม/ดูงาน @@ -60,6 +64,22 @@ export class DevelopmentHistoryController extends Controller { if (!checkId) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงการ/หลักสูตรการฝึกอบรม"); } + if (requestBody.posTypeId != null) { + const checkId = await this.posTypeRepository.findOne({ + where: { id: requestBody.posTypeId }, + }); + if (!checkId) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลประเภทตำแหน่ง"); + } + } + if (requestBody.posLevelId != null) { + const checkId = await this.posLevelRepository.findOne({ + where: { id: requestBody.posLevelId }, + }); + if (!checkId) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลระดับตำแหน่ง"); + } + } const development = Object.assign(new DevelopmentHistory(), requestBody); development.type = type; @@ -108,6 +128,22 @@ export class DevelopmentHistoryController extends Controller { if (!checkId) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงการ/หลักสูตรการฝึกอบรม"); } + if (requestBody.posTypeId != null) { + const checkId = await this.posTypeRepository.findOne({ + where: { id: requestBody.posTypeId }, + }); + if (!checkId) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลประเภทตำแหน่ง"); + } + } + if (requestBody.posLevelId != null) { + const checkId = await this.posLevelRepository.findOne({ + where: { id: requestBody.posLevelId }, + }); + if (!checkId) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลระดับตำแหน่ง"); + } + } Object.assign(development, requestBody); development.type = type; development.lastUpdateUserId = request.user.sub; diff --git a/src/entities/DevelopmentHistory.ts b/src/entities/DevelopmentHistory.ts index 306e645..12b4f6a 100644 --- a/src/entities/DevelopmentHistory.ts +++ b/src/entities/DevelopmentHistory.ts @@ -3,6 +3,8 @@ import { EntityBase } from "./base/Base"; import { PosLevel } from "./PosLevel"; import { PosType } from "./PosType"; import { Development } from "./Development"; +import { EmployeePosType } from "./EmployeePosType"; +import { EmployeePosLevel } from "./EmployeePosLevel"; @Entity("developmentHistory") export class DevelopmentHistory extends EntityBase { @@ -84,6 +86,28 @@ export class DevelopmentHistory extends EntityBase { @JoinColumn({ name: "posTypeId" }) posType: PosType; + @Column({ + nullable: true, + length: 40, + comment: "ไอดีระดับตำแหน่ง", + }) + employeePosLevelId: string | null; + + @ManyToOne(() => EmployeePosLevel, (employeePosLevel) => employeePosLevel.developmentHistorys) + @JoinColumn({ name: "employeePosLevelId" }) + employeePosLevel: EmployeePosLevel; + + @Column({ + nullable: true, + length: 40, + comment: "ไอดีประเภทตำแหน่ง", + }) + employeePosTypeId: string | null; + + @ManyToOne(() => EmployeePosType, (employeePosType) => employeePosType.developmentHistorys) + @JoinColumn({ name: "employeePosTypeId" }) + employeePosType: EmployeePosType; + @Column({ nullable: true, comment: "โครงการ/หลักสูตรการฝึกอบรม", diff --git a/src/entities/EmployeePosLevel.ts b/src/entities/EmployeePosLevel.ts index c84e309..e84960f 100644 --- a/src/entities/EmployeePosLevel.ts +++ b/src/entities/EmployeePosLevel.ts @@ -1,6 +1,7 @@ -import { Entity, Column, ManyToOne, JoinColumn } from "typeorm"; +import { Entity, Column, ManyToOne, JoinColumn, OneToMany } from "typeorm"; import { EntityBase } from "./base/Base"; import { EmployeePosType } from "./EmployeePosType"; +import { DevelopmentHistory } from "./DevelopmentHistory"; enum EmployeePosLevelAuthoritys { HEAD = "HEAD", @@ -40,6 +41,9 @@ export class EmployeePosLevel extends EntityBase { @ManyToOne(() => EmployeePosType, (posType: EmployeePosType) => posType.posLevels) @JoinColumn({ name: "posTypeId" }) posType: EmployeePosType; + + @OneToMany(() => DevelopmentHistory, (developmentHistory) => developmentHistory.employeePosLevel) + developmentHistorys: DevelopmentHistory[]; } export class CreateEmployeePosLevel { diff --git a/src/entities/EmployeePosType.ts b/src/entities/EmployeePosType.ts index 99b1cdb..cafb49d 100644 --- a/src/entities/EmployeePosType.ts +++ b/src/entities/EmployeePosType.ts @@ -1,6 +1,7 @@ import { Entity, Column, OneToMany } from "typeorm"; import { EntityBase } from "./base/Base"; import { EmployeePosLevel } from "./EmployeePosLevel"; +import { DevelopmentHistory } from "./DevelopmentHistory"; @Entity("employeePosType") export class EmployeePosType extends EntityBase { @@ -27,6 +28,9 @@ export class EmployeePosType extends EntityBase { @OneToMany(() => EmployeePosLevel, (posLevel: EmployeePosLevel) => posLevel.posType) posLevels: EmployeePosLevel[]; + + @OneToMany(() => DevelopmentHistory, (developmentHistory) => developmentHistory.employeePosType) + developmentHistorys: DevelopmentHistory[]; } export class CreateEmployeePosType { diff --git a/src/migration/1712120794817-update_table_developmentHistory_add_type.ts b/src/migration/1712120794817-update_table_developmentHistory_add_type.ts new file mode 100644 index 0000000..52e2b57 --- /dev/null +++ b/src/migration/1712120794817-update_table_developmentHistory_add_type.ts @@ -0,0 +1,20 @@ +import { MigrationInterface, QueryRunner } from "typeorm"; + +export class UpdateTableDevelopmentHistoryAddType1712120794817 implements MigrationInterface { + name = 'UpdateTableDevelopmentHistoryAddType1712120794817' + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`developmentHistory\` ADD \`employeePosLevelId\` varchar(40) NULL COMMENT 'ไอดีระดับตำแหน่ง'`); + await queryRunner.query(`ALTER TABLE \`developmentHistory\` ADD \`employeePosTypeId\` varchar(40) NULL COMMENT 'ไอดีประเภทตำแหน่ง'`); + await queryRunner.query(`ALTER TABLE \`developmentHistory\` ADD CONSTRAINT \`FK_a905f077069e27d2fc9bb8f5f5c\` FOREIGN KEY (\`employeePosLevelId\`) REFERENCES \`employeePosLevel\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`); + await queryRunner.query(`ALTER TABLE \`developmentHistory\` ADD CONSTRAINT \`FK_25dd3134b725bb2ec455872374f\` FOREIGN KEY (\`employeePosTypeId\`) REFERENCES \`employeePosType\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`); + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`developmentHistory\` DROP FOREIGN KEY \`FK_25dd3134b725bb2ec455872374f\``); + await queryRunner.query(`ALTER TABLE \`developmentHistory\` DROP FOREIGN KEY \`FK_a905f077069e27d2fc9bb8f5f5c\``); + await queryRunner.query(`ALTER TABLE \`developmentHistory\` DROP COLUMN \`employeePosTypeId\``); + await queryRunner.query(`ALTER TABLE \`developmentHistory\` DROP COLUMN \`employeePosLevelId\``); + } + +} From 4aabc4d1367e372287adb12db9b1681cc3a2bcc0 Mon Sep 17 00:00:00 2001 From: Kittapath Date: Wed, 3 Apr 2024 12:10:30 +0700 Subject: [PATCH 006/250] no message --- src/controllers/DevelopmentEmployeeHistoryController.ts | 2 +- src/controllers/DevelopmentHistoryController.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/controllers/DevelopmentEmployeeHistoryController.ts b/src/controllers/DevelopmentEmployeeHistoryController.ts index 4fcdb41..d226d0c 100644 --- a/src/controllers/DevelopmentEmployeeHistoryController.ts +++ b/src/controllers/DevelopmentEmployeeHistoryController.ts @@ -29,7 +29,7 @@ import { EmployeePosLevel } from "../entities/EmployeePosLevel"; @Route("api/v1/development/history/employee") @Tags("DevelopmentEmployeeHistory") @Security("bearerAuth") -export class DevelopmentHistoryController extends Controller { +export class DevelopmentEmployeeHistoryController extends Controller { private developmentHistoryRepository = AppDataSource.getRepository(DevelopmentHistory); private developmentRepository = AppDataSource.getRepository(Development); private posTypeRepository = AppDataSource.getRepository(EmployeePosType); diff --git a/src/controllers/DevelopmentHistoryController.ts b/src/controllers/DevelopmentHistoryController.ts index adc053b..8437110 100644 --- a/src/controllers/DevelopmentHistoryController.ts +++ b/src/controllers/DevelopmentHistoryController.ts @@ -29,7 +29,7 @@ import { PosLevel } from "../entities/PosLevel"; @Route("api/v1/development/history/officer") @Tags("DevelopmentOfficerHistory") @Security("bearerAuth") -export class DevelopmentHistoryController extends Controller { +export class DevelopmentOfficerHistoryController extends Controller { private developmentHistoryRepository = AppDataSource.getRepository(DevelopmentHistory); private developmentRepository = AppDataSource.getRepository(Development); private posTypeRepository = AppDataSource.getRepository(PosType); From 4d4306863deb1451250e54f3340f9c3641700ecb Mon Sep 17 00:00:00 2001 From: Kittapath Date: Wed, 3 Apr 2024 13:36:59 +0700 Subject: [PATCH 007/250] =?UTF-8?q?=E0=B9=80=E0=B8=9E=E0=B8=B4=E0=B9=88?= =?UTF-8?q?=E0=B8=A1=E0=B8=9F=E0=B8=B4=E0=B8=A7=E0=B8=95=E0=B8=B3=E0=B9=81?= =?UTF-8?q?=E0=B8=AB=E0=B8=99=E0=B9=88=E0=B8=87=E0=B8=97=E0=B8=B2=E0=B8=87?= =?UTF-8?q?=E0=B8=81=E0=B8=B2=E0=B8=A3=E0=B8=9A=E0=B8=A3=E0=B8=B4=E0=B8=AB?= =?UTF-8?q?=E0=B8=B2=E0=B8=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/entities/DevelopmentHistory.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/entities/DevelopmentHistory.ts b/src/entities/DevelopmentHistory.ts index 12b4f6a..90418c6 100644 --- a/src/entities/DevelopmentHistory.ts +++ b/src/entities/DevelopmentHistory.ts @@ -64,6 +64,14 @@ export class DevelopmentHistory extends EntityBase { }) position: string; + @Column({ + nullable: true, + comment: "ชื่อตำแหน่งทางการบริหาร", + length: 255, + default: null, + }) + posExecutive: string; + @Column({ nullable: true, length: 40, @@ -149,6 +157,8 @@ export class CreateDevelopmentHistory { @Column() position: string | null; @Column() + posExecutive: string | null; + @Column() posLevelId: string | null; @Column() posTypeId: string | null; @@ -174,6 +184,8 @@ export class UpdateDevelopmentHistory { @Column() position: string | null; @Column() + posExecutive: string | null; + @Column() posLevelId: string | null; @Column() posTypeId: string | null; From 8a5a7ac360f38840089f8763995009e891316e4b Mon Sep 17 00:00:00 2001 From: Kittapath Date: Wed, 3 Apr 2024 13:38:58 +0700 Subject: [PATCH 008/250] no message --- ...12-update_table_developmentHistory_add_type1.ts | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 src/migration/1712126314212-update_table_developmentHistory_add_type1.ts diff --git a/src/migration/1712126314212-update_table_developmentHistory_add_type1.ts b/src/migration/1712126314212-update_table_developmentHistory_add_type1.ts new file mode 100644 index 0000000..440e577 --- /dev/null +++ b/src/migration/1712126314212-update_table_developmentHistory_add_type1.ts @@ -0,0 +1,14 @@ +import { MigrationInterface, QueryRunner } from "typeorm"; + +export class UpdateTableDevelopmentHistoryAddType11712126314212 implements MigrationInterface { + name = 'UpdateTableDevelopmentHistoryAddType11712126314212' + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`developmentHistory\` ADD \`posExecutive\` varchar(255) NULL COMMENT 'ชื่อตำแหน่งทางการบริหาร'`); + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`developmentHistory\` DROP COLUMN \`posExecutive\``); + } + +} From d1b7330b917b9df4bd8fd98b41ad2c869b7af48b Mon Sep 17 00:00:00 2001 From: AdisakKanthawilang Date: Wed, 3 Apr 2024 14:11:33 +0700 Subject: [PATCH 009/250] DEV_010 --- .../DevelopmentHistoryController.ts | 30 +++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/src/controllers/DevelopmentHistoryController.ts b/src/controllers/DevelopmentHistoryController.ts index 8437110..cab66f6 100644 --- a/src/controllers/DevelopmentHistoryController.ts +++ b/src/controllers/DevelopmentHistoryController.ts @@ -208,15 +208,41 @@ export class DevelopmentOfficerHistoryController extends Controller { * * @param {string} id Id โครงการ */ - @Get("{id}") + @Get("{id}") async GetDevelopemtHistoryById(@Path() id: string) { const type = "OFFICER"; const getDevelopment = await this.developmentHistoryRepository.findOne({ + relations: ["development"], where: { id: id, type: type }, }); if (!getDevelopment) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลประวัติการฝึกอบรม/ดูงานนี้"); } - return new HttpSuccess(getDevelopment); + + const formattedData = { + rank: getDevelopment.rank ? getDevelopment.rank : null, + prefix: getDevelopment.prefix ? getDevelopment.prefix : null, + firstName: getDevelopment.firstName ? getDevelopment.firstName : null, + lastName: getDevelopment.lastName ? getDevelopment.lastName : null, + citizenId: getDevelopment.citizenId ? getDevelopment.citizenId : null, + position: getDevelopment.position ? getDevelopment.position : null, + posLevelId: getDevelopment.posLevelId ? getDevelopment.posLevelId : null, + posTypeId: getDevelopment.posTypeId ? getDevelopment.posTypeId : null, + developmentId: getDevelopment.developmentId ? getDevelopment.developmentId : null, + order: getDevelopment.order ? getDevelopment.order : null, + dateOrder: getDevelopment.dateOrder ? getDevelopment.dateOrder : null, + year: getDevelopment.development.year ? getDevelopment.development.year : null, + projectName: getDevelopment.development.projectName ? getDevelopment.development.projectName : null, + dateStart: getDevelopment.development.dateStart ? getDevelopment.development.dateStart : null, + dateEnd: getDevelopment.development.dateEnd ? getDevelopment.development.dateEnd : null, + totalDate: getDevelopment.development.totalDate ? getDevelopment.development.totalDate : null, + addressAcademic: getDevelopment.development.addressAcademic ? getDevelopment.development.addressAcademic : null, + topicAcademic: getDevelopment.development.topicAcademic ? getDevelopment.development.topicAcademic : null, + dateStartAcademic: new Date(), + dateEndAcademic: new Date(), + org: null, + }; + + return new HttpSuccess(formattedData); } } From e8a5fa5e42c24730d7bdabd2584664e2e0ef7903 Mon Sep 17 00:00:00 2001 From: AdisakKanthawilang Date: Wed, 3 Apr 2024 14:48:59 +0700 Subject: [PATCH 010/250] DEV_10 (EMP) --- .../DevelopmentEmployeeHistoryController.ts | 28 ++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/src/controllers/DevelopmentEmployeeHistoryController.ts b/src/controllers/DevelopmentEmployeeHistoryController.ts index d226d0c..6f3f590 100644 --- a/src/controllers/DevelopmentEmployeeHistoryController.ts +++ b/src/controllers/DevelopmentEmployeeHistoryController.ts @@ -216,11 +216,37 @@ export class DevelopmentEmployeeHistoryController extends Controller { async GetDevelopemtHistoryById(@Path() id: string) { const type = "EMPLOYEE"; const getDevelopment = await this.developmentHistoryRepository.findOne({ + relations: ["development"], where: { id: id, type: type }, }); if (!getDevelopment) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลประวัติการฝึกอบรม/ดูงานนี้"); } - return new HttpSuccess(getDevelopment); + + const formattedData = { + rank: getDevelopment.rank ? getDevelopment.rank : null, + prefix: getDevelopment.prefix ? getDevelopment.prefix : null, + firstName: getDevelopment.firstName ? getDevelopment.firstName : null, + lastName: getDevelopment.lastName ? getDevelopment.lastName : null, + citizenId: getDevelopment.citizenId ? getDevelopment.citizenId : null, + position: getDevelopment.position ? getDevelopment.position : null, + posLevelId: getDevelopment.posLevelId ? getDevelopment.posLevelId : null, + posTypeId: getDevelopment.posTypeId ? getDevelopment.posTypeId : null, + developmentId: getDevelopment.developmentId ? getDevelopment.developmentId : null, + order: getDevelopment.order ? getDevelopment.order : null, + dateOrder: getDevelopment.dateOrder ? getDevelopment.dateOrder : null, + year: getDevelopment.development.year ? getDevelopment.development.year : null, + projectName: getDevelopment.development.projectName ? getDevelopment.development.projectName : null, + dateStart: getDevelopment.development.dateStart ? getDevelopment.development.dateStart : null, + dateEnd: getDevelopment.development.dateEnd ? getDevelopment.development.dateEnd : null, + totalDate: getDevelopment.development.totalDate ? getDevelopment.development.totalDate : null, + addressAcademic: getDevelopment.development.addressAcademic ? getDevelopment.development.addressAcademic : null, + topicAcademic: getDevelopment.development.topicAcademic ? getDevelopment.development.topicAcademic : null, + dateStartAcademic: new Date(), + dateEndAcademic: new Date(), + org: null, + }; + + return new HttpSuccess(formattedData); } } From daf4188144b4bbb95f925983d7d5327a2f82010c Mon Sep 17 00:00:00 2001 From: Kittapath Date: Wed, 3 Apr 2024 14:54:56 +0700 Subject: [PATCH 011/250] =?UTF-8?q?=E0=B8=84=E0=B9=89=E0=B8=99=E0=B8=AB?= =?UTF-8?q?=E0=B8=B2=E0=B9=82=E0=B8=84=E0=B8=A3=E0=B8=87=E0=B8=81=E0=B8=B2?= =?UTF-8?q?=E0=B8=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/DevelopmentController.ts | 49 ++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/src/controllers/DevelopmentController.ts b/src/controllers/DevelopmentController.ts index 451a952..3d0c821 100644 --- a/src/controllers/DevelopmentController.ts +++ b/src/controllers/DevelopmentController.ts @@ -316,6 +316,55 @@ export class DevelopmentController extends Controller { return new HttpSuccess(development.id); } + /** + * API ค้นหาโครงการ + * + * @summary DEV_00 - ค้นหาโครงการ # + * + * @param {string} id Id โครงการ + */ + @Get("search") + async ListDevelopemt( + @Query("page") page: number = 1, + @Query("pageSize") pageSize: number = 10, + @Query() searchField?: "year" | "projectName", + @Query() searchKeyword: string = "", + ) { + let queryLike = "developer.projectName LIKE :keyword"; + if (searchField == "year") { + queryLike = "developer.year LIKE :keyword"; + } + const [record, total] = await this.developmentRepository + .createQueryBuilder("developer") + .andWhere( + searchKeyword != undefined && searchKeyword != null && searchKeyword != "" + ? queryLike + : "1=1", + { + keyword: `%${searchKeyword}%`, + }, + ) + .skip((page - 1) * pageSize) + .take(pageSize) + .getManyAndCount(); + + const data = await Promise.all( + record.map((_data) => { + return { + id: _data.id, + year: _data.year, + projectName: _data.projectName, + dateStart: _data.dateStart, + dateEnd: _data.dateEnd, + totalDate: _data.totalDate, + addressAcademic: _data.addressAcademic, + topicAcademic: _data.topicAcademic, + }; + }), + ); + return new HttpSuccess({ data: data, total }); + } + /** * API ลบโครงการ/หลักสูตรการฝึกอบรม * From 682010fe665227323d376fab7449388cfb91f1a4 Mon Sep 17 00:00:00 2001 From: Kittapath Date: Wed, 3 Apr 2024 16:14:00 +0700 Subject: [PATCH 012/250] no message --- src/controllers/DevelopmentController.ts | 15 +++++++++--- src/entities/Development.ts | 24 +++++++++++++++++++ src/entities/DevelopmentHistory.ts | 8 +++---- ...te_table_development_add_dateStudyStart.ts | 16 +++++++++++++ ...e_table_development_add_dateStudyStart1.ts | 16 +++++++++++++ 5 files changed, 72 insertions(+), 7 deletions(-) create mode 100644 src/migration/1712135164363-update_table_development_add_dateStudyStart.ts create mode 100644 src/migration/1712135296648-update_table_development_add_dateStudyStart1.ts diff --git a/src/controllers/DevelopmentController.ts b/src/controllers/DevelopmentController.ts index 3d0c821..3def58d 100644 --- a/src/controllers/DevelopmentController.ts +++ b/src/controllers/DevelopmentController.ts @@ -63,7 +63,7 @@ export class DevelopmentController extends Controller { "โครงการ/หลักสูตรการฝึกอบรม: " + requestBody.projectName + " ปีงบประมาณ: " + - requestBody.year + + (requestBody.year + 543) + " มีอยู่ในระบบแล้ว", ); } @@ -225,7 +225,7 @@ export class DevelopmentController extends Controller { "โครงการ/หลักสูตรการฝึกอบรม: " + requestBody.projectName + " ปีงบประมาณ: " + - requestBody.year + + (requestBody.year + 543) + " มีอยู่ในระบบแล้ว", ); } @@ -443,6 +443,15 @@ export class DevelopmentController extends Controller { if (!getDevelopment) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงการ/หลักสูตรการฝึกอบรมนี้"); } - return new HttpSuccess(getDevelopment); + let _getDevelopment: any = getDevelopment; + _getDevelopment.actualPeoples = getDevelopment.developmentActualPeoples; + _getDevelopment.plannedPeoples = getDevelopment.developmentPlannedPeoples; + _getDevelopment.actualGoals = getDevelopment.developmentActualGoals; + _getDevelopment.plannedGoals = getDevelopment.developmentPlannedGoals; + delete _getDevelopment.developmentActualPeoples; + delete _getDevelopment.developmentPlannedPeoples; + delete _getDevelopment.developmentActualGoals; + delete _getDevelopment.developmentPlannedGoals; + return new HttpSuccess(_getDevelopment); } } diff --git a/src/entities/Development.ts b/src/entities/Development.ts index a3d5368..ef4a228 100644 --- a/src/entities/Development.ts +++ b/src/entities/Development.ts @@ -265,6 +265,22 @@ export class Development extends EntityBase { }) addressAcademic: string; + @Column({ + nullable: true, + type: "datetime", + comment: "วันเริ่มต้นการศึกษาดูงาน", + default: null, + }) + dateStudyStart: Date; + + @Column({ + nullable: true, + type: "datetime", + comment: "วันสิ้นสุดการศึกษาดูงาน", + default: null, + }) + dateStudyEnd: Date; + @Column({ nullable: true, comment: "จังหวัด(ข้อมูลวิชาการ)", @@ -376,6 +392,10 @@ export class CreateDevelopment { @Column() provinceActualId: string | null; @Column() + dateStudyStart: Date | null; + @Column() + dateStudyEnd: Date | null; + @Column() actualPeoples: CreateActualPeople[]; @Column() plannedPeoples: CreatePlannedPeople[]; @@ -461,6 +481,10 @@ export class UpdateDevelopment { @Column() provinceActualId: string | null; @Column() + dateStudyStart: Date | null; + @Column() + dateStudyEnd: Date | null; + @Column() actualPeoples: CreateActualPeople[]; @Column() plannedPeoples: CreatePlannedPeople[]; diff --git a/src/entities/DevelopmentHistory.ts b/src/entities/DevelopmentHistory.ts index 90418c6..e8a25db 100644 --- a/src/entities/DevelopmentHistory.ts +++ b/src/entities/DevelopmentHistory.ts @@ -137,11 +137,11 @@ export class DevelopmentHistory extends EntityBase { @Column({ nullable: true, + type: "datetime", comment: "คำสั่งลงวันที่/หนังสืออนุมัติลงวันที่", default: null, - length: 255, }) - dateOrder: string; + dateOrder: Date; } export class CreateDevelopmentHistory { @Column() @@ -167,7 +167,7 @@ export class CreateDevelopmentHistory { @Column() order: string | null; @Column() - dateOrder: string | null; + dateOrder: Date | null; } export class UpdateDevelopmentHistory { @@ -194,5 +194,5 @@ export class UpdateDevelopmentHistory { @Column() order: string | null; @Column() - dateOrder: string | null; + dateOrder: Date | null; } diff --git a/src/migration/1712135164363-update_table_development_add_dateStudyStart.ts b/src/migration/1712135164363-update_table_development_add_dateStudyStart.ts new file mode 100644 index 0000000..87d7c30 --- /dev/null +++ b/src/migration/1712135164363-update_table_development_add_dateStudyStart.ts @@ -0,0 +1,16 @@ +import { MigrationInterface, QueryRunner } from "typeorm"; + +export class UpdateTableDevelopmentAddDateStudyStart1712135164363 implements MigrationInterface { + name = 'UpdateTableDevelopmentAddDateStudyStart1712135164363' + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`development\` ADD \`dateStudyStart\` datetime NULL COMMENT 'วันเริ่มต้นการศึกษาดูงาน'`); + await queryRunner.query(`ALTER TABLE \`development\` ADD \`dateStudyEnd\` datetime NULL COMMENT 'วันสิ้นสุดการศึกษาดูงาน'`); + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`dateStudyEnd\``); + await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`dateStudyStart\``); + } + +} diff --git a/src/migration/1712135296648-update_table_development_add_dateStudyStart1.ts b/src/migration/1712135296648-update_table_development_add_dateStudyStart1.ts new file mode 100644 index 0000000..1819ff4 --- /dev/null +++ b/src/migration/1712135296648-update_table_development_add_dateStudyStart1.ts @@ -0,0 +1,16 @@ +import { MigrationInterface, QueryRunner } from "typeorm"; + +export class UpdateTableDevelopmentAddDateStudyStart11712135296648 implements MigrationInterface { + name = 'UpdateTableDevelopmentAddDateStudyStart11712135296648' + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`developmentHistory\` DROP COLUMN \`dateOrder\``); + await queryRunner.query(`ALTER TABLE \`developmentHistory\` ADD \`dateOrder\` datetime NULL COMMENT 'คำสั่งลงวันที่/หนังสืออนุมัติลงวันที่'`); + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`developmentHistory\` DROP COLUMN \`dateOrder\``); + await queryRunner.query(`ALTER TABLE \`developmentHistory\` ADD \`dateOrder\` varchar(255) NULL COMMENT 'คำสั่งลงวันที่/หนังสืออนุมัติลงวันที่'`); + } + +} From 80f0a154f9a7007b4144124e498edb95dab37d6a Mon Sep 17 00:00:00 2001 From: Kittapath Date: Wed, 3 Apr 2024 16:33:17 +0700 Subject: [PATCH 013/250] no message --- src/entities/Development.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/entities/Development.ts b/src/entities/Development.ts index ef4a228..08e2a46 100644 --- a/src/entities/Development.ts +++ b/src/entities/Development.ts @@ -392,9 +392,9 @@ export class CreateDevelopment { @Column() provinceActualId: string | null; @Column() - dateStudyStart: Date | null; + dateStudyStart?: Date | null; @Column() - dateStudyEnd: Date | null; + dateStudyEnd?: Date | null; @Column() actualPeoples: CreateActualPeople[]; @Column() @@ -481,9 +481,9 @@ export class UpdateDevelopment { @Column() provinceActualId: string | null; @Column() - dateStudyStart: Date | null; + dateStudyStart?: Date | null; @Column() - dateStudyEnd: Date | null; + dateStudyEnd?: Date | null; @Column() actualPeoples: CreateActualPeople[]; @Column() From 4f73cad70bc5dc9b141a63bc814a40056bd0960a Mon Sep 17 00:00:00 2001 From: AdisakKanthawilang Date: Wed, 3 Apr 2024 17:08:39 +0700 Subject: [PATCH 014/250] =?UTF-8?q?=E0=B9=81=E0=B8=81=E0=B9=89=E0=B8=8A?= =?UTF-8?q?=E0=B8=B7=E0=B9=88=E0=B8=AD=E0=B8=9F=E0=B8=B4=E0=B8=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/DevelopmentEmployeeHistoryController.ts | 4 ++-- src/controllers/DevelopmentHistoryController.ts | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/controllers/DevelopmentEmployeeHistoryController.ts b/src/controllers/DevelopmentEmployeeHistoryController.ts index 6f3f590..e50813e 100644 --- a/src/controllers/DevelopmentEmployeeHistoryController.ts +++ b/src/controllers/DevelopmentEmployeeHistoryController.ts @@ -242,8 +242,8 @@ export class DevelopmentEmployeeHistoryController extends Controller { totalDate: getDevelopment.development.totalDate ? getDevelopment.development.totalDate : null, addressAcademic: getDevelopment.development.addressAcademic ? getDevelopment.development.addressAcademic : null, topicAcademic: getDevelopment.development.topicAcademic ? getDevelopment.development.topicAcademic : null, - dateStartAcademic: new Date(), - dateEndAcademic: new Date(), + dateStudyStart: getDevelopment.development.dateStudyStart ? getDevelopment.development.dateStudyStart : null, + dateStudyEnd: getDevelopment.development.dateStudyEnd ? getDevelopment.development.dateStudyEnd : null, org: null, }; diff --git a/src/controllers/DevelopmentHistoryController.ts b/src/controllers/DevelopmentHistoryController.ts index cab66f6..7b48fc1 100644 --- a/src/controllers/DevelopmentHistoryController.ts +++ b/src/controllers/DevelopmentHistoryController.ts @@ -238,8 +238,8 @@ export class DevelopmentOfficerHistoryController extends Controller { totalDate: getDevelopment.development.totalDate ? getDevelopment.development.totalDate : null, addressAcademic: getDevelopment.development.addressAcademic ? getDevelopment.development.addressAcademic : null, topicAcademic: getDevelopment.development.topicAcademic ? getDevelopment.development.topicAcademic : null, - dateStartAcademic: new Date(), - dateEndAcademic: new Date(), + dateStudyStart: getDevelopment.development.dateStudyStart ? getDevelopment.development.dateStudyStart : null, + dateStudyEnd: getDevelopment.development.dateStudyEnd ? getDevelopment.development.dateStudyEnd : null, org: null, }; From 61c44b8f51dc02c17659cef38538674f952806b2 Mon Sep 17 00:00:00 2001 From: Kittapath Date: Wed, 3 Apr 2024 17:32:11 +0700 Subject: [PATCH 015/250] no message --- src/controllers/DevelopmentController.ts | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/controllers/DevelopmentController.ts b/src/controllers/DevelopmentController.ts index 3def58d..f093b11 100644 --- a/src/controllers/DevelopmentController.ts +++ b/src/controllers/DevelopmentController.ts @@ -405,13 +405,17 @@ export class DevelopmentController extends Controller { async GetDevelopmentLists( @Query("page") page: number = 1, @Query("pageSize") pageSize: number = 10, + @Query("year") year: number, @Query("keyword") keyword?: string, - @Query("year") year?: number, ) { const [development, total] = await AppDataSource.getRepository(Development) .createQueryBuilder("development") - .andWhere(year == null ? "development.year LIKE :year" : "1=1", { year: `${year}` }) - .orWhere("development.projectName LIKE :keyword", { keyword: `${keyword}` }) + .andWhere(year > 0 ? "development.year LIKE :year" : "1=1", { + year: `${year.toString()}`, + }) + .andWhere(keyword != undefined ? "development.projectName LIKE :keyword" : "1=1", { + keyword: `%${keyword}%`, + }) .select(["development.id", "development.projectName", "development.year"]) .orderBy("development.year", "DESC") .orderBy("development.createdAt", "DESC") From 3c2ce93724233cb8fcbe2db8cfa4f4969d42e41f Mon Sep 17 00:00:00 2001 From: Bright Date: Wed, 3 Apr 2024 18:10:46 +0700 Subject: [PATCH 016/250] =?UTF-8?q?DEV=5F009=20=E0=B9=80=E0=B8=AB=E0=B8=A5?= =?UTF-8?q?=E0=B8=B7=E0=B8=AD=20map?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DevelopmentHistoryController.ts | 79 +++++++++++++++++-- tsoa.json | 5 +- 2 files changed, 78 insertions(+), 6 deletions(-) diff --git a/src/controllers/DevelopmentHistoryController.ts b/src/controllers/DevelopmentHistoryController.ts index 7b48fc1..70cdf5c 100644 --- a/src/controllers/DevelopmentHistoryController.ts +++ b/src/controllers/DevelopmentHistoryController.ts @@ -13,7 +13,7 @@ import { Query, } from "tsoa"; import { AppDataSource } from "../database/data-source"; -import { Not } from "typeorm"; +import { Brackets, Not } from "typeorm"; import HttpSuccess from "../interfaces/http-success"; import HttpError from "../interfaces/http-error"; import HttpStatusCode from "../interfaces/http-status"; @@ -189,10 +189,79 @@ export class DevelopmentOfficerHistoryController extends Controller { const type = "OFFICER"; const [development, total] = await AppDataSource.getRepository(DevelopmentHistory) .createQueryBuilder("developmentHistory") - // .andWhere(year == null ? "developmentHistory.year LIKE :year" : "1=1", { year: `${year}` }) - // .orWhere("developmentHistory.projectName LIKE :keyword", { keyword: `${keyword}` }) - // .select(["development.id", "development.projectName", "development.year"]) - // .orderBy("developmentHistory.year", "DESC") + .leftJoinAndSelect("developmentHistory.development", "development") + .leftJoinAndSelect("developmentHistory.posLevel", "posLevel") + .leftJoinAndSelect("developmentHistory.posType", "posType") + .andWhere("development.year = :year", { year: year }) + .andWhere("developmentHistory.type = :type", { type: type }) + .andWhere( + new Brackets((qb) => { + qb.where( + keyword != null && keyword != "" + ? "developmentHistory.prefix LIKE :keyword" + : "1=1", + { + keyword: `%${keyword}%`, + }, + ) + .orWhere( + keyword != null && keyword != "" + ? "developmentHistory.firstName LIKE :keyword" + : "1=1", + { + keyword: `%${keyword}%`, + }, + ) + .orWhere( + keyword != null && keyword != "" + ? "developmentHistory.lastName LIKE :keyword" + : "1=1", + { + keyword: `%${keyword}%`, + }, + ) + .orWhere( + keyword != null && keyword != "" + ? "developmentHistory.position LIKE :keyword" + : "1=1", + { + keyword: `%${keyword}%`, + }, + ) + .orWhere( + keyword != null && keyword != "" + ? "developmentHistory.position LIKE :keyword" + : "1=1", + { + keyword: `%${keyword}%`, + }, + ) + .orWhere( + keyword != null && keyword != "" + ? "development.projectName LIKE :keyword" + : "1=1", + { + keyword: `%${keyword}%`, + }, + ) + .orWhere( + keyword != null && keyword != "" + ? "posType.posTypeName LIKE :keyword" + : "1=1", + { + keyword: `%${keyword}%`, + }, + ) + .orWhere( + keyword != null && keyword != "" + ? "posLevel.posLevelName LIKE :keyword" + : "1=1", + { + keyword: `%${keyword}%`, + }, + ); + }), + ) .orderBy("developmentHistory.createdAt", "DESC") .skip((page - 1) * pageSize) .take(pageSize) diff --git a/tsoa.json b/tsoa.json index c0d60df..63f028c 100644 --- a/tsoa.json +++ b/tsoa.json @@ -33,7 +33,10 @@ "name": "Development", "description": "ชื่อโครงการ/กิจกรรม/หลักสูตร" }, { - "name": "DevelopmentHistory", "description": "ประวัติการฝึกอบรม/ดูงาน" + "name": "DevelopmentOfficerHistory", "description": "ประวัติการฝึกอบรม/ดูงาน ขรก." + }, + { + "name": "DevelopmentEmployeeHistory", "description": "ประวัติการฝึกอบรม/ดูงานลูกจ้าง." } ] }, From c88a83f43e6b1c5a61650afcc528517172e58ee4 Mon Sep 17 00:00:00 2001 From: Bright Date: Wed, 3 Apr 2024 18:28:47 +0700 Subject: [PATCH 017/250] no message --- src/controllers/DevelopmentHistoryController.ts | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/controllers/DevelopmentHistoryController.ts b/src/controllers/DevelopmentHistoryController.ts index 70cdf5c..4a6e123 100644 --- a/src/controllers/DevelopmentHistoryController.ts +++ b/src/controllers/DevelopmentHistoryController.ts @@ -266,8 +266,18 @@ export class DevelopmentOfficerHistoryController extends Controller { .skip((page - 1) * pageSize) .take(pageSize) .getManyAndCount(); + + const formattedData = development.map(item => ({ + id: item.id, + citizenId: item.citizenId, + fullName: item.prefix+item.firstName+" "+item.lastName, + position: item.position, + posType: item.posType.posTypeName, + posLevel: item.posLevel.posLevelName, + projectName: item.development.projectName, + })); - return new HttpSuccess({ data: development, total }); + return new HttpSuccess({ data: formattedData, total }); } /** From 8375ac15491645171fd94c8b2cd1114ea7616745 Mon Sep 17 00:00:00 2001 From: Kittapath Date: Wed, 3 Apr 2024 18:58:54 +0700 Subject: [PATCH 018/250] no message --- tsoa.json | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tsoa.json b/tsoa.json index c0d60df..4156cdf 100644 --- a/tsoa.json +++ b/tsoa.json @@ -33,7 +33,10 @@ "name": "Development", "description": "ชื่อโครงการ/กิจกรรม/หลักสูตร" }, { - "name": "DevelopmentHistory", "description": "ประวัติการฝึกอบรม/ดูงาน" + "name": "DevelopmentOfficerHistory", "description": "ประวัติการฝึกอบรม/ดูงานข้าราชการ" + }, + { + "name": "DevelopmentEmployeeHistory", "description": "ประวัติการฝึกอบรม/ดูงานลูกจ้าง" } ] }, From e52e986d3be7bfb5a363200130d3923f78712968 Mon Sep 17 00:00:00 2001 From: Bright Date: Wed, 3 Apr 2024 20:15:58 +0700 Subject: [PATCH 019/250] =?UTF-8?q?DEV=5F009=20=E0=B8=A5=E0=B8=B9=E0=B8=81?= =?UTF-8?q?=E0=B8=88=E0=B9=89=E0=B8=B2=E0=B8=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DevelopmentEmployeeHistoryController.ts | 91 +++++++++++++++++-- 1 file changed, 85 insertions(+), 6 deletions(-) diff --git a/src/controllers/DevelopmentEmployeeHistoryController.ts b/src/controllers/DevelopmentEmployeeHistoryController.ts index e50813e..dcdaa1f 100644 --- a/src/controllers/DevelopmentEmployeeHistoryController.ts +++ b/src/controllers/DevelopmentEmployeeHistoryController.ts @@ -13,7 +13,7 @@ import { Query, } from "tsoa"; import { AppDataSource } from "../database/data-source"; -import { Not } from "typeorm"; +import { Brackets, Not } from "typeorm"; import HttpSuccess from "../interfaces/http-success"; import HttpError from "../interfaces/http-error"; import HttpStatusCode from "../interfaces/http-status"; @@ -193,16 +193,95 @@ export class DevelopmentEmployeeHistoryController extends Controller { const type = "EMPLOYEE"; const [development, total] = await AppDataSource.getRepository(DevelopmentHistory) .createQueryBuilder("developmentHistory") - // .andWhere(year == null ? "developmentHistory.year LIKE :year" : "1=1", { year: `${year}` }) - // .orWhere("developmentHistory.projectName LIKE :keyword", { keyword: `${keyword}` }) - // .select(["development.id", "development.projectName", "development.year"]) - // .orderBy("developmentHistory.year", "DESC") + .leftJoinAndSelect("developmentHistory.development", "development") + .leftJoinAndSelect("developmentHistory.employeePosLevel", "employeePosLevel") + .leftJoinAndSelect("developmentHistory.employeePosType", "employeePosType") + .andWhere("development.year = :year", { year: year }) + .andWhere("developmentHistory.type = :type", { type: type }) + .andWhere( + new Brackets((qb) => { + qb.where( + keyword != null && keyword != "" + ? "developmentHistory.prefix LIKE :keyword" + : "1=1", + { + keyword: `%${keyword}%`, + }, + ) + .orWhere( + keyword != null && keyword != "" + ? "developmentHistory.firstName LIKE :keyword" + : "1=1", + { + keyword: `%${keyword}%`, + }, + ) + .orWhere( + keyword != null && keyword != "" + ? "developmentHistory.lastName LIKE :keyword" + : "1=1", + { + keyword: `%${keyword}%`, + }, + ) + .orWhere( + keyword != null && keyword != "" + ? "developmentHistory.position LIKE :keyword" + : "1=1", + { + keyword: `%${keyword}%`, + }, + ) + .orWhere( + keyword != null && keyword != "" + ? "developmentHistory.position LIKE :keyword" + : "1=1", + { + keyword: `%${keyword}%`, + }, + ) + .orWhere( + keyword != null && keyword != "" + ? "development.projectName LIKE :keyword" + : "1=1", + { + keyword: `%${keyword}%`, + }, + ) + .orWhere( + keyword != null && keyword != "" + ? "employeePosType.posTypeName LIKE :keyword" + : "1=1", + { + keyword: `%${keyword}%`, + }, + ) + .orWhere( + keyword != null && keyword != "" + ? "employeePosLevel.posLevelName LIKE :keyword" + : "1=1", + { + keyword: `%${keyword}%`, + }, + ); + }), + ) .orderBy("developmentHistory.createdAt", "DESC") .skip((page - 1) * pageSize) .take(pageSize) .getManyAndCount(); + + const formattedData = development.map(item => ({ + id: item.id, + citizenId: item.citizenId, + fullName: item.prefix+item.firstName+" "+item.lastName, + position: item.position, + posType: item.employeePosType.posTypeName, + posLevel: item.employeePosLevel.posLevelName, + projectName: item.development.projectName, + })); - return new HttpSuccess({ data: development, total }); + return new HttpSuccess({ data: formattedData, total }); } /** From 59d426f5d5b3a6f3b3d11f2e4628d908a2544bc1 Mon Sep 17 00:00:00 2001 From: Bright Date: Thu, 4 Apr 2024 10:05:34 +0700 Subject: [PATCH 020/250] no message --- src/controllers/DevelopmentHistoryController.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/controllers/DevelopmentHistoryController.ts b/src/controllers/DevelopmentHistoryController.ts index 4a6e123..a905e02 100644 --- a/src/controllers/DevelopmentHistoryController.ts +++ b/src/controllers/DevelopmentHistoryController.ts @@ -192,7 +192,7 @@ export class DevelopmentOfficerHistoryController extends Controller { .leftJoinAndSelect("developmentHistory.development", "development") .leftJoinAndSelect("developmentHistory.posLevel", "posLevel") .leftJoinAndSelect("developmentHistory.posType", "posType") - .andWhere("development.year = :year", { year: year }) + .andWhere(year != 0 || year != null ? "development.year = :year" : "1=1", { year: year }) .andWhere("developmentHistory.type = :type", { type: type }) .andWhere( new Brackets((qb) => { @@ -245,7 +245,7 @@ export class DevelopmentOfficerHistoryController extends Controller { }, ) .orWhere( - keyword != null && keyword != "" + keyword != null && keyword != "" ? "posType.posTypeName LIKE :keyword" : "1=1", { From b4108b879998c257fa13cab02f596495d46cb3f3 Mon Sep 17 00:00:00 2001 From: AdisakKanthawilang Date: Thu, 4 Apr 2024 10:21:53 +0700 Subject: [PATCH 021/250] =?UTF-8?q?=E0=B9=81=E0=B8=81=E0=B9=89=E0=B9=84?= =?UTF-8?q?=E0=B8=82=E0=B8=9F=E0=B8=B4=E0=B8=A7=20devemp?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/DevelopmentEmployeeHistoryController.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/controllers/DevelopmentEmployeeHistoryController.ts b/src/controllers/DevelopmentEmployeeHistoryController.ts index dcdaa1f..2949967 100644 --- a/src/controllers/DevelopmentEmployeeHistoryController.ts +++ b/src/controllers/DevelopmentEmployeeHistoryController.ts @@ -309,8 +309,8 @@ export class DevelopmentEmployeeHistoryController extends Controller { lastName: getDevelopment.lastName ? getDevelopment.lastName : null, citizenId: getDevelopment.citizenId ? getDevelopment.citizenId : null, position: getDevelopment.position ? getDevelopment.position : null, - posLevelId: getDevelopment.posLevelId ? getDevelopment.posLevelId : null, - posTypeId: getDevelopment.posTypeId ? getDevelopment.posTypeId : null, + posLevelId: getDevelopment.employeePosLevelId ? getDevelopment.employeePosLevelId : null, + posTypeId: getDevelopment.employeePosTypeId ? getDevelopment.employeePosTypeId : null, developmentId: getDevelopment.developmentId ? getDevelopment.developmentId : null, order: getDevelopment.order ? getDevelopment.order : null, dateOrder: getDevelopment.dateOrder ? getDevelopment.dateOrder : null, From 6ab68394a52fe14aeb882f95c14170cd11b97b1f Mon Sep 17 00:00:00 2001 From: Bright Date: Thu, 4 Apr 2024 10:42:29 +0700 Subject: [PATCH 022/250] no message --- src/controllers/DevelopmentEmployeeHistoryController.ts | 2 +- src/controllers/DevelopmentHistoryController.ts | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/controllers/DevelopmentEmployeeHistoryController.ts b/src/controllers/DevelopmentEmployeeHistoryController.ts index 2949967..ae36d4e 100644 --- a/src/controllers/DevelopmentEmployeeHistoryController.ts +++ b/src/controllers/DevelopmentEmployeeHistoryController.ts @@ -196,7 +196,7 @@ export class DevelopmentEmployeeHistoryController extends Controller { .leftJoinAndSelect("developmentHistory.development", "development") .leftJoinAndSelect("developmentHistory.employeePosLevel", "employeePosLevel") .leftJoinAndSelect("developmentHistory.employeePosType", "employeePosType") - .andWhere("development.year = :year", { year: year }) + .andWhere(year != 0 || year != null || year != undefined ? "development.year = :year" : "1=1", { year: year }) .andWhere("developmentHistory.type = :type", { type: type }) .andWhere( new Brackets((qb) => { diff --git a/src/controllers/DevelopmentHistoryController.ts b/src/controllers/DevelopmentHistoryController.ts index a905e02..429b4c2 100644 --- a/src/controllers/DevelopmentHistoryController.ts +++ b/src/controllers/DevelopmentHistoryController.ts @@ -192,7 +192,7 @@ export class DevelopmentOfficerHistoryController extends Controller { .leftJoinAndSelect("developmentHistory.development", "development") .leftJoinAndSelect("developmentHistory.posLevel", "posLevel") .leftJoinAndSelect("developmentHistory.posType", "posType") - .andWhere(year != 0 || year != null ? "development.year = :year" : "1=1", { year: year }) + .andWhere(year != 0 || year != null || year != undefined ? "development.year = :year" : "1=1", { year: year }) .andWhere("developmentHistory.type = :type", { type: type }) .andWhere( new Brackets((qb) => { @@ -274,6 +274,7 @@ export class DevelopmentOfficerHistoryController extends Controller { position: item.position, posType: item.posType.posTypeName, posLevel: item.posLevel.posLevelName, + posExecutive: item.posExecutive, projectName: item.development.projectName, })); From d3ecbf3bd1495057988c0da29dabf319e70d459a Mon Sep 17 00:00:00 2001 From: Bright Date: Thu, 4 Apr 2024 11:31:42 +0700 Subject: [PATCH 023/250] =?UTF-8?q?=E0=B8=94=E0=B8=B1=E0=B8=81=20posType,?= =?UTF-8?q?=20posLevel=20=E0=B8=A1=E0=B8=B5=E0=B8=84=E0=B9=88=E0=B8=B2=20n?= =?UTF-8?q?ull?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/DevelopmentEmployeeHistoryController.ts | 6 +++--- src/controllers/DevelopmentHistoryController.ts | 7 +++---- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/controllers/DevelopmentEmployeeHistoryController.ts b/src/controllers/DevelopmentEmployeeHistoryController.ts index ae36d4e..2b1f386 100644 --- a/src/controllers/DevelopmentEmployeeHistoryController.ts +++ b/src/controllers/DevelopmentEmployeeHistoryController.ts @@ -196,7 +196,7 @@ export class DevelopmentEmployeeHistoryController extends Controller { .leftJoinAndSelect("developmentHistory.development", "development") .leftJoinAndSelect("developmentHistory.employeePosLevel", "employeePosLevel") .leftJoinAndSelect("developmentHistory.employeePosType", "employeePosType") - .andWhere(year != 0 || year != null || year != undefined ? "development.year = :year" : "1=1", { year: year }) + .andWhere(year != 0 && year != null && year != undefined ? "development.year = :year" : "1=1", { year: year }) .andWhere("developmentHistory.type = :type", { type: type }) .andWhere( new Brackets((qb) => { @@ -276,8 +276,8 @@ export class DevelopmentEmployeeHistoryController extends Controller { citizenId: item.citizenId, fullName: item.prefix+item.firstName+" "+item.lastName, position: item.position, - posType: item.employeePosType.posTypeName, - posLevel: item.employeePosLevel.posLevelName, + posType: item.employeePosType ? item.employeePosType.posTypeName : null, + posLevel: item.employeePosLevel ? item.employeePosLevel.posLevelName : null, projectName: item.development.projectName, })); diff --git a/src/controllers/DevelopmentHistoryController.ts b/src/controllers/DevelopmentHistoryController.ts index 429b4c2..f00ad71 100644 --- a/src/controllers/DevelopmentHistoryController.ts +++ b/src/controllers/DevelopmentHistoryController.ts @@ -192,7 +192,7 @@ export class DevelopmentOfficerHistoryController extends Controller { .leftJoinAndSelect("developmentHistory.development", "development") .leftJoinAndSelect("developmentHistory.posLevel", "posLevel") .leftJoinAndSelect("developmentHistory.posType", "posType") - .andWhere(year != 0 || year != null || year != undefined ? "development.year = :year" : "1=1", { year: year }) + .andWhere(year != 0 && year != null && year != undefined ? "development.year = :year" : "1=1", { year: year }) .andWhere("developmentHistory.type = :type", { type: type }) .andWhere( new Brackets((qb) => { @@ -266,14 +266,13 @@ export class DevelopmentOfficerHistoryController extends Controller { .skip((page - 1) * pageSize) .take(pageSize) .getManyAndCount(); - const formattedData = development.map(item => ({ id: item.id, citizenId: item.citizenId, fullName: item.prefix+item.firstName+" "+item.lastName, position: item.position, - posType: item.posType.posTypeName, - posLevel: item.posLevel.posLevelName, + posType: item.posType ? item.posType.posTypeName : null, + posLevel: item.posLevel ? item.posLevel.posLevelName : null, posExecutive: item.posExecutive, projectName: item.development.projectName, })); From 34902c15d53c17bba9e0d973151ce08deebcdd1f Mon Sep 17 00:00:00 2001 From: AdisakKanthawilang Date: Thu, 4 Apr 2024 14:17:19 +0700 Subject: [PATCH 024/250] devscholarship entity --- src/entities/DevelopmentScholarship.ts | 387 +++++++++++++++++++++++++ 1 file changed, 387 insertions(+) create mode 100644 src/entities/DevelopmentScholarship.ts diff --git a/src/entities/DevelopmentScholarship.ts b/src/entities/DevelopmentScholarship.ts new file mode 100644 index 0000000..29700e2 --- /dev/null +++ b/src/entities/DevelopmentScholarship.ts @@ -0,0 +1,387 @@ +import { Entity, Column, ManyToOne, JoinColumn, Double } from "typeorm"; +import { EntityBase } from "./base/Base"; + +@Entity("developmentScholarship") +export class DevelopmentScholarship extends EntityBase { + + @Column({ + nullable: true, + comment: "ยศ", + length: 40, + default: null, + }) + rank: string; + + @Column({ + nullable: true, + comment: "คำนำหน้าชื่อ", + length: 40, + default: null, + }) + prefix: string; + + @Column({ + nullable: true, + comment: "ชื่อ", + length: 255, + default: null, + }) + firstName: string; + + @Column({ + nullable: true, + comment: "นามสกุล", + length: 255, + default: null, + }) + lastName: string; + + @Column({ + nullable: true, + comment: "เลขประจำตัวประชาชน", + default: null, + length: 13, + }) + citizenId: string; + + @Column({ + nullable: true, + comment: "ตำแหน่ง", + default: null, + length: 255, + }) + position: string; + + @Column({ + nullable: true, + comment: "ชื่อตำแหน่งทางการบริหาร", + length: 255, + default: null, + }) + posExecutive: string; + + @Column({ + nullable: true, + comment: "ยศ(ผู้ค้ำ)", + length: 40, + default: null, + }) + guarantorRank: string; + + @Column({ + nullable: true, + comment: "คำนำหน้าชื่อ(ผู้ค้ำ)", + length: 40, + default: null, + }) + guarantorPrefix: string; + + @Column({ + nullable: true, + comment: "ชื่อ(ผู้ค้ำ)", + length: 255, + default: null, + }) + guarantorFirstName: string; + + @Column({ + nullable: true, + comment: "นามสกุล(ผู้ค้ำ)", + length: 255, + default: null, + }) + guarantorLastName: string; + + @Column({ + nullable: true, + comment: "เลขประจำตัวประชาชน(ผู้ค้ำ)", + default: null, + length: 13, + }) + guarantorCitizenId: string; + + @Column({ + nullable: true, + comment: "ตำแหน่ง(ผู้ค้ำ)", + default: null, + length: 255, + }) + guarantorPosition: string; + + @Column({ + nullable: true, + comment: "ชื่อตำแหน่งทางการบริหาร(ผู้ค้ำ)", + length: 255, + default: null, + }) + guarantorPosExecutive: string; + + @Column({ + nullable: true, + comment: "ปีงบประมาณที่ได้รับทุน", + }) + scholarshipYear: number; + + @Column({ + //แหล่งงบประมาณกทม = BKK , แหล่งงบประมาณอื่นๆ = OTHER + nullable: true, + comment: "แหล่งงบประมาณ", + length: 10, + default: null, + }) + budgetSource: string; + + @Column({ + comment: "งบประมาณที่ได้รับอนุมัติตลอดหลักสูตร", + default: 0, + nullable: true, + type: "double", + }) + budgetApprove: Double; + + @Column({ + nullable: true, + comment: "เลขที่หนังสืออนุมัติ", + length: 40, + default: null, + }) + bookNo: string; + + @Column({ + nullable: true, + type: "date", + comment: "ลงวันที่(หนังสือ)", + default: null, + }) + bookNoDate: Date; + + @Column({ + nullable: true, + type: "date", + comment: "หนังสืออนุมัติเมื่อวันที่", + default: null, + }) + bookApproveDate: Date; + + @Column({ + comment: "ใช้เวลาราชการ", + default: false, + }) + useOfficialTime: boolean; + + @Column({ + nullable: true, + comment: "เปลี่ยนแปลงรายละเอียด", + type: "text", + default: null, + }) + changeDetail: string; + + @Column({ + //การศึกษาในประเทศ = DOMESTICE , + //ฝึกอบรมในประเทศที่ส่งไปพัฒนากับหน่วยวงานภายนอก (หลักสูตรที่ไม่มีการไปต่างประเทศ) = NOABROAD + //ฝึกอบรมในประเทศที่ส่งไปพัฒนากับหน่วยวงานภายนอก (หลักสูตรที่มีการไปต่างประเทศ) = ABROAD + //ฝึกอบรมในประเทศที่ส่งไปพัฒนากับหน่วยวงานภายนอก (หลักสูตรประเภทนักบริหาร) = EXECUTIVE + nullable: true, + comment: "เลือกประเภททุน", + length: 40, + default: null, + }) + scholarshipType: string; + + @Column({ + //ทุน 1 (ก)(ข)(ค) = FUND1 , ทุน 2 (ก)(ข) = FUND2 + nullable: true, + comment: "ประเภททุน", + length: 40, + default: null, + }) + fundType: string; + + @Column({ + nullable: true, + comment: "เลขที่สัญญา", + length: 40, + default: null, + }) + contractNo: string; + + @Column({ + nullable: true, + type: "date", + comment: "ลงวันที่(เลขที่สัญญา)", + default: null, + }) + contractDate: Date; + + @Column({ + nullable: true, + comment: "เลขที่หนังสือรายงานตัวกลับ", + length: 40, + default: null, + }) + reportBackNo: string; + + @Column({ + nullable: true, + type: "date", + comment: "ลงวันที่(เลขที่หนังสือรายงานตัวกลับ)", + default: null, + }) + reportBackNoDate: Date; + + @Column({ + nullable: true, + type: "date", + comment: "รายงานตัวกลับวันที่", + default: null, + }) + reportBackDate: Date; + + //เพิ่มต่อจากนี้ + + @Column({ + nullable: true, + comment: "หลักสูตรการฝึกอบรม", + length: 255, + default: null, + }) + trainingCourseName: string; + + @Column({ + nullable: true, + comment: "สถาบันการศึกษา/หน่วยงานผู้จัดการฝึกอบรม", + length: 255, + default: null, + }) + trainingplaceName: string; + + @Column({ + nullable: true, + type: "date", + comment: "วันที่เริ่มต้นการฝึกอบรม", + default: null, + }) + trainingStartDate: Date; + + @Column({ + nullable: true, + type: "date", + comment: "วันที่สิ้นสุดการฝึกอบรม", + default: null, + }) + trainingEndDate: Date; + + @Column({ + nullable: true, + type: "datetime", + comment: "สถานที่ศึกษาดูงาน", + default: null, + }) + studyTourPlace: Date; + + @Column({ + nullable: true, + type: "datetime", + comment: "หัวข้อไปศึกษาดูงาน", + default: null, + }) + studyTourTopic: Date; + + @Column({ + nullable: true, + comment: "เลขที่คำสั่ง/เลขที่หนังสืออนุมัติ", + default: null, + length: 255, + }) + order: string; + + @Column({ + nullable: true, + type: "datetime", + comment: "คำสั่งลงวันที่/หนังสืออนุมัติลงวันที่", + default: null, + }) + dateOrder: Date; +} +export class CreateDevelopmentHistory { + rank: string | null; + prefix: string | null; + firstName: string | null; + lastName: string | null; + citizenId: string | null; + position: string | null; + posExecutive: string | null; + guarantorType: string | null; + guarantorRank: string | null; + guarantorPrefix: string | null; + guarantorFirstName: string | null; + guarantorLastName: string | null; + guarantorCitizenId: string | null; + guarantorPosition: string | null; + guarantorPosExecutive: string | null; + scholarshipYear: number | null; + budgetSource: string | null; + budgetApprove: Double | null; + bookNo: string | null; + bookDate: Date | null; + bookApproveDate: Date | null; + useOfficialTime: boolean | null; + changeDetail: string | null; + scholarshipType: string | null; + fundType: string | null; + contractNo: string | null; + contractDate: Date | null; + reportBackNo: string | null; + reportBackNoDate: Date | null; + reportBackDate: Date | null; + trainingCourseName: string | null; + trainingplaceName: string | null; + trainingStartDate: Date | null; + trainingEndtDate: Date | null; + order: string | null; + dateOrder: Date | null; + studyTourPlace: Date | null; + studyTourTopic: Date | null; +} + +export class UpdateDevelopmentHistory { + rank: string | null; + prefix: string | null; + firstName: string | null; + lastName: string | null; + citizenId: string | null; + position: string | null; + posExecutive: string | null; + guarantorType: string | null; + guarantorRank: string | null; + guarantorPrefix: string | null; + guarantorFirstName: string | null; + guarantorLastName: string | null; + guarantorCitizenId: string | null; + guarantorPosition: string | null; + guarantorPosExecutive: string | null; + scholarshipYear: number | null; + budgetSource: string | null; + budgetApprove: Double | null; + bookNo: string | null; + bookDate: Date | null; + bookApproveDate: Date | null; + useOfficialTime: boolean | null; + changeDetail: string | null; + scholarshipType: string | null; + fundType: string | null; + contractNo: string | null; + contractDate: Date | null; + reportBackNo: string | null; + reportBackNoDate: Date | null; + reportBackDate: Date | null; + trainingCourseName: string | null; + trainingplaceName: string | null; + trainingStartDate: Date | null; + trainingEndtDate: Date | null; + order: string | null; + dateOrder: Date | null; + studyTourPlace: Date | null; + studyTourTopic: Date | null; +} From 6660ab230b7590cd32f5e7e47e27558dcbb7ae9d Mon Sep 17 00:00:00 2001 From: Bright Date: Thu, 4 Apr 2024 14:40:38 +0700 Subject: [PATCH 025/250] no message --- src/controllers/DevelopmentEmployeeHistoryController.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/controllers/DevelopmentEmployeeHistoryController.ts b/src/controllers/DevelopmentEmployeeHistoryController.ts index 2b1f386..5c05601 100644 --- a/src/controllers/DevelopmentEmployeeHistoryController.ts +++ b/src/controllers/DevelopmentEmployeeHistoryController.ts @@ -85,6 +85,8 @@ export class DevelopmentEmployeeHistoryController extends Controller { development.type = type; development.employeePosTypeId = requestBody.posTypeId; development.employeePosLevelId = requestBody.posLevelId; + development.posTypeId = null; + development.posLevelId = null; development.createdUserId = request.user.sub; development.createdFullName = request.user.name; development.lastUpdateUserId = request.user.sub; From b91ffb1bba80bc5312e931b6dce3ef83730bf639 Mon Sep 17 00:00:00 2001 From: Bright Date: Thu, 4 Apr 2024 14:52:10 +0700 Subject: [PATCH 026/250] no message --- src/controllers/DevelopmentEmployeeHistoryController.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/controllers/DevelopmentEmployeeHistoryController.ts b/src/controllers/DevelopmentEmployeeHistoryController.ts index 5c05601..06cc922 100644 --- a/src/controllers/DevelopmentEmployeeHistoryController.ts +++ b/src/controllers/DevelopmentEmployeeHistoryController.ts @@ -152,6 +152,8 @@ export class DevelopmentEmployeeHistoryController extends Controller { development.type = type; development.employeePosTypeId = requestBody.posTypeId; development.employeePosLevelId = requestBody.posLevelId; + development.posTypeId = null; + development.posLevelId = null; development.lastUpdateUserId = request.user.sub; development.lastUpdateFullName = request.user.name; await this.developmentHistoryRepository.save(development); From c0f6c5ab9d85cd511fa61ebee7f68c246e5f558f Mon Sep 17 00:00:00 2001 From: AdisakKanthawilang Date: Thu, 4 Apr 2024 17:20:44 +0700 Subject: [PATCH 027/250] fix entity and api --- .../DevelopmentEmployeeHistoryController.ts | 4 +- .../DevelopmentHistoryController.ts | 4 +- src/entities/DevelopmentScholarship.ts | 218 ++++++++++++++---- 3 files changed, 183 insertions(+), 43 deletions(-) diff --git a/src/controllers/DevelopmentEmployeeHistoryController.ts b/src/controllers/DevelopmentEmployeeHistoryController.ts index 2b1f386..d0ab136 100644 --- a/src/controllers/DevelopmentEmployeeHistoryController.ts +++ b/src/controllers/DevelopmentEmployeeHistoryController.ts @@ -295,7 +295,7 @@ export class DevelopmentEmployeeHistoryController extends Controller { async GetDevelopemtHistoryById(@Path() id: string) { const type = "EMPLOYEE"; const getDevelopment = await this.developmentHistoryRepository.findOne({ - relations: ["development"], + relations: ["development","employeePosLevel","employeePosType"], where: { id: id, type: type }, }); if (!getDevelopment) { @@ -310,7 +310,9 @@ export class DevelopmentEmployeeHistoryController extends Controller { citizenId: getDevelopment.citizenId ? getDevelopment.citizenId : null, position: getDevelopment.position ? getDevelopment.position : null, posLevelId: getDevelopment.employeePosLevelId ? getDevelopment.employeePosLevelId : null, + posLevelName: getDevelopment.employeePosLevel.posLevelName ? getDevelopment.employeePosLevel.posLevelName : null, posTypeId: getDevelopment.employeePosTypeId ? getDevelopment.employeePosTypeId : null, + posTypeName: getDevelopment.employeePosType.posTypeName ? getDevelopment.employeePosType.posTypeName : null, developmentId: getDevelopment.developmentId ? getDevelopment.developmentId : null, order: getDevelopment.order ? getDevelopment.order : null, dateOrder: getDevelopment.dateOrder ? getDevelopment.dateOrder : null, diff --git a/src/controllers/DevelopmentHistoryController.ts b/src/controllers/DevelopmentHistoryController.ts index f00ad71..ea8f9cc 100644 --- a/src/controllers/DevelopmentHistoryController.ts +++ b/src/controllers/DevelopmentHistoryController.ts @@ -291,7 +291,7 @@ export class DevelopmentOfficerHistoryController extends Controller { async GetDevelopemtHistoryById(@Path() id: string) { const type = "OFFICER"; const getDevelopment = await this.developmentHistoryRepository.findOne({ - relations: ["development"], + relations: ["development","posLevel","posType"], where: { id: id, type: type }, }); if (!getDevelopment) { @@ -306,7 +306,9 @@ export class DevelopmentOfficerHistoryController extends Controller { citizenId: getDevelopment.citizenId ? getDevelopment.citizenId : null, position: getDevelopment.position ? getDevelopment.position : null, posLevelId: getDevelopment.posLevelId ? getDevelopment.posLevelId : null, + posLevelName: getDevelopment.posLevel.posLevelName ? getDevelopment.posLevel.posLevelName : null, posTypeId: getDevelopment.posTypeId ? getDevelopment.posTypeId : null, + posTypeName: getDevelopment.posType.posTypeName ? getDevelopment.posType.posTypeName : null, developmentId: getDevelopment.developmentId ? getDevelopment.developmentId : null, order: getDevelopment.order ? getDevelopment.order : null, dateOrder: getDevelopment.dateOrder ? getDevelopment.dateOrder : null, diff --git a/src/entities/DevelopmentScholarship.ts b/src/entities/DevelopmentScholarship.ts index 29700e2..fe2a478 100644 --- a/src/entities/DevelopmentScholarship.ts +++ b/src/entities/DevelopmentScholarship.ts @@ -3,7 +3,6 @@ import { EntityBase } from "./base/Base"; @Entity("developmentScholarship") export class DevelopmentScholarship extends EntityBase { - @Column({ nullable: true, comment: "ยศ", @@ -238,7 +237,134 @@ export class DevelopmentScholarship extends EntityBase { }) reportBackDate: Date; - //เพิ่มต่อจากนี้ + @Column({ + //ปริญญาตรี = BACHELOR , ปริญญาโท = GRADUATE , ปริญญาเอก = MASTER , ปริญญาดุษฎีบัณฑิต = DOCTOR + nullable: true, + comment: "ระดับปริญญา", + length: 10, + default: null, + }) + degreeLevel: string; + + @Column({ + nullable: true, + comment: "หลักสูตรการศึกษา", + length: 255, + default: null, + }) + courseOfStudy: string; + + @Column({ + nullable: true, + comment: "สาขาวิชา", + length: 255, + default: null, + }) + fieldOfStudy: string; + + @Column({ + nullable: true, + comment: "คณะ", + length: 255, + default: null, + }) + faculty: string; + + @Column({ + nullable: true, + comment: "สถาบันการศึกษา", + length: 255, + default: null, + }) + educationalInstitution: string; + + @Column({ + nullable: true, + comment: "วันเริ่มต้นการศึกษา", + length: 255, + default: null, + }) + studyStartDate: string; + + @Column({ + nullable: true, + comment: "วันสิ้นสุดการศึกษา", + length: 255, + default: null, + }) + studyEndDate: string; + + @Column({ + nullable: true, + type: "datetime", + comment: "สถานที่ไปศึกษาดูงาน", + default: null, + }) + studyTourPlace: Date; + + @Column({ + nullable: true, + type: "datetime", + comment: "หัวข้อการไปศึกษาดูงาน", + default: null, + }) + studyTourTopic: Date; + + @Column({ + nullable: true, + type: "datetime", + comment: "วันเริ่มต้นการศึกษาดูงาน", + default: null, + }) + studyTourStartDate: Date; + + @Column({ + nullable: true, + type: "datetime", + comment: "วันสิ้นสุดการศึกษาดูงาน", + default: null, + }) + studyTourEndDate: Date; + + @Column({ + nullable: true, + comment: "ประเทศที่เดินทางไปศึกษาดูงาน", + length: 255, + default: null, + }) + studyTourCountry: string; + + @Column({ + nullable: true, + comment: "หัวข้อการไปศึกษาดูงานต่างประเทศ", + length: 255, + default: null, + }) + studyTourAbroadTopic: string; + + @Column({ + nullable: true, + type: "datetime", + comment: "วันเริ่มต้นการศึกษาดูงานต่างประเทศ", + default: null, + }) + studyTourAbroadStartDate: Date; + + @Column({ + nullable: true, + type: "datetime", + comment: "วันสิ้นสุดการศึกษาดูงานต่างประเทศ", + default: null, + }) + studyTourAbroadEndDate: Date; + + @Column({ + nullable: true, + comment: "รวมระยะเวลาในการศึกษา", + length: 40, + default: null, + }) + totalStudyPeriod: string; @Column({ nullable: true, @@ -248,18 +374,10 @@ export class DevelopmentScholarship extends EntityBase { }) trainingCourseName: string; - @Column({ - nullable: true, - comment: "สถาบันการศึกษา/หน่วยงานผู้จัดการฝึกอบรม", - length: 255, - default: null, - }) - trainingplaceName: string; - @Column({ nullable: true, type: "date", - comment: "วันที่เริ่มต้นการฝึกอบรม", + comment: "วันเริ่มต้นการฝึกอบรม", default: null, }) trainingStartDate: Date; @@ -267,26 +385,18 @@ export class DevelopmentScholarship extends EntityBase { @Column({ nullable: true, type: "date", - comment: "วันที่สิ้นสุดการฝึกอบรม", + comment: "วันสิ้นสุดการฝึกอบรม", default: null, }) trainingEndDate: Date; @Column({ nullable: true, - type: "datetime", - comment: "สถานที่ศึกษาดูงาน", + comment: "รวมระยะเวลาในการฝึกอบรม", + length: 40, default: null, }) - studyTourPlace: Date; - - @Column({ - nullable: true, - type: "datetime", - comment: "หัวข้อไปศึกษาดูงาน", - default: null, - }) - studyTourTopic: Date; + totalTrainingTime: string; @Column({ nullable: true, @@ -304,7 +414,7 @@ export class DevelopmentScholarship extends EntityBase { }) dateOrder: Date; } -export class CreateDevelopmentHistory { +export class CreateDevelopmentScholarship { rank: string | null; prefix: string | null; firstName: string | null; @@ -312,7 +422,6 @@ export class CreateDevelopmentHistory { citizenId: string | null; position: string | null; posExecutive: string | null; - guarantorType: string | null; guarantorRank: string | null; guarantorPrefix: string | null; guarantorFirstName: string | null; @@ -324,7 +433,7 @@ export class CreateDevelopmentHistory { budgetSource: string | null; budgetApprove: Double | null; bookNo: string | null; - bookDate: Date | null; + bookNoDate: Date | null; bookApproveDate: Date | null; useOfficialTime: boolean | null; changeDetail: string | null; @@ -335,17 +444,31 @@ export class CreateDevelopmentHistory { reportBackNo: string | null; reportBackNoDate: Date | null; reportBackDate: Date | null; - trainingCourseName: string | null; - trainingplaceName: string | null; - trainingStartDate: Date | null; - trainingEndtDate: Date | null; - order: string | null; - dateOrder: Date | null; + degreeLevel: string | null; + courseOfStudy: string | null; + fieldOfStudy: string | null; + faculty: string | null; + educationalInstitution: string | null; + studyStartDate: string | null; + studyEndDate: string | null; studyTourPlace: Date | null; studyTourTopic: Date | null; + studyTourStartDate: Date | null; + studyTourEndDate: Date | null; + studyTourCountry: string | null; + studyTourAbroadTopic: string | null; + studyTourAbroadStartDate: Date | null; + studyTourAbroadEndDate: Date | null; + totalStudyPeriod: string | null; + trainingCourseName: string | null; + trainingStartDate: Date | null; + trainingEndDate: Date | null; + totalTrainingTime: string | null; + order: string | null; + dateOrder: Date | null; } -export class UpdateDevelopmentHistory { +export class UpdateDevelopmentScholarship { rank: string | null; prefix: string | null; firstName: string | null; @@ -353,7 +476,6 @@ export class UpdateDevelopmentHistory { citizenId: string | null; position: string | null; posExecutive: string | null; - guarantorType: string | null; guarantorRank: string | null; guarantorPrefix: string | null; guarantorFirstName: string | null; @@ -365,7 +487,7 @@ export class UpdateDevelopmentHistory { budgetSource: string | null; budgetApprove: Double | null; bookNo: string | null; - bookDate: Date | null; + bookNoDate: Date | null; bookApproveDate: Date | null; useOfficialTime: boolean | null; changeDetail: string | null; @@ -376,12 +498,26 @@ export class UpdateDevelopmentHistory { reportBackNo: string | null; reportBackNoDate: Date | null; reportBackDate: Date | null; - trainingCourseName: string | null; - trainingplaceName: string | null; - trainingStartDate: Date | null; - trainingEndtDate: Date | null; - order: string | null; - dateOrder: Date | null; + degreeLevel: string | null; + courseOfStudy: string | null; + fieldOfStudy: string | null; + faculty: string | null; + educationalInstitution: string | null; + studyStartDate: string | null; + studyEndDate: string | null; studyTourPlace: Date | null; studyTourTopic: Date | null; + studyTourStartDate: Date | null; + studyTourEndDate: Date | null; + studyTourCountry: string | null; + studyTourAbroadTopic: string | null; + studyTourAbroadStartDate: Date | null; + studyTourAbroadEndDate: Date | null; + totalStudyPeriod: string | null; + trainingCourseName: string | null; + trainingStartDate: Date | null; + trainingEndDate: Date | null; + totalTrainingTime: string | null; + order: string | null; + dateOrder: Date | null; } From 288266fbdaffab59378f3e0105a62d5f9ab9dcc5 Mon Sep 17 00:00:00 2001 From: AdisakKanthawilang Date: Thu, 4 Apr 2024 17:48:41 +0700 Subject: [PATCH 028/250] fix api --- src/controllers/DevelopmentHistoryController.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/controllers/DevelopmentHistoryController.ts b/src/controllers/DevelopmentHistoryController.ts index ea8f9cc..eb5055e 100644 --- a/src/controllers/DevelopmentHistoryController.ts +++ b/src/controllers/DevelopmentHistoryController.ts @@ -309,6 +309,7 @@ export class DevelopmentOfficerHistoryController extends Controller { posLevelName: getDevelopment.posLevel.posLevelName ? getDevelopment.posLevel.posLevelName : null, posTypeId: getDevelopment.posTypeId ? getDevelopment.posTypeId : null, posTypeName: getDevelopment.posType.posTypeName ? getDevelopment.posType.posTypeName : null, + posExecutive: getDevelopment.posExecutive ? getDevelopment.posExecutive : null, developmentId: getDevelopment.developmentId ? getDevelopment.developmentId : null, order: getDevelopment.order ? getDevelopment.order : null, dateOrder: getDevelopment.dateOrder ? getDevelopment.dateOrder : null, From daaa18b3c1b0a0821c313bf3fe7155a429458020 Mon Sep 17 00:00:00 2001 From: Kittapath Date: Thu, 4 Apr 2024 17:52:47 +0700 Subject: [PATCH 029/250] migrate --- .../1712227929512-add_table_devscholar.ts | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 src/migration/1712227929512-add_table_devscholar.ts diff --git a/src/migration/1712227929512-add_table_devscholar.ts b/src/migration/1712227929512-add_table_devscholar.ts new file mode 100644 index 0000000..8cb8817 --- /dev/null +++ b/src/migration/1712227929512-add_table_devscholar.ts @@ -0,0 +1,14 @@ +import { MigrationInterface, QueryRunner } from "typeorm"; + +export class AddTableDevscholar1712227929512 implements MigrationInterface { + name = 'AddTableDevscholar1712227929512' + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(`CREATE TABLE \`developmentScholarship\` (\`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', \`rank\` varchar(40) NULL COMMENT 'ยศ', \`prefix\` varchar(40) NULL COMMENT 'คำนำหน้าชื่อ', \`firstName\` varchar(255) NULL COMMENT 'ชื่อ', \`lastName\` varchar(255) NULL COMMENT 'นามสกุล', \`citizenId\` varchar(13) NULL COMMENT 'เลขประจำตัวประชาชน', \`position\` varchar(255) NULL COMMENT 'ตำแหน่ง', \`posExecutive\` varchar(255) NULL COMMENT 'ชื่อตำแหน่งทางการบริหาร', \`guarantorRank\` varchar(40) NULL COMMENT 'ยศ(ผู้ค้ำ)', \`guarantorPrefix\` varchar(40) NULL COMMENT 'คำนำหน้าชื่อ(ผู้ค้ำ)', \`guarantorFirstName\` varchar(255) NULL COMMENT 'ชื่อ(ผู้ค้ำ)', \`guarantorLastName\` varchar(255) NULL COMMENT 'นามสกุล(ผู้ค้ำ)', \`guarantorCitizenId\` varchar(13) NULL COMMENT 'เลขประจำตัวประชาชน(ผู้ค้ำ)', \`guarantorPosition\` varchar(255) NULL COMMENT 'ตำแหน่ง(ผู้ค้ำ)', \`guarantorPosExecutive\` varchar(255) NULL COMMENT 'ชื่อตำแหน่งทางการบริหาร(ผู้ค้ำ)', \`scholarshipYear\` int NULL COMMENT 'ปีงบประมาณที่ได้รับทุน', \`budgetSource\` varchar(10) NULL COMMENT 'แหล่งงบประมาณ', \`budgetApprove\` double NULL COMMENT 'งบประมาณที่ได้รับอนุมัติตลอดหลักสูตร' DEFAULT '0', \`bookNo\` varchar(40) NULL COMMENT 'เลขที่หนังสืออนุมัติ', \`bookNoDate\` date NULL COMMENT 'ลงวันที่(หนังสือ)', \`bookApproveDate\` date NULL COMMENT 'หนังสืออนุมัติเมื่อวันที่', \`useOfficialTime\` tinyint NOT NULL COMMENT 'ใช้เวลาราชการ' DEFAULT 0, \`changeDetail\` text NULL COMMENT 'เปลี่ยนแปลงรายละเอียด', \`scholarshipType\` varchar(40) NULL COMMENT 'เลือกประเภททุน', \`fundType\` varchar(40) NULL COMMENT 'ประเภททุน', \`contractNo\` varchar(40) NULL COMMENT 'เลขที่สัญญา', \`contractDate\` date NULL COMMENT 'ลงวันที่(เลขที่สัญญา)', \`reportBackNo\` varchar(40) NULL COMMENT 'เลขที่หนังสือรายงานตัวกลับ', \`reportBackNoDate\` date NULL COMMENT 'ลงวันที่(เลขที่หนังสือรายงานตัวกลับ)', \`reportBackDate\` date NULL COMMENT 'รายงานตัวกลับวันที่', \`degreeLevel\` varchar(10) NULL COMMENT 'ระดับปริญญา', \`courseOfStudy\` varchar(255) NULL COMMENT 'หลักสูตรการศึกษา', \`fieldOfStudy\` varchar(255) NULL COMMENT 'สาขาวิชา', \`faculty\` varchar(255) NULL COMMENT 'คณะ', \`educationalInstitution\` varchar(255) NULL COMMENT 'สถาบันการศึกษา', \`studyStartDate\` varchar(255) NULL COMMENT 'วันเริ่มต้นการศึกษา', \`studyEndDate\` varchar(255) NULL COMMENT 'วันสิ้นสุดการศึกษา', \`studyTourPlace\` datetime NULL COMMENT 'สถานที่ไปศึกษาดูงาน', \`studyTourTopic\` datetime NULL COMMENT 'หัวข้อการไปศึกษาดูงาน', \`studyTourStartDate\` datetime NULL COMMENT 'วันเริ่มต้นการศึกษาดูงาน', \`studyTourEndDate\` datetime NULL COMMENT 'วันสิ้นสุดการศึกษาดูงาน', \`studyTourCountry\` varchar(255) NULL COMMENT 'ประเทศที่เดินทางไปศึกษาดูงาน', \`studyTourAbroadTopic\` varchar(255) NULL COMMENT 'หัวข้อการไปศึกษาดูงานต่างประเทศ', \`studyTourAbroadStartDate\` datetime NULL COMMENT 'วันเริ่มต้นการศึกษาดูงานต่างประเทศ', \`studyTourAbroadEndDate\` datetime NULL COMMENT 'วันสิ้นสุดการศึกษาดูงานต่างประเทศ', \`totalStudyPeriod\` varchar(40) NULL COMMENT 'รวมระยะเวลาในการศึกษา', \`trainingCourseName\` varchar(255) NULL COMMENT 'หลักสูตรการฝึกอบรม', \`trainingStartDate\` date NULL COMMENT 'วันเริ่มต้นการฝึกอบรม', \`trainingEndDate\` date NULL COMMENT 'วันสิ้นสุดการฝึกอบรม', \`totalTrainingTime\` varchar(40) NULL COMMENT 'รวมระยะเวลาในการฝึกอบรม', \`order\` varchar(255) NULL COMMENT 'เลขที่คำสั่ง/เลขที่หนังสืออนุมัติ', \`dateOrder\` datetime NULL COMMENT 'คำสั่งลงวันที่/หนังสืออนุมัติลงวันที่', PRIMARY KEY (\`id\`)) ENGINE=InnoDB`); + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(`DROP TABLE \`developmentScholarship\``); + } + +} From 7e9aa4e0faf14dc34837561e7e560c6abe432fb4 Mon Sep 17 00:00:00 2001 From: Bright Date: Thu, 4 Apr 2024 18:05:18 +0700 Subject: [PATCH 030/250] no message --- .../DevelopmentScholarshipController.ts | 327 ++++++++++++++++++ tsoa.json | 3 + 2 files changed, 330 insertions(+) create mode 100644 src/controllers/DevelopmentScholarshipController.ts diff --git a/src/controllers/DevelopmentScholarshipController.ts b/src/controllers/DevelopmentScholarshipController.ts new file mode 100644 index 0000000..31a6767 --- /dev/null +++ b/src/controllers/DevelopmentScholarshipController.ts @@ -0,0 +1,327 @@ +import { + Controller, + Get, + Post, + Put, + Delete, + Route, + Security, + Tags, + Body, + Path, + Request, + Query, +} from "tsoa"; +import { AppDataSource } from "../database/data-source"; +import { Brackets, Not } from "typeorm"; +import HttpSuccess from "../interfaces/http-success"; +import HttpError from "../interfaces/http-error"; +import HttpStatusCode from "../interfaces/http-status"; +import { Development } from "../entities/Development"; +import { + CreateDevelopmentHistory, + DevelopmentHistory, + UpdateDevelopmentHistory, +} from "../entities/DevelopmentHistory"; +import { PosType } from "../entities/PosType"; +import { PosLevel } from "../entities/PosLevel"; + +@Route("api/v1/development/scholarship") +@Tags("DevelopmentScholarship") +@Security("bearerAuth") +export class DevelopmentScholarshipController extends Controller { + private developmentHistoryRepository = AppDataSource.getRepository(DevelopmentHistory); + private developmentRepository = AppDataSource.getRepository(Development); + private posTypeRepository = AppDataSource.getRepository(PosType); + private posLevelRepository = AppDataSource.getRepository(PosLevel); + + // /** + // * API เพิ่มประวัติการฝึกอบรม/ดูงาน + // * + // * @summary DEV_006 - เพิ่มประวัติการฝึกอบรม/ดูงาน#6 + // * + // */ + // @Post() + // async CreateDevelopmentHistory( + // @Body() requestBody: CreateDevelopmentHistory, + // @Request() request: { user: Record }, + // ) { + // const type = "OFFICER"; + // const chk_name = await this.developmentHistoryRepository.find({ + // where: { + // citizenId: requestBody.citizenId, + // developmentId: requestBody.developmentId, + // type: type, + // }, + // }); + // if (chk_name.length > 0) { + // throw new HttpError(HttpStatusCode.NOT_FOUND, "ประวัติการฝึกอบรม/ดูงาน มีอยู่ในระบบแล้ว"); + // } + + // const checkId = await this.developmentRepository.findOne({ + // where: { id: requestBody.developmentId }, + // }); + // if (!checkId) { + // throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงการ/หลักสูตรการฝึกอบรม"); + // } + // if (requestBody.posTypeId != null) { + // const checkId = await this.posTypeRepository.findOne({ + // where: { id: requestBody.posTypeId }, + // }); + // if (!checkId) { + // throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลประเภทตำแหน่ง"); + // } + // } + // if (requestBody.posLevelId != null) { + // const checkId = await this.posLevelRepository.findOne({ + // where: { id: requestBody.posLevelId }, + // }); + // if (!checkId) { + // throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลระดับตำแหน่ง"); + // } + // } + + // const development = Object.assign(new DevelopmentHistory(), requestBody); + // development.type = type; + // development.createdUserId = request.user.sub; + // development.createdFullName = request.user.name; + // development.lastUpdateUserId = request.user.sub; + // development.lastUpdateFullName = request.user.name; + // await this.developmentHistoryRepository.save(development); + // return new HttpSuccess(development.id); + // } + +// /** +// * API แก้ไขประวัติการฝึกอบรม/ดูงาน +// * +// * @summary DEV_007 - แก้ไขประวัติการฝึกอบรม/ดูงาน #7 +// * +// * @param {string} id Id โครงการ +// */ +// @Put("{id}") +// async UpdateDevelopmentHistory( +// @Path() id: string, +// @Body() requestBody: UpdateDevelopmentHistory, +// @Request() request: { user: Record }, +// ) { +// const type = "OFFICER"; +// const development = await this.developmentHistoryRepository.findOne({ +// where: { id: id, type: type }, +// }); +// if (!development) { +// throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลประวัติการฝึกอบรม/ดูงานนี้"); +// } +// const chk_name = await this.developmentHistoryRepository.find({ +// where: { +// citizenId: requestBody.citizenId, +// developmentId: requestBody.developmentId, +// type: type, +// id: Not(id), +// }, +// }); +// if (chk_name.length > 0) { +// throw new HttpError(HttpStatusCode.NOT_FOUND, "ประวัติการฝึกอบรม/ดูงาน มีอยู่ในระบบแล้ว"); +// } +// const checkId = await this.developmentRepository.findOne({ +// where: { id: requestBody.developmentId }, +// }); +// if (!checkId) { +// throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงการ/หลักสูตรการฝึกอบรม"); +// } +// if (requestBody.posTypeId != null) { +// const checkId = await this.posTypeRepository.findOne({ +// where: { id: requestBody.posTypeId }, +// }); +// if (!checkId) { +// throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลประเภทตำแหน่ง"); +// } +// } +// if (requestBody.posLevelId != null) { +// const checkId = await this.posLevelRepository.findOne({ +// where: { id: requestBody.posLevelId }, +// }); +// if (!checkId) { +// throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลระดับตำแหน่ง"); +// } +// } +// Object.assign(development, requestBody); +// development.type = type; +// development.lastUpdateUserId = request.user.sub; +// development.lastUpdateFullName = request.user.name; +// await this.developmentHistoryRepository.save(development); +// return new HttpSuccess(development.id); +// } + +// /** +// * API ลบประวัติการฝึกอบรม/ดูงาน +// * +// * @summary DEV_008 - ลบประวัติการฝึกอบรม/ดูงาน #8 +// * +// * @param {string} id Id โครงการ +// */ +// @Delete("{id}") +// async DeleteDevelopmentHistory(@Path() id: string) { +// const type = "OFFICER"; +// const development = await this.developmentHistoryRepository.findOne({ +// where: { id: id, type: type }, +// }); +// if (!development) { +// throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลประวัติการฝึกอบรม/ดูงานนี้"); +// } + +// await this.developmentHistoryRepository.remove(development); +// return new HttpSuccess(); +// } + +// /** +// * API รายการประวัติการฝึกอบรม/ดูงาน +// * +// * @summary DEV_009 - รายการประวัติการฝึกอบรม/ดูงาน #9 +// * +// */ +// @Get() +// async GetDevelopmentHistoryLists( +// @Query("page") page: number = 1, +// @Query("pageSize") pageSize: number = 10, +// @Query("keyword") keyword?: string, +// @Query("year") year?: number, +// ) { +// const type = "OFFICER"; +// const [development, total] = await AppDataSource.getRepository(DevelopmentHistory) +// .createQueryBuilder("developmentHistory") +// .leftJoinAndSelect("developmentHistory.development", "development") +// .leftJoinAndSelect("developmentHistory.posLevel", "posLevel") +// .leftJoinAndSelect("developmentHistory.posType", "posType") +// .andWhere(year != 0 && year != null && year != undefined ? "development.year = :year" : "1=1", { year: year }) +// .andWhere("developmentHistory.type = :type", { type: type }) +// .andWhere( +// new Brackets((qb) => { +// qb.where( +// keyword != null && keyword != "" +// ? "developmentHistory.prefix LIKE :keyword" +// : "1=1", +// { +// keyword: `%${keyword}%`, +// }, +// ) +// .orWhere( +// keyword != null && keyword != "" +// ? "developmentHistory.firstName LIKE :keyword" +// : "1=1", +// { +// keyword: `%${keyword}%`, +// }, +// ) +// .orWhere( +// keyword != null && keyword != "" +// ? "developmentHistory.lastName LIKE :keyword" +// : "1=1", +// { +// keyword: `%${keyword}%`, +// }, +// ) +// .orWhere( +// keyword != null && keyword != "" +// ? "developmentHistory.position LIKE :keyword" +// : "1=1", +// { +// keyword: `%${keyword}%`, +// }, +// ) +// .orWhere( +// keyword != null && keyword != "" +// ? "developmentHistory.position LIKE :keyword" +// : "1=1", +// { +// keyword: `%${keyword}%`, +// }, +// ) +// .orWhere( +// keyword != null && keyword != "" +// ? "development.projectName LIKE :keyword" +// : "1=1", +// { +// keyword: `%${keyword}%`, +// }, +// ) +// .orWhere( +// keyword != null && keyword != "" +// ? "posType.posTypeName LIKE :keyword" +// : "1=1", +// { +// keyword: `%${keyword}%`, +// }, +// ) +// .orWhere( +// keyword != null && keyword != "" +// ? "posLevel.posLevelName LIKE :keyword" +// : "1=1", +// { +// keyword: `%${keyword}%`, +// }, +// ); +// }), +// ) +// .orderBy("developmentHistory.createdAt", "DESC") +// .skip((page - 1) * pageSize) +// .take(pageSize) +// .getManyAndCount(); +// const formattedData = development.map(item => ({ +// id: item.id, +// citizenId: item.citizenId, +// fullName: item.prefix+item.firstName+" "+item.lastName, +// position: item.position, +// posType: item.posType ? item.posType.posTypeName : null, +// posLevel: item.posLevel ? item.posLevel.posLevelName : null, +// posExecutive: item.posExecutive, +// projectName: item.development.projectName, +// })); + +// return new HttpSuccess({ data: formattedData, total }); +// } + +// /** +// * API รายละเอียดประวัติการฝึกอบรม/ดูงาน +// * +// * @summary DEV_010 - รายละเอียดประวัติการฝึกอบรม/ดูงาน #10 +// * +// * @param {string} id Id โครงการ +// */ +// @Get("{id}") +// async GetDevelopemtHistoryById(@Path() id: string) { +// const type = "OFFICER"; +// const getDevelopment = await this.developmentHistoryRepository.findOne({ +// relations: ["development"], +// where: { id: id, type: type }, +// }); +// if (!getDevelopment) { +// throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลประวัติการฝึกอบรม/ดูงานนี้"); +// } + +// const formattedData = { +// rank: getDevelopment.rank ? getDevelopment.rank : null, +// prefix: getDevelopment.prefix ? getDevelopment.prefix : null, +// firstName: getDevelopment.firstName ? getDevelopment.firstName : null, +// lastName: getDevelopment.lastName ? getDevelopment.lastName : null, +// citizenId: getDevelopment.citizenId ? getDevelopment.citizenId : null, +// position: getDevelopment.position ? getDevelopment.position : null, +// posLevelId: getDevelopment.posLevelId ? getDevelopment.posLevelId : null, +// posTypeId: getDevelopment.posTypeId ? getDevelopment.posTypeId : null, +// developmentId: getDevelopment.developmentId ? getDevelopment.developmentId : null, +// order: getDevelopment.order ? getDevelopment.order : null, +// dateOrder: getDevelopment.dateOrder ? getDevelopment.dateOrder : null, +// year: getDevelopment.development.year ? getDevelopment.development.year : null, +// projectName: getDevelopment.development.projectName ? getDevelopment.development.projectName : null, +// dateStart: getDevelopment.development.dateStart ? getDevelopment.development.dateStart : null, +// dateEnd: getDevelopment.development.dateEnd ? getDevelopment.development.dateEnd : null, +// totalDate: getDevelopment.development.totalDate ? getDevelopment.development.totalDate : null, +// addressAcademic: getDevelopment.development.addressAcademic ? getDevelopment.development.addressAcademic : null, +// topicAcademic: getDevelopment.development.topicAcademic ? getDevelopment.development.topicAcademic : null, +// dateStudyStart: getDevelopment.development.dateStudyStart ? getDevelopment.development.dateStudyStart : null, +// dateStudyEnd: getDevelopment.development.dateStudyEnd ? getDevelopment.development.dateStudyEnd : null, +// org: null, +// }; + +// return new HttpSuccess(formattedData); +// } +} diff --git a/tsoa.json b/tsoa.json index 63f028c..3475583 100644 --- a/tsoa.json +++ b/tsoa.json @@ -37,6 +37,9 @@ }, { "name": "DevelopmentEmployeeHistory", "description": "ประวัติการฝึกอบรม/ดูงานลูกจ้าง." + }, + { + "name": "DevelopmentScholarship", "description": "ทุนการศึกษา/ฝึกอบรม" } ] }, From de746486d18db6b58ab1d3efdf40bea2017c849b Mon Sep 17 00:00:00 2001 From: Kittapath Date: Thu, 4 Apr 2024 19:59:28 +0700 Subject: [PATCH 031/250] =?UTF-8?q?=E0=B9=81=E0=B8=81=E0=B9=89=E0=B8=9F?= =?UTF-8?q?=E0=B8=B4=E0=B8=A7=E0=B8=82=E0=B8=AD=E0=B8=97=E0=B8=B8=E0=B8=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DevelopmentScholarshipController.ts | 502 ++++++++---------- src/entities/DevelopmentScholarship.ts | 235 ++++---- src/entities/PosLevel.ts | 13 + src/entities/PosType.ts | 13 + .../1712235509538-add_table_devscholar1.ts | 98 ++++ 5 files changed, 451 insertions(+), 410 deletions(-) create mode 100644 src/migration/1712235509538-add_table_devscholar1.ts diff --git a/src/controllers/DevelopmentScholarshipController.ts b/src/controllers/DevelopmentScholarshipController.ts index 31a6767..ad7543f 100644 --- a/src/controllers/DevelopmentScholarshipController.ts +++ b/src/controllers/DevelopmentScholarshipController.ts @@ -13,16 +13,15 @@ import { Query, } from "tsoa"; import { AppDataSource } from "../database/data-source"; -import { Brackets, Not } from "typeorm"; +import { Brackets } from "typeorm"; import HttpSuccess from "../interfaces/http-success"; import HttpError from "../interfaces/http-error"; import HttpStatusCode from "../interfaces/http-status"; -import { Development } from "../entities/Development"; import { - CreateDevelopmentHistory, - DevelopmentHistory, - UpdateDevelopmentHistory, -} from "../entities/DevelopmentHistory"; + CreateDevelopmentScholarship, + DevelopmentScholarship, + UpdateDevelopmentScholarship, +} from "../entities/DevelopmentScholarship"; import { PosType } from "../entities/PosType"; import { PosLevel } from "../entities/PosLevel"; @@ -30,298 +29,223 @@ import { PosLevel } from "../entities/PosLevel"; @Tags("DevelopmentScholarship") @Security("bearerAuth") export class DevelopmentScholarshipController extends Controller { - private developmentHistoryRepository = AppDataSource.getRepository(DevelopmentHistory); - private developmentRepository = AppDataSource.getRepository(Development); + private developmentScholarshipRepository = AppDataSource.getRepository(DevelopmentScholarship); private posTypeRepository = AppDataSource.getRepository(PosType); private posLevelRepository = AppDataSource.getRepository(PosLevel); - // /** - // * API เพิ่มประวัติการฝึกอบรม/ดูงาน - // * - // * @summary DEV_006 - เพิ่มประวัติการฝึกอบรม/ดูงาน#6 - // * - // */ - // @Post() - // async CreateDevelopmentHistory( - // @Body() requestBody: CreateDevelopmentHistory, - // @Request() request: { user: Record }, - // ) { - // const type = "OFFICER"; - // const chk_name = await this.developmentHistoryRepository.find({ - // where: { - // citizenId: requestBody.citizenId, - // developmentId: requestBody.developmentId, - // type: type, - // }, - // }); - // if (chk_name.length > 0) { - // throw new HttpError(HttpStatusCode.NOT_FOUND, "ประวัติการฝึกอบรม/ดูงาน มีอยู่ในระบบแล้ว"); - // } + /** + * API เพิ่มทุนการศึกษา/ฝึกอบรม + * + * @summary DEV_011 - เพิ่มทุนการศึกษา/ฝึกอบรม#11 + * + */ + @Post() + async CreateDevelopmentScholarship( + @Body() requestBody: CreateDevelopmentScholarship, + @Request() request: { user: Record }, + ) { + if (requestBody.posTypeId != null) { + const checkId = await this.posTypeRepository.findOne({ + where: { id: requestBody.posTypeId }, + }); + if (!checkId) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลประเภทตำแหน่ง"); + } + } + if (requestBody.posLevelId != null) { + const checkId = await this.posLevelRepository.findOne({ + where: { id: requestBody.posLevelId }, + }); + if (!checkId) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลระดับตำแหน่ง"); + } + } - // const checkId = await this.developmentRepository.findOne({ - // where: { id: requestBody.developmentId }, - // }); - // if (!checkId) { - // throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงการ/หลักสูตรการฝึกอบรม"); - // } - // if (requestBody.posTypeId != null) { - // const checkId = await this.posTypeRepository.findOne({ - // where: { id: requestBody.posTypeId }, - // }); - // if (!checkId) { - // throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลประเภทตำแหน่ง"); - // } - // } - // if (requestBody.posLevelId != null) { - // const checkId = await this.posLevelRepository.findOne({ - // where: { id: requestBody.posLevelId }, - // }); - // if (!checkId) { - // throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลระดับตำแหน่ง"); - // } - // } + const development = Object.assign(new DevelopmentScholarship(), requestBody); + development.createdUserId = request.user.sub; + development.createdFullName = request.user.name; + development.lastUpdateUserId = request.user.sub; + development.lastUpdateFullName = request.user.name; + await this.developmentScholarshipRepository.save(development); + return new HttpSuccess(development.id); + } - // const development = Object.assign(new DevelopmentHistory(), requestBody); - // development.type = type; - // development.createdUserId = request.user.sub; - // development.createdFullName = request.user.name; - // development.lastUpdateUserId = request.user.sub; - // development.lastUpdateFullName = request.user.name; - // await this.developmentHistoryRepository.save(development); - // return new HttpSuccess(development.id); - // } + /** + * API แก้ไขทุนการศึกษา/ฝึกอบรม + * + * @summary DEV_012 - แก้ไขทุนการศึกษา/ฝึกอบรม #12 + * + * @param {string} id Id โครงการ + */ + @Put("{id}") + async UpdateDevelopmentScholarship( + @Path() id: string, + @Body() requestBody: UpdateDevelopmentScholarship, + @Request() request: { user: Record }, + ) { + const development = await this.developmentScholarshipRepository.findOne({ + where: { id: id }, + }); + if (!development) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลทุนการศึกษา/ฝึกอบรมนี้"); + } + if (requestBody.posTypeId != null) { + const checkId = await this.posTypeRepository.findOne({ + where: { id: requestBody.posTypeId }, + }); + if (!checkId) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลประเภทตำแหน่ง"); + } + } + if (requestBody.posLevelId != null) { + const checkId = await this.posLevelRepository.findOne({ + where: { id: requestBody.posLevelId }, + }); + if (!checkId) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลระดับตำแหน่ง"); + } + } + Object.assign(development, requestBody); + development.lastUpdateUserId = request.user.sub; + development.lastUpdateFullName = request.user.name; + await this.developmentScholarshipRepository.save(development); + return new HttpSuccess(development.id); + } -// /** -// * API แก้ไขประวัติการฝึกอบรม/ดูงาน -// * -// * @summary DEV_007 - แก้ไขประวัติการฝึกอบรม/ดูงาน #7 -// * -// * @param {string} id Id โครงการ -// */ -// @Put("{id}") -// async UpdateDevelopmentHistory( -// @Path() id: string, -// @Body() requestBody: UpdateDevelopmentHistory, -// @Request() request: { user: Record }, -// ) { -// const type = "OFFICER"; -// const development = await this.developmentHistoryRepository.findOne({ -// where: { id: id, type: type }, -// }); -// if (!development) { -// throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลประวัติการฝึกอบรม/ดูงานนี้"); -// } -// const chk_name = await this.developmentHistoryRepository.find({ -// where: { -// citizenId: requestBody.citizenId, -// developmentId: requestBody.developmentId, -// type: type, -// id: Not(id), -// }, -// }); -// if (chk_name.length > 0) { -// throw new HttpError(HttpStatusCode.NOT_FOUND, "ประวัติการฝึกอบรม/ดูงาน มีอยู่ในระบบแล้ว"); -// } -// const checkId = await this.developmentRepository.findOne({ -// where: { id: requestBody.developmentId }, -// }); -// if (!checkId) { -// throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงการ/หลักสูตรการฝึกอบรม"); -// } -// if (requestBody.posTypeId != null) { -// const checkId = await this.posTypeRepository.findOne({ -// where: { id: requestBody.posTypeId }, -// }); -// if (!checkId) { -// throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลประเภทตำแหน่ง"); -// } -// } -// if (requestBody.posLevelId != null) { -// const checkId = await this.posLevelRepository.findOne({ -// where: { id: requestBody.posLevelId }, -// }); -// if (!checkId) { -// throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลระดับตำแหน่ง"); -// } -// } -// Object.assign(development, requestBody); -// development.type = type; -// development.lastUpdateUserId = request.user.sub; -// development.lastUpdateFullName = request.user.name; -// await this.developmentHistoryRepository.save(development); -// return new HttpSuccess(development.id); -// } + /** + * API ลบทุนการศึกษา/ฝึกอบรม + * + * @summary DEV_013 - ลบทุนการศึกษา/ฝึกอบรม #13 + * + * @param {string} id Id โครงการ + */ + @Delete("{id}") + async DeleteDevelopmentScholarship(@Path() id: string) { + const development = await this.developmentScholarshipRepository.findOne({ + where: { id: id }, + }); + if (!development) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลทุนการศึกษา/ฝึกอบรมนี้"); + } -// /** -// * API ลบประวัติการฝึกอบรม/ดูงาน -// * -// * @summary DEV_008 - ลบประวัติการฝึกอบรม/ดูงาน #8 -// * -// * @param {string} id Id โครงการ -// */ -// @Delete("{id}") -// async DeleteDevelopmentHistory(@Path() id: string) { -// const type = "OFFICER"; -// const development = await this.developmentHistoryRepository.findOne({ -// where: { id: id, type: type }, -// }); -// if (!development) { -// throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลประวัติการฝึกอบรม/ดูงานนี้"); -// } + await this.developmentScholarshipRepository.remove(development); + return new HttpSuccess(); + } -// await this.developmentHistoryRepository.remove(development); -// return new HttpSuccess(); -// } + /** + * API รายการทุนการศึกษา/ฝึกอบรม + * + * @summary DEV_014 - รายการทุนการศึกษา/ฝึกอบรม #14 + * + */ + @Get() + async GetDevelopmentScholarshipLists( + @Query("page") page: number = 1, + @Query("pageSize") pageSize: number = 10, + @Query("keyword") keyword?: string, + @Query("year") year?: number, + ) { + const type = "OFFICER"; + const [development, total] = await AppDataSource.getRepository(DevelopmentScholarship) + .createQueryBuilder("developmentScholarship") + .leftJoinAndSelect("developmentScholarship.posLevel", "posLevel") + .leftJoinAndSelect("developmentScholarship.posType", "posType") + .andWhere( + year != 0 && year != null && year != undefined + ? "developmentScholarship.scholarshipYear = :scholarshipYear" + : "1=1", + { year: year }, + ) + .andWhere("developmentScholarship.type = :type", { type: type }) + .andWhere( + new Brackets((qb) => { + qb.where( + keyword != null && keyword != "" + ? "developmentScholarship.prefix LIKE :keyword" + : "1=1", + { + keyword: `%${keyword}%`, + }, + ) + .orWhere( + keyword != null && keyword != "" + ? "developmentScholarship.firstName LIKE :keyword" + : "1=1", + { + keyword: `%${keyword}%`, + }, + ) + .orWhere( + keyword != null && keyword != "" + ? "developmentScholarship.lastName LIKE :keyword" + : "1=1", + { + keyword: `%${keyword}%`, + }, + ) + .orWhere( + keyword != null && keyword != "" + ? "developmentScholarship.position LIKE :keyword" + : "1=1", + { + keyword: `%${keyword}%`, + }, + ) + .orWhere( + keyword != null && keyword != "" + ? "developmentScholarship.position LIKE :keyword" + : "1=1", + { + keyword: `%${keyword}%`, + }, + ) + .orWhere( + keyword != null && keyword != "" ? "posType.posTypeName LIKE :keyword" : "1=1", + { + keyword: `%${keyword}%`, + }, + ) + .orWhere( + keyword != null && keyword != "" ? "posLevel.posLevelName LIKE :keyword" : "1=1", + { + keyword: `%${keyword}%`, + }, + ); + }), + ) + .orderBy("developmentScholarship.createdAt", "DESC") + .skip((page - 1) * pageSize) + .take(pageSize) + .getManyAndCount(); + const formattedData = development.map((item) => ({ + id: item.id, + citizenId: item.citizenId, + fullName: item.prefix + item.firstName + " " + item.lastName, + position: item.position, + posType: item.posType ? item.posType.posTypeName : null, + posLevel: item.posLevel ? item.posLevel.posLevelName : null, + posExecutive: item.posExecutive, + })); -// /** -// * API รายการประวัติการฝึกอบรม/ดูงาน -// * -// * @summary DEV_009 - รายการประวัติการฝึกอบรม/ดูงาน #9 -// * -// */ -// @Get() -// async GetDevelopmentHistoryLists( -// @Query("page") page: number = 1, -// @Query("pageSize") pageSize: number = 10, -// @Query("keyword") keyword?: string, -// @Query("year") year?: number, -// ) { -// const type = "OFFICER"; -// const [development, total] = await AppDataSource.getRepository(DevelopmentHistory) -// .createQueryBuilder("developmentHistory") -// .leftJoinAndSelect("developmentHistory.development", "development") -// .leftJoinAndSelect("developmentHistory.posLevel", "posLevel") -// .leftJoinAndSelect("developmentHistory.posType", "posType") -// .andWhere(year != 0 && year != null && year != undefined ? "development.year = :year" : "1=1", { year: year }) -// .andWhere("developmentHistory.type = :type", { type: type }) -// .andWhere( -// new Brackets((qb) => { -// qb.where( -// keyword != null && keyword != "" -// ? "developmentHistory.prefix LIKE :keyword" -// : "1=1", -// { -// keyword: `%${keyword}%`, -// }, -// ) -// .orWhere( -// keyword != null && keyword != "" -// ? "developmentHistory.firstName LIKE :keyword" -// : "1=1", -// { -// keyword: `%${keyword}%`, -// }, -// ) -// .orWhere( -// keyword != null && keyword != "" -// ? "developmentHistory.lastName LIKE :keyword" -// : "1=1", -// { -// keyword: `%${keyword}%`, -// }, -// ) -// .orWhere( -// keyword != null && keyword != "" -// ? "developmentHistory.position LIKE :keyword" -// : "1=1", -// { -// keyword: `%${keyword}%`, -// }, -// ) -// .orWhere( -// keyword != null && keyword != "" -// ? "developmentHistory.position LIKE :keyword" -// : "1=1", -// { -// keyword: `%${keyword}%`, -// }, -// ) -// .orWhere( -// keyword != null && keyword != "" -// ? "development.projectName LIKE :keyword" -// : "1=1", -// { -// keyword: `%${keyword}%`, -// }, -// ) -// .orWhere( -// keyword != null && keyword != "" -// ? "posType.posTypeName LIKE :keyword" -// : "1=1", -// { -// keyword: `%${keyword}%`, -// }, -// ) -// .orWhere( -// keyword != null && keyword != "" -// ? "posLevel.posLevelName LIKE :keyword" -// : "1=1", -// { -// keyword: `%${keyword}%`, -// }, -// ); -// }), -// ) -// .orderBy("developmentHistory.createdAt", "DESC") -// .skip((page - 1) * pageSize) -// .take(pageSize) -// .getManyAndCount(); -// const formattedData = development.map(item => ({ -// id: item.id, -// citizenId: item.citizenId, -// fullName: item.prefix+item.firstName+" "+item.lastName, -// position: item.position, -// posType: item.posType ? item.posType.posTypeName : null, -// posLevel: item.posLevel ? item.posLevel.posLevelName : null, -// posExecutive: item.posExecutive, -// projectName: item.development.projectName, -// })); + return new HttpSuccess({ data: formattedData, total }); + } -// return new HttpSuccess({ data: formattedData, total }); -// } + /** + * API รายละเอียดทุนการศึกษา/ฝึกอบรม + * + * @summary DEV_015 - รายละเอียดทุนการศึกษา/ฝึกอบรม #15 + * + * @param {string} id Id โครงการ + */ + @Get("{id}") + async GetDevelopemtScholarshipById(@Path() id: string) { + const getDevelopment = await this.developmentScholarshipRepository.findOne({ + where: { id: id }, + }); + if (!getDevelopment) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลทุนการศึกษา/ฝึกอบรมนี้"); + } -// /** -// * API รายละเอียดประวัติการฝึกอบรม/ดูงาน -// * -// * @summary DEV_010 - รายละเอียดประวัติการฝึกอบรม/ดูงาน #10 -// * -// * @param {string} id Id โครงการ -// */ -// @Get("{id}") -// async GetDevelopemtHistoryById(@Path() id: string) { -// const type = "OFFICER"; -// const getDevelopment = await this.developmentHistoryRepository.findOne({ -// relations: ["development"], -// where: { id: id, type: type }, -// }); -// if (!getDevelopment) { -// throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลประวัติการฝึกอบรม/ดูงานนี้"); -// } - -// const formattedData = { -// rank: getDevelopment.rank ? getDevelopment.rank : null, -// prefix: getDevelopment.prefix ? getDevelopment.prefix : null, -// firstName: getDevelopment.firstName ? getDevelopment.firstName : null, -// lastName: getDevelopment.lastName ? getDevelopment.lastName : null, -// citizenId: getDevelopment.citizenId ? getDevelopment.citizenId : null, -// position: getDevelopment.position ? getDevelopment.position : null, -// posLevelId: getDevelopment.posLevelId ? getDevelopment.posLevelId : null, -// posTypeId: getDevelopment.posTypeId ? getDevelopment.posTypeId : null, -// developmentId: getDevelopment.developmentId ? getDevelopment.developmentId : null, -// order: getDevelopment.order ? getDevelopment.order : null, -// dateOrder: getDevelopment.dateOrder ? getDevelopment.dateOrder : null, -// year: getDevelopment.development.year ? getDevelopment.development.year : null, -// projectName: getDevelopment.development.projectName ? getDevelopment.development.projectName : null, -// dateStart: getDevelopment.development.dateStart ? getDevelopment.development.dateStart : null, -// dateEnd: getDevelopment.development.dateEnd ? getDevelopment.development.dateEnd : null, -// totalDate: getDevelopment.development.totalDate ? getDevelopment.development.totalDate : null, -// addressAcademic: getDevelopment.development.addressAcademic ? getDevelopment.development.addressAcademic : null, -// topicAcademic: getDevelopment.development.topicAcademic ? getDevelopment.development.topicAcademic : null, -// dateStudyStart: getDevelopment.development.dateStudyStart ? getDevelopment.development.dateStudyStart : null, -// dateStudyEnd: getDevelopment.development.dateStudyEnd ? getDevelopment.development.dateStudyEnd : null, -// org: null, -// }; - -// return new HttpSuccess(formattedData); -// } + return new HttpSuccess(getDevelopment); + } } diff --git a/src/entities/DevelopmentScholarship.ts b/src/entities/DevelopmentScholarship.ts index fe2a478..4cccefa 100644 --- a/src/entities/DevelopmentScholarship.ts +++ b/src/entities/DevelopmentScholarship.ts @@ -1,5 +1,7 @@ import { Entity, Column, ManyToOne, JoinColumn, Double } from "typeorm"; import { EntityBase } from "./base/Base"; +import { PosLevel } from "./PosLevel"; +import { PosType } from "./PosType"; @Entity("developmentScholarship") export class DevelopmentScholarship extends EntityBase { @@ -59,6 +61,28 @@ export class DevelopmentScholarship extends EntityBase { }) posExecutive: string; + @Column({ + nullable: true, + length: 40, + comment: "ไอดีระดับตำแหน่ง", + }) + posLevelId: string | null; + + @ManyToOne(() => PosLevel, (posLevel) => posLevel.developmentScholars) + @JoinColumn({ name: "posLevelId" }) + posLevel: PosLevel; + + @Column({ + nullable: true, + length: 40, + comment: "ไอดีประเภทตำแหน่ง", + }) + posTypeId: string | null; + + @ManyToOne(() => PosType, (posType) => posType.developmentScholars) + @JoinColumn({ name: "posTypeId" }) + posType: PosType; + @Column({ nullable: true, comment: "ยศ(ผู้ค้ำ)", @@ -115,6 +139,28 @@ export class DevelopmentScholarship extends EntityBase { }) guarantorPosExecutive: string; + @Column({ + nullable: true, + length: 40, + comment: "ไอดีระดับตำแหน่ง(ผู้ค้ำ)", + }) + posLevelguarantorId: string | null; + + @ManyToOne(() => PosLevel, (posLevel) => posLevel.developmentScholarGuarantors) + @JoinColumn({ name: "posLevelguarantorId" }) + posLevelguarantor: PosLevel; + + @Column({ + nullable: true, + length: 40, + comment: "ไอดีประเภทตำแหน่ง(ผู้ค้ำ)", + }) + posTypeguarantorId: string | null; + + @ManyToOne(() => PosType, (posType) => posType.developmentScholarGuarantors) + @JoinColumn({ name: "posTypeguarantorId" }) + posTypeguarantor: PosType; + @Column({ nullable: true, comment: "ปีงบประมาณที่ได้รับทุน", @@ -177,7 +223,7 @@ export class DevelopmentScholarship extends EntityBase { changeDetail: string; @Column({ - //การศึกษาในประเทศ = DOMESTICE , + //การศึกษาในประเทศ = DOMESTICE //ฝึกอบรมในประเทศที่ส่งไปพัฒนากับหน่วยวงานภายนอก (หลักสูตรที่ไม่มีการไปต่างประเทศ) = NOABROAD //ฝึกอบรมในประเทศที่ส่งไปพัฒนากับหน่วยวงานภายนอก (หลักสูตรที่มีการไปต่างประเทศ) = ABROAD //ฝึกอบรมในประเทศที่ส่งไปพัฒนากับหน่วยวงานภายนอก (หลักสูตรประเภทนักบริหาร) = EXECUTIVE @@ -238,29 +284,28 @@ export class DevelopmentScholarship extends EntityBase { reportBackDate: Date; @Column({ - //ปริญญาตรี = BACHELOR , ปริญญาโท = GRADUATE , ปริญญาเอก = MASTER , ปริญญาดุษฎีบัณฑิต = DOCTOR nullable: true, comment: "ระดับปริญญา", - length: 10, + length: 255, default: null, }) degreeLevel: string; @Column({ nullable: true, - comment: "หลักสูตรการศึกษา", + comment: "หลักสูตรการศึกษา/หลักสูตรการฝึกอบรม", length: 255, default: null, }) - courseOfStudy: string; + course: string; @Column({ nullable: true, - comment: "สาขาวิชา", + comment: "สาขาวิชา/สาขา", length: 255, default: null, }) - fieldOfStudy: string; + field: string; @Column({ nullable: true, @@ -272,7 +317,7 @@ export class DevelopmentScholarship extends EntityBase { @Column({ nullable: true, - comment: "สถาบันการศึกษา", + comment: "สถาบันการศึกษา/สถาบันการศึกษา_หน่วยงานผู้จัดการฝึกอบรม/สถานที่ไปศึกษาดูงานในประเทศ", length: 255, default: null, }) @@ -280,35 +325,35 @@ export class DevelopmentScholarship extends EntityBase { @Column({ nullable: true, - comment: "วันเริ่มต้นการศึกษา", - length: 255, + type: "datetime", + comment: "วันเริ่มต้นการศึกษา/วันเริ่มต้นการฝึกอบรม/วันเริ่มต้นการศึกษาดูงานในประเทศ", default: null, }) - studyStartDate: string; - - @Column({ - nullable: true, - comment: "วันสิ้นสุดการศึกษา", - length: 255, - default: null, - }) - studyEndDate: string; + startDate: Date; @Column({ nullable: true, type: "datetime", + comment: "วันสิ้นสุดการศึกษา/วันสิ้นสุดการฝึกอบรม/วันสิ้นสุดการศึกษาดูงานในประเทศ", + default: null, + }) + endDate: Date; + + @Column({ + nullable: true, comment: "สถานที่ไปศึกษาดูงาน", + length: 255, default: null, }) - studyTourPlace: Date; + studyPlace: string; @Column({ nullable: true, - type: "datetime", - comment: "หัวข้อการไปศึกษาดูงาน", + comment: "หัวข้อการไปศึกษาดูงาน/หัวข้อการไปศึกษาดูงานในประเทศ", + length: 255, default: null, }) - studyTourTopic: Date; + studyTopic: string; @Column({ nullable: true, @@ -316,7 +361,7 @@ export class DevelopmentScholarship extends EntityBase { comment: "วันเริ่มต้นการศึกษาดูงาน", default: null, }) - studyTourStartDate: Date; + studyStartDate: Date; @Column({ nullable: true, @@ -324,7 +369,7 @@ export class DevelopmentScholarship extends EntityBase { comment: "วันสิ้นสุดการศึกษาดูงาน", default: null, }) - studyTourEndDate: Date; + studyEndDate: Date; @Column({ nullable: true, @@ -332,7 +377,7 @@ export class DevelopmentScholarship extends EntityBase { length: 255, default: null, }) - studyTourCountry: string; + studyCountry: string; @Column({ nullable: true, @@ -340,7 +385,7 @@ export class DevelopmentScholarship extends EntityBase { length: 255, default: null, }) - studyTourAbroadTopic: string; + studyAbroadTopic: string; @Column({ nullable: true, @@ -348,7 +393,7 @@ export class DevelopmentScholarship extends EntityBase { comment: "วันเริ่มต้นการศึกษาดูงานต่างประเทศ", default: null, }) - studyTourAbroadStartDate: Date; + studyAbroadStartDate: Date; @Column({ nullable: true, @@ -356,79 +401,35 @@ export class DevelopmentScholarship extends EntityBase { comment: "วันสิ้นสุดการศึกษาดูงานต่างประเทศ", default: null, }) - studyTourAbroadEndDate: Date; + studyAbroadEndDate: Date; @Column({ nullable: true, - comment: "รวมระยะเวลาในการศึกษา", + comment: "รวมระยะเวลาในการศึกษา/รวมระยะเวลาในการฝึกอบรม", length: 40, default: null, }) - totalStudyPeriod: string; - - @Column({ - nullable: true, - comment: "หลักสูตรการฝึกอบรม", - length: 255, - default: null, - }) - trainingCourseName: string; - - @Column({ - nullable: true, - type: "date", - comment: "วันเริ่มต้นการฝึกอบรม", - default: null, - }) - trainingStartDate: Date; - - @Column({ - nullable: true, - type: "date", - comment: "วันสิ้นสุดการฝึกอบรม", - default: null, - }) - trainingEndDate: Date; - - @Column({ - nullable: true, - comment: "รวมระยะเวลาในการฝึกอบรม", - length: 40, - default: null, - }) - totalTrainingTime: string; - - @Column({ - nullable: true, - comment: "เลขที่คำสั่ง/เลขที่หนังสืออนุมัติ", - default: null, - length: 255, - }) - order: string; - - @Column({ - nullable: true, - type: "datetime", - comment: "คำสั่งลงวันที่/หนังสืออนุมัติลงวันที่", - default: null, - }) - dateOrder: Date; + totalPeriod: string; } export class CreateDevelopmentScholarship { - rank: string | null; + rank?: string | null; prefix: string | null; firstName: string | null; lastName: string | null; citizenId: string | null; position: string | null; posExecutive: string | null; - guarantorRank: string | null; + posLevelId: string | null; + posTypeId: string | null; + guarantorRank?: string | null; guarantorPrefix: string | null; guarantorFirstName: string | null; guarantorLastName: string | null; guarantorCitizenId: string | null; guarantorPosition: string | null; guarantorPosExecutive: string | null; + posLevelguarantorId: string | null; + posTypeguarantorId: string | null; scholarshipYear: number | null; budgetSource: string | null; budgetApprove: Double | null; @@ -445,44 +446,42 @@ export class CreateDevelopmentScholarship { reportBackNoDate: Date | null; reportBackDate: Date | null; degreeLevel: string | null; - courseOfStudy: string | null; - fieldOfStudy: string | null; + course: string | null; + field: string | null; faculty: string | null; educationalInstitution: string | null; - studyStartDate: string | null; - studyEndDate: string | null; - studyTourPlace: Date | null; - studyTourTopic: Date | null; - studyTourStartDate: Date | null; - studyTourEndDate: Date | null; - studyTourCountry: string | null; - studyTourAbroadTopic: string | null; - studyTourAbroadStartDate: Date | null; - studyTourAbroadEndDate: Date | null; - totalStudyPeriod: string | null; - trainingCourseName: string | null; - trainingStartDate: Date | null; - trainingEndDate: Date | null; - totalTrainingTime: string | null; - order: string | null; - dateOrder: Date | null; + startDate: Date | null; + endDate: Date | null; + studyPlace: Date | null; + studyTopic: Date | null; + studyStartDate: Date | null; + studyEndDate: Date | null; + studyCountry: string | null; + studyAbroadTopic: string | null; + studyAbroadStartDate: Date | null; + studyAbroadEndDate: Date | null; + totalPeriod: string | null; } export class UpdateDevelopmentScholarship { - rank: string | null; + rank?: string | null; prefix: string | null; firstName: string | null; lastName: string | null; citizenId: string | null; position: string | null; posExecutive: string | null; - guarantorRank: string | null; + posLevelId: string | null; + posTypeId: string | null; + guarantorRank?: string | null; guarantorPrefix: string | null; guarantorFirstName: string | null; guarantorLastName: string | null; guarantorCitizenId: string | null; guarantorPosition: string | null; guarantorPosExecutive: string | null; + posLevelguarantorId: string | null; + posTypeguarantorId: string | null; scholarshipYear: number | null; budgetSource: string | null; budgetApprove: Double | null; @@ -499,25 +498,19 @@ export class UpdateDevelopmentScholarship { reportBackNoDate: Date | null; reportBackDate: Date | null; degreeLevel: string | null; - courseOfStudy: string | null; - fieldOfStudy: string | null; + course: string | null; + field: string | null; faculty: string | null; educationalInstitution: string | null; - studyStartDate: string | null; - studyEndDate: string | null; - studyTourPlace: Date | null; - studyTourTopic: Date | null; - studyTourStartDate: Date | null; - studyTourEndDate: Date | null; - studyTourCountry: string | null; - studyTourAbroadTopic: string | null; - studyTourAbroadStartDate: Date | null; - studyTourAbroadEndDate: Date | null; - totalStudyPeriod: string | null; - trainingCourseName: string | null; - trainingStartDate: Date | null; - trainingEndDate: Date | null; - totalTrainingTime: string | null; - order: string | null; - dateOrder: Date | null; + startDate: Date | null; + endDate: Date | null; + studyPlace: Date | null; + studyTopic: Date | null; + studyStartDate: Date | null; + studyEndDate: Date | null; + studyCountry: string | null; + studyAbroadTopic: string | null; + studyAbroadStartDate: Date | null; + studyAbroadEndDate: Date | null; + totalPeriod: string | null; } diff --git a/src/entities/PosLevel.ts b/src/entities/PosLevel.ts index cecb35f..e3c526d 100644 --- a/src/entities/PosLevel.ts +++ b/src/entities/PosLevel.ts @@ -4,6 +4,7 @@ import { PosType } from "./PosType"; import { ActualGoal } from "./ActualGoal"; import { PlannedGoal } from "./PlannedGoal"; import { DevelopmentHistory } from "./DevelopmentHistory"; +import { DevelopmentScholarship } from "./DevelopmentScholarship"; enum PosLevelAuthority { HEAD = "HEAD", @@ -55,6 +56,18 @@ export class PosLevel extends EntityBase { @OneToMany(() => DevelopmentHistory, (developmentHistory) => developmentHistory.posLevel) developmentHistorys: DevelopmentHistory[]; + + @OneToMany( + () => DevelopmentScholarship, + (developmentScholarship) => developmentScholarship.posLevel, + ) + developmentScholars: DevelopmentScholarship[]; + + @OneToMany( + () => DevelopmentScholarship, + (developmentScholarship) => developmentScholarship.posLevelguarantor, + ) + developmentScholarGuarantors: DevelopmentScholarship[]; } export class CreatePosLevel { diff --git a/src/entities/PosType.ts b/src/entities/PosType.ts index f6a89f6..6a8574c 100644 --- a/src/entities/PosType.ts +++ b/src/entities/PosType.ts @@ -4,6 +4,7 @@ import { PosLevel } from "./PosLevel"; import { ActualGoal } from "./ActualGoal"; import { PlannedGoal } from "./PlannedGoal"; import { DevelopmentHistory } from "./DevelopmentHistory"; +import { DevelopmentScholarship } from "./DevelopmentScholarship"; @Entity("posType") export class PosType extends EntityBase { @@ -34,6 +35,18 @@ export class PosType extends EntityBase { @OneToMany(() => DevelopmentHistory, (developmentHistory) => developmentHistory.posType) developmentHistorys: DevelopmentHistory[]; + + @OneToMany( + () => DevelopmentScholarship, + (developmentScholarship) => developmentScholarship.posType, + ) + developmentScholars: DevelopmentScholarship[]; + + @OneToMany( + () => DevelopmentScholarship, + (developmentScholarship) => developmentScholarship.posTypeguarantor, + ) + developmentScholarGuarantors: DevelopmentScholarship[]; } export class CreatePosType { diff --git a/src/migration/1712235509538-add_table_devscholar1.ts b/src/migration/1712235509538-add_table_devscholar1.ts new file mode 100644 index 0000000..214598c --- /dev/null +++ b/src/migration/1712235509538-add_table_devscholar1.ts @@ -0,0 +1,98 @@ +import { MigrationInterface, QueryRunner } from "typeorm"; + +export class AddTableDevscholar11712235509538 implements MigrationInterface { + name = 'AddTableDevscholar11712235509538' + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`developmentScholarship\` DROP COLUMN \`courseOfStudy\``); + await queryRunner.query(`ALTER TABLE \`developmentScholarship\` DROP COLUMN \`dateOrder\``); + await queryRunner.query(`ALTER TABLE \`developmentScholarship\` DROP COLUMN \`fieldOfStudy\``); + await queryRunner.query(`ALTER TABLE \`developmentScholarship\` DROP COLUMN \`order\``); + await queryRunner.query(`ALTER TABLE \`developmentScholarship\` DROP COLUMN \`studyTourAbroadEndDate\``); + await queryRunner.query(`ALTER TABLE \`developmentScholarship\` DROP COLUMN \`studyTourAbroadStartDate\``); + await queryRunner.query(`ALTER TABLE \`developmentScholarship\` DROP COLUMN \`studyTourAbroadTopic\``); + await queryRunner.query(`ALTER TABLE \`developmentScholarship\` DROP COLUMN \`studyTourCountry\``); + await queryRunner.query(`ALTER TABLE \`developmentScholarship\` DROP COLUMN \`studyTourEndDate\``); + await queryRunner.query(`ALTER TABLE \`developmentScholarship\` DROP COLUMN \`studyTourPlace\``); + await queryRunner.query(`ALTER TABLE \`developmentScholarship\` DROP COLUMN \`studyTourStartDate\``); + await queryRunner.query(`ALTER TABLE \`developmentScholarship\` DROP COLUMN \`studyTourTopic\``); + await queryRunner.query(`ALTER TABLE \`developmentScholarship\` DROP COLUMN \`totalStudyPeriod\``); + await queryRunner.query(`ALTER TABLE \`developmentScholarship\` DROP COLUMN \`totalTrainingTime\``); + await queryRunner.query(`ALTER TABLE \`developmentScholarship\` DROP COLUMN \`trainingCourseName\``); + await queryRunner.query(`ALTER TABLE \`developmentScholarship\` DROP COLUMN \`trainingEndDate\``); + await queryRunner.query(`ALTER TABLE \`developmentScholarship\` DROP COLUMN \`trainingStartDate\``); + await queryRunner.query(`ALTER TABLE \`developmentScholarship\` ADD \`posLevelId\` varchar(40) NULL COMMENT 'ไอดีระดับตำแหน่ง'`); + await queryRunner.query(`ALTER TABLE \`developmentScholarship\` ADD \`posTypeId\` varchar(40) NULL COMMENT 'ไอดีประเภทตำแหน่ง'`); + await queryRunner.query(`ALTER TABLE \`developmentScholarship\` ADD \`posLevelguarantorId\` varchar(40) NULL COMMENT 'ไอดีระดับตำแหน่ง(ผู้ค้ำ)'`); + await queryRunner.query(`ALTER TABLE \`developmentScholarship\` ADD \`posTypeguarantorId\` varchar(40) NULL COMMENT 'ไอดีประเภทตำแหน่ง(ผู้ค้ำ)'`); + await queryRunner.query(`ALTER TABLE \`developmentScholarship\` ADD \`course\` varchar(255) NULL COMMENT 'หลักสูตรการศึกษา/หลักสูตรการฝึกอบรม'`); + await queryRunner.query(`ALTER TABLE \`developmentScholarship\` ADD \`field\` varchar(255) NULL COMMENT 'สาขาวิชา/สาขา'`); + await queryRunner.query(`ALTER TABLE \`developmentScholarship\` ADD \`startDate\` datetime NULL COMMENT 'วันเริ่มต้นการศึกษา/วันเริ่มต้นการฝึกอบรม/วันเริ่มต้นการศึกษาดูงานในประเทศ'`); + await queryRunner.query(`ALTER TABLE \`developmentScholarship\` ADD \`endDate\` datetime NULL COMMENT 'วันสิ้นสุดการศึกษา/วันสิ้นสุดการฝึกอบรม/วันสิ้นสุดการศึกษาดูงานในประเทศ'`); + await queryRunner.query(`ALTER TABLE \`developmentScholarship\` ADD \`studyPlace\` varchar(255) NULL COMMENT 'สถานที่ไปศึกษาดูงาน'`); + await queryRunner.query(`ALTER TABLE \`developmentScholarship\` ADD \`studyTopic\` varchar(255) NULL COMMENT 'หัวข้อการไปศึกษาดูงาน/หัวข้อการไปศึกษาดูงานในประเทศ'`); + await queryRunner.query(`ALTER TABLE \`developmentScholarship\` ADD \`studyCountry\` varchar(255) NULL COMMENT 'ประเทศที่เดินทางไปศึกษาดูงาน'`); + await queryRunner.query(`ALTER TABLE \`developmentScholarship\` ADD \`studyAbroadTopic\` varchar(255) NULL COMMENT 'หัวข้อการไปศึกษาดูงานต่างประเทศ'`); + await queryRunner.query(`ALTER TABLE \`developmentScholarship\` ADD \`studyAbroadStartDate\` datetime NULL COMMENT 'วันเริ่มต้นการศึกษาดูงานต่างประเทศ'`); + await queryRunner.query(`ALTER TABLE \`developmentScholarship\` ADD \`studyAbroadEndDate\` datetime NULL COMMENT 'วันสิ้นสุดการศึกษาดูงานต่างประเทศ'`); + await queryRunner.query(`ALTER TABLE \`developmentScholarship\` ADD \`totalPeriod\` varchar(40) NULL COMMENT 'รวมระยะเวลาในการศึกษา/รวมระยะเวลาในการฝึกอบรม'`); + await queryRunner.query(`ALTER TABLE \`developmentScholarship\` DROP COLUMN \`degreeLevel\``); + await queryRunner.query(`ALTER TABLE \`developmentScholarship\` ADD \`degreeLevel\` varchar(255) NULL COMMENT 'ระดับปริญญา'`); + await queryRunner.query(`ALTER TABLE \`developmentScholarship\` CHANGE \`educationalInstitution\` \`educationalInstitution\` varchar(255) NULL COMMENT 'สถาบันการศึกษา/สถาบันการศึกษา_หน่วยงานผู้จัดการฝึกอบรม/สถานที่ไปศึกษาดูงานในประเทศ'`); + await queryRunner.query(`ALTER TABLE \`developmentScholarship\` DROP COLUMN \`studyStartDate\``); + await queryRunner.query(`ALTER TABLE \`developmentScholarship\` ADD \`studyStartDate\` datetime NULL COMMENT 'วันเริ่มต้นการศึกษาดูงาน'`); + await queryRunner.query(`ALTER TABLE \`developmentScholarship\` DROP COLUMN \`studyEndDate\``); + await queryRunner.query(`ALTER TABLE \`developmentScholarship\` ADD \`studyEndDate\` datetime NULL COMMENT 'วันสิ้นสุดการศึกษาดูงาน'`); + await queryRunner.query(`ALTER TABLE \`developmentScholarship\` ADD CONSTRAINT \`FK_c95a104dc1c147cd9ffe676097a\` FOREIGN KEY (\`posLevelId\`) REFERENCES \`posLevel\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`); + await queryRunner.query(`ALTER TABLE \`developmentScholarship\` ADD CONSTRAINT \`FK_4f93cbcfe04f319f043ca6bafe8\` FOREIGN KEY (\`posTypeId\`) REFERENCES \`posType\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`); + await queryRunner.query(`ALTER TABLE \`developmentScholarship\` ADD CONSTRAINT \`FK_264f2b2fc644c7173484c3b67d9\` FOREIGN KEY (\`posLevelguarantorId\`) REFERENCES \`posLevel\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`); + await queryRunner.query(`ALTER TABLE \`developmentScholarship\` ADD CONSTRAINT \`FK_5a83bbe2bac1e79113df21ed6ef\` FOREIGN KEY (\`posTypeguarantorId\`) REFERENCES \`posType\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`); + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`developmentScholarship\` DROP FOREIGN KEY \`FK_5a83bbe2bac1e79113df21ed6ef\``); + await queryRunner.query(`ALTER TABLE \`developmentScholarship\` DROP FOREIGN KEY \`FK_264f2b2fc644c7173484c3b67d9\``); + await queryRunner.query(`ALTER TABLE \`developmentScholarship\` DROP FOREIGN KEY \`FK_4f93cbcfe04f319f043ca6bafe8\``); + await queryRunner.query(`ALTER TABLE \`developmentScholarship\` DROP FOREIGN KEY \`FK_c95a104dc1c147cd9ffe676097a\``); + await queryRunner.query(`ALTER TABLE \`developmentScholarship\` DROP COLUMN \`studyEndDate\``); + await queryRunner.query(`ALTER TABLE \`developmentScholarship\` ADD \`studyEndDate\` varchar(255) NULL COMMENT 'วันสิ้นสุดการศึกษา'`); + await queryRunner.query(`ALTER TABLE \`developmentScholarship\` DROP COLUMN \`studyStartDate\``); + await queryRunner.query(`ALTER TABLE \`developmentScholarship\` ADD \`studyStartDate\` varchar(255) NULL COMMENT 'วันเริ่มต้นการศึกษา'`); + await queryRunner.query(`ALTER TABLE \`developmentScholarship\` CHANGE \`educationalInstitution\` \`educationalInstitution\` varchar(255) NULL COMMENT 'สถาบันการศึกษา'`); + await queryRunner.query(`ALTER TABLE \`developmentScholarship\` DROP COLUMN \`degreeLevel\``); + await queryRunner.query(`ALTER TABLE \`developmentScholarship\` ADD \`degreeLevel\` varchar(10) NULL COMMENT 'ระดับปริญญา'`); + await queryRunner.query(`ALTER TABLE \`developmentScholarship\` DROP COLUMN \`totalPeriod\``); + await queryRunner.query(`ALTER TABLE \`developmentScholarship\` DROP COLUMN \`studyAbroadEndDate\``); + await queryRunner.query(`ALTER TABLE \`developmentScholarship\` DROP COLUMN \`studyAbroadStartDate\``); + await queryRunner.query(`ALTER TABLE \`developmentScholarship\` DROP COLUMN \`studyAbroadTopic\``); + await queryRunner.query(`ALTER TABLE \`developmentScholarship\` DROP COLUMN \`studyCountry\``); + await queryRunner.query(`ALTER TABLE \`developmentScholarship\` DROP COLUMN \`studyTopic\``); + await queryRunner.query(`ALTER TABLE \`developmentScholarship\` DROP COLUMN \`studyPlace\``); + await queryRunner.query(`ALTER TABLE \`developmentScholarship\` DROP COLUMN \`endDate\``); + await queryRunner.query(`ALTER TABLE \`developmentScholarship\` DROP COLUMN \`startDate\``); + await queryRunner.query(`ALTER TABLE \`developmentScholarship\` DROP COLUMN \`field\``); + await queryRunner.query(`ALTER TABLE \`developmentScholarship\` DROP COLUMN \`course\``); + await queryRunner.query(`ALTER TABLE \`developmentScholarship\` DROP COLUMN \`posTypeguarantorId\``); + await queryRunner.query(`ALTER TABLE \`developmentScholarship\` DROP COLUMN \`posLevelguarantorId\``); + await queryRunner.query(`ALTER TABLE \`developmentScholarship\` DROP COLUMN \`posTypeId\``); + await queryRunner.query(`ALTER TABLE \`developmentScholarship\` DROP COLUMN \`posLevelId\``); + await queryRunner.query(`ALTER TABLE \`developmentScholarship\` ADD \`trainingStartDate\` date NULL COMMENT 'วันเริ่มต้นการฝึกอบรม'`); + await queryRunner.query(`ALTER TABLE \`developmentScholarship\` ADD \`trainingEndDate\` date NULL COMMENT 'วันสิ้นสุดการฝึกอบรม'`); + await queryRunner.query(`ALTER TABLE \`developmentScholarship\` ADD \`trainingCourseName\` varchar(255) NULL COMMENT 'หลักสูตรการฝึกอบรม'`); + await queryRunner.query(`ALTER TABLE \`developmentScholarship\` ADD \`totalTrainingTime\` varchar(40) NULL COMMENT 'รวมระยะเวลาในการฝึกอบรม'`); + await queryRunner.query(`ALTER TABLE \`developmentScholarship\` ADD \`totalStudyPeriod\` varchar(40) NULL COMMENT 'รวมระยะเวลาในการศึกษา'`); + await queryRunner.query(`ALTER TABLE \`developmentScholarship\` ADD \`studyTourTopic\` datetime NULL COMMENT 'หัวข้อการไปศึกษาดูงาน'`); + await queryRunner.query(`ALTER TABLE \`developmentScholarship\` ADD \`studyTourStartDate\` datetime NULL COMMENT 'วันเริ่มต้นการศึกษาดูงาน'`); + await queryRunner.query(`ALTER TABLE \`developmentScholarship\` ADD \`studyTourPlace\` datetime NULL COMMENT 'สถานที่ไปศึกษาดูงาน'`); + await queryRunner.query(`ALTER TABLE \`developmentScholarship\` ADD \`studyTourEndDate\` datetime NULL COMMENT 'วันสิ้นสุดการศึกษาดูงาน'`); + await queryRunner.query(`ALTER TABLE \`developmentScholarship\` ADD \`studyTourCountry\` varchar(255) NULL COMMENT 'ประเทศที่เดินทางไปศึกษาดูงาน'`); + await queryRunner.query(`ALTER TABLE \`developmentScholarship\` ADD \`studyTourAbroadTopic\` varchar(255) NULL COMMENT 'หัวข้อการไปศึกษาดูงานต่างประเทศ'`); + await queryRunner.query(`ALTER TABLE \`developmentScholarship\` ADD \`studyTourAbroadStartDate\` datetime NULL COMMENT 'วันเริ่มต้นการศึกษาดูงานต่างประเทศ'`); + await queryRunner.query(`ALTER TABLE \`developmentScholarship\` ADD \`studyTourAbroadEndDate\` datetime NULL COMMENT 'วันสิ้นสุดการศึกษาดูงานต่างประเทศ'`); + await queryRunner.query(`ALTER TABLE \`developmentScholarship\` ADD \`order\` varchar(255) NULL COMMENT 'เลขที่คำสั่ง/เลขที่หนังสืออนุมัติ'`); + await queryRunner.query(`ALTER TABLE \`developmentScholarship\` ADD \`fieldOfStudy\` varchar(255) NULL COMMENT 'สาขาวิชา'`); + await queryRunner.query(`ALTER TABLE \`developmentScholarship\` ADD \`dateOrder\` datetime NULL COMMENT 'คำสั่งลงวันที่/หนังสืออนุมัติลงวันที่'`); + await queryRunner.query(`ALTER TABLE \`developmentScholarship\` ADD \`courseOfStudy\` varchar(255) NULL COMMENT 'หลักสูตรการศึกษา'`); + } + +} From 14f5a082caf7272a96f98ce7c3042a4fca7beaff Mon Sep 17 00:00:00 2001 From: AdisakKanthawilang Date: Fri, 5 Apr 2024 10:19:28 +0700 Subject: [PATCH 032/250] list --- .../DevelopmentScholarshipController.ts | 30 +++++-------------- 1 file changed, 7 insertions(+), 23 deletions(-) diff --git a/src/controllers/DevelopmentScholarshipController.ts b/src/controllers/DevelopmentScholarshipController.ts index ad7543f..7f7abe9 100644 --- a/src/controllers/DevelopmentScholarshipController.ts +++ b/src/controllers/DevelopmentScholarshipController.ts @@ -144,8 +144,8 @@ export class DevelopmentScholarshipController extends Controller { @Query("pageSize") pageSize: number = 10, @Query("keyword") keyword?: string, @Query("year") year?: number, + @Query("scholarshipType") scholarshipType?: string, ) { - const type = "OFFICER"; const [development, total] = await AppDataSource.getRepository(DevelopmentScholarship) .createQueryBuilder("developmentScholarship") .leftJoinAndSelect("developmentScholarship.posLevel", "posLevel") @@ -154,30 +154,14 @@ export class DevelopmentScholarshipController extends Controller { year != 0 && year != null && year != undefined ? "developmentScholarship.scholarshipYear = :scholarshipYear" : "1=1", - { year: year }, + { scholarshipYear: year }, ) - .andWhere("developmentScholarship.type = :type", { type: type }) + .andWhere("developmentScholarship.scholarshipType = :scholarshipType", { scholarshipType: scholarshipType }) .andWhere( - new Brackets((qb) => { - qb.where( - keyword != null && keyword != "" - ? "developmentScholarship.prefix LIKE :keyword" - : "1=1", - { - keyword: `%${keyword}%`, - }, - ) - .orWhere( + new Brackets((qb) => { + qb.where( keyword != null && keyword != "" - ? "developmentScholarship.firstName LIKE :keyword" - : "1=1", - { - keyword: `%${keyword}%`, - }, - ) - .orWhere( - keyword != null && keyword != "" - ? "developmentScholarship.lastName LIKE :keyword" + ? `CONCAT(developmentScholarship.prefix, developmentScholarship.firstName," ",developmentScholarship.lastName) like '%${keyword}%'` : "1=1", { keyword: `%${keyword}%`, @@ -193,7 +177,7 @@ export class DevelopmentScholarshipController extends Controller { ) .orWhere( keyword != null && keyword != "" - ? "developmentScholarship.position LIKE :keyword" + ? "developmentScholarship.posExecutive LIKE :keyword" : "1=1", { keyword: `%${keyword}%`, From f00c0d289ec354238bffd4698f5d59b33809bddc Mon Sep 17 00:00:00 2001 From: Bright Date: Fri, 5 Apr 2024 10:24:19 +0700 Subject: [PATCH 033/250] map DEV_015 --- .../DevelopmentScholarshipController.ts | 54 ++++++++++++++++++- 1 file changed, 52 insertions(+), 2 deletions(-) diff --git a/src/controllers/DevelopmentScholarshipController.ts b/src/controllers/DevelopmentScholarshipController.ts index 7f7abe9..07f128a 100644 --- a/src/controllers/DevelopmentScholarshipController.ts +++ b/src/controllers/DevelopmentScholarshipController.ts @@ -229,7 +229,57 @@ export class DevelopmentScholarshipController extends Controller { if (!getDevelopment) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลทุนการศึกษา/ฝึกอบรมนี้"); } - - return new HttpSuccess(getDevelopment); + const formattedData = { + rank: getDevelopment.rank ? getDevelopment.rank : null, + prefix: getDevelopment.prefix ? getDevelopment.prefix : null, + firstName: getDevelopment.firstName ? getDevelopment.firstName : null, + lastName: getDevelopment.lastName ? getDevelopment.lastName : null, + citizenId: getDevelopment.citizenId ? getDevelopment.citizenId : null, + position: getDevelopment.position ? getDevelopment.position : null, + posExecutive: getDevelopment.posExecutive ? getDevelopment.posExecutive : null, + posLevelId: getDevelopment.posLevelId ? getDevelopment.posLevelId : null, + posTypeId: getDevelopment.posTypeId ? getDevelopment.posTypeId : null, + guarantorRank: getDevelopment.guarantorRank ? getDevelopment.guarantorRank : null, + guarantorPrefix: getDevelopment.guarantorPrefix ? getDevelopment.guarantorPrefix : null, + guarantorFirstName: getDevelopment.guarantorFirstName ? getDevelopment.guarantorFirstName : null, + guarantorLastName: getDevelopment.guarantorLastName ? getDevelopment.guarantorLastName : null, + guarantorCitizenId: getDevelopment.guarantorCitizenId ? getDevelopment.guarantorCitizenId : null, + guarantorPosition: getDevelopment.guarantorPosition ? getDevelopment.guarantorPosition : null, + guarantorPosExecutive: getDevelopment.guarantorPosExecutive ? getDevelopment.guarantorPosExecutive : null, + posLevelguarantorId: getDevelopment.posLevelguarantorId ? getDevelopment.posLevelguarantorId : null, + posTypeguarantorId: getDevelopment.posTypeguarantorId ? getDevelopment.posTypeguarantorId : null, + scholarshipYear: getDevelopment.scholarshipYear ? getDevelopment.scholarshipYear : null, + budgetSource: getDevelopment.budgetSource ? getDevelopment.budgetSource : null, + budgetApprove: getDevelopment.budgetApprove ? getDevelopment.budgetApprove : null, + bookNo: getDevelopment.bookNo ? getDevelopment.bookNo : null, + bookNoDate: getDevelopment.bookNoDate ? getDevelopment.bookNoDate : null, + bookApproveDate: getDevelopment.bookApproveDate ? getDevelopment.bookApproveDate : null, + useOfficialTime: getDevelopment.useOfficialTime ? getDevelopment.useOfficialTime : null, + changeDetail: getDevelopment.changeDetail ? getDevelopment.changeDetail : null, + scholarshipType: getDevelopment.scholarshipType ? getDevelopment.scholarshipType : null, + fundType: getDevelopment.fundType ? getDevelopment.fundType : null, + contractNo: getDevelopment.contractNo ? getDevelopment.contractNo : null, + contractDate: getDevelopment.contractDate ? getDevelopment.contractDate : null, + reportBackNo: getDevelopment.reportBackNo ? getDevelopment.reportBackNo : null, + reportBackNoDate: getDevelopment.reportBackNoDate ? getDevelopment.reportBackNoDate : null, + reportBackDate: getDevelopment.reportBackDate ? getDevelopment.reportBackDate : null, + degreeLevel: getDevelopment.degreeLevel ? getDevelopment.degreeLevel : null, + course: getDevelopment.course ? getDevelopment.course : null, + field: getDevelopment.field ? getDevelopment.field : null, + faculty: getDevelopment.faculty ? getDevelopment.faculty : null, + educationalInstitution: getDevelopment.educationalInstitution ? getDevelopment.educationalInstitution : null, + startDate: getDevelopment.startDate ? getDevelopment.startDate : null, + endDate: getDevelopment.endDate ? getDevelopment.endDate : null, + studyPlace: getDevelopment.studyPlace ? getDevelopment.studyPlace : null, + studyTopic: getDevelopment.studyTopic ? getDevelopment.studyTopic : null, + studyStartDate: getDevelopment.studyStartDate ? getDevelopment.studyStartDate : null, + studyEndDate: getDevelopment.studyEndDate ? getDevelopment.studyEndDate : null, + studyCountry: getDevelopment.studyCountry ? getDevelopment.studyCountry : null, + studyAbroadTopic: getDevelopment.studyAbroadTopic ? getDevelopment.studyAbroadTopic : null, + studyAbroadStartDate: getDevelopment.studyAbroadStartDate ? getDevelopment.studyAbroadStartDate : null, + studyAbroadEndDate: getDevelopment.studyAbroadEndDate ? getDevelopment.studyAbroadEndDate : null, + totalPeriod: getDevelopment.totalPeriod ? getDevelopment.totalPeriod : null + }; + return new HttpSuccess(formattedData); } } From 3de8591ce0005c85bf2731451bb31f0dddbf739a Mon Sep 17 00:00:00 2001 From: AdisakKanthawilang Date: Fri, 5 Apr 2024 10:27:01 +0700 Subject: [PATCH 034/250] fix --- src/controllers/DevelopmentScholarshipController.ts | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/controllers/DevelopmentScholarshipController.ts b/src/controllers/DevelopmentScholarshipController.ts index 7f7abe9..063cfe0 100644 --- a/src/controllers/DevelopmentScholarshipController.ts +++ b/src/controllers/DevelopmentScholarshipController.ts @@ -151,12 +151,18 @@ export class DevelopmentScholarshipController extends Controller { .leftJoinAndSelect("developmentScholarship.posLevel", "posLevel") .leftJoinAndSelect("developmentScholarship.posType", "posType") .andWhere( - year != 0 && year != null && year != undefined + year !== 0 && year != null && year != undefined ? "developmentScholarship.scholarshipYear = :scholarshipYear" : "1=1", { scholarshipYear: year }, ) - .andWhere("developmentScholarship.scholarshipType = :scholarshipType", { scholarshipType: scholarshipType }) + .andWhere( + scholarshipType != null && scholarshipType != undefined + ? + "developmentScholarship.scholarshipType = :scholarshipType" + : "1=1", + { scholarshipType: scholarshipType } + ) .andWhere( new Brackets((qb) => { qb.where( From 7acf30d9a5df5417c2ab1d16bedb95650c2a0aee Mon Sep 17 00:00:00 2001 From: AdisakKanthawilang Date: Fri, 5 Apr 2024 12:01:30 +0700 Subject: [PATCH 035/250] fix api --- src/controllers/DevelopmentScholarshipController.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/controllers/DevelopmentScholarshipController.ts b/src/controllers/DevelopmentScholarshipController.ts index b8ce77b..644c8c1 100644 --- a/src/controllers/DevelopmentScholarshipController.ts +++ b/src/controllers/DevelopmentScholarshipController.ts @@ -230,6 +230,7 @@ export class DevelopmentScholarshipController extends Controller { @Get("{id}") async GetDevelopemtScholarshipById(@Path() id: string) { const getDevelopment = await this.developmentScholarshipRepository.findOne({ + relations: ["posLevel", "posType","posLevelguarantor","posTypeguarantor"], where: { id: id }, }); if (!getDevelopment) { @@ -244,7 +245,9 @@ export class DevelopmentScholarshipController extends Controller { position: getDevelopment.position ? getDevelopment.position : null, posExecutive: getDevelopment.posExecutive ? getDevelopment.posExecutive : null, posLevelId: getDevelopment.posLevelId ? getDevelopment.posLevelId : null, + posLevelName: getDevelopment.posLevel.posLevelName ? getDevelopment.posLevel.posLevelName : null, posTypeId: getDevelopment.posTypeId ? getDevelopment.posTypeId : null, + posTypeName: getDevelopment.posType.posTypeName ? getDevelopment.posType.posTypeName : null, guarantorRank: getDevelopment.guarantorRank ? getDevelopment.guarantorRank : null, guarantorPrefix: getDevelopment.guarantorPrefix ? getDevelopment.guarantorPrefix : null, guarantorFirstName: getDevelopment.guarantorFirstName ? getDevelopment.guarantorFirstName : null, @@ -253,7 +256,9 @@ export class DevelopmentScholarshipController extends Controller { guarantorPosition: getDevelopment.guarantorPosition ? getDevelopment.guarantorPosition : null, guarantorPosExecutive: getDevelopment.guarantorPosExecutive ? getDevelopment.guarantorPosExecutive : null, posLevelguarantorId: getDevelopment.posLevelguarantorId ? getDevelopment.posLevelguarantorId : null, + posLevelGuarantorName: getDevelopment.posLevelguarantor.posLevelName ? getDevelopment.posLevelguarantor.posLevelName : null, posTypeguarantorId: getDevelopment.posTypeguarantorId ? getDevelopment.posTypeguarantorId : null, + posTypeGuarantorName: getDevelopment.posTypeguarantor.posTypeName ? getDevelopment.posTypeguarantor.posTypeName : null, scholarshipYear: getDevelopment.scholarshipYear ? getDevelopment.scholarshipYear : null, budgetSource: getDevelopment.budgetSource ? getDevelopment.budgetSource : null, budgetApprove: getDevelopment.budgetApprove ? getDevelopment.budgetApprove : null, From 7beac004b2cc33bcb986d80287e6c71d4fcff661 Mon Sep 17 00:00:00 2001 From: AdisakKanthawilang Date: Fri, 5 Apr 2024 12:17:07 +0700 Subject: [PATCH 036/250] fix --- src/controllers/DevelopmentScholarshipController.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/controllers/DevelopmentScholarshipController.ts b/src/controllers/DevelopmentScholarshipController.ts index 644c8c1..5c441a0 100644 --- a/src/controllers/DevelopmentScholarshipController.ts +++ b/src/controllers/DevelopmentScholarshipController.ts @@ -245,9 +245,9 @@ export class DevelopmentScholarshipController extends Controller { position: getDevelopment.position ? getDevelopment.position : null, posExecutive: getDevelopment.posExecutive ? getDevelopment.posExecutive : null, posLevelId: getDevelopment.posLevelId ? getDevelopment.posLevelId : null, - posLevelName: getDevelopment.posLevel.posLevelName ? getDevelopment.posLevel.posLevelName : null, + posLevelName: getDevelopment.posLevel?.posLevelName ? getDevelopment.posLevel?.posLevelName : null, posTypeId: getDevelopment.posTypeId ? getDevelopment.posTypeId : null, - posTypeName: getDevelopment.posType.posTypeName ? getDevelopment.posType.posTypeName : null, + posTypeName: getDevelopment.posType?.posTypeName ? getDevelopment.posType?.posTypeName : null, guarantorRank: getDevelopment.guarantorRank ? getDevelopment.guarantorRank : null, guarantorPrefix: getDevelopment.guarantorPrefix ? getDevelopment.guarantorPrefix : null, guarantorFirstName: getDevelopment.guarantorFirstName ? getDevelopment.guarantorFirstName : null, @@ -256,9 +256,9 @@ export class DevelopmentScholarshipController extends Controller { guarantorPosition: getDevelopment.guarantorPosition ? getDevelopment.guarantorPosition : null, guarantorPosExecutive: getDevelopment.guarantorPosExecutive ? getDevelopment.guarantorPosExecutive : null, posLevelguarantorId: getDevelopment.posLevelguarantorId ? getDevelopment.posLevelguarantorId : null, - posLevelGuarantorName: getDevelopment.posLevelguarantor.posLevelName ? getDevelopment.posLevelguarantor.posLevelName : null, + posLevelguarantorName: getDevelopment.posLevelguarantor?.posLevelName ? getDevelopment.posLevelguarantor?.posLevelName : null, posTypeguarantorId: getDevelopment.posTypeguarantorId ? getDevelopment.posTypeguarantorId : null, - posTypeGuarantorName: getDevelopment.posTypeguarantor.posTypeName ? getDevelopment.posTypeguarantor.posTypeName : null, + posTypeguarantorName: getDevelopment.posTypeguarantor?.posTypeName ? getDevelopment.posTypeguarantor?.posTypeName : null, scholarshipYear: getDevelopment.scholarshipYear ? getDevelopment.scholarshipYear : null, budgetSource: getDevelopment.budgetSource ? getDevelopment.budgetSource : null, budgetApprove: getDevelopment.budgetApprove ? getDevelopment.budgetApprove : null, From 01cd72a9faceb5a698cab8cbff5161d2cdcb57dc Mon Sep 17 00:00:00 2001 From: AdisakKanthawilang Date: Fri, 5 Apr 2024 13:26:46 +0700 Subject: [PATCH 037/250] fix entity --- src/entities/DevelopmentScholarship.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/entities/DevelopmentScholarship.ts b/src/entities/DevelopmentScholarship.ts index 4cccefa..1c25403 100644 --- a/src/entities/DevelopmentScholarship.ts +++ b/src/entities/DevelopmentScholarship.ts @@ -452,8 +452,8 @@ export class CreateDevelopmentScholarship { educationalInstitution: string | null; startDate: Date | null; endDate: Date | null; - studyPlace: Date | null; - studyTopic: Date | null; + studyPlace: string | null; + studyTopic: string | null; studyStartDate: Date | null; studyEndDate: Date | null; studyCountry: string | null; @@ -504,8 +504,8 @@ export class UpdateDevelopmentScholarship { educationalInstitution: string | null; startDate: Date | null; endDate: Date | null; - studyPlace: Date | null; - studyTopic: Date | null; + studyPlace: string | null; + studyTopic: string | null; studyStartDate: Date | null; studyEndDate: Date | null; studyCountry: string | null; From 3dc49ec507e08c2e18ff11e88526b2a10641ad3e Mon Sep 17 00:00:00 2001 From: AdisakKanthawilang Date: Fri, 5 Apr 2024 15:45:06 +0700 Subject: [PATCH 038/250] fix --- src/entities/DevelopmentScholarship.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/entities/DevelopmentScholarship.ts b/src/entities/DevelopmentScholarship.ts index 1c25403..847ce4d 100644 --- a/src/entities/DevelopmentScholarship.ts +++ b/src/entities/DevelopmentScholarship.ts @@ -436,7 +436,7 @@ export class CreateDevelopmentScholarship { bookNo: string | null; bookNoDate: Date | null; bookApproveDate: Date | null; - useOfficialTime: boolean | null; + useOfficialTime: boolean | false; changeDetail: string | null; scholarshipType: string | null; fundType: string | null; @@ -488,7 +488,7 @@ export class UpdateDevelopmentScholarship { bookNo: string | null; bookNoDate: Date | null; bookApproveDate: Date | null; - useOfficialTime: boolean | null; + useOfficialTime: boolean | false; changeDetail: string | null; scholarshipType: string | null; fundType: string | null; From 58a30a7c74e0357fa7b7d7c29e94bee1ec96c858 Mon Sep 17 00:00:00 2001 From: Kittapath Date: Tue, 9 Apr 2024 11:38:13 +0700 Subject: [PATCH 039/250] set report development --- src/controllers/ReportController.ts | 127 ++++++++++++++++++++++++++++ 1 file changed, 127 insertions(+) create mode 100644 src/controllers/ReportController.ts diff --git a/src/controllers/ReportController.ts b/src/controllers/ReportController.ts new file mode 100644 index 0000000..f0b976d --- /dev/null +++ b/src/controllers/ReportController.ts @@ -0,0 +1,127 @@ +import { + Controller, + Get, + Post, + Put, + Delete, + Route, + Security, + Tags, + Body, + Path, + Request, + Query, +} from "tsoa"; +import { AppDataSource } from "../database/data-source"; +import { Brackets, Not } from "typeorm"; +import HttpSuccess from "../interfaces/http-success"; +import HttpError from "../interfaces/http-error"; +import HttpStatusCode from "../interfaces/http-status"; +import { Development } from "../entities/Development"; +import { + CreateDevelopmentHistory, + DevelopmentHistory, + UpdateDevelopmentHistory, +} from "../entities/DevelopmentHistory"; +import { PosType } from "../entities/PosType"; +import { PosLevel } from "../entities/PosLevel"; + +@Route("api/v1/development/report") +@Tags("Report") +@Security("bearerAuth") +export class ReportController extends Controller { + private developmentHistoryRepository = AppDataSource.getRepository(DevelopmentHistory); + private developmentRepository = AppDataSource.getRepository(Development); + private posTypeRepository = AppDataSource.getRepository(PosType); + private posLevelRepository = AppDataSource.getRepository(PosLevel); + + /** + * API Report รายการโครงการ/หลักสูตรการฝึกอบรมที่หน่วยงานของกรุงเทพมหานครเป็นผู้จัด + * + * @summary DEV_0xx - Report รายการโครงการ/หลักสูตรการฝึกอบรมที่หน่วยงานของกรุงเทพมหานครเป็นผู้จัด #xx + * + * @param {string} type type ประเภท report + */ + @Get("main/{type}") + async GetReportDevelopemtMain(@Path() type: string) { + const _type = type.trim().toUpperCase(); + const formattedData = { + org: _type, + }; + + return new HttpSuccess({ + template: "development", + reportName: "development", + data: { + data: formattedData, + }, + }); + } + + /** + * API Report รายการประวัติการฝึกอบรม/ดูงานของข้าราชการกรุงเทพมหานครสามัญ + * + * @summary DEV_0xx - Report รายการประวัติการฝึกอบรม/ดูงานของข้าราชการกรุงเทพมหานครสามัญ #xx + * + * @param {string} type type ประเภท report + */ + @Get("history-officer/{type}") + async GetReportDevelopemtHistoryOfficer(@Path() type: string) { + const _type = type.trim().toUpperCase(); + const formattedData = { + org: _type, + }; + + return new HttpSuccess({ + template: "development", + reportName: "development", + data: { + data: formattedData, + }, + }); + } + + /** + * API Report รายการประวัติฝึกอบรม/ดูงานลูกจ้าง + * + * @summary DEV_0xx - Report รายการประวัติฝึกอบรม/ดูงานลูกจ้าง #xx + * + * @param {string} type type ประเภท report + */ + @Get("history-employee/{type}") + async GetReportDevelopemtHistoryEmployee(@Path() type: string) { + const _type = type.trim().toUpperCase(); + const formattedData = { + org: _type, + }; + + return new HttpSuccess({ + template: "development", + reportName: "development", + data: { + data: formattedData, + }, + }); + } + + /** + * API Report รายการข้าราชการฯที่ได้รับทุนการศึกษา/ฝึกอบรม + * + * @summary DEV_0xx - Report รายการข้าราชการฯที่ได้รับทุนการศึกษา/ฝึกอบรม #xx + * + */ + @Get("scholarship") + async GetReportDevelopemtScholarship() { + const formattedData = { + org: "_type", + }; + + return new HttpSuccess({ + template: "development", + reportName: "development", + data: { + data: formattedData, + }, + }); + } +} From 68c31be431be4f368a2031c6da17df2857edfdff Mon Sep 17 00:00:00 2001 From: Kittapath Date: Tue, 9 Apr 2024 16:30:29 +0700 Subject: [PATCH 040/250] useOfficialTime send false --- .../DevelopmentScholarshipController.ts | 77 ++++++++++++------- 1 file changed, 49 insertions(+), 28 deletions(-) diff --git a/src/controllers/DevelopmentScholarshipController.ts b/src/controllers/DevelopmentScholarshipController.ts index 5c441a0..295dc9c 100644 --- a/src/controllers/DevelopmentScholarshipController.ts +++ b/src/controllers/DevelopmentScholarshipController.ts @@ -158,21 +158,20 @@ export class DevelopmentScholarshipController extends Controller { ) .andWhere( scholarshipType != null && scholarshipType != undefined - ? - "developmentScholarship.scholarshipType = :scholarshipType" - : "1=1", - { scholarshipType: scholarshipType } - ) + ? "developmentScholarship.scholarshipType = :scholarshipType" + : "1=1", + { scholarshipType: scholarshipType }, + ) .andWhere( - new Brackets((qb) => { - qb.where( - keyword != null && keyword != "" - ? `CONCAT(developmentScholarship.prefix, developmentScholarship.firstName," ",developmentScholarship.lastName) like '%${keyword}%'` - : "1=1", - { - keyword: `%${keyword}%`, - }, - ) + new Brackets((qb) => { + qb.where( + keyword != null && keyword != "" + ? `CONCAT(developmentScholarship.prefix, developmentScholarship.firstName," ",developmentScholarship.lastName) like '%${keyword}%'` + : "1=1", + { + keyword: `%${keyword}%`, + }, + ) .orWhere( keyword != null && keyword != "" ? "developmentScholarship.position LIKE :keyword" @@ -230,7 +229,7 @@ export class DevelopmentScholarshipController extends Controller { @Get("{id}") async GetDevelopemtScholarshipById(@Path() id: string) { const getDevelopment = await this.developmentScholarshipRepository.findOne({ - relations: ["posLevel", "posType","posLevelguarantor","posTypeguarantor"], + relations: ["posLevel", "posType", "posLevelguarantor", "posTypeguarantor"], where: { id: id }, }); if (!getDevelopment) { @@ -245,27 +244,43 @@ export class DevelopmentScholarshipController extends Controller { position: getDevelopment.position ? getDevelopment.position : null, posExecutive: getDevelopment.posExecutive ? getDevelopment.posExecutive : null, posLevelId: getDevelopment.posLevelId ? getDevelopment.posLevelId : null, - posLevelName: getDevelopment.posLevel?.posLevelName ? getDevelopment.posLevel?.posLevelName : null, + posLevelName: getDevelopment.posLevel?.posLevelName + ? getDevelopment.posLevel?.posLevelName + : null, posTypeId: getDevelopment.posTypeId ? getDevelopment.posTypeId : null, posTypeName: getDevelopment.posType?.posTypeName ? getDevelopment.posType?.posTypeName : null, guarantorRank: getDevelopment.guarantorRank ? getDevelopment.guarantorRank : null, guarantorPrefix: getDevelopment.guarantorPrefix ? getDevelopment.guarantorPrefix : null, - guarantorFirstName: getDevelopment.guarantorFirstName ? getDevelopment.guarantorFirstName : null, + guarantorFirstName: getDevelopment.guarantorFirstName + ? getDevelopment.guarantorFirstName + : null, guarantorLastName: getDevelopment.guarantorLastName ? getDevelopment.guarantorLastName : null, - guarantorCitizenId: getDevelopment.guarantorCitizenId ? getDevelopment.guarantorCitizenId : null, + guarantorCitizenId: getDevelopment.guarantorCitizenId + ? getDevelopment.guarantorCitizenId + : null, guarantorPosition: getDevelopment.guarantorPosition ? getDevelopment.guarantorPosition : null, - guarantorPosExecutive: getDevelopment.guarantorPosExecutive ? getDevelopment.guarantorPosExecutive : null, - posLevelguarantorId: getDevelopment.posLevelguarantorId ? getDevelopment.posLevelguarantorId : null, - posLevelguarantorName: getDevelopment.posLevelguarantor?.posLevelName ? getDevelopment.posLevelguarantor?.posLevelName : null, - posTypeguarantorId: getDevelopment.posTypeguarantorId ? getDevelopment.posTypeguarantorId : null, - posTypeguarantorName: getDevelopment.posTypeguarantor?.posTypeName ? getDevelopment.posTypeguarantor?.posTypeName : null, + guarantorPosExecutive: getDevelopment.guarantorPosExecutive + ? getDevelopment.guarantorPosExecutive + : null, + posLevelguarantorId: getDevelopment.posLevelguarantorId + ? getDevelopment.posLevelguarantorId + : null, + posLevelguarantorName: getDevelopment.posLevelguarantor?.posLevelName + ? getDevelopment.posLevelguarantor?.posLevelName + : null, + posTypeguarantorId: getDevelopment.posTypeguarantorId + ? getDevelopment.posTypeguarantorId + : null, + posTypeguarantorName: getDevelopment.posTypeguarantor?.posTypeName + ? getDevelopment.posTypeguarantor?.posTypeName + : null, scholarshipYear: getDevelopment.scholarshipYear ? getDevelopment.scholarshipYear : null, budgetSource: getDevelopment.budgetSource ? getDevelopment.budgetSource : null, budgetApprove: getDevelopment.budgetApprove ? getDevelopment.budgetApprove : null, bookNo: getDevelopment.bookNo ? getDevelopment.bookNo : null, bookNoDate: getDevelopment.bookNoDate ? getDevelopment.bookNoDate : null, bookApproveDate: getDevelopment.bookApproveDate ? getDevelopment.bookApproveDate : null, - useOfficialTime: getDevelopment.useOfficialTime ? getDevelopment.useOfficialTime : null, + useOfficialTime: getDevelopment.useOfficialTime ? getDevelopment.useOfficialTime : false, changeDetail: getDevelopment.changeDetail ? getDevelopment.changeDetail : null, scholarshipType: getDevelopment.scholarshipType ? getDevelopment.scholarshipType : null, fundType: getDevelopment.fundType ? getDevelopment.fundType : null, @@ -278,7 +293,9 @@ export class DevelopmentScholarshipController extends Controller { course: getDevelopment.course ? getDevelopment.course : null, field: getDevelopment.field ? getDevelopment.field : null, faculty: getDevelopment.faculty ? getDevelopment.faculty : null, - educationalInstitution: getDevelopment.educationalInstitution ? getDevelopment.educationalInstitution : null, + educationalInstitution: getDevelopment.educationalInstitution + ? getDevelopment.educationalInstitution + : null, startDate: getDevelopment.startDate ? getDevelopment.startDate : null, endDate: getDevelopment.endDate ? getDevelopment.endDate : null, studyPlace: getDevelopment.studyPlace ? getDevelopment.studyPlace : null, @@ -287,9 +304,13 @@ export class DevelopmentScholarshipController extends Controller { studyEndDate: getDevelopment.studyEndDate ? getDevelopment.studyEndDate : null, studyCountry: getDevelopment.studyCountry ? getDevelopment.studyCountry : null, studyAbroadTopic: getDevelopment.studyAbroadTopic ? getDevelopment.studyAbroadTopic : null, - studyAbroadStartDate: getDevelopment.studyAbroadStartDate ? getDevelopment.studyAbroadStartDate : null, - studyAbroadEndDate: getDevelopment.studyAbroadEndDate ? getDevelopment.studyAbroadEndDate : null, - totalPeriod: getDevelopment.totalPeriod ? getDevelopment.totalPeriod : null + studyAbroadStartDate: getDevelopment.studyAbroadStartDate + ? getDevelopment.studyAbroadStartDate + : null, + studyAbroadEndDate: getDevelopment.studyAbroadEndDate + ? getDevelopment.studyAbroadEndDate + : null, + totalPeriod: getDevelopment.totalPeriod ? getDevelopment.totalPeriod : null, }; return new HttpSuccess(formattedData); } From 166c919bbea84c8b972143200f18c7bc11a9e9f2 Mon Sep 17 00:00:00 2001 From: Kittapath Date: Tue, 9 Apr 2024 21:59:23 +0700 Subject: [PATCH 041/250] =?UTF-8?q?=E0=B9=80=E0=B8=9E=E0=B8=B4=E0=B9=88?= =?UTF-8?q?=E0=B8=A1=E0=B8=95=E0=B8=B3=E0=B9=81=E0=B8=AB=E0=B8=99=E0=B9=88?= =?UTF-8?q?=E0=B8=87=E0=B9=80=E0=B8=A5=E0=B8=B7=E0=B8=AD=E0=B8=81=E0=B9=84?= =?UTF-8?q?=E0=B8=94=E0=B9=89=E0=B8=AB=E0=B8=A5=E0=B8=B2=E0=B8=A2=E0=B8=AD?= =?UTF-8?q?=E0=B8=B1=E0=B8=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/DevelopmentController.ts | 159 ++++++++++++------ .../DevelopmentScholarshipController.ts | 30 ++++ src/entities/Development.ts | 115 +++++++++++-- src/entities/DevelopmentScholarship.ts | 11 ++ src/entities/PlannedGoal.ts | 81 ++++----- src/entities/PlannedGoalPosition.ts | 59 +++++++ src/entities/PosLevel.ts | 9 +- src/entities/PosType.ts | 8 +- src/entities/Province.ts | 7 +- ...date_table_developement_add_projectType.ts | 60 +++++++ 10 files changed, 424 insertions(+), 115 deletions(-) create mode 100644 src/entities/PlannedGoalPosition.ts create mode 100644 src/migration/1712670681087-update_table_developement_add_projectType.ts diff --git a/src/controllers/DevelopmentController.ts b/src/controllers/DevelopmentController.ts index f093b11..b7013c5 100644 --- a/src/controllers/DevelopmentController.ts +++ b/src/controllers/DevelopmentController.ts @@ -14,7 +14,7 @@ import { Example, } from "tsoa"; import { AppDataSource } from "../database/data-source"; -import { Not } from "typeorm"; +import { In, Not } from "typeorm"; import HttpSuccess from "../interfaces/http-success"; import HttpError from "../interfaces/http-error"; import HttpStatusCode from "../interfaces/http-status"; @@ -26,6 +26,7 @@ import { PlannedGoal } from "../entities/PlannedGoal"; import { Province } from "../entities/Province"; import { PosType } from "../entities/PosType"; import { PosLevel } from "../entities/PosLevel"; +import { PlannedGoalPosition } from "../entities/PlannedGoalPosition"; @Route("api/v1/development/main") @Tags("Development") @@ -36,6 +37,7 @@ export class DevelopmentController extends Controller { private plannedPeopleRepository = AppDataSource.getRepository(PlannedPeople); private actualGoalRepository = AppDataSource.getRepository(ActualGoal); private plannedGoalRepository = AppDataSource.getRepository(PlannedGoal); + private plannedGoalPositionRepository = AppDataSource.getRepository(PlannedGoalPosition); private provinceRepository = AppDataSource.getRepository(Province); private posTypeRepository = AppDataSource.getRepository(PosType); private posLevelRepository = AppDataSource.getRepository(PosLevel); @@ -68,14 +70,6 @@ export class DevelopmentController extends Controller { ); } - if (requestBody.provinceId != null) { - const checkId = await this.provinceRepository.findOne({ - where: { id: requestBody.provinceId }, - }); - if (!checkId) { - throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลจังหวัดสถานที่ดำเนินการ"); - } - } if (requestBody.provinceActualId != null) { const checkId = await this.provinceRepository.findOne({ where: { id: requestBody.provinceActualId }, @@ -87,6 +81,15 @@ export class DevelopmentController extends Controller { const development = Object.assign(new Development(), requestBody); + if (requestBody.provinceIds != null) { + const chkProvince = await this.provinceRepository.find({ + where: { + id: In(requestBody.provinceIds), + }, + }); + + development.provinces = chkProvince; + } development.createdUserId = request.user.sub; development.createdFullName = request.user.name; development.lastUpdateUserId = request.user.sub; @@ -143,22 +146,6 @@ export class DevelopmentController extends Controller { ); await Promise.all( requestBody.plannedGoals.map(async (x) => { - if (x.posTypePlannedId != null) { - const checkId = await this.posTypeRepository.findOne({ - where: { id: x.posTypePlannedId }, - }); - if (!checkId) { - throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลประเภทตำแหน่ง"); - } - } - if (x.posLevelPlannedId != null) { - const checkId = await this.posLevelRepository.findOne({ - where: { id: x.posLevelPlannedId }, - }); - if (!checkId) { - throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลระดับตำแหน่ง"); - } - } const data = Object.assign(new PlannedGoal(), x); data.createdUserId = request.user.sub; data.createdFullName = request.user.name; @@ -166,6 +153,34 @@ export class DevelopmentController extends Controller { data.lastUpdateFullName = request.user.name; data.developmentPlannedGoalId = development.id; await this.plannedGoalRepository.save(data); + + await Promise.all( + x.positions.map(async (y) => { + const _data = Object.assign(new PlannedGoalPosition(), y); + if (y.posTypePlannedId != null) { + const checkId = await this.posTypeRepository.findOne({ + where: { id: y.posTypePlannedId }, + }); + if (!checkId) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลประเภทตำแหน่ง"); + } + } + if (y.posLevelPlannedId != null) { + const checkId = await this.posLevelRepository.findOne({ + where: { id: y.posLevelPlannedId }, + }); + if (!checkId) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลระดับตำแหน่ง"); + } + } + _data.createdUserId = request.user.sub; + _data.createdFullName = request.user.name; + _data.lastUpdateUserId = request.user.sub; + _data.lastUpdateFullName = request.user.name; + _data.plannedGoalId = data.id; + await this.plannedGoalPositionRepository.save(_data); + }), + ); }), ); return new HttpSuccess(development.id); @@ -196,14 +211,6 @@ export class DevelopmentController extends Controller { if (!development) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงการ/หลักสูตรการฝึกอบรมนี้"); } - if (requestBody.provinceId != null) { - const checkId = await this.provinceRepository.findOne({ - where: { id: requestBody.provinceId }, - }); - if (!checkId) { - throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลจังหวัดสถานที่ดำเนินการ"); - } - } if (requestBody.provinceActualId != null) { const checkId = await this.provinceRepository.findOne({ where: { id: requestBody.provinceActualId }, @@ -230,6 +237,23 @@ export class DevelopmentController extends Controller { ); } Object.assign(development, requestBody); + if ( + development.developmentPlannedGoals != null && + development.developmentPlannedGoals.length > 0 + ) { + const plannedGoalPosition = await this.plannedGoalPositionRepository.find({ + where: { plannedGoalId: In(development.developmentPlannedGoals.map((x) => x.id)) }, + }); + await this.plannedGoalPositionRepository.remove(plannedGoalPosition); + } + if (requestBody.provinceIds != null) { + const chkProvince = await this.provinceRepository.find({ + where: { + id: In(requestBody.provinceIds), + }, + }); + development.provinces = chkProvince; + } development.lastUpdateUserId = request.user.sub; development.lastUpdateFullName = request.user.name; await this.developmentRepository.save(development); @@ -288,22 +312,6 @@ export class DevelopmentController extends Controller { ); await Promise.all( requestBody.plannedGoals.map(async (x) => { - if (x.posTypePlannedId != null) { - const checkId = await this.posTypeRepository.findOne({ - where: { id: x.posTypePlannedId }, - }); - if (!checkId) { - throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลประเภทตำแหน่ง"); - } - } - if (x.posLevelPlannedId != null) { - const checkId = await this.posLevelRepository.findOne({ - where: { id: x.posLevelPlannedId }, - }); - if (!checkId) { - throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลระดับตำแหน่ง"); - } - } const data = Object.assign(new PlannedGoal(), x); data.createdUserId = request.user.sub; data.createdFullName = request.user.name; @@ -311,6 +319,34 @@ export class DevelopmentController extends Controller { data.lastUpdateFullName = request.user.name; data.developmentPlannedGoalId = development.id; await this.plannedGoalRepository.save(data); + + await Promise.all( + x.positions.map(async (y) => { + const _data = Object.assign(new PlannedGoalPosition(), y); + if (y.posTypePlannedId != null) { + const checkId = await this.posTypeRepository.findOne({ + where: { id: y.posTypePlannedId }, + }); + if (!checkId) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลประเภทตำแหน่ง"); + } + } + if (y.posLevelPlannedId != null) { + const checkId = await this.posLevelRepository.findOne({ + where: { id: y.posLevelPlannedId }, + }); + if (!checkId) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลระดับตำแหน่ง"); + } + } + _data.createdUserId = request.user.sub; + _data.createdFullName = request.user.name; + _data.lastUpdateUserId = request.user.sub; + _data.lastUpdateFullName = request.user.name; + _data.plannedGoalId = data.id; + await this.plannedGoalPositionRepository.save(_data); + }), + ); }), ); return new HttpSuccess(development.id); @@ -387,6 +423,15 @@ export class DevelopmentController extends Controller { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงการ/หลักสูตรการฝึกอบรมนี้"); } + if ( + development.developmentPlannedGoals != null && + development.developmentPlannedGoals.length > 0 + ) { + const plannedGoalPosition = await this.plannedGoalPositionRepository.find({ + where: { plannedGoalId: In(development.developmentPlannedGoals.map((x) => x.id)) }, + }); + await this.plannedGoalPositionRepository.remove(plannedGoalPosition); + } await this.actualPeopleRepository.remove(development.developmentActualPeoples); await this.plannedPeopleRepository.remove(development.developmentPlannedPeoples); await this.actualGoalRepository.remove(development.developmentActualGoals); @@ -437,12 +482,15 @@ export class DevelopmentController extends Controller { async GetDevelopemtById(@Path() id: string) { const getDevelopment = await this.developmentRepository.findOne({ where: { id: id }, - relations: { - developmentActualPeoples: true, - developmentPlannedPeoples: true, - developmentActualGoals: true, - developmentPlannedGoals: true, - }, + relations: [ + "developmentActualPeoples", + "developmentPlannedPeoples", + "developmentActualGoals", + "developmentPlannedGoals", + "developmentPlannedGoals.plannedGoalPositions", + "provinces", + // "provinces.developmentProvinces", + ], }); if (!getDevelopment) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงการ/หลักสูตรการฝึกอบรมนี้"); @@ -452,6 +500,7 @@ export class DevelopmentController extends Controller { _getDevelopment.plannedPeoples = getDevelopment.developmentPlannedPeoples; _getDevelopment.actualGoals = getDevelopment.developmentActualGoals; _getDevelopment.plannedGoals = getDevelopment.developmentPlannedGoals; + // _getDevelopment.provinces = getDevelopment.provinces.map(x=>x.developmentProvinces); delete _getDevelopment.developmentActualPeoples; delete _getDevelopment.developmentPlannedPeoples; delete _getDevelopment.developmentActualGoals; diff --git a/src/controllers/DevelopmentScholarshipController.ts b/src/controllers/DevelopmentScholarshipController.ts index 295dc9c..3525811 100644 --- a/src/controllers/DevelopmentScholarshipController.ts +++ b/src/controllers/DevelopmentScholarshipController.ts @@ -311,7 +311,37 @@ export class DevelopmentScholarshipController extends Controller { ? getDevelopment.studyAbroadEndDate : null, totalPeriod: getDevelopment.totalPeriod ? getDevelopment.totalPeriod : null, + status: getDevelopment.status ? getDevelopment.status : null, }; return new HttpSuccess(formattedData); } + + /** + * API เปลี่ยนสถานะ + * + * @summary DEV_0 - เปลี่ยนสถานะ # + * + * @param {string} id Id โครงการ + * @param {string} status status สถานะ + */ + @Get("status/{id}/{status}") + async ChangeStatusDevelopemtScholarshipById(@Path() id: string, @Path() status: string) { + const getDevelopment = await this.developmentScholarshipRepository.findOne({ + where: { id: id }, + }); + if (!getDevelopment) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลทุนการศึกษา/ฝึกอบรมนี้"); + } + const _status = status.trim().toUpperCase(); + getDevelopment.status = _status; + if (_status == "GRADUATE") { + //xxxxxxxxxxxxxxxxxxxบันทึกลงทะเบียน + } else if (_status == "NOTGRADUATE") { + } else { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบสถานะนี้ในระบบ"); + } + await this.developmentScholarshipRepository.remove(getDevelopment); + + return new HttpSuccess(); + } } diff --git a/src/entities/Development.ts b/src/entities/Development.ts index 08e2a46..ca6d988 100644 --- a/src/entities/Development.ts +++ b/src/entities/Development.ts @@ -1,4 +1,4 @@ -import { Entity, Column, ManyToOne, JoinColumn, OneToOne, OneToMany, Double } from "typeorm"; +import { Entity, Column, ManyToOne, JoinColumn, OneToMany, Double, ManyToMany } from "typeorm"; import { EntityBase } from "./base/Base"; import { Province } from "./Province"; import { ActualPeople, CreateActualPeople } from "./ActualPeople"; @@ -159,17 +159,6 @@ export class Development extends EntityBase { }) address: string; - @Column({ - nullable: true, - comment: "จังหวัด", - default: null, - }) - provinceId: string; - - @ManyToOne(() => Province, (province: Province) => province.developments) - @JoinColumn({ name: "provinceId" }) - province: Province; - @Column({ nullable: true, comment: "ประเภทงบประมาณ", @@ -281,6 +270,73 @@ export class Development extends EntityBase { }) dateStudyEnd: Date; + @Column({ + // STRATEGIC_PROJECT = โครงการตามยุทธศาสตร์ + // MISSION_PROJECT = โครงการตามภารกิจประจำของหน่วยงาน + // NEW_PROJECT = โครงการใหม่ + // ONGOING_PROJECT = โครงการต่อเนื่อง + nullable: true, + comment: "ประเภทโครงการ", + default: null, + }) + projectType: string; + + @Column({ + // GO_BACK = ไป-กลับ + // HOLD = พักค้าง + // GO_BACK_HOLD = ไป-กลับและพักค้าง + nullable: true, + comment: "ลักษณะ", + default: null, + }) + projectCharacteristics: string; + + @Column({ + nullable: true, + comment: "จำนวน(วัน)", + default: null, + }) + projectDay: number; + + @Column({ + nullable: true, + comment: "จำนวน(คืน)", + default: null, + }) + projectNigth: number; + + @Column({ + // TRAINING = การอบรม + // MEETING = การประชุม + // SEMINAR = การสัมมนา + // STUDY_TOUR = การศึกษาดูงาน + // ACADEMIC_SEMINAR = การสัมมนาทางวิชาการ + // WORKSHOP = การสัมมนาเชิงปฏิบัติการ + // SPECIAL_LECTURE = การบรรยายพิเศษ + // STUDY_TRAINING = การฝึกศึกษา + nullable: true, + comment: "เทคนิควิธีการที่ใช้ในการพัฒนา", + default: null, + }) + projectTechniques: string; + + @Column({ + nullable: true, + comment: "จำนวน(รุ่น)", + default: null, + }) + projectModal: number; + + @Column({ + // เงินบำรุง = MAINTENANCE + // เงินกองทุน = FUND + // เงินอุดหนุน = SUBSIDY + nullable: true, + comment: "ประเภทย่อย", + default: null, + }) + budgetSub: string; + @Column({ nullable: true, comment: "จังหวัด(ข้อมูลวิชาการ)", @@ -292,6 +348,9 @@ export class Development extends EntityBase { @JoinColumn({ name: "provinceActualId" }) provinceActual: Province; + @ManyToMany(() => Province, (provinces) => provinces.developmentProvinces) + provinces: Province[]; + @OneToMany( () => ActualPeople, (actualPeople: ActualPeople) => actualPeople.developmentActualPeople, @@ -362,7 +421,7 @@ export class CreateDevelopment { @Column() address: string | null; @Column() - provinceId: string | null; + provinceIds: string[]; @Column() budget: string | null; @Column() @@ -396,6 +455,20 @@ export class CreateDevelopment { @Column() dateStudyEnd?: Date | null; @Column() + projectType: string | null; + @Column() + projectCharacteristics: string | null; + @Column() + projectDay: number | null; + @Column() + projectNigth: number | null; + @Column() + projectTechniques: string | null; + @Column() + projectModal: number | null; + @Column() + budgetSub: string | null; + @Column() actualPeoples: CreateActualPeople[]; @Column() plannedPeoples: CreatePlannedPeople[]; @@ -451,7 +524,7 @@ export class UpdateDevelopment { @Column() address: string | null; @Column() - provinceId: string | null; + provinceIds: string[]; @Column() budget: string | null; @Column() @@ -485,6 +558,20 @@ export class UpdateDevelopment { @Column() dateStudyEnd?: Date | null; @Column() + projectType?: string | null; + @Column() + projectCharacteristics?: string | null; + @Column() + projectDay?: number | null; + @Column() + projectNigth?: number | null; + @Column() + projectTechniques?: string | null; + @Column() + projectModal?: number | null; + @Column() + budgetSub: string | null; + @Column() actualPeoples: CreateActualPeople[]; @Column() plannedPeoples: CreatePlannedPeople[]; diff --git a/src/entities/DevelopmentScholarship.ts b/src/entities/DevelopmentScholarship.ts index 847ce4d..1ebb953 100644 --- a/src/entities/DevelopmentScholarship.ts +++ b/src/entities/DevelopmentScholarship.ts @@ -5,6 +5,17 @@ import { PosType } from "./PosType"; @Entity("developmentScholarship") export class DevelopmentScholarship extends EntityBase { + @Column({ + // PENDING = ค่าเริ่มต้น + // GRADUATE = สำเร็จการศึกษา + // NOTGRADUATE = ไม่จบการศึกษา + nullable: true, + comment: "สถานะ", + length: 40, + default: "PENDING", + }) + status: string; + @Column({ nullable: true, comment: "ยศ", diff --git a/src/entities/PlannedGoal.ts b/src/entities/PlannedGoal.ts index 5758ed8..ec70ffe 100644 --- a/src/entities/PlannedGoal.ts +++ b/src/entities/PlannedGoal.ts @@ -1,8 +1,7 @@ -import { Entity, Column, ManyToOne, JoinColumn } from "typeorm"; +import { Entity, Column, ManyToOne, JoinColumn, OneToMany } from "typeorm"; import { EntityBase } from "./base/Base"; import { Development } from "./Development"; -import { PosType } from "./PosType"; -import { PosLevel } from "./PosLevel"; +import { CreatePlannedGoalPosition, PlannedGoalPosition } from "./PlannedGoalPosition"; @Entity("plannedGoal") export class PlannedGoal extends EntityBase { @@ -20,41 +19,41 @@ export class PlannedGoal extends EntityBase { }) groupTargetSub: string; - @Column({ - nullable: true, - comment: "ตำแหน่ง", - default: null, - }) - position: string; + // @Column({ + // nullable: true, + // comment: "ตำแหน่ง", + // default: null, + // }) + // position: string; - @Column({ - nullable: true, - comment: "ประเภทตำแหน่ง", - default: null, - }) - posTypePlannedId: string; + // @Column({ + // nullable: true, + // comment: "ประเภทตำแหน่ง", + // default: null, + // }) + // posTypePlannedId: string; - @ManyToOne(() => PosType, (posType: PosType) => posType.plannedGoals) - @JoinColumn({ name: "posTypePlannedId" }) - posTypePlanned: PosType; + // @ManyToOne(() => PosType, (posType: PosType) => posType.plannedGoals) + // @JoinColumn({ name: "posTypePlannedId" }) + // posTypePlanned: PosType; - @Column({ - nullable: true, - comment: "ระดับตำแหน่ง", - default: null, - }) - posLevelPlannedId: string; + // @Column({ + // nullable: true, + // comment: "ระดับตำแหน่ง", + // default: null, + // }) + // posLevelPlannedId: string; - @ManyToOne(() => PosLevel, (posLevel: PosLevel) => posLevel.plannedGoals) - @JoinColumn({ name: "posLevelPlannedId" }) - posLevelPlanned: PosLevel; + // @ManyToOne(() => PosLevel, (posLevel: PosLevel) => posLevel.plannedGoals) + // @JoinColumn({ name: "posLevelPlannedId" }) + // posLevelPlanned: PosLevel; - @Column({ - nullable: true, - comment: "ประเภท(กลุ่มอาชีพ คุณสมบัติ)", - default: null, - }) - type: string; + // @Column({ + // nullable: true, + // comment: "ประเภท(กลุ่มอาชีพ คุณสมบัติ)", + // default: null, + // }) + // type: string; @Column({ nullable: true, @@ -73,6 +72,12 @@ export class PlannedGoal extends EntityBase { @ManyToOne(() => Development, (development: Development) => development.developmentPlannedGoals) @JoinColumn({ name: "developmentPlannedGoalId" }) developmentPlannedGoal: Development; + + @OneToMany( + () => PlannedGoalPosition, + (plannedGoalPosition: PlannedGoalPosition) => plannedGoalPosition.plannedGoal, + ) + plannedGoalPositions: PlannedGoalPosition[]; } export class CreatePlannedGoal { @@ -81,11 +86,11 @@ export class CreatePlannedGoal { @Column() groupTargetSub: string | null; @Column() - position: string | null; - @Column() - posTypePlannedId: string | null; - @Column() - posLevelPlannedId: string | null; + positions: CreatePlannedGoalPosition[]; + // @Column() + // posTypePlannedId: string | null; + // @Column() + // posLevelPlannedId: string | null; @Column() type: string | null; @Column() diff --git a/src/entities/PlannedGoalPosition.ts b/src/entities/PlannedGoalPosition.ts new file mode 100644 index 0000000..01a088c --- /dev/null +++ b/src/entities/PlannedGoalPosition.ts @@ -0,0 +1,59 @@ +import { Entity, Column, ManyToOne, JoinColumn } from "typeorm"; +import { EntityBase } from "./base/Base"; +import { PosType } from "./PosType"; +import { PosLevel } from "./PosLevel"; +import { PlannedGoal } from "./PlannedGoal"; + +@Entity("plannedGoalPosition") +export class PlannedGoalPosition extends EntityBase { + @Column({ + nullable: true, + comment: "ตำแหน่ง", + default: null, + }) + position: string; + + @Column({ + nullable: true, + comment: "ประเภทตำแหน่ง", + default: null, + }) + posTypePlannedId: string; + + @ManyToOne(() => PosType, (posType: PosType) => posType.plannedGoalPositions) + @JoinColumn({ name: "posTypePlannedId" }) + posTypePlanned: PosType; + + @Column({ + nullable: true, + comment: "ระดับตำแหน่ง", + default: null, + }) + posLevelPlannedId: string; + + @ManyToOne(() => PosLevel, (posLevel: PosLevel) => posLevel.plannedGoalPositions) + @JoinColumn({ name: "posLevelPlannedId" }) + posLevelPlanned: PosLevel; + + @Column({ + nullable: true, + comment: "id โครงการ", + default: null, + }) + plannedGoalId: string; + + @ManyToOne(() => PlannedGoal, (plannedGoal: PlannedGoal) => plannedGoal.plannedGoalPositions) + @JoinColumn({ name: "plannedGoalId" }) + plannedGoal: PlannedGoal; +} + +export class CreatePlannedGoalPosition { + @Column() + position: string | null; + @Column() + posTypePlannedId: string | null; + @Column() + posLevelPlannedId: string | null; +} + +export type UpdatePlannedGoalPosition = Partial; diff --git a/src/entities/PosLevel.ts b/src/entities/PosLevel.ts index e3c526d..705b6b8 100644 --- a/src/entities/PosLevel.ts +++ b/src/entities/PosLevel.ts @@ -2,9 +2,9 @@ import { Entity, Column, ManyToOne, JoinColumn, OneToMany } from "typeorm"; import { EntityBase } from "./base/Base"; import { PosType } from "./PosType"; import { ActualGoal } from "./ActualGoal"; -import { PlannedGoal } from "./PlannedGoal"; import { DevelopmentHistory } from "./DevelopmentHistory"; import { DevelopmentScholarship } from "./DevelopmentScholarship"; +import { PlannedGoalPosition } from "./PlannedGoalPosition"; enum PosLevelAuthority { HEAD = "HEAD", @@ -51,8 +51,11 @@ export class PosLevel extends EntityBase { @OneToMany(() => ActualGoal, (actualGoal: ActualGoal) => actualGoal.posLevelActual) actualGoals: ActualGoal[]; - @OneToMany(() => PlannedGoal, (plannedGoal: PlannedGoal) => plannedGoal.posLevelPlanned) - plannedGoals: PlannedGoal[]; + @OneToMany( + () => PlannedGoalPosition, + (plannedGoalPosition: PlannedGoalPosition) => plannedGoalPosition.posLevelPlanned, + ) + plannedGoalPositions: PlannedGoalPosition[]; @OneToMany(() => DevelopmentHistory, (developmentHistory) => developmentHistory.posLevel) developmentHistorys: DevelopmentHistory[]; diff --git a/src/entities/PosType.ts b/src/entities/PosType.ts index 6a8574c..d18e7fb 100644 --- a/src/entities/PosType.ts +++ b/src/entities/PosType.ts @@ -5,6 +5,7 @@ import { ActualGoal } from "./ActualGoal"; import { PlannedGoal } from "./PlannedGoal"; import { DevelopmentHistory } from "./DevelopmentHistory"; import { DevelopmentScholarship } from "./DevelopmentScholarship"; +import { PlannedGoalPosition } from "./PlannedGoalPosition"; @Entity("posType") export class PosType extends EntityBase { @@ -30,8 +31,11 @@ export class PosType extends EntityBase { @OneToMany(() => ActualGoal, (actualGoal: ActualGoal) => actualGoal.posTypeActual) actualGoals: ActualGoal[]; - @OneToMany(() => PlannedGoal, (plannedGoal: PlannedGoal) => plannedGoal.posTypePlanned) - plannedGoals: PlannedGoal[]; + @OneToMany( + () => PlannedGoalPosition, + (plannedGoalPosition: PlannedGoalPosition) => plannedGoalPosition.posTypePlanned, + ) + plannedGoalPositions: PlannedGoalPosition[]; @OneToMany(() => DevelopmentHistory, (developmentHistory) => developmentHistory.posType) developmentHistorys: DevelopmentHistory[]; diff --git a/src/entities/Province.ts b/src/entities/Province.ts index 0ab83ff..e251957 100644 --- a/src/entities/Province.ts +++ b/src/entities/Province.ts @@ -1,4 +1,4 @@ -import { Entity, Column, OneToMany } from "typeorm"; +import { Entity, Column, OneToMany, ManyToMany, JoinTable } from "typeorm"; import { EntityBase } from "./base/Base"; import { Development } from "./Development"; @@ -12,8 +12,9 @@ export class Province extends EntityBase { }) name: string; - @OneToMany(() => Development, (development: Development) => development.province) - developments: Development[]; + @ManyToMany(() => Development, (development) => development.provinces) + @JoinTable() + developmentProvinces: Development[]; @OneToMany(() => Development, (development: Development) => development.provinceActual) developmentActuals: Development[]; diff --git a/src/migration/1712670681087-update_table_developement_add_projectType.ts b/src/migration/1712670681087-update_table_developement_add_projectType.ts new file mode 100644 index 0000000..f9ee7ca --- /dev/null +++ b/src/migration/1712670681087-update_table_developement_add_projectType.ts @@ -0,0 +1,60 @@ +import { MigrationInterface, QueryRunner } from "typeorm"; + +export class UpdateTableDevelopementAddProjectType1712670681087 implements MigrationInterface { + name = 'UpdateTableDevelopementAddProjectType1712670681087' + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`plannedGoal\` DROP FOREIGN KEY \`FK_0e6aba627301f35aa3570b44bf5\``); + await queryRunner.query(`ALTER TABLE \`plannedGoal\` DROP FOREIGN KEY \`FK_308d02f616b878261a3890b4d40\``); + await queryRunner.query(`ALTER TABLE \`development\` DROP FOREIGN KEY \`FK_c7552b4624cc7347144be758e6e\``); + await queryRunner.query(`CREATE TABLE \`plannedGoalPosition\` (\`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', \`position\` varchar(255) NULL COMMENT 'ตำแหน่ง', \`posTypePlannedId\` varchar(255) NULL COMMENT 'ประเภทตำแหน่ง', \`posLevelPlannedId\` varchar(255) NULL COMMENT 'ระดับตำแหน่ง', \`plannedGoalId\` varchar(255) NULL COMMENT 'id โครงการ', PRIMARY KEY (\`id\`)) ENGINE=InnoDB`); + await queryRunner.query(`CREATE TABLE \`province_development_provinces_development\` (\`provinceId\` varchar(36) NOT NULL, \`developmentId\` varchar(36) NOT NULL, INDEX \`IDX_32e044775dec4423645a09d90e\` (\`provinceId\`), INDEX \`IDX_66246e941aca36d81e7c8e0c88\` (\`developmentId\`), PRIMARY KEY (\`provinceId\`, \`developmentId\`)) ENGINE=InnoDB`); + await queryRunner.query(`ALTER TABLE \`plannedGoal\` DROP COLUMN \`position\``); + await queryRunner.query(`ALTER TABLE \`plannedGoal\` DROP COLUMN \`posTypePlannedId\``); + await queryRunner.query(`ALTER TABLE \`plannedGoal\` DROP COLUMN \`posLevelPlannedId\``); + await queryRunner.query(`ALTER TABLE \`plannedGoal\` DROP COLUMN \`type\``); + await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`provinceId\``); + await queryRunner.query(`ALTER TABLE \`development\` ADD \`projectType\` varchar(255) NULL COMMENT 'ประเภทโครงการ'`); + await queryRunner.query(`ALTER TABLE \`development\` ADD \`projectCharacteristics\` varchar(255) NULL COMMENT 'ลักษณะ'`); + await queryRunner.query(`ALTER TABLE \`development\` ADD \`projectDay\` int NULL COMMENT 'จำนวน(วัน)'`); + await queryRunner.query(`ALTER TABLE \`development\` ADD \`projectNigth\` int NULL COMMENT 'จำนวน(คืน)'`); + await queryRunner.query(`ALTER TABLE \`development\` ADD \`projectTechniques\` varchar(255) NULL COMMENT 'เทคนิควิธีการที่ใช้ในการพัฒนา'`); + await queryRunner.query(`ALTER TABLE \`development\` ADD \`projectModal\` int NULL COMMENT 'จำนวน(รุ่น)'`); + await queryRunner.query(`ALTER TABLE \`development\` ADD \`budgetSub\` varchar(255) NULL COMMENT 'ประเภทย่อย'`); + await queryRunner.query(`ALTER TABLE \`developmentScholarship\` ADD \`status\` varchar(40) NULL COMMENT 'สถานะ' DEFAULT 'PENDING'`); + await queryRunner.query(`ALTER TABLE \`plannedGoalPosition\` ADD CONSTRAINT \`FK_4eef5d8c3ab92f7af4a762150a4\` FOREIGN KEY (\`posTypePlannedId\`) REFERENCES \`posType\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`); + await queryRunner.query(`ALTER TABLE \`plannedGoalPosition\` ADD CONSTRAINT \`FK_8e7e0bf6eebd99f58e9b47c6b05\` FOREIGN KEY (\`posLevelPlannedId\`) REFERENCES \`posLevel\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`); + await queryRunner.query(`ALTER TABLE \`plannedGoalPosition\` ADD CONSTRAINT \`FK_f2fad93b1a4a3454f0de1c12c62\` FOREIGN KEY (\`plannedGoalId\`) REFERENCES \`plannedGoal\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`); + await queryRunner.query(`ALTER TABLE \`province_development_provinces_development\` ADD CONSTRAINT \`FK_32e044775dec4423645a09d90e6\` FOREIGN KEY (\`provinceId\`) REFERENCES \`province\`(\`id\`) ON DELETE CASCADE ON UPDATE CASCADE`); + await queryRunner.query(`ALTER TABLE \`province_development_provinces_development\` ADD CONSTRAINT \`FK_66246e941aca36d81e7c8e0c888\` FOREIGN KEY (\`developmentId\`) REFERENCES \`development\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`); + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`province_development_provinces_development\` DROP FOREIGN KEY \`FK_66246e941aca36d81e7c8e0c888\``); + await queryRunner.query(`ALTER TABLE \`province_development_provinces_development\` DROP FOREIGN KEY \`FK_32e044775dec4423645a09d90e6\``); + await queryRunner.query(`ALTER TABLE \`plannedGoalPosition\` DROP FOREIGN KEY \`FK_f2fad93b1a4a3454f0de1c12c62\``); + await queryRunner.query(`ALTER TABLE \`plannedGoalPosition\` DROP FOREIGN KEY \`FK_8e7e0bf6eebd99f58e9b47c6b05\``); + await queryRunner.query(`ALTER TABLE \`plannedGoalPosition\` DROP FOREIGN KEY \`FK_4eef5d8c3ab92f7af4a762150a4\``); + await queryRunner.query(`ALTER TABLE \`developmentScholarship\` DROP COLUMN \`status\``); + await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`budgetSub\``); + await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`projectModal\``); + await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`projectTechniques\``); + await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`projectNigth\``); + await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`projectDay\``); + await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`projectCharacteristics\``); + await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`projectType\``); + await queryRunner.query(`ALTER TABLE \`development\` ADD \`provinceId\` varchar(255) NULL COMMENT 'จังหวัด'`); + await queryRunner.query(`ALTER TABLE \`plannedGoal\` ADD \`type\` varchar(255) NULL COMMENT 'ประเภท(กลุ่มอาชีพ คุณสมบัติ)'`); + await queryRunner.query(`ALTER TABLE \`plannedGoal\` ADD \`posLevelPlannedId\` varchar(255) NULL COMMENT 'ระดับตำแหน่ง'`); + await queryRunner.query(`ALTER TABLE \`plannedGoal\` ADD \`posTypePlannedId\` varchar(255) NULL COMMENT 'ประเภทตำแหน่ง'`); + await queryRunner.query(`ALTER TABLE \`plannedGoal\` ADD \`position\` varchar(255) NULL COMMENT 'ตำแหน่ง'`); + await queryRunner.query(`DROP INDEX \`IDX_66246e941aca36d81e7c8e0c88\` ON \`province_development_provinces_development\``); + await queryRunner.query(`DROP INDEX \`IDX_32e044775dec4423645a09d90e\` ON \`province_development_provinces_development\``); + await queryRunner.query(`DROP TABLE \`province_development_provinces_development\``); + await queryRunner.query(`DROP TABLE \`plannedGoalPosition\``); + await queryRunner.query(`ALTER TABLE \`development\` ADD CONSTRAINT \`FK_c7552b4624cc7347144be758e6e\` FOREIGN KEY (\`provinceId\`) REFERENCES \`province\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`); + await queryRunner.query(`ALTER TABLE \`plannedGoal\` ADD CONSTRAINT \`FK_308d02f616b878261a3890b4d40\` FOREIGN KEY (\`posTypePlannedId\`) REFERENCES \`posType\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`); + await queryRunner.query(`ALTER TABLE \`plannedGoal\` ADD CONSTRAINT \`FK_0e6aba627301f35aa3570b44bf5\` FOREIGN KEY (\`posLevelPlannedId\`) REFERENCES \`posLevel\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`); + } + +} From b8e1c93cb48f4eba2e9f65e8d515f1eacba5e5dc Mon Sep 17 00:00:00 2001 From: Kittapath Date: Wed, 10 Apr 2024 11:53:25 +0700 Subject: [PATCH 042/250] =?UTF-8?q?=E0=B8=9A=E0=B8=B1=E0=B8=99=E0=B8=97?= =?UTF-8?q?=E0=B8=B6=E0=B8=81=E0=B8=A5=E0=B8=87=E0=B8=97=E0=B8=B0=E0=B9=80?= =?UTF-8?q?=E0=B8=9A=E0=B8=B5=E0=B8=A2=E0=B8=99=E0=B8=9B=E0=B8=A3=E0=B8=B0?= =?UTF-8?q?=E0=B8=A7=E0=B8=B1=E0=B8=95=E0=B8=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DevelopmentScholarshipController.ts | 60 ++++++++++++++++--- src/entities/DevelopmentScholarship.ts | 10 ++++ ...-update_table_scholarship_add_ProfileId.ts | 14 +++++ 3 files changed, 77 insertions(+), 7 deletions(-) create mode 100644 src/migration/1712721970803-update_table_scholarship_add_ProfileId.ts diff --git a/src/controllers/DevelopmentScholarshipController.ts b/src/controllers/DevelopmentScholarshipController.ts index 3525811..10b552b 100644 --- a/src/controllers/DevelopmentScholarshipController.ts +++ b/src/controllers/DevelopmentScholarshipController.ts @@ -24,6 +24,7 @@ import { } from "../entities/DevelopmentScholarship"; import { PosType } from "../entities/PosType"; import { PosLevel } from "../entities/PosLevel"; +import CallAPI from "../interfaces/call-api"; @Route("api/v1/development/scholarship") @Tags("DevelopmentScholarship") @@ -75,7 +76,7 @@ export class DevelopmentScholarshipController extends Controller { * * @summary DEV_012 - แก้ไขทุนการศึกษา/ฝึกอบรม #12 * - * @param {string} id Id โครงการ + * @param {string} id Id ข้าราชการฯที่ได้รับทุนการศึกษา */ @Put("{id}") async UpdateDevelopmentScholarship( @@ -117,7 +118,7 @@ export class DevelopmentScholarshipController extends Controller { * * @summary DEV_013 - ลบทุนการศึกษา/ฝึกอบรม #13 * - * @param {string} id Id โครงการ + * @param {string} id Id ข้าราชการฯที่ได้รับทุนการศึกษา */ @Delete("{id}") async DeleteDevelopmentScholarship(@Path() id: string) { @@ -224,7 +225,7 @@ export class DevelopmentScholarshipController extends Controller { * * @summary DEV_015 - รายละเอียดทุนการศึกษา/ฝึกอบรม #15 * - * @param {string} id Id โครงการ + * @param {string} id Id ข้าราชการฯที่ได้รับทุนการศึกษา */ @Get("{id}") async GetDevelopemtScholarshipById(@Path() id: string) { @@ -321,11 +322,15 @@ export class DevelopmentScholarshipController extends Controller { * * @summary DEV_0 - เปลี่ยนสถานะ # * - * @param {string} id Id โครงการ + * @param {string} id Id ข้าราชการฯที่ได้รับทุนการศึกษา * @param {string} status status สถานะ */ @Get("status/{id}/{status}") - async ChangeStatusDevelopemtScholarshipById(@Path() id: string, @Path() status: string) { + async ChangeStatusDevelopemtScholarshipById( + @Path() id: string, + @Path() status: string, + @Request() request: { user: Record }, + ) { const getDevelopment = await this.developmentScholarshipRepository.findOne({ where: { id: id }, }); @@ -335,12 +340,53 @@ export class DevelopmentScholarshipController extends Controller { const _status = status.trim().toUpperCase(); getDevelopment.status = _status; if (_status == "GRADUATE") { - //xxxxxxxxxxxxxxxxxxxบันทึกลงทะเบียน + if (getDevelopment.scholarshipType != null) { + switch (getDevelopment.scholarshipType.trim().toUpperCase()) { + case "DOMESTICE": + getDevelopment.scholarshipType = "การศึกษาในประเทศ"; + break; + case "NOABROAD": + getDevelopment.scholarshipType = + "ฝึกอบรมในประเทศที่ส่งไปพัฒนากับหน่วยวงานภายนอก (หลักสูตรที่ไม่มีการไปต่างประเทศ)"; + break; + case "ABROAD": + getDevelopment.scholarshipType = + "ฝึกอบรมในประเทศที่ส่งไปพัฒนากับหน่วยวงานภายนอก (หลักสูตรที่มีการไปต่างประเทศ)"; + break; + case "EXECUTIVE": + getDevelopment.scholarshipType = + "ฝึกอบรมในประเทศที่ส่งไปพัฒนากับหน่วยวงานภายนอก (หลักสูตรประเภทนักบริหาร)"; + break; + default: + break; + } + } + let profileEdu = await new CallAPI().PostData(request, "org/profile/educations", { + profileId: getDevelopment.profileId, + institute: getDevelopment.educationalInstitution, + startDate: getDevelopment.startDate, + endDate: getDevelopment.endDate, + finishDate: null, + isEducation: false, + degree: null, + field: getDevelopment.field, + fundName: getDevelopment.scholarshipType, + gpa: null, + country: getDevelopment.studyCountry, + other: null, + duration: getDevelopment.totalPeriod, + durationYear: 0, + note: null, + educationLevel: getDevelopment.degreeLevel, + educationLevelId: null, + isDate: false, + positionPath: null, + positionPathId: null, + }); } else if (_status == "NOTGRADUATE") { } else { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบสถานะนี้ในระบบ"); } - await this.developmentScholarshipRepository.remove(getDevelopment); return new HttpSuccess(); } diff --git a/src/entities/DevelopmentScholarship.ts b/src/entities/DevelopmentScholarship.ts index 1ebb953..fa3e020 100644 --- a/src/entities/DevelopmentScholarship.ts +++ b/src/entities/DevelopmentScholarship.ts @@ -5,6 +5,14 @@ import { PosType } from "./PosType"; @Entity("developmentScholarship") export class DevelopmentScholarship extends EntityBase { + @Column({ + nullable: true, + comment: "id profile", + length: 40, + default: null, + }) + profileId: string; + @Column({ // PENDING = ค่าเริ่มต้น // GRADUATE = สำเร็จการศึกษา @@ -423,6 +431,7 @@ export class DevelopmentScholarship extends EntityBase { totalPeriod: string; } export class CreateDevelopmentScholarship { + profileId: string | null; rank?: string | null; prefix: string | null; firstName: string | null; @@ -475,6 +484,7 @@ export class CreateDevelopmentScholarship { } export class UpdateDevelopmentScholarship { + profileId: string | null; rank?: string | null; prefix: string | null; firstName: string | null; diff --git a/src/migration/1712721970803-update_table_scholarship_add_ProfileId.ts b/src/migration/1712721970803-update_table_scholarship_add_ProfileId.ts new file mode 100644 index 0000000..6cb2892 --- /dev/null +++ b/src/migration/1712721970803-update_table_scholarship_add_ProfileId.ts @@ -0,0 +1,14 @@ +import { MigrationInterface, QueryRunner } from "typeorm"; + +export class UpdateTableScholarshipAddProfileId1712721970803 implements MigrationInterface { + name = 'UpdateTableScholarshipAddProfileId1712721970803' + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`developmentScholarship\` ADD \`profileId\` varchar(40) NULL COMMENT 'id profile'`); + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`developmentScholarship\` DROP COLUMN \`profileId\``); + } + +} From f14478274be2a3c44043bd91c7d2539d304a560c Mon Sep 17 00:00:00 2001 From: AdisakKanthawilang Date: Thu, 11 Apr 2024 11:35:19 +0700 Subject: [PATCH 043/250] enitity startegy --- src/entities/StrategyChild1.ts | 38 ++++++++++++++++++ src/entities/StrategyChild2.ts | 50 ++++++++++++++++++++++++ src/entities/StrategyChild3.ts | 55 ++++++++++++++++++++++++++ src/entities/StrategyChild4.ts | 62 ++++++++++++++++++++++++++++++ src/entities/StrategyChild5.ts | 70 ++++++++++++++++++++++++++++++++++ 5 files changed, 275 insertions(+) create mode 100644 src/entities/StrategyChild1.ts create mode 100644 src/entities/StrategyChild2.ts create mode 100644 src/entities/StrategyChild3.ts create mode 100644 src/entities/StrategyChild4.ts create mode 100644 src/entities/StrategyChild5.ts diff --git a/src/entities/StrategyChild1.ts b/src/entities/StrategyChild1.ts new file mode 100644 index 0000000..0cd0ab4 --- /dev/null +++ b/src/entities/StrategyChild1.ts @@ -0,0 +1,38 @@ +import { Entity, Column, ManyToOne, JoinColumn, OneToMany, PrimaryGeneratedColumn } from "typeorm"; +import { EntityBase } from "./base/Base"; +import { StrategyChild2 } from "./StrategyChild2"; +import { StrategyChild3 } from "./StrategyChild3"; +import { StrategyChild4 } from "./StrategyChild4"; +import { StrategyChild5 } from "./StrategyChild5"; + + +@Entity("strategyChild1") +export class StrategyChild1 extends EntityBase { + @Column({ + nullable: true, + comment: "ชื่อยุทธศาสตร์", + length: 255, + default: null, + }) + strategyChild1Name: string; + + @OneToMany(() => StrategyChild2, (strategyChild2) => strategyChild2.strategyChild1) + strategyChild2s: StrategyChild2[]; + + @OneToMany(() => StrategyChild3, (strategyChild3) => strategyChild3.strategyChild1) + strategyChild3s: StrategyChild3[]; + + @OneToMany(() => StrategyChild4, (strategyChild4) => strategyChild4.strategyChild1) + strategyChild4s: StrategyChild4[]; + + @OneToMany(() => StrategyChild5, (strategyChild5) => strategyChild5.strategyChild1) + strategyChild5s: StrategyChild5[]; + +} + +export class CreateStrategyChild1 { + @Column() + strategyChild1Name: string; +} + +export type UpdateStrategyChild1 = Partial; diff --git a/src/entities/StrategyChild2.ts b/src/entities/StrategyChild2.ts new file mode 100644 index 0000000..fbc74ef --- /dev/null +++ b/src/entities/StrategyChild2.ts @@ -0,0 +1,50 @@ +import { Entity, Column, ManyToOne, JoinColumn, OneToMany, PrimaryGeneratedColumn } from "typeorm"; +import { EntityBase } from "./base/Base"; +import { StrategyChild1 } from "./StrategyChild1"; +import { StrategyChild3 } from "./StrategyChild3"; +import { StrategyChild4 } from "./StrategyChild4"; +import { StrategyChild5 } from "./StrategyChild5"; + + +@Entity("strategyChild2") +export class StrategyChild2 extends EntityBase { + @Column({ + nullable: true, + comment: "ชื่อยุทธศาสตร์/แผน", + length: 255, + default: null, + }) + strategyChild2Name: string; + + @Column({ + length: 40, + comment: "คีย์นอก(FK)ของตาราง strategyChild1", + }) + strategyChild1Id: string; + + @ManyToOne(() => StrategyChild1, (strategyChild1) => strategyChild1.strategyChild2s) + @JoinColumn({ name: "strategyChild1Id" }) + strategyChild1: StrategyChild1; + + @OneToMany(() => StrategyChild3, (strategyChild3) => strategyChild3.strategyChild2) + strategyChild3s: StrategyChild3[]; + + @OneToMany(() => StrategyChild4, (strategyChild4) => strategyChild4.strategyChild2) + strategyChild4s: StrategyChild4[]; + + @OneToMany(() => StrategyChild5, (strategyChild5) => strategyChild5.strategyChild2) + strategyChild5s: StrategyChild5[]; + + + +} + +export class CreateStrategyChild2 { + @Column() + strategyChild2Name: string; + + @Column("uuid") + strategyChild1Id: string; +} + +export type UpdateStrategyChild2 = Partial; diff --git a/src/entities/StrategyChild3.ts b/src/entities/StrategyChild3.ts new file mode 100644 index 0000000..2166902 --- /dev/null +++ b/src/entities/StrategyChild3.ts @@ -0,0 +1,55 @@ +import { Entity, Column, ManyToOne, JoinColumn, OneToMany, PrimaryGeneratedColumn } from "typeorm"; +import { EntityBase } from "./base/Base"; +import { StrategyChild1 } from "./StrategyChild1"; +import { StrategyChild2 } from "./StrategyChild2"; +import { StrategyChild4 } from "./StrategyChild4"; +import { StrategyChild5 } from "./StrategyChild5"; + + +@Entity("strategyChild3") +export class StrategyChild3 extends EntityBase { + @Column({ + nullable: true, + comment: "ยุทธศาสตร์ที่", + length: 255, + default: null, + }) + strategyChild3Name: string; + + @Column({ + length: 40, + comment: "คีย์นอก(FK)ของตาราง strategyChild1", + }) + strategyChild1Id: string; + + @Column({ + length: 40, + comment: "คีย์นอก(FK)ของตาราง strategyChild2", + }) + strategyChild2Id: string; + + @ManyToOne(() => StrategyChild1, (strategyChild1) => strategyChild1.strategyChild3s) + @JoinColumn({ name: "strategyChild1Id" }) + strategyChild1: StrategyChild1; + + @ManyToOne(() => StrategyChild2, (strategyChild2) => strategyChild2.strategyChild3s) + @JoinColumn({ name: "strategyChild2Id" }) + strategyChild2: StrategyChild2; + + @OneToMany(() => StrategyChild4, (strategyChild4) => strategyChild4.strategyChild3) + strategyChild4s: StrategyChild4[]; + + @OneToMany(() => StrategyChild5, (strategyChild5) => strategyChild5.strategyChild3) + strategyChild5s: StrategyChild5[]; + +} + +export class CreateStrategyChild3 { + @Column() + strategyChild3Name: string; + + @Column("uuid") + strategyChild2Id: string; +} + +export type UpdateStrategyChild3 = Partial; diff --git a/src/entities/StrategyChild4.ts b/src/entities/StrategyChild4.ts new file mode 100644 index 0000000..290fd85 --- /dev/null +++ b/src/entities/StrategyChild4.ts @@ -0,0 +1,62 @@ +import { Entity, Column, ManyToOne, JoinColumn, OneToMany, PrimaryGeneratedColumn } from "typeorm"; +import { EntityBase } from "./base/Base"; +import { StrategyChild1 } from "./StrategyChild1"; +import { StrategyChild2 } from "./StrategyChild2"; +import { StrategyChild3 } from "./StrategyChild3"; +import { StrategyChild5 } from "./StrategyChild5"; + + +@Entity("strategyChild4") +export class StrategyChild4 extends EntityBase { + @Column({ + nullable: true, + comment: "ยุทธศาสตร์ย่อยที่", + length: 255, + default: null, + }) + strategyChild4Name: string; + + @Column({ + length: 40, + comment: "คีย์นอก(FK)ของตาราง strategyChild1", + }) + strategyChild1Id: string; + + @Column({ + length: 40, + comment: "คีย์นอก(FK)ของตาราง strategyChild2", + }) + strategyChild2Id: string; + + @Column({ + length: 40, + comment: "คีย์นอก(FK)ของตาราง strategyChild3", + }) + strategyChild3Id: string; + + @ManyToOne(() => StrategyChild1, (strategyChild1) => strategyChild1.strategyChild4s) + @JoinColumn({ name: "strategyChild1Id" }) + strategyChild1: StrategyChild1; + + @ManyToOne(() => StrategyChild2, (strategyChild2) => strategyChild2.strategyChild4s) + @JoinColumn({ name: "strategyChild2Id" }) + strategyChild2: StrategyChild2; + + @ManyToOne(() => StrategyChild3, (strategyChild3) => strategyChild3.strategyChild4s) + @JoinColumn({ name: "strategyChild3Id" }) + strategyChild3: StrategyChild3; + + @OneToMany(() => StrategyChild5, (strategyChild5) => strategyChild5.strategyChild4) + strategyChild5s: StrategyChild5[]; +} + + +export class CreateStrategyChild4 { + @Column() + strategyChild4Name: string; + + @Column("uuid") + strategyChild3Id: string; +} + +export type UpdateStrategyChild4 = Partial; diff --git a/src/entities/StrategyChild5.ts b/src/entities/StrategyChild5.ts new file mode 100644 index 0000000..2fa84a4 --- /dev/null +++ b/src/entities/StrategyChild5.ts @@ -0,0 +1,70 @@ +import { Entity, Column, ManyToOne, JoinColumn, OneToMany, PrimaryGeneratedColumn } from "typeorm"; +import { EntityBase } from "./base/Base"; +import { StrategyChild1 } from "./StrategyChild1"; +import { StrategyChild2 } from "./StrategyChild2"; +import { StrategyChild3 } from "./StrategyChild3"; +import { StrategyChild4 } from "./StrategyChild4"; + + +@Entity("strategyChild5") +export class StrategyChild5 extends EntityBase { + @Column({ + nullable: true, + comment: "กลยุทธ์ที่", + length: 255, + default: null, + }) + strategyChild5Name: string; + + @Column({ + length: 40, + comment: "คีย์นอก(FK)ของตาราง strategyChild1", + }) + strategyChild1Id: string; + + @Column({ + length: 40, + comment: "คีย์นอก(FK)ของตาราง strategyChild2", + }) + strategyChild2Id: string; + + @Column({ + length: 40, + comment: "คีย์นอก(FK)ของตาราง strategyChild3", + }) + strategyChild3Id: string; + + @Column({ + length: 40, + comment: "คีย์นอก(FK)ของตาราง strategyChild4", + }) + strategyChild4Id: string; + + @ManyToOne(() => StrategyChild1, (strategyChild1) => strategyChild1.strategyChild5s) + @JoinColumn({ name: "strategyChild1Id" }) + strategyChild1: StrategyChild1; + + @ManyToOne(() => StrategyChild2, (strategyChild2) => strategyChild2.strategyChild5s) + @JoinColumn({ name: "strategyChild2Id" }) + strategyChild2: StrategyChild2; + + @ManyToOne(() => StrategyChild3, (strategyChild3) => strategyChild3.strategyChild5s) + @JoinColumn({ name: "strategyChild3Id" }) + strategyChild3: StrategyChild3; + + @ManyToOne(() => StrategyChild4, (strategyChild4) => strategyChild4.strategyChild5s) + @JoinColumn({ name: "strategyChild4Id" }) + strategyChild4: StrategyChild4; + +} + + +export class CreateStrategyChild5 { + @Column() + strategyChild5Name: string; + + @Column("uuid") + strategyChild4Id: string; +} + +export type UpdateStrategyChild5 = Partial; From 4f8b2cec736ba0419dbde5b3efd815323814bbf7 Mon Sep 17 00:00:00 2001 From: Kittapath Date: Thu, 11 Apr 2024 11:39:56 +0700 Subject: [PATCH 044/250] =?UTF-8?q?=E0=B8=9B=E0=B8=A3=E0=B8=B1=E0=B8=9A?= =?UTF-8?q?=E0=B9=82=E0=B8=84=E0=B8=A3=E0=B8=87=E0=B8=B2=E0=B8=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/DevelopmentController.ts | 1057 +++++++++++++---- .../DevelopmentScholarshipController.ts | 1 + src/entities/Development.ts | 422 +++---- src/entities/DevelopmentAddress.ts | 42 + src/entities/DevelopmentEvaluation.ts | 90 ++ src/entities/DevelopmentProjectTechnique.ts | 39 + src/entities/DevelopmentProjectType.ts | 32 + src/entities/Province.ts | 9 +- ...1712778363784-update_table_dev_refresh1.ts | 92 ++ ...1712779710145-update_table_dev_refresh2.ts | 16 + 10 files changed, 1317 insertions(+), 483 deletions(-) create mode 100644 src/entities/DevelopmentAddress.ts create mode 100644 src/entities/DevelopmentEvaluation.ts create mode 100644 src/entities/DevelopmentProjectTechnique.ts create mode 100644 src/entities/DevelopmentProjectType.ts create mode 100644 src/migration/1712778363784-update_table_dev_refresh1.ts create mode 100644 src/migration/1712779710145-update_table_dev_refresh2.ts diff --git a/src/controllers/DevelopmentController.ts b/src/controllers/DevelopmentController.ts index b7013c5..466db5e 100644 --- a/src/controllers/DevelopmentController.ts +++ b/src/controllers/DevelopmentController.ts @@ -18,21 +18,42 @@ import { In, Not } from "typeorm"; import HttpSuccess from "../interfaces/http-success"; import HttpError from "../interfaces/http-error"; import HttpStatusCode from "../interfaces/http-status"; -import { Development, CreateDevelopment, UpdateDevelopment } from "../entities/Development"; -import { ActualPeople } from "../entities/ActualPeople"; -import { PlannedPeople } from "../entities/PlannedPeople"; -import { ActualGoal } from "../entities/ActualGoal"; -import { PlannedGoal } from "../entities/PlannedGoal"; +import { + Development, + CreateDevelopment, + UpdateDevelopment1, + UpdateDevelopment2_1, + UpdateDevelopment2_2, + UpdateDevelopment3, + UpdateDevelopment4, + UpdateDevelopment5, +} from "../entities/Development"; +import { ActualPeople, CreateActualPeople } from "../entities/ActualPeople"; +import { CreatePlannedPeople, PlannedPeople } from "../entities/PlannedPeople"; +import { ActualGoal, CreateActualGoal } from "../entities/ActualGoal"; +import { CreatePlannedGoal, PlannedGoal } from "../entities/PlannedGoal"; import { Province } from "../entities/Province"; import { PosType } from "../entities/PosType"; import { PosLevel } from "../entities/PosLevel"; import { PlannedGoalPosition } from "../entities/PlannedGoalPosition"; +import { DevelopmentHistory } from "../entities/DevelopmentHistory"; +import { DevelopmentProjectType } from "../entities/DevelopmentProjectType"; +import { DevelopmentProjectTechnique } from "../entities/DevelopmentProjectTechnique"; +import { DevelopmentEvaluation } from "../entities/DevelopmentEvaluation"; +import { DevelopmentAddress } from "../entities/DevelopmentAddress"; @Route("api/v1/development/main") @Tags("Development") @Security("bearerAuth") export class DevelopmentController extends Controller { private developmentRepository = AppDataSource.getRepository(Development); + private developmentAddresssRepository = AppDataSource.getRepository(DevelopmentAddress); + private developmentEvaluationRepository = AppDataSource.getRepository(DevelopmentEvaluation); + private developmentProjectTypeRepository = AppDataSource.getRepository(DevelopmentProjectType); + private developmentProjectTechniqueRepository = AppDataSource.getRepository( + DevelopmentProjectTechnique, + ); + private developmentHistoryRepository = AppDataSource.getRepository(DevelopmentHistory); private actualPeopleRepository = AppDataSource.getRepository(ActualPeople); private plannedPeopleRepository = AppDataSource.getRepository(PlannedPeople); private actualGoalRepository = AppDataSource.getRepository(ActualGoal); @@ -70,155 +91,34 @@ export class DevelopmentController extends Controller { ); } - if (requestBody.provinceActualId != null) { - const checkId = await this.provinceRepository.findOne({ - where: { id: requestBody.provinceActualId }, - }); - if (!checkId) { - throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลจังหวัดข้อมูลด้านวิชาการ"); - } - } - const development = Object.assign(new Development(), requestBody); - - if (requestBody.provinceIds != null) { - const chkProvince = await this.provinceRepository.find({ - where: { - id: In(requestBody.provinceIds), - }, - }); - - development.provinces = chkProvince; - } development.createdUserId = request.user.sub; development.createdFullName = request.user.name; development.lastUpdateUserId = request.user.sub; development.lastUpdateFullName = request.user.name; await this.developmentRepository.save(development); - await Promise.all( - requestBody.actualPeoples.map(async (x) => { - const data = Object.assign(new ActualPeople(), x); - data.createdUserId = request.user.sub; - data.createdFullName = request.user.name; - data.lastUpdateUserId = request.user.sub; - data.lastUpdateFullName = request.user.name; - data.developmentActualPeopleId = development.id; - await this.actualPeopleRepository.save(data); - }), - ); - await Promise.all( - requestBody.plannedPeoples.map(async (x) => { - const data = Object.assign(new PlannedPeople(), x); - data.createdUserId = request.user.sub; - data.createdFullName = request.user.name; - data.lastUpdateUserId = request.user.sub; - data.lastUpdateFullName = request.user.name; - data.developmentPlannedPeopleId = development.id; - await this.plannedPeopleRepository.save(data); - }), - ); - await Promise.all( - requestBody.actualGoals.map(async (x) => { - if (x.posTypeActualId != null) { - const checkId = await this.posTypeRepository.findOne({ - where: { id: x.posTypeActualId }, - }); - if (!checkId) { - throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลประเภทตำแหน่ง"); - } - } - if (x.posLevelActualId != null) { - const checkId = await this.posLevelRepository.findOne({ - where: { id: x.posLevelActualId }, - }); - if (!checkId) { - throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลระดับตำแหน่ง"); - } - } - const data = Object.assign(new ActualGoal(), x); - data.createdUserId = request.user.sub; - data.createdFullName = request.user.name; - data.lastUpdateUserId = request.user.sub; - data.lastUpdateFullName = request.user.name; - data.developmentActualGoalId = development.id; - await this.actualGoalRepository.save(data); - }), - ); - await Promise.all( - requestBody.plannedGoals.map(async (x) => { - const data = Object.assign(new PlannedGoal(), x); - data.createdUserId = request.user.sub; - data.createdFullName = request.user.name; - data.lastUpdateUserId = request.user.sub; - data.lastUpdateFullName = request.user.name; - data.developmentPlannedGoalId = development.id; - await this.plannedGoalRepository.save(data); - - await Promise.all( - x.positions.map(async (y) => { - const _data = Object.assign(new PlannedGoalPosition(), y); - if (y.posTypePlannedId != null) { - const checkId = await this.posTypeRepository.findOne({ - where: { id: y.posTypePlannedId }, - }); - if (!checkId) { - throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลประเภทตำแหน่ง"); - } - } - if (y.posLevelPlannedId != null) { - const checkId = await this.posLevelRepository.findOne({ - where: { id: y.posLevelPlannedId }, - }); - if (!checkId) { - throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลระดับตำแหน่ง"); - } - } - _data.createdUserId = request.user.sub; - _data.createdFullName = request.user.name; - _data.lastUpdateUserId = request.user.sub; - _data.lastUpdateFullName = request.user.name; - _data.plannedGoalId = data.id; - await this.plannedGoalPositionRepository.save(_data); - }), - ); - }), - ); return new HttpSuccess(development.id); } /** - * API แก้ไขโครงการ/หลักสูตรการฝึกอบรม + * API แก้ไขโครงการ/หลักสูตรการฝึกอบรม Tab1 * - * @summary DEV_002 - แก้ไขโครงการ/หลักสูตรการฝึกอบรม #2 + * @summary DEV_00 - แก้ไขโครงการ/หลักสูตรการฝึกอบรมTab1 # * * @param {string} id Id โครงการ */ - @Put("{id}") - async UpdateDevelopment( + @Put("tab1/{id}") + async UpdateDevelopmentTab1( @Path() id: string, - @Body() requestBody: UpdateDevelopment, + @Body() requestBody: UpdateDevelopment1, @Request() request: { user: Record }, ) { const development = await this.developmentRepository.findOne({ where: { id }, - relations: { - developmentActualPeoples: true, - developmentPlannedPeoples: true, - developmentActualGoals: true, - developmentPlannedGoals: true, - }, }); if (!development) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงการ/หลักสูตรการฝึกอบรมนี้"); } - if (requestBody.provinceActualId != null) { - const checkId = await this.provinceRepository.findOne({ - where: { id: requestBody.provinceActualId }, - }); - if (!checkId) { - throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลจังหวัดข้อมูลด้านวิชาการ"); - } - } const chk_name = await this.developmentRepository.find({ where: { projectName: requestBody.projectName, @@ -237,116 +137,562 @@ export class DevelopmentController extends Controller { ); } Object.assign(development, requestBody); - if ( - development.developmentPlannedGoals != null && - development.developmentPlannedGoals.length > 0 - ) { - const plannedGoalPosition = await this.plannedGoalPositionRepository.find({ - where: { plannedGoalId: In(development.developmentPlannedGoals.map((x) => x.id)) }, - }); - await this.plannedGoalPositionRepository.remove(plannedGoalPosition); - } - if (requestBody.provinceIds != null) { - const chkProvince = await this.provinceRepository.find({ - where: { - id: In(requestBody.provinceIds), - }, - }); - development.provinces = chkProvince; - } development.lastUpdateUserId = request.user.sub; development.lastUpdateFullName = request.user.name; await this.developmentRepository.save(development); - await this.actualPeopleRepository.remove(development.developmentActualPeoples); - await this.plannedPeopleRepository.remove(development.developmentPlannedPeoples); - await this.actualGoalRepository.remove(development.developmentActualGoals); - await this.plannedGoalRepository.remove(development.developmentPlannedGoals); + return new HttpSuccess(development.id); + } + + /** + * API เพิ่มโครงการ/หลักสูตรการฝึกอบรมtab2-1 + * + * @summary DEV_00 - เพิ่มโครงการ/หลักสูตรการฝึกอบรมtab2-1 # + * + * @param {string} id Id โครงการ + */ + @Put("tab2_1_add/{id}") + async CreateDevelopmenttab2_1( + @Path() id: string, + @Body() requestBody: CreatePlannedGoal, + @Request() request: { user: Record }, + ) { + const development = await this.developmentRepository.findOne({ + where: { id }, + }); + if (!development) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงการ/หลักสูตรการฝึกอบรมนี้"); + } + const data = Object.assign(new PlannedGoal(), requestBody); + data.createdUserId = request.user.sub; + data.createdFullName = request.user.name; + data.lastUpdateUserId = request.user.sub; + data.lastUpdateFullName = request.user.name; + data.developmentPlannedGoalId = development.id; + await this.plannedGoalRepository.save(data); + await Promise.all( - requestBody.actualPeoples.map(async (x) => { - const data = Object.assign(new ActualPeople(), x); - data.createdUserId = request.user.sub; - data.createdFullName = request.user.name; - data.lastUpdateUserId = request.user.sub; - data.lastUpdateFullName = request.user.name; - data.developmentActualPeopleId = development.id; - await this.actualPeopleRepository.save(data); - }), - ); - await Promise.all( - requestBody.plannedPeoples.map(async (x) => { - const data = Object.assign(new PlannedPeople(), x); - data.createdUserId = request.user.sub; - data.createdFullName = request.user.name; - data.lastUpdateUserId = request.user.sub; - data.lastUpdateFullName = request.user.name; - data.developmentPlannedPeopleId = development.id; - await this.plannedPeopleRepository.save(data); - }), - ); - await Promise.all( - requestBody.actualGoals.map(async (x) => { - if (x.posTypeActualId != null) { + requestBody.positions.map(async (x) => { + const _data = Object.assign(new PlannedGoalPosition(), x); + if (x.posTypePlannedId != null) { const checkId = await this.posTypeRepository.findOne({ - where: { id: x.posTypeActualId }, + where: { id: x.posTypePlannedId }, }); if (!checkId) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลประเภทตำแหน่ง"); } } - if (x.posLevelActualId != null) { + if (x.posLevelPlannedId != null) { const checkId = await this.posLevelRepository.findOne({ - where: { id: x.posLevelActualId }, + where: { id: x.posLevelPlannedId }, }); if (!checkId) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลระดับตำแหน่ง"); } } - const data = Object.assign(new ActualGoal(), x); - data.createdUserId = request.user.sub; - data.createdFullName = request.user.name; - data.lastUpdateUserId = request.user.sub; - data.lastUpdateFullName = request.user.name; - data.developmentActualGoalId = development.id; - await this.actualGoalRepository.save(data); + _data.createdUserId = request.user.sub; + _data.createdFullName = request.user.name; + _data.lastUpdateUserId = request.user.sub; + _data.lastUpdateFullName = request.user.name; + _data.plannedGoalId = data.id; + await this.plannedGoalPositionRepository.save(_data); }), ); + return new HttpSuccess(data.id); + } + + /** + * API เพิ่มโครงการ/หลักสูตรการฝึกอบรมtab2-2 + * + * @summary DEV_00 - เพิ่มโครงการ/หลักสูตรการฝึกอบรมtab2-2 # + * + * @param {string} id Id โครงการ + */ + @Put("tab2_2_add/{id}") + async CreateDevelopmenttab2_2( + @Path() id: string, + @Body() requestBody: CreatePlannedPeople, + @Request() request: { user: Record }, + ) { + const development = await this.developmentRepository.findOne({ + where: { id }, + }); + if (!development) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงการ/หลักสูตรการฝึกอบรมนี้"); + } + const data = Object.assign(new PlannedPeople(), requestBody); + data.createdUserId = request.user.sub; + data.createdFullName = request.user.name; + data.lastUpdateUserId = request.user.sub; + data.lastUpdateFullName = request.user.name; + data.developmentPlannedPeopleId = development.id; + await this.plannedPeopleRepository.save(data); + return new HttpSuccess(data.id); + } + + /** + * API เพิ่มโครงการ/หลักสูตรการฝึกอบรมtab2-3 + * + * @summary DEV_00 - เพิ่มโครงการ/หลักสูตรการฝึกอบรมtab2-3 # + * + * @param {string} id Id โครงการ + */ + @Put("tab2_3_add/{id}") + async CreateDevelopmenttab2_3( + @Path() id: string, + @Body() requestBody: CreateActualGoal, + @Request() request: { user: Record }, + ) { + const development = await this.developmentRepository.findOne({ + where: { id }, + }); + if (!development) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงการ/หลักสูตรการฝึกอบรมนี้"); + } + if (requestBody.posTypeActualId != null) { + const checkId = await this.posTypeRepository.findOne({ + where: { id: requestBody.posTypeActualId }, + }); + if (!checkId) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลประเภทตำแหน่ง"); + } + } + if (requestBody.posLevelActualId != null) { + const checkId = await this.posLevelRepository.findOne({ + where: { id: requestBody.posLevelActualId }, + }); + if (!checkId) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลระดับตำแหน่ง"); + } + } + const data = Object.assign(new ActualGoal(), requestBody); + data.createdUserId = request.user.sub; + data.createdFullName = request.user.name; + data.lastUpdateUserId = request.user.sub; + data.lastUpdateFullName = request.user.name; + data.developmentActualGoalId = development.id; + await this.actualGoalRepository.save(data); + return new HttpSuccess(data.id); + } + + /** + * API เพิ่มโครงการ/หลักสูตรการฝึกอบรมtab2-4 + * + * @summary DEV_00 - เพิ่มโครงการ/หลักสูตรการฝึกอบรมtab2-4 # + * + * @param {string} id Id โครงการ + */ + @Put("tab2_4_add/{id}") + async CreateDevelopmenttab2_4( + @Path() id: string, + @Body() requestBody: CreateActualPeople[], + @Request() request: { user: Record }, + ) { + const development = await this.developmentRepository.findOne({ + where: { id }, + }); + if (!development) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงการ/หลักสูตรการฝึกอบรมนี้"); + } + const data = Object.assign(new ActualPeople(), requestBody); + data.createdUserId = request.user.sub; + data.createdFullName = request.user.name; + data.lastUpdateUserId = request.user.sub; + data.lastUpdateFullName = request.user.name; + data.developmentActualPeopleId = development.id; + await this.actualPeopleRepository.save(data); + return new HttpSuccess(data.id); + } + + /** + * API แก้ไขโครงการ/หลักสูตรการฝึกอบรมtab2-1 + * + * @summary DEV_00 - แก้ไขโครงการ/หลักสูตรการฝึกอบรมtab2-1 # + * + * @param {string} id Id โครงการ + */ + @Put("tab2_1_edit/{id}") + async UpdateDevelopmenttab2_1( + @Path() id: string, + @Body() requestBody: CreatePlannedGoal, + @Request() request: { user: Record }, + ) { + const development = await this.plannedGoalRepository.findOne({ + where: { id }, + relations: { + plannedGoalPositions: true, + }, + }); + if (!development) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงการ/หลักสูตรการฝึกอบรมนี้"); + } + + await this.plannedGoalPositionRepository.remove(development.plannedGoalPositions); + const _requestBody: any = requestBody; + delete _requestBody.positions; + Object.assign(development, requestBody); + development.lastUpdateUserId = request.user.sub; + development.lastUpdateFullName = request.user.name; + await this.plannedGoalRepository.save(development); + + if (requestBody.positions != null) { + await Promise.all( + requestBody.positions.map(async (x) => { + const _data = Object.assign(new PlannedGoalPosition(), x); + if (x.posTypePlannedId != null) { + const checkId = await this.posTypeRepository.findOne({ + where: { id: x.posTypePlannedId }, + }); + if (!checkId) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลประเภทตำแหน่ง"); + } + } + if (x.posLevelPlannedId != null) { + const checkId = await this.posLevelRepository.findOne({ + where: { id: x.posLevelPlannedId }, + }); + if (!checkId) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลระดับตำแหน่ง"); + } + } + _data.createdUserId = request.user.sub; + _data.createdFullName = request.user.name; + _data.lastUpdateUserId = request.user.sub; + _data.lastUpdateFullName = request.user.name; + _data.plannedGoalId = development.id; + await this.plannedGoalPositionRepository.save(_data); + }), + ); + } + return new HttpSuccess(development.id); + } + + /** + * API แก้ไขโครงการ/หลักสูตรการฝึกอบรมtab2-2 + * + * @summary DEV_00 - แก้ไขโครงการ/หลักสูตรการฝึกอบรมtab2-2 # + * + * @param {string} id Id โครงการ + */ + @Put("tab2_2_edit/{id}") + async UpdateDevelopmenttab2_2( + @Path() id: string, + @Body() requestBody: CreatePlannedPeople, + @Request() request: { user: Record }, + ) { + const development = await this.plannedPeopleRepository.findOne({ + where: { id }, + }); + if (!development) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงการ/หลักสูตรการฝึกอบรมนี้"); + } + Object.assign(development, requestBody); + development.lastUpdateUserId = request.user.sub; + development.lastUpdateFullName = request.user.name; + await this.plannedPeopleRepository.save(development); + return new HttpSuccess(development.id); + } + + /** + * API แก้ไขโครงการ/หลักสูตรการฝึกอบรมtab2-3 + * + * @summary DEV_00 - แก้ไขโครงการ/หลักสูตรการฝึกอบรมtab2-3 # + * + * @param {string} id Id โครงการ + */ + @Put("tab2_3_edit/{id}") + async UpdateDevelopmenttab2_3( + @Path() id: string, + @Body() requestBody: CreateActualGoal, + @Request() request: { user: Record }, + ) { + const development = await this.actualGoalRepository.findOne({ + where: { id }, + }); + if (!development) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงการ/หลักสูตรการฝึกอบรมนี้"); + } + if (requestBody.posTypeActualId != null) { + const checkId = await this.posTypeRepository.findOne({ + where: { id: requestBody.posTypeActualId }, + }); + if (!checkId) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลประเภทตำแหน่ง"); + } + } + if (requestBody.posLevelActualId != null) { + const checkId = await this.posLevelRepository.findOne({ + where: { id: requestBody.posLevelActualId }, + }); + if (!checkId) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลระดับตำแหน่ง"); + } + } + Object.assign(development, requestBody); + development.lastUpdateUserId = request.user.sub; + development.lastUpdateFullName = request.user.name; + await this.actualGoalRepository.save(development); + return new HttpSuccess(development.id); + } + + /** + * API แก้ไขโครงการ/หลักสูตรการฝึกอบรมtab2-4 + * + * @summary DEV_00 - แก้ไขโครงการ/หลักสูตรการฝึกอบรมtab2-4 # + * + * @param {string} id Id โครงการ + */ + @Put("tab2_4_edit/{id}") + async UpdateDevelopmenttab2_4( + @Path() id: string, + @Body() requestBody: CreateActualPeople, + @Request() request: { user: Record }, + ) { + const development = await this.actualPeopleRepository.findOne({ + where: { id }, + }); + if (!development) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงการ/หลักสูตรการฝึกอบรมนี้"); + } + Object.assign(development, requestBody); + development.lastUpdateUserId = request.user.sub; + development.lastUpdateFullName = request.user.name; + await this.actualPeopleRepository.save(development); + return new HttpSuccess(development.id); + } + + /** + * API ลบโครงการ/หลักสูตรการฝึกอบรมtab2-1 + * + * @summary DEV_00 - ลบโครงการ/หลักสูตรการฝึกอบรมtab2-1 # + * + * @param {string} id Id รายการ + */ + @Delete("tab2_1/{id}") + async DeleteDevelopmenttab2_1(@Path() id: string) { + const development = await this.plannedGoalRepository.findOne({ + where: { id }, + }); + if (!development) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลกลุ่มเป้าหมายตามแผน"); + } + const _development = await this.plannedGoalPositionRepository.find({ + where: { plannedGoalId: id }, + }); + await this.plannedGoalPositionRepository.remove(_development); + await this.plannedGoalRepository.remove(development); + return new HttpSuccess(development.id); + } + + /** + * API ลบโครงการ/หลักสูตรการฝึกอบรมtab2-2 + * + * @summary DEV_00 - ลบโครงการ/หลักสูตรการฝึกอบรมtab2-2 # + * + * @param {string} id Id รายการ + */ + @Delete("tab2_2/{id}") + async DeleteDevelopmenttab2_2(@Path() id: string) { + const development = await this.plannedPeopleRepository.findOne({ + where: { id }, + }); + if (!development) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลผู้เกี่ยวข้องเป้าหมายตามแผน"); + } + await this.plannedPeopleRepository.remove(development); + return new HttpSuccess(development.id); + } + + /** + * API ลบโครงการ/หลักสูตรการฝึกอบรมtab2-3 + * + * @summary DEV_00 - ลบโครงการ/หลักสูตรการฝึกอบรมtab2-3 # + * + * @param {string} id Id รายการ + */ + @Delete("tab2_3/{id}") + async DeleteDevelopmenttab2_3(@Path() id: string) { + const development = await this.actualGoalRepository.findOne({ + where: { id }, + }); + if (!development) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลกลุ่มเป้าหมายตามจริง"); + } + await this.actualGoalRepository.remove(development); + return new HttpSuccess(development.id); + } + + /** + * API ลบโครงการ/หลักสูตรการฝึกอบรมtab2-4 + * + * @summary DEV_00 - ลบโครงการ/หลักสูตรการฝึกอบรมtab2-4 # + * + * @param {string} id Id รายการ + */ + @Delete("tab2_4/{id}") + async DeleteDevelopmenttab2_4(@Path() id: string) { + const development = await this.actualPeopleRepository.findOne({ + where: { id }, + }); + if (!development) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลผู้เกี่ยวข้องเป้าหมายตามจริง"); + } + await this.actualPeopleRepository.remove(development); + return new HttpSuccess(development.id); + } + + /** + * API แก้ไขโครงการ/หลักสูตรการฝึกอบรม tab3 + * + * @summary DEV_00 - แก้ไขโครงการ/หลักสูตรการฝึกอบรม tab3 # + * + * @param {string} id Id โครงการ + */ + @Put("tab3/{id}") + async UpdateDevelopmentTab3( + @Path() id: string, + @Body() requestBody: UpdateDevelopment3, + @Request() request: { user: Record }, + ) { + const development = await this.developmentRepository.findOne({ + where: { id }, + relations: { + developmentProjectTypes: true, + developmentProjectTechniques: true, + }, + }); + if (!development) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงการ/หลักสูตรการฝึกอบรมนี้"); + } + Object.assign(development, requestBody); + development.lastUpdateUserId = request.user.sub; + development.lastUpdateFullName = request.user.name; + await this.developmentRepository.save(development); + await this.developmentProjectTypeRepository.remove(development.developmentProjectTypes); + await this.developmentProjectTechniqueRepository.remove( + development.developmentProjectTechniques, + ); + if (requestBody.developmentProjectTypes != null) { + await Promise.all( + requestBody.developmentProjectTypes.map(async (x) => { + let data = new DevelopmentProjectType(); + data.name = x; + data.createdUserId = request.user.sub; + data.createdFullName = request.user.name; + data.lastUpdateUserId = request.user.sub; + data.lastUpdateFullName = request.user.name; + data.developmentId = development.id; + await this.developmentProjectTypeRepository.save(data); + }), + ); + } + if (requestBody.developmentProjectTechniques != null) { + await Promise.all( + requestBody.developmentProjectTechniques.map(async (x) => { + let data = new DevelopmentProjectTechnique(); + data.name = x; + data.createdUserId = request.user.sub; + data.createdFullName = request.user.name; + data.lastUpdateUserId = request.user.sub; + data.lastUpdateFullName = request.user.name; + data.developmentId = development.id; + await this.developmentProjectTechniqueRepository.save(data); + }), + ); + } + return new HttpSuccess(development.id); + } + + /** + * API แก้ไขโครงการ/หลักสูตรการฝึกอบรม tab4 + * + * @summary DEV_00 - แก้ไขโครงการ/หลักสูตรการฝึกอบรม tab4 # + * + * @param {string} id Id โครงการ + */ + @Put("tab4/{id}") + async UpdateDevelopmentTab4( + @Path() id: string, + @Body() requestBody: UpdateDevelopment4, + @Request() request: { user: Record }, + ) { + const development = await this.developmentRepository.findOne({ + where: { id }, + relations: { + developmentEvaluations: true, + }, + }); + if (!development) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงการ/หลักสูตรการฝึกอบรมนี้"); + } + Object.assign(development, requestBody); + development.lastUpdateUserId = request.user.sub; + development.lastUpdateFullName = request.user.name; + await this.developmentRepository.save(development); + await this.developmentEvaluationRepository.remove(development.developmentEvaluations); await Promise.all( - requestBody.plannedGoals.map(async (x) => { - const data = Object.assign(new PlannedGoal(), x); + requestBody.developmentEvaluations.map(async (x) => { + const data = Object.assign(new DevelopmentEvaluation(), x); data.createdUserId = request.user.sub; data.createdFullName = request.user.name; data.lastUpdateUserId = request.user.sub; data.lastUpdateFullName = request.user.name; - data.developmentPlannedGoalId = development.id; - await this.plannedGoalRepository.save(data); + data.developmentId = development.id; + await this.developmentEvaluationRepository.save(data); + }), + ); + return new HttpSuccess(development.id); + } - await Promise.all( - x.positions.map(async (y) => { - const _data = Object.assign(new PlannedGoalPosition(), y); - if (y.posTypePlannedId != null) { - const checkId = await this.posTypeRepository.findOne({ - where: { id: y.posTypePlannedId }, - }); - if (!checkId) { - throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลประเภทตำแหน่ง"); - } - } - if (y.posLevelPlannedId != null) { - const checkId = await this.posLevelRepository.findOne({ - where: { id: y.posLevelPlannedId }, - }); - if (!checkId) { - throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลระดับตำแหน่ง"); - } - } - _data.createdUserId = request.user.sub; - _data.createdFullName = request.user.name; - _data.lastUpdateUserId = request.user.sub; - _data.lastUpdateFullName = request.user.name; - _data.plannedGoalId = data.id; - await this.plannedGoalPositionRepository.save(_data); - }), - ); + /** + * API แก้ไขโครงการ/หลักสูตรการฝึกอบรม tab5 + * + * @summary DEV_00 - แก้ไขโครงการ/หลักสูตรการฝึกอบรม tab5 # + * + * @param {string} id Id โครงการ + */ + @Put("tab5/{id}") + async UpdateDevelopmentTab5( + @Path() id: string, + @Body() requestBody: UpdateDevelopment5, + @Request() request: { user: Record }, + ) { + const development = await this.developmentRepository.findOne({ + where: { id }, + relations: { + developmentAddresss: true, + }, + }); + if (!development) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงการ/หลักสูตรการฝึกอบรมนี้"); + } + if (requestBody.provinceActualId != null) { + const checkId = await this.provinceRepository.findOne({ + where: { id: requestBody.provinceActualId }, + }); + if (!checkId) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลจังหวัดข้อมูลด้านวิชาการ"); + } + } + Object.assign(development, requestBody); + development.lastUpdateUserId = request.user.sub; + development.lastUpdateFullName = request.user.name; + await this.developmentRepository.save(development); + await this.developmentAddresssRepository.remove(development.developmentAddresss); + await Promise.all( + requestBody.developmentAddresss.map(async (x) => { + const data = Object.assign(new DevelopmentAddress(), x); + const chkProvince = await this.provinceRepository.find({ + where: { + id: x.provinceId, + }, + }); + if (chkProvince == null) return; + data.createdUserId = request.user.sub; + data.createdFullName = request.user.name; + data.lastUpdateUserId = request.user.sub; + data.lastUpdateFullName = request.user.name; + data.developmentId = development.id; + await this.developmentAddresssRepository.save(data); }), ); return new HttpSuccess(development.id); @@ -417,6 +763,10 @@ export class DevelopmentController extends Controller { developmentPlannedPeoples: true, developmentActualGoals: true, developmentPlannedGoals: true, + developmentProjectTypes: true, + developmentProjectTechniques: true, + developmentEvaluations: true, + developmentAddresss: true, }, }); if (!development) { @@ -436,6 +786,12 @@ export class DevelopmentController extends Controller { await this.plannedPeopleRepository.remove(development.developmentPlannedPeoples); await this.actualGoalRepository.remove(development.developmentActualGoals); await this.plannedGoalRepository.remove(development.developmentPlannedGoals); + await this.developmentProjectTypeRepository.remove(development.developmentProjectTypes); + await this.developmentProjectTechniqueRepository.remove( + development.developmentProjectTechniques, + ); + await this.developmentEvaluationRepository.remove(development.developmentEvaluations); + await this.developmentAddresssRepository.remove(development.developmentAddresss); await this.developmentRepository.remove(development); return new HttpSuccess(); } @@ -451,6 +807,7 @@ export class DevelopmentController extends Controller { @Query("page") page: number = 1, @Query("pageSize") pageSize: number = 10, @Query("year") year: number, + @Query("status") status: string, @Query("keyword") keyword?: string, ) { const [development, total] = await AppDataSource.getRepository(Development) @@ -458,6 +815,9 @@ export class DevelopmentController extends Controller { .andWhere(year > 0 ? "development.year LIKE :year" : "1=1", { year: `${year.toString()}`, }) + .andWhere(status != undefined ? "development.status LIKE :status" : "1=1", { + status: `%${status}%`, + }) .andWhere(keyword != undefined ? "development.projectName LIKE :keyword" : "1=1", { keyword: `%${keyword}%`, }) @@ -472,14 +832,106 @@ export class DevelopmentController extends Controller { } /** - * API รายละเอียดโครงการ/หลักสูตรการฝึกอบรม + * API ปิดโครงการ * - * @summary DEV_005 - รายละเอียดโครงการ/หลักสูตรการฝึกอบรม #5 + * @summary DEV_00 - ปิดโครงการ # * * @param {string} id Id โครงการ */ - @Get("{id}") - async GetDevelopemtById(@Path() id: string) { + @Get("finish/{id}") + async FinishDevelopemtById( + @Path() id: string, + @Request() request: { user: Record }, + ) { + const getDevelopment = await this.developmentRepository.findOne({ + where: { id: id }, + }); + if (!getDevelopment) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงการ/หลักสูตรการฝึกอบรมนี้"); + } + getDevelopment.status = "FINISH"; + getDevelopment.lastUpdateUserId = request.user.sub; + getDevelopment.lastUpdateFullName = request.user.name; + await this.developmentRepository.save(getDevelopment); + return new HttpSuccess(getDevelopment); + } + + /** + * API สถานะโครงการ + * + * @summary DEV_00 - สถานะโครงการ # + * + * @param {string} id Id โครงการ + */ + @Get("status/{id}") + async StatusDevelopemtById(@Path() id: string) { + const getDevelopment = await this.developmentRepository.findOne({ + where: { id: id }, + select: ["id", "status"], + }); + return new HttpSuccess(getDevelopment); + } + + /** + * API รายละเอียดโครงการ/หลักสูตรการฝึกอบรม tab1 + * + * @summary DEV_00 - รายละเอียดโครงการ/หลักสูตรการฝึกอบรมtab1 # + * + * @param {string} id Id โครงการ + */ + @Get("tab1/{id}") + async GetDevelopemtTab1ById(@Path() id: string) { + const getDevelopment = await this.developmentRepository.findOne({ + where: { id: id }, + select: ["id", "year", "projectName", "reason", "objective"], + }); + if (!getDevelopment) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงการ/หลักสูตรการฝึกอบรมนี้"); + } + return new HttpSuccess(getDevelopment); + } + + /** + * API รายละเอียดโครงการ/หลักสูตรการฝึกอบรม tab2 + * + * @summary DEV_00 - รายละเอียดโครงการ/หลักสูตรการฝึกอบรมtab2 # + * + * @param {string} id Id โครงการ + */ + @Get("tab2/{id}") + async GetDevelopemtTab2ById(@Path() id: string) { + const getDevelopment = await this.developmentRepository.findOne({ + where: { id: id }, + relations: [ + "developmentActualPeoples", + "developmentPlannedPeoples", + "developmentActualGoals", + "developmentPlannedGoals", + "developmentPlannedGoals.plannedGoalPositions", + ], + }); + if (!getDevelopment) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงการ/หลักสูตรการฝึกอบรมนี้"); + } + let _getDevelopment: any = { + id: getDevelopment.id, + actualPeoples: getDevelopment.developmentActualPeoples, + plannedPeoples: getDevelopment.developmentPlannedPeoples, + actualGoals: getDevelopment.developmentActualGoals, + plannedGoals: getDevelopment.developmentPlannedGoals, + }; + return new HttpSuccess(_getDevelopment); + } + + /** + * API รายละเอียดโครงการ/หลักสูตรการฝึกอบรม tab3 + * + * @summary DEV_00 - รายละเอียดโครงการ/หลักสูตรการฝึกอบรมtab3 # + * + * @param {string} id Id โครงการ + */ + @Get("tab3/{id}") + async GetDevelopemtTab3ById(@Path() id: string) { const getDevelopment = await this.developmentRepository.findOne({ where: { id: id }, relations: [ @@ -507,4 +959,167 @@ export class DevelopmentController extends Controller { delete _getDevelopment.developmentPlannedGoals; return new HttpSuccess(_getDevelopment); } + + /** + * API รายละเอียดโครงการ/หลักสูตรการฝึกอบรม tab4 + * + * @summary DEV_00 - รายละเอียดโครงการ/หลักสูตรการฝึกอบรมtab4 # + * + * @param {string} id Id โครงการ + */ + @Get("tab4/{id}") + async GetDevelopemtTab4ById(@Path() id: string) { + const getDevelopment = await this.developmentRepository.findOne({ + where: { id: id }, + relations: [ + "developmentActualPeoples", + "developmentPlannedPeoples", + "developmentActualGoals", + "developmentPlannedGoals", + "developmentPlannedGoals.plannedGoalPositions", + "provinces", + // "provinces.developmentProvinces", + ], + }); + if (!getDevelopment) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงการ/หลักสูตรการฝึกอบรมนี้"); + } + let _getDevelopment: any = getDevelopment; + _getDevelopment.actualPeoples = getDevelopment.developmentActualPeoples; + _getDevelopment.plannedPeoples = getDevelopment.developmentPlannedPeoples; + _getDevelopment.actualGoals = getDevelopment.developmentActualGoals; + _getDevelopment.plannedGoals = getDevelopment.developmentPlannedGoals; + // _getDevelopment.provinces = getDevelopment.provinces.map(x=>x.developmentProvinces); + delete _getDevelopment.developmentActualPeoples; + delete _getDevelopment.developmentPlannedPeoples; + delete _getDevelopment.developmentActualGoals; + delete _getDevelopment.developmentPlannedGoals; + return new HttpSuccess(_getDevelopment); + } + + /** + * API รายละเอียดโครงการ/หลักสูตรการฝึกอบรม tab5 + * + * @summary DEV_00 - รายละเอียดโครงการ/หลักสูตรการฝึกอบรมtab5 # + * + * @param {string} id Id โครงการ + */ + @Get("tab5/{id}") + async GetDevelopemtTab5ById(@Path() id: string) { + const getDevelopment = await this.developmentRepository.findOne({ + where: { id: id }, + relations: [ + "developmentActualPeoples", + "developmentPlannedPeoples", + "developmentActualGoals", + "developmentPlannedGoals", + "developmentPlannedGoals.plannedGoalPositions", + "provinces", + // "provinces.developmentProvinces", + ], + }); + if (!getDevelopment) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงการ/หลักสูตรการฝึกอบรมนี้"); + } + let _getDevelopment: any = getDevelopment; + _getDevelopment.actualPeoples = getDevelopment.developmentActualPeoples; + _getDevelopment.plannedPeoples = getDevelopment.developmentPlannedPeoples; + _getDevelopment.actualGoals = getDevelopment.developmentActualGoals; + _getDevelopment.plannedGoals = getDevelopment.developmentPlannedGoals; + // _getDevelopment.provinces = getDevelopment.provinces.map(x=>x.developmentProvinces); + delete _getDevelopment.developmentActualPeoples; + delete _getDevelopment.developmentPlannedPeoples; + delete _getDevelopment.developmentActualGoals; + delete _getDevelopment.developmentPlannedGoals; + return new HttpSuccess(_getDevelopment); + } + + /** + * API รายละเอียดโครงการ/หลักสูตรการฝึกอบรม tab6 + * + * @summary DEV_00 - รายละเอียดโครงการ/หลักสูตรการฝึกอบรมtab6 # + * + * @param {string} id Id โครงการ + */ + @Get("tab6/{id}") + async GetDevelopemtTab6ById(@Path() id: string) { + const getDevelopment = await this.developmentRepository.findOne({ + where: { id: id }, + relations: [ + "developmentActualPeoples", + "developmentPlannedPeoples", + "developmentActualGoals", + "developmentPlannedGoals", + "developmentPlannedGoals.plannedGoalPositions", + "provinces", + // "provinces.developmentProvinces", + ], + }); + if (!getDevelopment) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงการ/หลักสูตรการฝึกอบรมนี้"); + } + let _getDevelopment: any = getDevelopment; + _getDevelopment.actualPeoples = getDevelopment.developmentActualPeoples; + _getDevelopment.plannedPeoples = getDevelopment.developmentPlannedPeoples; + _getDevelopment.actualGoals = getDevelopment.developmentActualGoals; + _getDevelopment.plannedGoals = getDevelopment.developmentPlannedGoals; + // _getDevelopment.provinces = getDevelopment.provinces.map(x=>x.developmentProvinces); + delete _getDevelopment.developmentActualPeoples; + delete _getDevelopment.developmentPlannedPeoples; + delete _getDevelopment.developmentActualGoals; + delete _getDevelopment.developmentPlannedGoals; + return new HttpSuccess(_getDevelopment); + } + + /** + * API upload User + * + * @summary DEV_0 - upload User # + * + * @param {string} id Id โครงการ + */ + @Get("zxczxc/{id}") + async UploadUserDevelopemtById( + @Path() id: string, + @Request() request: { user: Record }, + ) { + const getDevelopment = await this.developmentRepository.findOne({ + where: { id: id }, + relations: ["developmentHistory"], + }); + if (!getDevelopment) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงการ/หลักสูตรการฝึกอบรมนี้"); + } + await this.developmentHistoryRepository.remove(getDevelopment.developmentHistorys); + + // await Promise.all( + // positions.map(async (x) => { + // const data = Object.assign(new DevelopmentHistory(), x); + // if (x.posTypeId != null) { + // const checkId = await this.posTypeRepository.findOne({ + // where: { id: x.posTypeId }, + // }); + // if (!checkId) { + // throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลประเภทตำแหน่ง"); + // } + // } + // if (x.posLevelId != null) { + // const checkId = await this.posLevelRepository.findOne({ + // where: { id: x.posLevelId }, + // }); + // if (!checkId) { + // throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลระดับตำแหน่ง"); + // } + // } + // data.developmentId = getDevelopment.id; + // data.createdUserId = request.user.sub; + // data.createdFullName = request.user.name; + // data.lastUpdateUserId = request.user.sub; + // data.lastUpdateFullName = request.user.name; + // await this.plannedGoalPositionRepository.save(data); + // }), + // ); + + return new HttpSuccess(); + } } diff --git a/src/controllers/DevelopmentScholarshipController.ts b/src/controllers/DevelopmentScholarshipController.ts index 10b552b..3ef6c50 100644 --- a/src/controllers/DevelopmentScholarshipController.ts +++ b/src/controllers/DevelopmentScholarshipController.ts @@ -313,6 +313,7 @@ export class DevelopmentScholarshipController extends Controller { : null, totalPeriod: getDevelopment.totalPeriod ? getDevelopment.totalPeriod : null, status: getDevelopment.status ? getDevelopment.status : null, + profileId: getDevelopment.profileId ? getDevelopment.profileId : null, }; return new HttpSuccess(formattedData); } diff --git a/src/entities/Development.ts b/src/entities/Development.ts index ca6d988..bae93d3 100644 --- a/src/entities/Development.ts +++ b/src/entities/Development.ts @@ -6,9 +6,22 @@ import { CreatePlannedPeople, PlannedPeople } from "./PlannedPeople"; import { ActualGoal, CreateActualGoal } from "./ActualGoal"; import { CreatePlannedGoal, PlannedGoal } from "./PlannedGoal"; import { DevelopmentHistory } from "./DevelopmentHistory"; +import { DevelopmentProjectType } from "./DevelopmentProjectType"; +import { DevelopmentProjectTechnique } from "./DevelopmentProjectTechnique"; +import { CreateDevelopmentEvaluation, DevelopmentEvaluation } from "./DevelopmentEvaluation"; +import { CreateDevelopmentAddress, DevelopmentAddress } from "./DevelopmentAddress"; @Entity("development") export class Development extends EntityBase { + @Column({ + // กำลังดำเนินการ (ONGOING) + // เสร็จสิ้น (FINISH) + nullable: true, + comment: "สถานะ", + default: "ONGOING", + }) + status: string; + ////////////////////////////////////////tab ข้อมูลเบื้องต้น @Column({ nullable: true, comment: "ปีงบประมาณ", @@ -35,61 +48,118 @@ export class Development extends EntityBase { }) objective: string; + ////////////////////////////////////////tab เป้าหมาย + @OneToMany( + () => ActualPeople, + (actualPeople: ActualPeople) => actualPeople.developmentActualPeople, + ) + developmentActualPeoples: ActualPeople[]; + + @OneToMany(() => ActualGoal, (actualGoal: ActualGoal) => actualGoal.developmentActualGoal) + developmentActualGoals: ActualGoal[]; + + @OneToMany( + () => PlannedPeople, + (plannedPeople: PlannedPeople) => plannedPeople.developmentPlannedPeople, + ) + developmentPlannedPeoples: PlannedPeople[]; + + @OneToMany(() => PlannedGoal, (plannedGoal: PlannedGoal) => plannedGoal.developmentPlannedGoal) + developmentPlannedGoals: PlannedGoal[]; + + ////////////////////////////////////////tab ลักษณะโครงการ + @OneToMany( + () => DevelopmentProjectType, + (developmentProjectType: DevelopmentProjectType) => developmentProjectType.development, + ) + developmentProjectTypes: DevelopmentProjectType[]; + @Column({ - nullable: true, - comment: "ประเภทตัวชี้วัด", - default: null, + comment: "ไป-กลับ", + default: false, }) - metricType: string; + isBackPlanned: boolean; + + @Column({ + comment: "พักค้าง", + default: false, + }) + isHoldPlanned: boolean; @Column({ nullable: true, - comment: "ตัวชี้วัด", + comment: "จำนวน(วัน)(ไป-กลับ)", default: null, }) - indicators: string; + projectDayBackPlanned: number; @Column({ nullable: true, - comment: "เป้าหมาย", + comment: "จำนวน(วัน)(พักค้าง)", default: null, }) - target: string; + projectDayHoldPlanned: number; @Column({ nullable: true, - comment: "วิธีการคำนวณ/เครื่องมือ", + comment: "จำนวน(คืน)(พักค้าง)", default: null, }) - calculation: string; + projectNigthHoldPlanned: number; + + @Column({ + comment: "ไป-กลับ", + default: false, + }) + isBackActual: boolean; + + @Column({ + comment: "พักค้าง", + default: false, + }) + isHoldActual: boolean; @Column({ nullable: true, - comment: "ระยะเวลาวัดผล", + comment: "จำนวน(วัน)(ไป-กลับ)", default: null, }) - measuRement: string; + projectDayBackActual: number; @Column({ nullable: true, - comment: "ผลการดำเนิน", + comment: "จำนวน(วัน)(พักค้าง)", default: null, }) - results: string; + projectDayHoldActual: number; @Column({ nullable: true, - comment: "ปัญหาอุปสรรค", + comment: "จำนวน(คืน)(พักค้าง)", default: null, }) - obstacles: string; + projectNigthHoldActual: number; + + @OneToMany( + () => DevelopmentProjectTechnique, + (developmentProjectTechnique: DevelopmentProjectTechnique) => + developmentProjectTechnique.development, + ) + developmentProjectTechniques: DevelopmentProjectTechnique[]; @Column({ nullable: true, - comment: "ข้อเสนอเเนะ", + comment: "จำนวน(รุ่น)", default: null, }) - suggestions: string; + projectModal: number; + + ////////////////////////////////////////tab ผลประเมิน + @OneToMany( + () => DevelopmentEvaluation, + (developmentEvaluation: DevelopmentEvaluation) => developmentEvaluation.development, + ) + developmentEvaluations: DevelopmentEvaluation[]; @Column({ nullable: true, @@ -129,6 +199,7 @@ export class Development extends EntityBase { }) isOutBudget: boolean; + ////////////////////////////////////////tab อื่นๆ @Column({ nullable: true, type: "datetime", @@ -152,12 +223,11 @@ export class Development extends EntityBase { }) totalDate: number; - @Column({ - nullable: true, - comment: "ที่อยู่", - default: null, - }) - address: string; + @OneToMany( + () => DevelopmentAddress, + (developmentAddress: DevelopmentAddress) => developmentAddress.development, + ) + developmentAddresss: DevelopmentAddress[]; @Column({ nullable: true, @@ -166,6 +236,16 @@ export class Development extends EntityBase { }) budget: string; + @Column({ + // เงินบำรุง = MAINTENANCE + // เงินกองทุน = FUND + // เงินอุดหนุน = SUBSIDY + nullable: true, + comment: "ประเภทย่อย", + default: null, + }) + budgetSub: string; + @Column({ nullable: true, comment: "จํานวนงบประมาณที่ขอรับการจัดสรรฯ", @@ -210,14 +290,14 @@ export class Development extends EntityBase { comment: "โอกาสที่จะเกิด", default: null, }) - chance: string; + chance: number; @Column({ nullable: true, comment: "ผลกระทบจากการเกิด", default: null, }) - effects: string; + effects: number; @Column({ nullable: true, @@ -254,6 +334,17 @@ export class Development extends EntityBase { }) addressAcademic: string; + @Column({ + nullable: true, + comment: "จังหวัด(ข้อมูลวิชาการ)", + default: null, + }) + provinceActualId: string; + + @ManyToOne(() => Province, (province: Province) => province.developmentActuals) + @JoinColumn({ name: "provinceActualId" }) + provinceActual: Province; + @Column({ nullable: true, type: "datetime", @@ -270,105 +361,6 @@ export class Development extends EntityBase { }) dateStudyEnd: Date; - @Column({ - // STRATEGIC_PROJECT = โครงการตามยุทธศาสตร์ - // MISSION_PROJECT = โครงการตามภารกิจประจำของหน่วยงาน - // NEW_PROJECT = โครงการใหม่ - // ONGOING_PROJECT = โครงการต่อเนื่อง - nullable: true, - comment: "ประเภทโครงการ", - default: null, - }) - projectType: string; - - @Column({ - // GO_BACK = ไป-กลับ - // HOLD = พักค้าง - // GO_BACK_HOLD = ไป-กลับและพักค้าง - nullable: true, - comment: "ลักษณะ", - default: null, - }) - projectCharacteristics: string; - - @Column({ - nullable: true, - comment: "จำนวน(วัน)", - default: null, - }) - projectDay: number; - - @Column({ - nullable: true, - comment: "จำนวน(คืน)", - default: null, - }) - projectNigth: number; - - @Column({ - // TRAINING = การอบรม - // MEETING = การประชุม - // SEMINAR = การสัมมนา - // STUDY_TOUR = การศึกษาดูงาน - // ACADEMIC_SEMINAR = การสัมมนาทางวิชาการ - // WORKSHOP = การสัมมนาเชิงปฏิบัติการ - // SPECIAL_LECTURE = การบรรยายพิเศษ - // STUDY_TRAINING = การฝึกศึกษา - nullable: true, - comment: "เทคนิควิธีการที่ใช้ในการพัฒนา", - default: null, - }) - projectTechniques: string; - - @Column({ - nullable: true, - comment: "จำนวน(รุ่น)", - default: null, - }) - projectModal: number; - - @Column({ - // เงินบำรุง = MAINTENANCE - // เงินกองทุน = FUND - // เงินอุดหนุน = SUBSIDY - nullable: true, - comment: "ประเภทย่อย", - default: null, - }) - budgetSub: string; - - @Column({ - nullable: true, - comment: "จังหวัด(ข้อมูลวิชาการ)", - default: null, - }) - provinceActualId: string; - - @ManyToOne(() => Province, (province: Province) => province.developmentActuals) - @JoinColumn({ name: "provinceActualId" }) - provinceActual: Province; - - @ManyToMany(() => Province, (provinces) => provinces.developmentProvinces) - provinces: Province[]; - - @OneToMany( - () => ActualPeople, - (actualPeople: ActualPeople) => actualPeople.developmentActualPeople, - ) - developmentActualPeoples: ActualPeople[]; - - @OneToMany( - () => PlannedPeople, - (plannedPeople: PlannedPeople) => plannedPeople.developmentPlannedPeople, - ) - developmentPlannedPeoples: PlannedPeople[]; - - @OneToMany(() => ActualGoal, (actualGoal: ActualGoal) => actualGoal.developmentActualGoal) - developmentActualGoals: ActualGoal[]; - - @OneToMany(() => PlannedGoal, (plannedGoal: PlannedGoal) => plannedGoal.developmentPlannedGoal) - developmentPlannedGoals: PlannedGoal[]; - @OneToMany( () => DevelopmentHistory, (developmentHistory: DevelopmentHistory) => developmentHistory.development, @@ -380,105 +372,9 @@ export class CreateDevelopment { year: number; @Column() projectName: string; - @Column() - reason: string | null; - @Column() - objective: string | null; - @Column() - metricType: string | null; - @Column() - indicators: string | null; - @Column() - target: string | null; - @Column() - calculation: string | null; - @Column() - measuRement: string | null; - @Column() - results: string | null; - @Column() - obstacles: string | null; - @Column() - suggestions: string | null; - @Column() - project: string | null; - @Column() - isPassAllocate: boolean; - @Column() - isPassNoAllocate: boolean; - @Column() - isNoPass: boolean; - @Column() - isBudget: boolean; - @Column() - isOutBudget: boolean; - @Column() - dateStart: Date | null; - @Column() - dateEnd: Date | null; - @Column() - totalDate: number | null; - @Column() - address: string | null; - @Column() - provinceIds: string[]; - @Column() - budget: string | null; - @Column() - accept: Double | null; - @Column() - receive: Double | null; - @Column() - approved: Double | null; - @Column() - budgetPay: Double | null; - @Column() - issues: string | null; - @Column() - chance: string | null; - @Column() - effects: string | null; - @Column() - riskLevel: string | null; - @Column() - riskManagement: string | null; - @Column() - expect: string | null; - @Column() - topicAcademic: string | null; - @Column() - addressAcademic: string | null; - @Column() - provinceActualId: string | null; - @Column() - dateStudyStart?: Date | null; - @Column() - dateStudyEnd?: Date | null; - @Column() - projectType: string | null; - @Column() - projectCharacteristics: string | null; - @Column() - projectDay: number | null; - @Column() - projectNigth: number | null; - @Column() - projectTechniques: string | null; - @Column() - projectModal: number | null; - @Column() - budgetSub: string | null; - @Column() - actualPeoples: CreateActualPeople[]; - @Column() - plannedPeoples: CreatePlannedPeople[]; - @Column() - actualGoals: CreateActualGoal[]; - @Column() - plannedGoals: CreatePlannedGoal[]; } -export class UpdateDevelopment { +export class UpdateDevelopment1 { @Column() year: number; @Column() @@ -487,22 +383,50 @@ export class UpdateDevelopment { reason: string | null; @Column() objective: string | null; +} +export class UpdateDevelopment2_1 { @Column() - metricType: string | null; + actualGoals: CreateActualGoal[]; @Column() - indicators: string | null; + plannedGoals: CreatePlannedGoal[]; +} +export class UpdateDevelopment2_2 { @Column() - target: string | null; + actualPeoples: CreateActualPeople[]; @Column() - calculation: string | null; + plannedPeoples: CreatePlannedPeople[]; +} +export class UpdateDevelopment3 { @Column() - measuRement: string | null; + developmentProjectTypes?: string[]; @Column() - results: string | null; + isBackPlanned?: boolean | null; @Column() - obstacles: string | null; + isHoldPlanned?: boolean | null; @Column() - suggestions: string | null; + projectDayBackPlanned?: number | null; + @Column() + projectDayHoldPlanned?: number | null; + @Column() + projectNigthHoldPlanned?: number | null; + @Column() + isBackActual?: boolean | null; + @Column() + isHoldActual?: boolean | null; + @Column() + projectDayBackActual?: number | null; + @Column() + projectDayHoldActual?: number | null; + @Column() + projectNigthHoldActual?: number | null; + @Column() + developmentProjectTechniques?: string[]; + @Column() + projectModal?: number | null; +} +export class UpdateDevelopment4 { + @Column() + developmentEvaluations: CreateDevelopmentEvaluation[]; @Column() project: string | null; @Column() @@ -515,6 +439,8 @@ export class UpdateDevelopment { isBudget: boolean; @Column() isOutBudget: boolean; +} +export class UpdateDevelopment5 { @Column() dateStart: Date | null; @Column() @@ -522,12 +448,12 @@ export class UpdateDevelopment { @Column() totalDate: number | null; @Column() - address: string | null; - @Column() - provinceIds: string[]; + developmentAddresss: CreateDevelopmentAddress[]; @Column() budget: string | null; @Column() + budgetSub: string | null; + @Column() accept: Double | null; @Column() receive: Double | null; @@ -538,9 +464,9 @@ export class UpdateDevelopment { @Column() issues: string | null; @Column() - chance: string | null; + chance: number | null; @Column() - effects: string | null; + effects: number | null; @Column() riskLevel: string | null; @Column() @@ -554,29 +480,7 @@ export class UpdateDevelopment { @Column() provinceActualId: string | null; @Column() - dateStudyStart?: Date | null; + dateStudyStart: Date | null; @Column() - dateStudyEnd?: Date | null; - @Column() - projectType?: string | null; - @Column() - projectCharacteristics?: string | null; - @Column() - projectDay?: number | null; - @Column() - projectNigth?: number | null; - @Column() - projectTechniques?: string | null; - @Column() - projectModal?: number | null; - @Column() - budgetSub: string | null; - @Column() - actualPeoples: CreateActualPeople[]; - @Column() - plannedPeoples: CreatePlannedPeople[]; - @Column() - actualGoals: CreateActualGoal[]; - @Column() - plannedGoals: CreatePlannedGoal[]; + dateStudyEnd: Date | null; } diff --git a/src/entities/DevelopmentAddress.ts b/src/entities/DevelopmentAddress.ts new file mode 100644 index 0000000..e1490c8 --- /dev/null +++ b/src/entities/DevelopmentAddress.ts @@ -0,0 +1,42 @@ +import { Entity, Column, ManyToOne, JoinColumn } from "typeorm"; +import { EntityBase } from "./base/Base"; +import { Development } from "./Development"; +import { Province } from "./Province"; + +@Entity("developmentAddress") +export class DevelopmentAddress extends EntityBase { + @Column({ + nullable: true, + comment: "ที่อยู่", + default: null, + }) + address: string; + + @Column({ + nullable: true, + comment: "โครงการ/หลักสูตรการฝึกอบรม", + default: null, + }) + provinceId: string; + + @ManyToOne(() => Province, (province: Province) => province.developmentAddresss) + @JoinColumn({ name: "provinceId" }) + province: Province; + + @Column({ + nullable: true, + comment: "โครงการ/หลักสูตรการฝึกอบรม", + default: null, + }) + developmentId: string; + + @ManyToOne(() => Development, (development: Development) => development.developmentAddresss) + @JoinColumn({ name: "developmentId" }) + development: Development; +} +export class CreateDevelopmentAddress { + @Column() + address: string | null; + @Column() + provinceId: string; +} diff --git a/src/entities/DevelopmentEvaluation.ts b/src/entities/DevelopmentEvaluation.ts new file mode 100644 index 0000000..0e4a4c4 --- /dev/null +++ b/src/entities/DevelopmentEvaluation.ts @@ -0,0 +1,90 @@ +import { Entity, Column, ManyToOne, JoinColumn } from "typeorm"; +import { EntityBase } from "./base/Base"; +import { Development } from "./Development"; + +@Entity("developmentEvaluation") +export class DevelopmentEvaluation extends EntityBase { + @Column({ + nullable: true, + comment: "ตัวชี้วัด", + default: null, + }) + indicators: string; + + @Column({ + nullable: true, + comment: "เป้าหมาย", + default: null, + }) + target: number; + + @Column({ + nullable: true, + comment: "ประเภทตัวชี้วัด", + default: null, + }) + metricType: string; + + @Column({ + nullable: true, + comment: "วิธีการคำนวณ/เครื่องมือ", + default: null, + }) + calculation: string; + + @Column({ + nullable: true, + comment: "ระยะเวลาวัดผล", + default: null, + }) + measuRement: string; + + @Column({ + nullable: true, + comment: "ผลการดำเนิน", + default: null, + }) + results: string; + + @Column({ + nullable: true, + comment: "ปัญหาอุปสรรค", + default: null, + }) + obstacles: string; + + @Column({ + nullable: true, + comment: "ข้อเสนอเเนะ", + default: null, + }) + suggestions: string; + @Column({ + nullable: true, + comment: "โครงการ/หลักสูตรการฝึกอบรม", + default: null, + }) + developmentId: string; + + @ManyToOne(() => Development, (development: Development) => development.developmentEvaluations) + @JoinColumn({ name: "developmentId" }) + development: Development; +} +export class CreateDevelopmentEvaluation { + @Column() + indicators: string | null; + @Column() + target: number | null; + @Column() + metricType: string | null; + @Column() + calculation: string | null; + @Column() + measuRement: string | null; + @Column() + results: string | null; + @Column() + obstacles: string | null; + @Column() + suggestions: string | null; +} diff --git a/src/entities/DevelopmentProjectTechnique.ts b/src/entities/DevelopmentProjectTechnique.ts new file mode 100644 index 0000000..2d3ac30 --- /dev/null +++ b/src/entities/DevelopmentProjectTechnique.ts @@ -0,0 +1,39 @@ +import { Entity, Column, ManyToOne, JoinColumn } from "typeorm"; +import { EntityBase } from "./base/Base"; +import { Development } from "./Development"; + +@Entity("developmentProjectTechnique") +export class DevelopmentProjectTechnique extends EntityBase { + @Column({ + // TRAINING = การอบรม + // MEETING = การประชุม + // SEMINAR = การสัมมนา + // STUDY_TOUR = การศึกษาดูงาน + // ACADEMIC_SEMINAR = การสัมมนาทางวิชาการ + // WORKSHOP = การสัมมนาเชิงปฏิบัติการ + // SPECIAL_LECTURE = การบรรยายพิเศษ + // STUDY_TRAINING = การฝึกศึกษา + nullable: true, + comment: "เทคนิควิธีการที่ใช้ในการพัฒนา", + default: null, + }) + name: string; + + @Column({ + nullable: true, + comment: "โครงการ/หลักสูตรการฝึกอบรม", + default: null, + }) + developmentId: string; + + @ManyToOne( + () => Development, + (development: Development) => development.developmentProjectTechniques, + ) + @JoinColumn({ name: "developmentId" }) + development: Development; +} +export class CreateDevelopmentProjectTechnique { + @Column() + name: number; +} diff --git a/src/entities/DevelopmentProjectType.ts b/src/entities/DevelopmentProjectType.ts new file mode 100644 index 0000000..447dbbd --- /dev/null +++ b/src/entities/DevelopmentProjectType.ts @@ -0,0 +1,32 @@ +import { Entity, Column, ManyToOne, JoinColumn } from "typeorm"; +import { EntityBase } from "./base/Base"; +import { Development } from "./Development"; + +@Entity("developmentProjectType") +export class DevelopmentProjectType extends EntityBase { + @Column({ + // STRATEGIC_PROJECT = โครงการตามยุทธศาสตร์ + // MISSION_PROJECT = โครงการตามภารกิจประจำของหน่วยงาน + // NEW_PROJECT = โครงการใหม่ + // ONGOING_PROJECT = โครงการต่อเนื่อง + nullable: true, + comment: "ประเภทโครงการ", + default: null, + }) + name: string; + + @Column({ + nullable: true, + comment: "โครงการ/หลักสูตรการฝึกอบรม", + default: null, + }) + developmentId: string; + + @ManyToOne(() => Development, (development: Development) => development.developmentProjectTypes) + @JoinColumn({ name: "developmentId" }) + development: Development; +} +export class CreateDevelopmentProjectType { + @Column() + name: string; +} diff --git a/src/entities/Province.ts b/src/entities/Province.ts index e251957..7ba8848 100644 --- a/src/entities/Province.ts +++ b/src/entities/Province.ts @@ -1,6 +1,7 @@ import { Entity, Column, OneToMany, ManyToMany, JoinTable } from "typeorm"; import { EntityBase } from "./base/Base"; import { Development } from "./Development"; +import { DevelopmentAddress } from "./DevelopmentAddress"; @Entity("province") export class Province extends EntityBase { @@ -12,9 +13,11 @@ export class Province extends EntityBase { }) name: string; - @ManyToMany(() => Development, (development) => development.provinces) - @JoinTable() - developmentProvinces: Development[]; + @OneToMany( + () => DevelopmentAddress, + (developmentAddress: DevelopmentAddress) => developmentAddress.province, + ) + developmentAddresss: DevelopmentAddress[]; @OneToMany(() => Development, (development: Development) => development.provinceActual) developmentActuals: Development[]; diff --git a/src/migration/1712778363784-update_table_dev_refresh1.ts b/src/migration/1712778363784-update_table_dev_refresh1.ts new file mode 100644 index 0000000..859005e --- /dev/null +++ b/src/migration/1712778363784-update_table_dev_refresh1.ts @@ -0,0 +1,92 @@ +import { MigrationInterface, QueryRunner } from "typeorm"; + +export class UpdateTableDevRefresh11712778363784 implements MigrationInterface { + name = 'UpdateTableDevRefresh11712778363784' + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(`CREATE TABLE \`developmentAddress\` (\`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', \`address\` varchar(255) NULL COMMENT 'ที่อยู่', \`provinceId\` varchar(255) NULL COMMENT 'โครงการ/หลักสูตรการฝึกอบรม', \`developmentId\` varchar(255) NULL COMMENT 'โครงการ/หลักสูตรการฝึกอบรม', PRIMARY KEY (\`id\`)) ENGINE=InnoDB`); + await queryRunner.query(`CREATE TABLE \`developmentProjectType\` (\`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', \`name\` varchar(255) NULL COMMENT 'ประเภทโครงการ', \`developmentId\` varchar(255) NULL COMMENT 'โครงการ/หลักสูตรการฝึกอบรม', PRIMARY KEY (\`id\`)) ENGINE=InnoDB`); + await queryRunner.query(`CREATE TABLE \`developmentProjectTechnique\` (\`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', \`name\` varchar(255) NULL COMMENT 'เทคนิควิธีการที่ใช้ในการพัฒนา', \`developmentId\` varchar(255) NULL COMMENT 'โครงการ/หลักสูตรการฝึกอบรม', PRIMARY KEY (\`id\`)) ENGINE=InnoDB`); + await queryRunner.query(`CREATE TABLE \`developmentEvaluation\` (\`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', \`indicators\` varchar(255) NULL COMMENT 'ตัวชี้วัด', \`target\` int NULL COMMENT 'เป้าหมาย', \`metricType\` varchar(255) NULL COMMENT 'ประเภทตัวชี้วัด', \`calculation\` varchar(255) NULL COMMENT 'วิธีการคำนวณ/เครื่องมือ', \`measuRement\` varchar(255) NULL COMMENT 'ระยะเวลาวัดผล', \`results\` varchar(255) NULL COMMENT 'ผลการดำเนิน', \`obstacles\` varchar(255) NULL COMMENT 'ปัญหาอุปสรรค', \`suggestions\` varchar(255) NULL COMMENT 'ข้อเสนอเเนะ', \`developmentId\` varchar(255) NULL COMMENT 'โครงการ/หลักสูตรการฝึกอบรม', PRIMARY KEY (\`id\`)) ENGINE=InnoDB`); + await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`metricType\``); + await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`indicators\``); + await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`target\``); + await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`calculation\``); + await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`measuRement\``); + await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`results\``); + await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`obstacles\``); + await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`suggestions\``); + await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`address\``); + await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`dateStudyStart\``); + await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`dateStudyEnd\``); + await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`projectType\``); + await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`projectCharacteristics\``); + await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`projectDay\``); + await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`projectNigth\``); + await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`projectTechniques\``); + await queryRunner.query(`ALTER TABLE \`development\` ADD \`status\` varchar(255) NULL COMMENT 'สถานะ' DEFAULT 'ONGOING'`); + await queryRunner.query(`ALTER TABLE \`development\` ADD \`isBackPlanned\` tinyint NOT NULL COMMENT 'ไป-กลับ' DEFAULT 0`); + await queryRunner.query(`ALTER TABLE \`development\` ADD \`isHoldPlanned\` tinyint NOT NULL COMMENT 'พักค้าง' DEFAULT 0`); + await queryRunner.query(`ALTER TABLE \`development\` ADD \`projectDayBackPlanned\` int NULL COMMENT 'จำนวน(วัน)(ไป-กลับ)'`); + await queryRunner.query(`ALTER TABLE \`development\` ADD \`projectDayHoldPlanned\` int NULL COMMENT 'จำนวน(วัน)(พักค้าง)'`); + await queryRunner.query(`ALTER TABLE \`development\` ADD \`projectNigthHoldPlanned\` int NULL COMMENT 'จำนวน(คืน)(พักค้าง)'`); + await queryRunner.query(`ALTER TABLE \`development\` ADD \`isBackActual\` tinyint NOT NULL COMMENT 'ไป-กลับ' DEFAULT 0`); + await queryRunner.query(`ALTER TABLE \`development\` ADD \`isHoldActual\` tinyint NOT NULL COMMENT 'พักค้าง' DEFAULT 0`); + await queryRunner.query(`ALTER TABLE \`development\` ADD \`projectDayBackActual\` int NULL COMMENT 'จำนวน(วัน)(ไป-กลับ)'`); + await queryRunner.query(`ALTER TABLE \`development\` ADD \`projectDayHoldActual\` int NULL COMMENT 'จำนวน(วัน)(พักค้าง)'`); + await queryRunner.query(`ALTER TABLE \`development\` ADD \`projectNigthHoldActual\` int NULL COMMENT 'จำนวน(คืน)(พักค้าง)'`); + await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`chance\``); + await queryRunner.query(`ALTER TABLE \`development\` ADD \`chance\` int NULL COMMENT 'โอกาสที่จะเกิด'`); + await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`effects\``); + await queryRunner.query(`ALTER TABLE \`development\` ADD \`effects\` int NULL COMMENT 'ผลกระทบจากการเกิด'`); + await queryRunner.query(`ALTER TABLE \`developmentAddress\` ADD CONSTRAINT \`FK_e2721b3f440256b56ce83a04fb2\` FOREIGN KEY (\`provinceId\`) REFERENCES \`province\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`); + await queryRunner.query(`ALTER TABLE \`developmentAddress\` ADD CONSTRAINT \`FK_de5eb0e55892aa0cf019afb284d\` FOREIGN KEY (\`developmentId\`) REFERENCES \`development\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`); + await queryRunner.query(`ALTER TABLE \`developmentProjectType\` ADD CONSTRAINT \`FK_e9c5a726024b87bb10f23570a98\` FOREIGN KEY (\`developmentId\`) REFERENCES \`development\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`); + await queryRunner.query(`ALTER TABLE \`developmentProjectTechnique\` ADD CONSTRAINT \`FK_902408e69fa1cf0ed815859e089\` FOREIGN KEY (\`developmentId\`) REFERENCES \`development\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`); + await queryRunner.query(`ALTER TABLE \`developmentEvaluation\` ADD CONSTRAINT \`FK_1714596cf3e3e8311a766800289\` FOREIGN KEY (\`developmentId\`) REFERENCES \`development\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`); + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`developmentEvaluation\` DROP FOREIGN KEY \`FK_1714596cf3e3e8311a766800289\``); + await queryRunner.query(`ALTER TABLE \`developmentProjectTechnique\` DROP FOREIGN KEY \`FK_902408e69fa1cf0ed815859e089\``); + await queryRunner.query(`ALTER TABLE \`developmentProjectType\` DROP FOREIGN KEY \`FK_e9c5a726024b87bb10f23570a98\``); + await queryRunner.query(`ALTER TABLE \`developmentAddress\` DROP FOREIGN KEY \`FK_de5eb0e55892aa0cf019afb284d\``); + await queryRunner.query(`ALTER TABLE \`developmentAddress\` DROP FOREIGN KEY \`FK_e2721b3f440256b56ce83a04fb2\``); + await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`effects\``); + await queryRunner.query(`ALTER TABLE \`development\` ADD \`effects\` varchar(255) NULL COMMENT 'ผลกระทบจากการเกิด'`); + await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`chance\``); + await queryRunner.query(`ALTER TABLE \`development\` ADD \`chance\` varchar(255) NULL COMMENT 'โอกาสที่จะเกิด'`); + await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`projectNigthHoldActual\``); + await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`projectDayHoldActual\``); + await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`projectDayBackActual\``); + await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`isHoldActual\``); + await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`isBackActual\``); + await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`projectNigthHoldPlanned\``); + await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`projectDayHoldPlanned\``); + await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`projectDayBackPlanned\``); + await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`isHoldPlanned\``); + await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`isBackPlanned\``); + await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`status\``); + await queryRunner.query(`ALTER TABLE \`development\` ADD \`projectTechniques\` varchar(255) NULL COMMENT 'เทคนิควิธีการที่ใช้ในการพัฒนา'`); + await queryRunner.query(`ALTER TABLE \`development\` ADD \`projectNigth\` int NULL COMMENT 'จำนวน(คืน)'`); + await queryRunner.query(`ALTER TABLE \`development\` ADD \`projectDay\` int NULL COMMENT 'จำนวน(วัน)'`); + await queryRunner.query(`ALTER TABLE \`development\` ADD \`projectCharacteristics\` varchar(255) NULL COMMENT 'ลักษณะ'`); + await queryRunner.query(`ALTER TABLE \`development\` ADD \`projectType\` varchar(255) NULL COMMENT 'ประเภทโครงการ'`); + await queryRunner.query(`ALTER TABLE \`development\` ADD \`dateStudyEnd\` datetime NULL COMMENT 'วันสิ้นสุดการศึกษาดูงาน'`); + await queryRunner.query(`ALTER TABLE \`development\` ADD \`dateStudyStart\` datetime NULL COMMENT 'วันเริ่มต้นการศึกษาดูงาน'`); + await queryRunner.query(`ALTER TABLE \`development\` ADD \`address\` varchar(255) NULL COMMENT 'ที่อยู่'`); + await queryRunner.query(`ALTER TABLE \`development\` ADD \`suggestions\` varchar(255) NULL COMMENT 'ข้อเสนอเเนะ'`); + await queryRunner.query(`ALTER TABLE \`development\` ADD \`obstacles\` varchar(255) NULL COMMENT 'ปัญหาอุปสรรค'`); + await queryRunner.query(`ALTER TABLE \`development\` ADD \`results\` varchar(255) NULL COMMENT 'ผลการดำเนิน'`); + await queryRunner.query(`ALTER TABLE \`development\` ADD \`measuRement\` varchar(255) NULL COMMENT 'ระยะเวลาวัดผล'`); + await queryRunner.query(`ALTER TABLE \`development\` ADD \`calculation\` varchar(255) NULL COMMENT 'วิธีการคำนวณ/เครื่องมือ'`); + await queryRunner.query(`ALTER TABLE \`development\` ADD \`target\` varchar(255) NULL COMMENT 'เป้าหมาย'`); + await queryRunner.query(`ALTER TABLE \`development\` ADD \`indicators\` varchar(255) NULL COMMENT 'ตัวชี้วัด'`); + await queryRunner.query(`ALTER TABLE \`development\` ADD \`metricType\` varchar(255) NULL COMMENT 'ประเภทตัวชี้วัด'`); + await queryRunner.query(`DROP TABLE \`developmentEvaluation\``); + await queryRunner.query(`DROP TABLE \`developmentProjectTechnique\``); + await queryRunner.query(`DROP TABLE \`developmentProjectType\``); + await queryRunner.query(`DROP TABLE \`developmentAddress\``); + } + +} diff --git a/src/migration/1712779710145-update_table_dev_refresh2.ts b/src/migration/1712779710145-update_table_dev_refresh2.ts new file mode 100644 index 0000000..74635f4 --- /dev/null +++ b/src/migration/1712779710145-update_table_dev_refresh2.ts @@ -0,0 +1,16 @@ +import { MigrationInterface, QueryRunner } from "typeorm"; + +export class UpdateTableDevRefresh21712779710145 implements MigrationInterface { + name = 'UpdateTableDevRefresh21712779710145' + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`development\` ADD \`dateStudyStart\` datetime NULL COMMENT 'วันเริ่มต้นการศึกษาดูงาน'`); + await queryRunner.query(`ALTER TABLE \`development\` ADD \`dateStudyEnd\` datetime NULL COMMENT 'วันสิ้นสุดการศึกษาดูงาน'`); + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`dateStudyEnd\``); + await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`dateStudyStart\``); + } + +} From a4eed4f690ac0e131a1ee56cd58c564ccb6a5389 Mon Sep 17 00:00:00 2001 From: Kittapath Date: Thu, 11 Apr 2024 16:32:44 +0700 Subject: [PATCH 045/250] =?UTF-8?q?api=20=E0=B8=97=E0=B8=B8=E0=B8=99=20?= =?UTF-8?q?=E0=B8=82=E0=B8=AD=E0=B8=87=20user?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/DevelopmentController.ts | 346 ++++++++++++------ .../DevelopmentScholarshipController.ts | 84 +++++ src/entities/Development.ts | 34 +- ...s => DevelopmentProjectTechniqueActual.ts} | 8 +- .../DevelopmentProjectTechniquePlanned.ts | 39 ++ src/entities/DevelopmentScholarship.ts | 63 ++++ .../1712815316667-add_table_starty1.ts | 20 + ...ble_developmentScholarship_add_planType.ts | 26 ++ 8 files changed, 496 insertions(+), 124 deletions(-) rename src/entities/{DevelopmentProjectTechnique.ts => DevelopmentProjectTechniqueActual.ts} (86%) create mode 100644 src/entities/DevelopmentProjectTechniquePlanned.ts create mode 100644 src/migration/1712815316667-add_table_starty1.ts create mode 100644 src/migration/1712824449740-update_table_developmentScholarship_add_planType.ts diff --git a/src/controllers/DevelopmentController.ts b/src/controllers/DevelopmentController.ts index 466db5e..bf63fe5 100644 --- a/src/controllers/DevelopmentController.ts +++ b/src/controllers/DevelopmentController.ts @@ -38,9 +38,13 @@ import { PosLevel } from "../entities/PosLevel"; import { PlannedGoalPosition } from "../entities/PlannedGoalPosition"; import { DevelopmentHistory } from "../entities/DevelopmentHistory"; import { DevelopmentProjectType } from "../entities/DevelopmentProjectType"; -import { DevelopmentProjectTechnique } from "../entities/DevelopmentProjectTechnique"; -import { DevelopmentEvaluation } from "../entities/DevelopmentEvaluation"; +import { + CreateDevelopmentEvaluation, + DevelopmentEvaluation, +} from "../entities/DevelopmentEvaluation"; import { DevelopmentAddress } from "../entities/DevelopmentAddress"; +import { DevelopmentProjectTechniquePlanned } from "../entities/DevelopmentProjectTechniquePlanned"; +import { DevelopmentProjectTechniqueActual } from "../entities/DevelopmentProjectTechniqueActual"; @Route("api/v1/development/main") @Tags("Development") @@ -50,8 +54,11 @@ export class DevelopmentController extends Controller { private developmentAddresssRepository = AppDataSource.getRepository(DevelopmentAddress); private developmentEvaluationRepository = AppDataSource.getRepository(DevelopmentEvaluation); private developmentProjectTypeRepository = AppDataSource.getRepository(DevelopmentProjectType); - private developmentProjectTechniqueRepository = AppDataSource.getRepository( - DevelopmentProjectTechnique, + private developmentProjectTechniquePlannedRepository = AppDataSource.getRepository( + DevelopmentProjectTechniquePlanned, + ); + private developmentProjectTechniqueActualRepository = AppDataSource.getRepository( + DevelopmentProjectTechniqueActual, ); private developmentHistoryRepository = AppDataSource.getRepository(DevelopmentHistory); private actualPeopleRepository = AppDataSource.getRepository(ActualPeople); @@ -162,7 +169,7 @@ export class DevelopmentController extends Controller { if (!development) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงการ/หลักสูตรการฝึกอบรมนี้"); } - const data = Object.assign(new PlannedGoal(), requestBody); + const data = Object.assign(new PlannedGoal(), { ...requestBody, positions: [] }); data.createdUserId = request.user.sub; data.createdFullName = request.user.name; data.lastUpdateUserId = request.user.sub; @@ -284,7 +291,7 @@ export class DevelopmentController extends Controller { @Put("tab2_4_add/{id}") async CreateDevelopmenttab2_4( @Path() id: string, - @Body() requestBody: CreateActualPeople[], + @Body() requestBody: CreateActualPeople, @Request() request: { user: Record }, ) { const development = await this.developmentRepository.findOne({ @@ -308,7 +315,7 @@ export class DevelopmentController extends Controller { * * @summary DEV_00 - แก้ไขโครงการ/หลักสูตรการฝึกอบรมtab2-1 # * - * @param {string} id Id โครงการ + * @param {string} id Id รายการ */ @Put("tab2_1_edit/{id}") async UpdateDevelopmenttab2_1( @@ -327,9 +334,7 @@ export class DevelopmentController extends Controller { } await this.plannedGoalPositionRepository.remove(development.plannedGoalPositions); - const _requestBody: any = requestBody; - delete _requestBody.positions; - Object.assign(development, requestBody); + Object.assign(development, { ...requestBody, positions: [] }); development.lastUpdateUserId = request.user.sub; development.lastUpdateFullName = request.user.name; await this.plannedGoalRepository.save(development); @@ -371,7 +376,7 @@ export class DevelopmentController extends Controller { * * @summary DEV_00 - แก้ไขโครงการ/หลักสูตรการฝึกอบรมtab2-2 # * - * @param {string} id Id โครงการ + * @param {string} id Id รายการ */ @Put("tab2_2_edit/{id}") async UpdateDevelopmenttab2_2( @@ -397,7 +402,7 @@ export class DevelopmentController extends Controller { * * @summary DEV_00 - แก้ไขโครงการ/หลักสูตรการฝึกอบรมtab2-3 # * - * @param {string} id Id โครงการ + * @param {string} id Id รายการ */ @Put("tab2_3_edit/{id}") async UpdateDevelopmenttab2_3( @@ -439,7 +444,7 @@ export class DevelopmentController extends Controller { * * @summary DEV_00 - แก้ไขโครงการ/หลักสูตรการฝึกอบรมtab2-4 # * - * @param {string} id Id โครงการ + * @param {string} id Id รายการ */ @Put("tab2_4_edit/{id}") async UpdateDevelopmenttab2_4( @@ -557,19 +562,28 @@ export class DevelopmentController extends Controller { where: { id }, relations: { developmentProjectTypes: true, - developmentProjectTechniques: true, + developmentProjectTechniquePlanneds: true, + developmentProjectTechniqueActuals: true, }, }); if (!development) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงการ/หลักสูตรการฝึกอบรมนี้"); } - Object.assign(development, requestBody); + Object.assign(development, { + ...requestBody, + developmentProjectTypes: [], + developmentProjectTechniquePlanneds: [], + developmentProjectTechniqueActuals: [], + }); development.lastUpdateUserId = request.user.sub; development.lastUpdateFullName = request.user.name; await this.developmentRepository.save(development); await this.developmentProjectTypeRepository.remove(development.developmentProjectTypes); - await this.developmentProjectTechniqueRepository.remove( - development.developmentProjectTechniques, + await this.developmentProjectTechniquePlannedRepository.remove( + development.developmentProjectTechniquePlanneds, + ); + await this.developmentProjectTechniqueActualRepository.remove( + development.developmentProjectTechniqueActuals, ); if (requestBody.developmentProjectTypes != null) { await Promise.all( @@ -585,17 +599,31 @@ export class DevelopmentController extends Controller { }), ); } - if (requestBody.developmentProjectTechniques != null) { + if (requestBody.developmentProjectTechniquePlanneds != null) { await Promise.all( - requestBody.developmentProjectTechniques.map(async (x) => { - let data = new DevelopmentProjectTechnique(); + requestBody.developmentProjectTechniquePlanneds.map(async (x) => { + let data = new DevelopmentProjectTechniquePlanned(); data.name = x; data.createdUserId = request.user.sub; data.createdFullName = request.user.name; data.lastUpdateUserId = request.user.sub; data.lastUpdateFullName = request.user.name; data.developmentId = development.id; - await this.developmentProjectTechniqueRepository.save(data); + await this.developmentProjectTechniquePlannedRepository.save(data); + }), + ); + } + if (requestBody.developmentProjectTechniqueActuals != null) { + await Promise.all( + requestBody.developmentProjectTechniqueActuals.map(async (x) => { + let data = new DevelopmentProjectTechniquePlanned(); + data.name = x; + data.createdUserId = request.user.sub; + data.createdFullName = request.user.name; + data.lastUpdateUserId = request.user.sub; + data.lastUpdateFullName = request.user.name; + data.developmentId = development.id; + await this.developmentProjectTechniqueActualRepository.save(data); }), ); } @@ -617,9 +645,6 @@ export class DevelopmentController extends Controller { ) { const development = await this.developmentRepository.findOne({ where: { id }, - relations: { - developmentEvaluations: true, - }, }); if (!development) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงการ/หลักสูตรการฝึกอบรมนี้"); @@ -628,18 +653,80 @@ export class DevelopmentController extends Controller { development.lastUpdateUserId = request.user.sub; development.lastUpdateFullName = request.user.name; await this.developmentRepository.save(development); - await this.developmentEvaluationRepository.remove(development.developmentEvaluations); - await Promise.all( - requestBody.developmentEvaluations.map(async (x) => { - const data = Object.assign(new DevelopmentEvaluation(), x); - data.createdUserId = request.user.sub; - data.createdFullName = request.user.name; - data.lastUpdateUserId = request.user.sub; - data.lastUpdateFullName = request.user.name; - data.developmentId = development.id; - await this.developmentEvaluationRepository.save(data); - }), - ); + return new HttpSuccess(development.id); + } + + /** + * API เพิ่มโครงการ/หลักสูตรการฝึกอบรมtab4-1 + * + * @summary DEV_00 - เพิ่มโครงการ/หลักสูตรการฝึกอบรมtab4-1 # + * + * @param {string} id Id โครงการ + */ + @Put("tab4_1_add/{id}") + async CreateDevelopmenttab4_1( + @Path() id: string, + @Body() requestBody: CreateDevelopmentEvaluation, + @Request() request: { user: Record }, + ) { + const development = await this.developmentRepository.findOne({ + where: { id }, + }); + if (!development) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงการ/หลักสูตรการฝึกอบรมนี้"); + } + const data = Object.assign(new DevelopmentEvaluation(), requestBody); + data.createdUserId = request.user.sub; + data.createdFullName = request.user.name; + data.lastUpdateUserId = request.user.sub; + data.lastUpdateFullName = request.user.name; + data.developmentId = development.id; + await this.developmentEvaluationRepository.save(data); + return new HttpSuccess(data.id); + } + + /** + * API ลบโครงการ/หลักสูตรการฝึกอบรมtab4-1 + * + * @summary DEV_00 - ลบโครงการ/หลักสูตรการฝึกอบรมtab4-1 # + * + * @param {string} id Id รายการ + */ + @Delete("tab4_1/{id}") + async DeleteDevelopmenttab4_1(@Path() id: string) { + const development = await this.developmentEvaluationRepository.findOne({ + where: { id }, + }); + if (!development) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลผู้เกี่ยวข้องเป้าหมายตามแผน"); + } + await this.developmentEvaluationRepository.remove(development); + return new HttpSuccess(development.id); + } + + /** + * API แก้ไขโครงการ/หลักสูตรการฝึกอบรมtab4-1 + * + * @summary DEV_00 - แก้ไขโครงการ/หลักสูตรการฝึกอบรมtab4-1 # + * + * @param {string} id Id รายการ + */ + @Put("tab4_1_edit/{id}") + async UpdateDevelopmenttab4_1( + @Path() id: string, + @Body() requestBody: CreateDevelopmentEvaluation, + @Request() request: { user: Record }, + ) { + const development = await this.developmentEvaluationRepository.findOne({ + where: { id }, + }); + if (!development) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงการ/หลักสูตรการฝึกอบรมนี้"); + } + Object.assign(development, requestBody); + development.lastUpdateUserId = request.user.sub; + development.lastUpdateFullName = request.user.name; + await this.developmentEvaluationRepository.save(development); return new HttpSuccess(development.id); } @@ -658,9 +745,7 @@ export class DevelopmentController extends Controller { ) { const development = await this.developmentRepository.findOne({ where: { id }, - relations: { - developmentAddresss: true, - }, + relations: { developmentAddresss: true }, }); if (!development) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงการ/หลักสูตรการฝึกอบรมนี้"); @@ -673,28 +758,31 @@ export class DevelopmentController extends Controller { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลจังหวัดข้อมูลด้านวิชาการ"); } } - Object.assign(development, requestBody); + + Object.assign(development, { ...requestBody, developmentAddresss: [] }); development.lastUpdateUserId = request.user.sub; development.lastUpdateFullName = request.user.name; await this.developmentRepository.save(development); + await this.developmentAddresssRepository.remove(development.developmentAddresss); await Promise.all( requestBody.developmentAddresss.map(async (x) => { const data = Object.assign(new DevelopmentAddress(), x); - const chkProvince = await this.provinceRepository.find({ + const chkProvince = await this.provinceRepository.findOne({ where: { id: x.provinceId, }, }); if (chkProvince == null) return; + data.developmentId = development.id; data.createdUserId = request.user.sub; data.createdFullName = request.user.name; data.lastUpdateUserId = request.user.sub; data.lastUpdateFullName = request.user.name; - data.developmentId = development.id; await this.developmentAddresssRepository.save(data); }), ); + return new HttpSuccess(development.id); } @@ -703,7 +791,6 @@ export class DevelopmentController extends Controller { * * @summary DEV_00 - ค้นหาโครงการ # * - * @param {string} id Id โครงการ */ @Get("search") async ListDevelopemt( @@ -752,7 +839,7 @@ export class DevelopmentController extends Controller { * * @summary DEV_003 - ลบโครงการ/หลักสูตรการฝึกอบรม #3 * - * @param {string} id Id โครงการ + * @param {string} id Id รายการ */ @Delete("{id}") async DeleteDevelopment(@Path() id: string) { @@ -764,7 +851,8 @@ export class DevelopmentController extends Controller { developmentActualGoals: true, developmentPlannedGoals: true, developmentProjectTypes: true, - developmentProjectTechniques: true, + developmentProjectTechniquePlanneds: true, + developmentProjectTechniqueActuals: true, developmentEvaluations: true, developmentAddresss: true, }, @@ -787,8 +875,11 @@ export class DevelopmentController extends Controller { await this.actualGoalRepository.remove(development.developmentActualGoals); await this.plannedGoalRepository.remove(development.developmentPlannedGoals); await this.developmentProjectTypeRepository.remove(development.developmentProjectTypes); - await this.developmentProjectTechniqueRepository.remove( - development.developmentProjectTechniques, + await this.developmentProjectTechniquePlannedRepository.remove( + development.developmentProjectTechniquePlanneds, + ); + await this.developmentProjectTechniqueActualRepository.remove( + development.developmentProjectTechniqueActuals, ); await this.developmentEvaluationRepository.remove(development.developmentEvaluations); await this.developmentAddresssRepository.remove(development.developmentAddresss); @@ -915,10 +1006,38 @@ export class DevelopmentController extends Controller { } let _getDevelopment: any = { id: getDevelopment.id, - actualPeoples: getDevelopment.developmentActualPeoples, - plannedPeoples: getDevelopment.developmentPlannedPeoples, - actualGoals: getDevelopment.developmentActualGoals, - plannedGoals: getDevelopment.developmentPlannedGoals, + actualPeoples: + getDevelopment.developmentActualPeoples == null + ? null + : getDevelopment.developmentActualPeoples.sort((a, b) => + (a.groupTarget == null ? "" : a.groupTarget).localeCompare( + b.groupTarget == null ? "" : b.groupTarget, + ), + ), + plannedPeoples: + getDevelopment.developmentPlannedPeoples == null + ? null + : getDevelopment.developmentPlannedPeoples.sort((a, b) => + (a.groupTarget == null ? "" : a.groupTarget).localeCompare( + b.groupTarget == null ? "" : b.groupTarget, + ), + ), + actualGoals: + getDevelopment.developmentActualGoals == null + ? null + : getDevelopment.developmentActualGoals.sort((a, b) => + (a.groupTarget == null ? "" : a.groupTarget).localeCompare( + b.groupTarget == null ? "" : b.groupTarget, + ), + ), + plannedGoals: + getDevelopment.developmentPlannedGoals == null + ? null + : getDevelopment.developmentPlannedGoals.sort((a, b) => + (a.groupTarget == null ? "" : a.groupTarget).localeCompare( + b.groupTarget == null ? "" : b.groupTarget, + ), + ), }; return new HttpSuccess(_getDevelopment); } @@ -935,28 +1054,34 @@ export class DevelopmentController extends Controller { const getDevelopment = await this.developmentRepository.findOne({ where: { id: id }, relations: [ - "developmentActualPeoples", - "developmentPlannedPeoples", - "developmentActualGoals", - "developmentPlannedGoals", - "developmentPlannedGoals.plannedGoalPositions", - "provinces", - // "provinces.developmentProvinces", + "developmentProjectTypes", + "developmentProjectTechniquePlanneds", + "developmentProjectTechniqueActuals", ], }); if (!getDevelopment) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงการ/หลักสูตรการฝึกอบรมนี้"); } - let _getDevelopment: any = getDevelopment; - _getDevelopment.actualPeoples = getDevelopment.developmentActualPeoples; - _getDevelopment.plannedPeoples = getDevelopment.developmentPlannedPeoples; - _getDevelopment.actualGoals = getDevelopment.developmentActualGoals; - _getDevelopment.plannedGoals = getDevelopment.developmentPlannedGoals; - // _getDevelopment.provinces = getDevelopment.provinces.map(x=>x.developmentProvinces); - delete _getDevelopment.developmentActualPeoples; - delete _getDevelopment.developmentPlannedPeoples; - delete _getDevelopment.developmentActualGoals; - delete _getDevelopment.developmentPlannedGoals; + let _getDevelopment: any = { + developmentProjectTypes: getDevelopment.developmentProjectTypes.map((x) => x.name).sort(), + projectModal: getDevelopment.projectModal, + isBackPlanned: getDevelopment.isBackPlanned, + isHoldPlanned: getDevelopment.isHoldPlanned, + projectDayBackPlanned: getDevelopment.projectDayBackPlanned, + projectDayHoldPlanned: getDevelopment.projectDayHoldPlanned, + projectNigthHoldPlanned: getDevelopment.projectNigthHoldPlanned, + developmentProjectTechniquePlanneds: getDevelopment.developmentProjectTechniquePlanneds + .map((x) => x.name) + .sort(), + isBackActual: getDevelopment.isBackActual, + isHoldActual: getDevelopment.isHoldActual, + projectDayBackActual: getDevelopment.projectDayBackActual, + projectDayHoldActual: getDevelopment.projectDayHoldActual, + projectNigthHoldActual: getDevelopment.projectNigthHoldActual, + developmentProjectTechniqueActuals: getDevelopment.developmentProjectTechniqueActuals + .map((x) => x.name) + .sort(), + }; return new HttpSuccess(_getDevelopment); } @@ -971,29 +1096,28 @@ export class DevelopmentController extends Controller { async GetDevelopemtTab4ById(@Path() id: string) { const getDevelopment = await this.developmentRepository.findOne({ where: { id: id }, - relations: [ - "developmentActualPeoples", - "developmentPlannedPeoples", - "developmentActualGoals", - "developmentPlannedGoals", - "developmentPlannedGoals.plannedGoalPositions", - "provinces", - // "provinces.developmentProvinces", - ], + relations: ["developmentEvaluations"], }); if (!getDevelopment) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงการ/หลักสูตรการฝึกอบรมนี้"); } - let _getDevelopment: any = getDevelopment; - _getDevelopment.actualPeoples = getDevelopment.developmentActualPeoples; - _getDevelopment.plannedPeoples = getDevelopment.developmentPlannedPeoples; - _getDevelopment.actualGoals = getDevelopment.developmentActualGoals; - _getDevelopment.plannedGoals = getDevelopment.developmentPlannedGoals; - // _getDevelopment.provinces = getDevelopment.provinces.map(x=>x.developmentProvinces); - delete _getDevelopment.developmentActualPeoples; - delete _getDevelopment.developmentPlannedPeoples; - delete _getDevelopment.developmentActualGoals; - delete _getDevelopment.developmentPlannedGoals; + let _getDevelopment = { + developmentEvaluations: + getDevelopment.developmentEvaluations == null + ? null + : getDevelopment.developmentEvaluations.sort((a, b) => + (a.indicators == null ? "" : a.indicators).localeCompare( + b.indicators == null ? "" : b.indicators, + ), + ), + project: getDevelopment.project, + isPassAllocate: getDevelopment.isPassAllocate, + isPassNoAllocate: getDevelopment.isPassNoAllocate, + isNoPass: getDevelopment.isNoPass, + isBudget: getDevelopment.isBudget, + isOutBudget: getDevelopment.isOutBudget, + }; + return new HttpSuccess(_getDevelopment); } @@ -1008,29 +1132,39 @@ export class DevelopmentController extends Controller { async GetDevelopemtTab5ById(@Path() id: string) { const getDevelopment = await this.developmentRepository.findOne({ where: { id: id }, - relations: [ - "developmentActualPeoples", - "developmentPlannedPeoples", - "developmentActualGoals", - "developmentPlannedGoals", - "developmentPlannedGoals.plannedGoalPositions", - "provinces", - // "provinces.developmentProvinces", - ], + relations: ["developmentAddresss"], }); if (!getDevelopment) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงการ/หลักสูตรการฝึกอบรมนี้"); } - let _getDevelopment: any = getDevelopment; - _getDevelopment.actualPeoples = getDevelopment.developmentActualPeoples; - _getDevelopment.plannedPeoples = getDevelopment.developmentPlannedPeoples; - _getDevelopment.actualGoals = getDevelopment.developmentActualGoals; - _getDevelopment.plannedGoals = getDevelopment.developmentPlannedGoals; - // _getDevelopment.provinces = getDevelopment.provinces.map(x=>x.developmentProvinces); - delete _getDevelopment.developmentActualPeoples; - delete _getDevelopment.developmentPlannedPeoples; - delete _getDevelopment.developmentActualGoals; - delete _getDevelopment.developmentPlannedGoals; + let _getDevelopment = { + dateStart: getDevelopment.dateStart, + dateEnd: getDevelopment.dateEnd, + totalDate: getDevelopment.totalDate, + developmentAddresss: + getDevelopment.developmentAddresss == null + ? null + : getDevelopment.developmentAddresss.sort((a, b) => + (a.address == null ? "" : a.address).localeCompare( + b.address == null ? "" : b.address, + ), + ), + budget: getDevelopment.budget, + budgetSub: getDevelopment.budgetSub, + accept: getDevelopment.accept, + receive: getDevelopment.receive, + approved: getDevelopment.approved, + budgetPay: getDevelopment.budgetPay, + issues: getDevelopment.issues, + chance: getDevelopment.chance, + effects: getDevelopment.effects, + riskLevel: getDevelopment.riskLevel, + riskManagement: getDevelopment.riskManagement, + expect: getDevelopment.expect, + topicAcademic: getDevelopment.topicAcademic, + addressAcademic: getDevelopment.addressAcademic, + provinceActualId: getDevelopment.provinceActualId, + }; return new HttpSuccess(_getDevelopment); } diff --git a/src/controllers/DevelopmentScholarshipController.ts b/src/controllers/DevelopmentScholarshipController.ts index 3ef6c50..f305148 100644 --- a/src/controllers/DevelopmentScholarshipController.ts +++ b/src/controllers/DevelopmentScholarshipController.ts @@ -21,6 +21,7 @@ import { CreateDevelopmentScholarship, DevelopmentScholarship, UpdateDevelopmentScholarship, + UpdateDevelopmentScholarshipUser, } from "../entities/DevelopmentScholarship"; import { PosType } from "../entities/PosType"; import { PosLevel } from "../entities/PosLevel"; @@ -314,10 +315,91 @@ export class DevelopmentScholarshipController extends Controller { totalPeriod: getDevelopment.totalPeriod ? getDevelopment.totalPeriod : null, status: getDevelopment.status ? getDevelopment.status : null, profileId: getDevelopment.profileId ? getDevelopment.profileId : null, + planType: getDevelopment.planType ? getDevelopment.planType : null, + isNoUseBudget: getDevelopment.isNoUseBudget ? getDevelopment.isNoUseBudget : null, }; return new HttpSuccess(formattedData); } + /** + * API รายการทุนของ user + * + * @summary DEV_0 - รายการทุนของ user # + * + * @param {string} profileId profileId ข้าราชการฯที่ได้รับทุนการศึกษา + */ + @Get("user/{profileId}") + async GetDevelopemtScholarshipUserById(@Path() profileId: string) { + const getDevelopment = await this.developmentScholarshipRepository.find({ + where: { profileId: profileId }, + }); + const formattedData = getDevelopment.map((item) => ({ + id: item.id, + scholarshipYear: item.scholarshipYear, + scholarshipType: item.scholarshipType, + fundType: item.fundType, + })); + + return new HttpSuccess(formattedData); + } + + /** + * API รายละเอียดทุนของ user + * + * @summary DEV_0 - รายละเอียดทุนของ user # + * + * @param {string} id id รายการ + */ + @Get("user/detail/{id}") + async GetDevelopemtScholarshipUserDetailById(@Path() id: string) { + const getDevelopment = await this.developmentScholarshipRepository.findOne({ + where: { id: id }, + select: [ + "id", + "scholarshipYear", + "scholarshipType", + "fundType", + "governmentDate", + "isGraduated", + "graduatedDate", + "isNoGraduated", + "graduatedReason", + ], + }); + if (!getDevelopment) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลทุนการศึกษา/ฝึกอบรมนี้"); + } + + return new HttpSuccess(getDevelopment); + } + + /** + * API แก้ไขรายการทุนของ user + * + * @summary DEV_015 - แก้ไขรายการทุนของ user #15 + * + * @param {string} id รายการ + */ + @Put("user/detail/{id}") + async UpdateDevelopemtScholarshipUserById( + @Path() id: string, + @Body() requestBody: UpdateDevelopmentScholarshipUser, + @Request() request: { user: Record }, + ) { + const getDevelopment = await this.developmentScholarshipRepository.findOne({ + where: { id: id }, + }); + if (!getDevelopment) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลทุนการศึกษา/ฝึกอบรมนี้"); + } + Object.assign(getDevelopment, requestBody); + getDevelopment.lastUpdateUserId = request.user.sub; + getDevelopment.lastUpdateFullName = request.user.name; + await this.developmentScholarshipRepository.save(getDevelopment); + + return new HttpSuccess(getDevelopment.id); + } + /** * API เปลี่ยนสถานะ * @@ -340,6 +422,8 @@ export class DevelopmentScholarshipController extends Controller { } const _status = status.trim().toUpperCase(); getDevelopment.status = _status; + getDevelopment.lastUpdateUserId = request.user.sub; + getDevelopment.lastUpdateFullName = request.user.name; if (_status == "GRADUATE") { if (getDevelopment.scholarshipType != null) { switch (getDevelopment.scholarshipType.trim().toUpperCase()) { diff --git a/src/entities/Development.ts b/src/entities/Development.ts index bae93d3..3c1a34e 100644 --- a/src/entities/Development.ts +++ b/src/entities/Development.ts @@ -7,9 +7,10 @@ import { ActualGoal, CreateActualGoal } from "./ActualGoal"; import { CreatePlannedGoal, PlannedGoal } from "./PlannedGoal"; import { DevelopmentHistory } from "./DevelopmentHistory"; import { DevelopmentProjectType } from "./DevelopmentProjectType"; -import { DevelopmentProjectTechnique } from "./DevelopmentProjectTechnique"; +import { DevelopmentProjectTechniquePlanned } from "./DevelopmentProjectTechniquePlanned"; import { CreateDevelopmentEvaluation, DevelopmentEvaluation } from "./DevelopmentEvaluation"; import { CreateDevelopmentAddress, DevelopmentAddress } from "./DevelopmentAddress"; +import { DevelopmentProjectTechniqueActual } from "./DevelopmentProjectTechniqueActual"; @Entity("development") export class Development extends EntityBase { @@ -141,11 +142,18 @@ export class Development extends EntityBase { projectNigthHoldActual: number; @OneToMany( - () => DevelopmentProjectTechnique, - (developmentProjectTechnique: DevelopmentProjectTechnique) => - developmentProjectTechnique.development, + () => DevelopmentProjectTechniquePlanned, + (developmentProjectTechniquePlanned: DevelopmentProjectTechniquePlanned) => + developmentProjectTechniquePlanned.development, ) - developmentProjectTechniques: DevelopmentProjectTechnique[]; + developmentProjectTechniquePlanneds: DevelopmentProjectTechniquePlanned[]; + + @OneToMany( + () => DevelopmentProjectTechniqueActual, + (developmentProjectTechniqueActual: DevelopmentProjectTechniqueActual) => + developmentProjectTechniqueActual.development, + ) + developmentProjectTechniqueActuals: DevelopmentProjectTechniqueActual[]; @Column({ nullable: true, @@ -400,6 +408,8 @@ export class UpdateDevelopment3 { @Column() developmentProjectTypes?: string[]; @Column() + projectModal?: number | null; + @Column() isBackPlanned?: boolean | null; @Column() isHoldPlanned?: boolean | null; @@ -410,6 +420,8 @@ export class UpdateDevelopment3 { @Column() projectNigthHoldPlanned?: number | null; @Column() + developmentProjectTechniquePlanneds?: string[]; + @Column() isBackActual?: boolean | null; @Column() isHoldActual?: boolean | null; @@ -420,13 +432,11 @@ export class UpdateDevelopment3 { @Column() projectNigthHoldActual?: number | null; @Column() - developmentProjectTechniques?: string[]; - @Column() - projectModal?: number | null; + developmentProjectTechniqueActuals?: string[]; } export class UpdateDevelopment4 { - @Column() - developmentEvaluations: CreateDevelopmentEvaluation[]; + // @Column() + // developmentEvaluations: CreateDevelopmentEvaluation[]; @Column() project: string | null; @Column() @@ -479,8 +489,4 @@ export class UpdateDevelopment5 { addressAcademic: string | null; @Column() provinceActualId: string | null; - @Column() - dateStudyStart: Date | null; - @Column() - dateStudyEnd: Date | null; } diff --git a/src/entities/DevelopmentProjectTechnique.ts b/src/entities/DevelopmentProjectTechniqueActual.ts similarity index 86% rename from src/entities/DevelopmentProjectTechnique.ts rename to src/entities/DevelopmentProjectTechniqueActual.ts index 2d3ac30..a437e00 100644 --- a/src/entities/DevelopmentProjectTechnique.ts +++ b/src/entities/DevelopmentProjectTechniqueActual.ts @@ -2,8 +2,8 @@ import { Entity, Column, ManyToOne, JoinColumn } from "typeorm"; import { EntityBase } from "./base/Base"; import { Development } from "./Development"; -@Entity("developmentProjectTechnique") -export class DevelopmentProjectTechnique extends EntityBase { +@Entity("developmentProjectTechniqueActual") +export class DevelopmentProjectTechniqueActual extends EntityBase { @Column({ // TRAINING = การอบรม // MEETING = การประชุม @@ -28,12 +28,12 @@ export class DevelopmentProjectTechnique extends EntityBase { @ManyToOne( () => Development, - (development: Development) => development.developmentProjectTechniques, + (development: Development) => development.developmentProjectTechniqueActuals, ) @JoinColumn({ name: "developmentId" }) development: Development; } -export class CreateDevelopmentProjectTechnique { +export class CreateDevelopmentProjectTechniqueActual { @Column() name: number; } diff --git a/src/entities/DevelopmentProjectTechniquePlanned.ts b/src/entities/DevelopmentProjectTechniquePlanned.ts new file mode 100644 index 0000000..bb8d3dc --- /dev/null +++ b/src/entities/DevelopmentProjectTechniquePlanned.ts @@ -0,0 +1,39 @@ +import { Entity, Column, ManyToOne, JoinColumn } from "typeorm"; +import { EntityBase } from "./base/Base"; +import { Development } from "./Development"; + +@Entity("developmentProjectTechniquePlanned") +export class DevelopmentProjectTechniquePlanned extends EntityBase { + @Column({ + // TRAINING = การอบรม + // MEETING = การประชุม + // SEMINAR = การสัมมนา + // STUDY_TOUR = การศึกษาดูงาน + // ACADEMIC_SEMINAR = การสัมมนาทางวิชาการ + // WORKSHOP = การสัมมนาเชิงปฏิบัติการ + // SPECIAL_LECTURE = การบรรยายพิเศษ + // STUDY_TRAINING = การฝึกศึกษา + nullable: true, + comment: "เทคนิควิธีการที่ใช้ในการพัฒนา", + default: null, + }) + name: string; + + @Column({ + nullable: true, + comment: "โครงการ/หลักสูตรการฝึกอบรม", + default: null, + }) + developmentId: string; + + @ManyToOne( + () => Development, + (development: Development) => development.developmentProjectTechniquePlanneds, + ) + @JoinColumn({ name: "developmentId" }) + development: Development; +} +export class CreateDevelopmentProjectTechniquePlanned { + @Column() + name: number; +} diff --git a/src/entities/DevelopmentScholarship.ts b/src/entities/DevelopmentScholarship.ts index fa3e020..1c850af 100644 --- a/src/entities/DevelopmentScholarship.ts +++ b/src/entities/DevelopmentScholarship.ts @@ -429,6 +429,57 @@ export class DevelopmentScholarship extends EntityBase { default: null, }) totalPeriod: string; + + @Column({ + // ในแผนฯ (INPLAN) + // นอกแผนฯ (OUTPLAN) + nullable: true, + comment: "ในแผนฯ", + length: 40, + default: null, + }) + planType: string; + + @Column({ + comment: "ไม่ใช้งบประมาณ", + default: false, + }) + isNoUseBudget: boolean; + + @Column({ + nullable: true, + type: "datetime", + comment: "กลับเข้ารับราชการตั้งแต่", + default: null, + }) + governmentDate: Date; + + @Column({ + comment: "สำเร็จการศึกษาตามที่หลักสูตรกำหนด", + default: false, + }) + isGraduated: boolean; + + @Column({ + nullable: true, + type: "datetime", + comment: "ตั้งแต่", + default: null, + }) + graduatedDate: Date; + + @Column({ + comment: "เสร็จสิ้นการศึกษาตามที่หลักสูตรกำหนดแล้วแต่ยังไม่สำเร็จการศึกษา", + default: false, + }) + isNoGraduated: boolean; + + @Column({ + nullable: true, + comment: "เนื่องจาก", + default: null, + }) + graduatedReason: string; } export class CreateDevelopmentScholarship { profileId: string | null; @@ -481,6 +532,8 @@ export class CreateDevelopmentScholarship { studyAbroadStartDate: Date | null; studyAbroadEndDate: Date | null; totalPeriod: string | null; + planType: string | null; + isNoUseBudget: boolean | null; } export class UpdateDevelopmentScholarship { @@ -534,4 +587,14 @@ export class UpdateDevelopmentScholarship { studyAbroadStartDate: Date | null; studyAbroadEndDate: Date | null; totalPeriod: string | null; + planType: string | null; + isNoUseBudget: boolean | null; +} + +export class UpdateDevelopmentScholarshipUser { + governmentDate: Date | null; + isGraduated: boolean | null; + graduatedDate: Date | null; + isNoGraduated: boolean | null; + graduatedReason: string | null; } diff --git a/src/migration/1712815316667-add_table_starty1.ts b/src/migration/1712815316667-add_table_starty1.ts new file mode 100644 index 0000000..3a5d95f --- /dev/null +++ b/src/migration/1712815316667-add_table_starty1.ts @@ -0,0 +1,20 @@ +import { MigrationInterface, QueryRunner } from "typeorm"; + +export class AddTableStarty11712815316667 implements MigrationInterface { + name = 'AddTableStarty11712815316667' + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(`CREATE TABLE \`developmentProjectTechniquePlanned\` (\`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', \`name\` varchar(255) NULL COMMENT 'เทคนิควิธีการที่ใช้ในการพัฒนา', \`developmentId\` varchar(255) NULL COMMENT 'โครงการ/หลักสูตรการฝึกอบรม', PRIMARY KEY (\`id\`)) ENGINE=InnoDB`); + await queryRunner.query(`CREATE TABLE \`developmentProjectTechniqueActual\` (\`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', \`name\` varchar(255) NULL COMMENT 'เทคนิควิธีการที่ใช้ในการพัฒนา', \`developmentId\` varchar(255) NULL COMMENT 'โครงการ/หลักสูตรการฝึกอบรม', PRIMARY KEY (\`id\`)) ENGINE=InnoDB`); + await queryRunner.query(`ALTER TABLE \`developmentProjectTechniquePlanned\` ADD CONSTRAINT \`FK_7166cc94112552ea072a2cc6134\` FOREIGN KEY (\`developmentId\`) REFERENCES \`development\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`); + await queryRunner.query(`ALTER TABLE \`developmentProjectTechniqueActual\` ADD CONSTRAINT \`FK_aaaee1c5fb44bef093ed78a0c32\` FOREIGN KEY (\`developmentId\`) REFERENCES \`development\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`); + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`developmentProjectTechniqueActual\` DROP FOREIGN KEY \`FK_aaaee1c5fb44bef093ed78a0c32\``); + await queryRunner.query(`ALTER TABLE \`developmentProjectTechniquePlanned\` DROP FOREIGN KEY \`FK_7166cc94112552ea072a2cc6134\``); + await queryRunner.query(`DROP TABLE \`developmentProjectTechniqueActual\``); + await queryRunner.query(`DROP TABLE \`developmentProjectTechniquePlanned\``); + } + +} diff --git a/src/migration/1712824449740-update_table_developmentScholarship_add_planType.ts b/src/migration/1712824449740-update_table_developmentScholarship_add_planType.ts new file mode 100644 index 0000000..e9bce7e --- /dev/null +++ b/src/migration/1712824449740-update_table_developmentScholarship_add_planType.ts @@ -0,0 +1,26 @@ +import { MigrationInterface, QueryRunner } from "typeorm"; + +export class UpdateTableDevelopmentScholarshipAddPlanType1712824449740 implements MigrationInterface { + name = 'UpdateTableDevelopmentScholarshipAddPlanType1712824449740' + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`developmentScholarship\` ADD \`planType\` varchar(40) NULL COMMENT 'ในแผนฯ'`); + await queryRunner.query(`ALTER TABLE \`developmentScholarship\` ADD \`isNoUseBudget\` tinyint NOT NULL COMMENT 'ไม่ใช้งบประมาณ' DEFAULT 0`); + await queryRunner.query(`ALTER TABLE \`developmentScholarship\` ADD \`governmentDate\` datetime NULL COMMENT 'กลับเข้ารับราชการตั้งแต่'`); + await queryRunner.query(`ALTER TABLE \`developmentScholarship\` ADD \`isGraduated\` tinyint NOT NULL COMMENT 'สำเร็จการศึกษาตามที่หลักสูตรกำหนด' DEFAULT 0`); + await queryRunner.query(`ALTER TABLE \`developmentScholarship\` ADD \`graduatedDate\` datetime NULL COMMENT 'ตั้งแต่'`); + await queryRunner.query(`ALTER TABLE \`developmentScholarship\` ADD \`isNoGraduated\` tinyint NOT NULL COMMENT 'เสร็จสิ้นการศึกษาตามที่หลักสูตรกำหนดแล้วแต่ยังไม่สำเร็จการศึกษา' DEFAULT 0`); + await queryRunner.query(`ALTER TABLE \`developmentScholarship\` ADD \`graduatedReason\` varchar(255) NULL COMMENT 'เนื่องจาก'`); + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`developmentScholarship\` DROP COLUMN \`graduatedReason\``); + await queryRunner.query(`ALTER TABLE \`developmentScholarship\` DROP COLUMN \`isNoGraduated\``); + await queryRunner.query(`ALTER TABLE \`developmentScholarship\` DROP COLUMN \`graduatedDate\``); + await queryRunner.query(`ALTER TABLE \`developmentScholarship\` DROP COLUMN \`isGraduated\``); + await queryRunner.query(`ALTER TABLE \`developmentScholarship\` DROP COLUMN \`governmentDate\``); + await queryRunner.query(`ALTER TABLE \`developmentScholarship\` DROP COLUMN \`isNoUseBudget\``); + await queryRunner.query(`ALTER TABLE \`developmentScholarship\` DROP COLUMN \`planType\``); + } + +} From 371f09c26f5bfb1daa3b59b1044c8bdb66d6184a Mon Sep 17 00:00:00 2001 From: AnandaTon Date: Thu, 11 Apr 2024 18:02:03 +0700 Subject: [PATCH 046/250] =?UTF-8?q?api=20report=20=E0=B8=A3=E0=B8=B2?= =?UTF-8?q?=E0=B8=A2=E0=B8=81=E0=B8=B2=E0=B8=A3=E0=B8=9B=E0=B8=A3=E0=B8=B0?= =?UTF-8?q?=E0=B8=A7=E0=B8=B1=E0=B8=95=E0=B8=B4=E0=B8=81=E0=B8=B2=E0=B8=A3?= =?UTF-8?q?=E0=B8=9D=E0=B8=B6=E0=B8=81=E0=B8=AD=E0=B8=9A=E0=B8=A3=E0=B8=A1?= =?UTF-8?q?/=E0=B8=94=E0=B8=B9=E0=B8=87=E0=B8=B2=E0=B8=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/ReportController.ts | 99 +++++++++++++++++++++++------ 1 file changed, 80 insertions(+), 19 deletions(-) diff --git a/src/controllers/ReportController.ts b/src/controllers/ReportController.ts index f0b976d..dbd5be4 100644 --- a/src/controllers/ReportController.ts +++ b/src/controllers/ReportController.ts @@ -25,7 +25,7 @@ import { } from "../entities/DevelopmentHistory"; import { PosType } from "../entities/PosType"; import { PosLevel } from "../entities/PosLevel"; - +import Extension from "../interfaces/extension"; @Route("api/v1/development/report") @Tags("Report") @Security("bearerAuth") @@ -63,18 +63,49 @@ export class ReportController extends Controller { * * @summary DEV_0xx - Report รายการประวัติการฝึกอบรม/ดูงานของข้าราชการกรุงเทพมหานครสามัญ #xx * - * @param {string} type type ประเภท report */ - @Get("history-officer/{type}") - async GetReportDevelopemtHistoryOfficer(@Path() type: string) { - const _type = type.trim().toUpperCase(); - const formattedData = { - org: _type, - }; + @Get("history-officer/{year}") + async GetReportDevelopemtHistoryOfficer(@Query("year") year: number) { + const type = "OFFICER"; + const development = await AppDataSource.getRepository(DevelopmentHistory) + .createQueryBuilder("developmentHistory") + .leftJoinAndSelect("developmentHistory.posLevel", "posLevel") + .leftJoinAndSelect("developmentHistory.posType", "posType") + .leftJoinAndSelect("developmentHistory.development", "development") + .andWhere( + year != 0 && year != null && year != undefined ? "development.year = :year" : "1=1", + { year: year }, + ) + .andWhere("developmentHistory.type = :type", { type: type }) + .select([ + "developmentHistory.citizenId", + "developmentHistory.rank", + "developmentHistory.position", + "developmentHistory.posExecutive", + "developmentHistory.developmentId", + "developmentHistory.prefix", + "developmentHistory.firstName", + "developmentHistory.lastName", + "posLevel.posLevelName", + "posType.posTypeName", + "development.projectName", + ]) + .getMany(); + + const formattedData = development.map((item) => ({ + id: item.id, + citizenId: Extension.ToThaiNumber(item.citizenId.toString()), + fullName: item.prefix + item.firstName + " " + item.lastName, + position: item.position, + posType: item.posType ? item.posType.posTypeName : null, + posLevel: item.posLevel ? item.posLevel.posLevelName : null, + posExecutive: item.posExecutive, + projectName: item.development ? item.development.projectName : null, + })); return new HttpSuccess({ - template: "development", - reportName: "development", + template: "developmentHistoryOfficer", + reportName: "developmentHistoryOfficer", data: { data: formattedData, }, @@ -86,18 +117,48 @@ export class ReportController extends Controller { * * @summary DEV_0xx - Report รายการประวัติฝึกอบรม/ดูงานลูกจ้าง #xx * - * @param {string} type type ประเภท report + * @param {number} year year ปี report */ - @Get("history-employee/{type}") - async GetReportDevelopemtHistoryEmployee(@Path() type: string) { - const _type = type.trim().toUpperCase(); - const formattedData = { - org: _type, - }; + @Get("history-employee/{year}") + async GetReportDevelopemtHistoryEmployee(@Query("year") year: number = 2024) { + const type = "EMPLOYEE"; + const development = await AppDataSource.getRepository(DevelopmentHistory) + .createQueryBuilder("developmentHistory") + .leftJoinAndSelect("developmentHistory.employeePosLevel", "employeePosLevel") + .leftJoinAndSelect("developmentHistory.employeePosType", "employeePosType") + .leftJoinAndSelect("developmentHistory.development", "development") + .where("development.year = :year", { year }) + .andWhere("developmentHistory.type = :type", { type: type }) + .select([ + "developmentHistory.citizenId", + "developmentHistory.position", + "developmentHistory.developmentId", + "developmentHistory.prefix", + "developmentHistory.firstName", + "developmentHistory.lastName", + "employeePosLevel.posLevelName", + "employeePosType.posTypeName", + "employeePosType.posTypeShortName", + "development.projectName", + ]) + .getMany(); + + const formattedData = development.map((item) => ({ + id: item.id, + citizenId: Extension.ToThaiNumber(item.citizenId.toString()), + fullName: item.prefix + item.firstName + " " + item.lastName, + position: item.position, + employeePosType: item.employeePosType ? item.employeePosType.posTypeName : null, + employeePosLevel: + item.employeePosType.posTypeShortName + + " " + + Extension.ToThaiNumber(item.employeePosLevel.posLevelName.toString()), + projectName: item.development ? item.development.projectName : null, + })); return new HttpSuccess({ - template: "development", - reportName: "development", + template: "developmentHistoryEmployee", + reportName: "developmentHistoryEmployee", data: { data: formattedData, }, From 650c6fe3e330d84ab4ddd6473cdd74a34f25fcc2 Mon Sep 17 00:00:00 2001 From: Kittapath Date: Fri, 12 Apr 2024 14:22:44 +0700 Subject: [PATCH 047/250] =?UTF-8?q?=E0=B8=9A=E0=B8=B1=E0=B8=99=E0=B8=97?= =?UTF-8?q?=E0=B8=B6=E0=B8=81=E0=B8=AB=E0=B8=99=E0=B9=88=E0=B8=A7=E0=B8=A2?= =?UTF-8?q?=E0=B8=87=E0=B8=B2=E0=B8=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/DevelopmentController.ts | 44 ++++++++++++++++--- src/entities/Development.ts | 44 +++++++++++++++++++ ...13381-update_table_development_add_root.ts | 16 +++++++ ...ate_table_development_add_rootshortname.ts | 16 +++++++ 4 files changed, 115 insertions(+), 5 deletions(-) create mode 100644 src/migration/1712904313381-update_table_development_add_root.ts create mode 100644 src/migration/1712904744359-update_table_development_add_rootshortname.ts diff --git a/src/controllers/DevelopmentController.ts b/src/controllers/DevelopmentController.ts index bf63fe5..9981c45 100644 --- a/src/controllers/DevelopmentController.ts +++ b/src/controllers/DevelopmentController.ts @@ -799,12 +799,12 @@ export class DevelopmentController extends Controller { @Query() searchField?: "year" | "projectName", @Query() searchKeyword: string = "", ) { - let queryLike = "developer.projectName LIKE :keyword"; + let queryLike = "development.projectName LIKE :keyword"; if (searchField == "year") { - queryLike = "developer.year LIKE :keyword"; + queryLike = "development.year LIKE :keyword"; } const [record, total] = await this.developmentRepository - .createQueryBuilder("developer") + .createQueryBuilder("development") .andWhere( searchKeyword != undefined && searchKeyword != null && searchKeyword != "" ? queryLike @@ -899,6 +899,7 @@ export class DevelopmentController extends Controller { @Query("pageSize") pageSize: number = 10, @Query("year") year: number, @Query("status") status: string, + @Query("root") root?: string | null, @Query("keyword") keyword?: string, ) { const [development, total] = await AppDataSource.getRepository(Development) @@ -906,13 +907,16 @@ export class DevelopmentController extends Controller { .andWhere(year > 0 ? "development.year LIKE :year" : "1=1", { year: `${year.toString()}`, }) + .andWhere(root != undefined && root != null ? "development.root LIKE :root" : "1=1", { + root: `${root}`, + }) .andWhere(status != undefined ? "development.status LIKE :status" : "1=1", { status: `%${status}%`, }) .andWhere(keyword != undefined ? "development.projectName LIKE :keyword" : "1=1", { keyword: `%${keyword}%`, }) - .select(["development.id", "development.projectName", "development.year"]) + .select(["development.id", "development.projectName", "development.year", "development.root"]) .orderBy("development.year", "DESC") .orderBy("development.createdAt", "DESC") .skip((page - 1) * pageSize) @@ -974,7 +978,17 @@ export class DevelopmentController extends Controller { async GetDevelopemtTab1ById(@Path() id: string) { const getDevelopment = await this.developmentRepository.findOne({ where: { id: id }, - select: ["id", "year", "projectName", "reason", "objective"], + select: [ + "id", + "year", + "projectName", + "reason", + "objective", + "root", + "rootId", + "orgRootShortName", + "orgRevisionId", + ], }); if (!getDevelopment) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงการ/หลักสูตรการฝึกอบรมนี้"); @@ -1205,6 +1219,26 @@ export class DevelopmentController extends Controller { return new HttpSuccess(_getDevelopment); } + /** + * API list หน่วยงาน + * + * @summary DEV_00 - list หน่วยงาน # + * + */ + @Get("org/root") + async GetOrgDevelopemt(@Request() request: { user: Record }) { + const getOrg = await this.developmentRepository + .createQueryBuilder("development") + .select("development.root") + .groupBy("development.root") + .getRawMany(); + if (getOrg.length > 0) { + return new HttpSuccess(getOrg.map((x) => x.development_root)); + } + + return new HttpSuccess(getOrg); + } + /** * API upload User * diff --git a/src/entities/Development.ts b/src/entities/Development.ts index 3c1a34e..a708ece 100644 --- a/src/entities/Development.ts +++ b/src/entities/Development.ts @@ -14,6 +14,34 @@ import { DevelopmentProjectTechniqueActual } from "./DevelopmentProjectTechnique @Entity("development") export class Development extends EntityBase { + @Column({ + nullable: true, + comment: "id หน่วยงาน", + default: null, + }) + rootId: string; + + @Column({ + nullable: true, + comment: "ชื่อหน่วยงาน", + default: null, + }) + root: string; + + @Column({ + nullable: true, + comment: "ชื่อย่ิหน่วยงาน", + default: null, + }) + orgRootShortName: string; + + @Column({ + nullable: true, + comment: "id revision", + default: null, + }) + orgRevisionId: string; + @Column({ // กำลังดำเนินการ (ONGOING) // เสร็จสิ้น (FINISH) @@ -380,6 +408,14 @@ export class CreateDevelopment { year: number; @Column() projectName: string; + @Column() + root: string; + @Column() + rootId: string; + @Column() + orgRootShortName: string; + @Column() + orgRevisionId: string; } export class UpdateDevelopment1 { @@ -391,6 +427,14 @@ export class UpdateDevelopment1 { reason: string | null; @Column() objective: string | null; + @Column() + root: string; + @Column() + rootId: string; + @Column() + orgRootShortName: string; + @Column() + orgRevisionId: string; } export class UpdateDevelopment2_1 { @Column() diff --git a/src/migration/1712904313381-update_table_development_add_root.ts b/src/migration/1712904313381-update_table_development_add_root.ts new file mode 100644 index 0000000..1644d26 --- /dev/null +++ b/src/migration/1712904313381-update_table_development_add_root.ts @@ -0,0 +1,16 @@ +import { MigrationInterface, QueryRunner } from "typeorm"; + +export class UpdateTableDevelopmentAddRoot1712904313381 implements MigrationInterface { + name = 'UpdateTableDevelopmentAddRoot1712904313381' + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`development\` ADD \`rootId\` varchar(255) NULL COMMENT 'id หน่วยงาน'`); + await queryRunner.query(`ALTER TABLE \`development\` ADD \`root\` varchar(255) NULL COMMENT 'ชื่อหน่วยงาน'`); + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`root\``); + await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`rootId\``); + } + +} diff --git a/src/migration/1712904744359-update_table_development_add_rootshortname.ts b/src/migration/1712904744359-update_table_development_add_rootshortname.ts new file mode 100644 index 0000000..2fa0f19 --- /dev/null +++ b/src/migration/1712904744359-update_table_development_add_rootshortname.ts @@ -0,0 +1,16 @@ +import { MigrationInterface, QueryRunner } from "typeorm"; + +export class UpdateTableDevelopmentAddRootshortname1712904744359 implements MigrationInterface { + name = 'UpdateTableDevelopmentAddRootshortname1712904744359' + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`development\` ADD \`orgRootShortName\` varchar(255) NULL COMMENT 'ชื่อย่ิหน่วยงาน'`); + await queryRunner.query(`ALTER TABLE \`development\` ADD \`orgRevisionId\` varchar(255) NULL COMMENT 'id revision'`); + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`orgRevisionId\``); + await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`orgRootShortName\``); + } + +} From be703f8e3ba50cc3c94c2a12290d6f27deafbcd5 Mon Sep 17 00:00:00 2001 From: Kittapath Date: Sat, 13 Apr 2024 20:47:28 +0700 Subject: [PATCH 048/250] =?UTF-8?q?=E0=B9=82=E0=B8=84=E0=B8=A3=E0=B8=87?= =?UTF-8?q?=E0=B8=81=E0=B8=B2=E0=B8=A3=E0=B9=80=E0=B8=9E=E0=B8=B4=E0=B9=88?= =?UTF-8?q?=E0=B8=A1=E0=B8=9A=E0=B8=B1=E0=B8=99=E0=B8=97=E0=B8=B6=E0=B8=81?= =?UTF-8?q?=E0=B8=A2=E0=B8=B8=E0=B8=97=E0=B8=98=E0=B8=A8=E0=B8=B2=E0=B8=AA?= =?UTF-8?q?=E0=B8=95=E0=B8=A3=E0=B9=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/DevelopmentController.ts | 440 ++++++++++++++++-- .../DevelopmentHistoryController.ts | 59 ++- .../DevelopmentScholarshipController.ts | 2 + src/controllers/ReportController.ts | 131 +++++- src/entities/Development.ts | 131 ++++++ src/entities/DevelopmentHistory.ts | 34 ++ src/entities/DevelopmentScholarship.ts | 46 +- src/entities/StrategyChild1.ts | 6 +- src/entities/StrategyChild2.ts | 12 +- src/entities/StrategyChild3.ts | 10 +- src/entities/StrategyChild4.ts | 8 +- src/entities/StrategyChild5.ts | 9 +- ...ate_table_development_add_strategyChild.ts | 52 +++ ...te_table_development_add_strategyChild1.ts | 22 + ...ate_table_developmentscholar_add_rootid.ts | 20 + ...ble_developmentscholar_date_to_datetime.ts | 32 ++ 16 files changed, 930 insertions(+), 84 deletions(-) create mode 100644 src/migration/1712927871127-update_table_development_add_strategyChild.ts create mode 100644 src/migration/1712930900458-update_table_development_add_strategyChild1.ts create mode 100644 src/migration/1713012352435-update_table_developmentscholar_add_rootid.ts create mode 100644 src/migration/1713014657464-update_table_developmentscholar_date_to_datetime.ts diff --git a/src/controllers/DevelopmentController.ts b/src/controllers/DevelopmentController.ts index 9981c45..50c7ef6 100644 --- a/src/controllers/DevelopmentController.ts +++ b/src/controllers/DevelopmentController.ts @@ -11,7 +11,6 @@ import { Path, Request, Query, - Example, } from "tsoa"; import { AppDataSource } from "../database/data-source"; import { In, Not } from "typeorm"; @@ -22,8 +21,6 @@ import { Development, CreateDevelopment, UpdateDevelopment1, - UpdateDevelopment2_1, - UpdateDevelopment2_2, UpdateDevelopment3, UpdateDevelopment4, UpdateDevelopment5, @@ -45,6 +42,11 @@ import { import { DevelopmentAddress } from "../entities/DevelopmentAddress"; import { DevelopmentProjectTechniquePlanned } from "../entities/DevelopmentProjectTechniquePlanned"; import { DevelopmentProjectTechniqueActual } from "../entities/DevelopmentProjectTechniqueActual"; +import { StrategyChild1 } from "../entities/StrategyChild1"; +import { StrategyChild2 } from "../entities/StrategyChild2"; +import { StrategyChild3 } from "../entities/StrategyChild3"; +import { StrategyChild4 } from "../entities/StrategyChild4"; +import { StrategyChild5 } from "../entities/StrategyChild5"; @Route("api/v1/development/main") @Tags("Development") @@ -69,6 +71,11 @@ export class DevelopmentController extends Controller { private provinceRepository = AppDataSource.getRepository(Province); private posTypeRepository = AppDataSource.getRepository(PosType); private posLevelRepository = AppDataSource.getRepository(PosLevel); + private strategyChild1Repository = AppDataSource.getRepository(StrategyChild1); + private strategyChild2Repository = AppDataSource.getRepository(StrategyChild2); + private strategyChild3Repository = AppDataSource.getRepository(StrategyChild3); + private strategyChild4Repository = AppDataSource.getRepository(StrategyChild4); + private strategyChild5Repository = AppDataSource.getRepository(StrategyChild5); /** * API เพิ่มโครงการ/หลักสูตรการฝึกอบรม @@ -97,8 +104,188 @@ export class DevelopmentController extends Controller { " มีอยู่ในระบบแล้ว", ); } - + let _null: any = null; const development = Object.assign(new Development(), requestBody); + switch (requestBody.strategyChildPlannedNode) { + case 1: { + const checkId = await this.strategyChild1Repository.findOne({ + where: { id: requestBody.strategyChildPlannedId }, + }); + if (!checkId) { + throw new HttpError( + HttpStatusCode.NOT_FOUND, + "ไม่พบข้อมูลยุทธศาสตร์เป้าหมายตามแผนระดับ 1", + ); + } + development.strategyChild1PlannedId = checkId.id; + development.strategyChild2ActualId = _null; + development.strategyChild3ActualId = _null; + development.strategyChild4ActualId = _null; + development.strategyChild5ActualId = _null; + break; + } + case 2: { + const checkId = await this.strategyChild2Repository.findOne({ + where: { id: requestBody.strategyChildPlannedId }, + }); + if (!checkId) { + throw new HttpError( + HttpStatusCode.NOT_FOUND, + "ไม่พบข้อมูลยุทธศาสตร์เป้าหมายตามแผนระดับ 2", + ); + } + development.strategyChild1PlannedId = checkId.strategyChild1Id; + development.strategyChild2PlannedId = checkId.id; + development.strategyChild3ActualId = _null; + development.strategyChild4ActualId = _null; + development.strategyChild5ActualId = _null; + break; + } + case 3: { + const checkId = await this.strategyChild3Repository.findOne({ + where: { id: requestBody.strategyChildPlannedId }, + }); + if (!checkId) { + throw new HttpError( + HttpStatusCode.NOT_FOUND, + "ไม่พบข้อมูลยุทธศาสตร์เป้าหมายตามแผนระดับ 2", + ); + } + development.strategyChild1PlannedId = checkId.strategyChild1Id; + development.strategyChild2PlannedId = checkId.strategyChild2Id; + development.strategyChild3PlannedId = checkId.id; + development.strategyChild4ActualId = _null; + development.strategyChild5ActualId = _null; + break; + } + case 4: { + const checkId = await this.strategyChild4Repository.findOne({ + where: { id: requestBody.strategyChildPlannedId }, + }); + if (!checkId) { + throw new HttpError( + HttpStatusCode.NOT_FOUND, + "ไม่พบข้อมูลยุทธศาสตร์เป้าหมายตามแผนระดับ 3", + ); + } + development.strategyChild1PlannedId = checkId.strategyChild1Id; + development.strategyChild2PlannedId = checkId.strategyChild2Id; + development.strategyChild3PlannedId = checkId.strategyChild3Id; + development.strategyChild4PlannedId = checkId.id; + development.strategyChild5ActualId = _null; + break; + } + case 5: { + const checkId = await this.strategyChild5Repository.findOne({ + where: { id: requestBody.strategyChildPlannedId }, + }); + if (!checkId) { + throw new HttpError( + HttpStatusCode.NOT_FOUND, + "ไม่พบข้อมูลยุทธศาสตร์เป้าหมายตามแผนระดับ 2", + ); + } + development.strategyChild1PlannedId = checkId.strategyChild1Id; + development.strategyChild2PlannedId = checkId.strategyChild2Id; + development.strategyChild3PlannedId = checkId.strategyChild3Id; + development.strategyChild4PlannedId = checkId.strategyChild4Id; + development.strategyChild5PlannedId = checkId.id; + break; + } + + default: + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลยุทธศาสตร์เป้าหมายตามแผน"); + } + switch (requestBody.strategyChildActualNode) { + case 1: { + const checkId = await this.strategyChild1Repository.findOne({ + where: { id: requestBody.strategyChildActualId }, + }); + if (!checkId) { + throw new HttpError( + HttpStatusCode.NOT_FOUND, + "ไม่พบข้อมูลยุทธศาสตร์เป้าหมายตามจริงระดับ 1", + ); + } + development.strategyChild1ActualId = checkId.id; + development.strategyChild2ActualId = _null; + development.strategyChild3ActualId = _null; + development.strategyChild4ActualId = _null; + development.strategyChild5ActualId = _null; + break; + } + case 2: { + const checkId = await this.strategyChild2Repository.findOne({ + where: { id: requestBody.strategyChildActualId }, + }); + if (!checkId) { + throw new HttpError( + HttpStatusCode.NOT_FOUND, + "ไม่พบข้อมูลยุทธศาสตร์เป้าหมายตามจริงระดับ 2", + ); + } + development.strategyChild1ActualId = checkId.strategyChild1Id; + development.strategyChild2ActualId = checkId.id; + development.strategyChild3ActualId = _null; + development.strategyChild4ActualId = _null; + development.strategyChild5ActualId = _null; + break; + } + case 3: { + const checkId = await this.strategyChild3Repository.findOne({ + where: { id: requestBody.strategyChildActualId }, + }); + if (!checkId) { + throw new HttpError( + HttpStatusCode.NOT_FOUND, + "ไม่พบข้อมูลยุทธศาสตร์เป้าหมายตามจริงระดับ 3", + ); + } + development.strategyChild1ActualId = checkId.strategyChild1Id; + development.strategyChild2ActualId = checkId.strategyChild2Id; + development.strategyChild3ActualId = checkId.id; + development.strategyChild4ActualId = _null; + development.strategyChild5ActualId = _null; + break; + } + case 4: { + const checkId = await this.strategyChild4Repository.findOne({ + where: { id: requestBody.strategyChildActualId }, + }); + if (!checkId) { + throw new HttpError( + HttpStatusCode.NOT_FOUND, + "ไม่พบข้อมูลยุทธศาสตร์เป้าหมายตามจริงระดับ 4", + ); + } + development.strategyChild1ActualId = checkId.strategyChild1Id; + development.strategyChild2ActualId = checkId.strategyChild2Id; + development.strategyChild3ActualId = checkId.strategyChild3Id; + development.strategyChild4ActualId = checkId.id; + development.strategyChild5ActualId = _null; + break; + } + case 5: { + const checkId = await this.strategyChild5Repository.findOne({ + where: { id: requestBody.strategyChildActualId }, + }); + if (!checkId) { + throw new HttpError( + HttpStatusCode.NOT_FOUND, + "ไม่พบข้อมูลยุทธศาสตร์เป้าหมายตามจริงระดับ 5", + ); + } + development.strategyChild1ActualId = checkId.strategyChild1Id; + development.strategyChild2ActualId = checkId.strategyChild2Id; + development.strategyChild3ActualId = checkId.strategyChild3Id; + development.strategyChild4ActualId = checkId.strategyChild4Id; + development.strategyChild5ActualId = checkId.id; + break; + } + + default: + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลยุทธศาสตร์เป้าหมายตามจริง"); + } development.createdUserId = request.user.sub; development.createdFullName = request.user.name; development.lastUpdateUserId = request.user.sub; @@ -143,6 +330,187 @@ export class DevelopmentController extends Controller { " มีอยู่ในระบบแล้ว", ); } + let _null: any = null; + switch (requestBody.strategyChildPlannedNode) { + case 1: { + const checkId = await this.strategyChild1Repository.findOne({ + where: { id: requestBody.strategyChildPlannedId }, + }); + if (!checkId) { + throw new HttpError( + HttpStatusCode.NOT_FOUND, + "ไม่พบข้อมูลยุทธศาสตร์เป้าหมายตามแผนระดับ 1", + ); + } + development.strategyChild1PlannedId = checkId.id; + development.strategyChild2ActualId = _null; + development.strategyChild3ActualId = _null; + development.strategyChild4ActualId = _null; + development.strategyChild5ActualId = _null; + break; + } + case 2: { + const checkId = await this.strategyChild2Repository.findOne({ + where: { id: requestBody.strategyChildPlannedId }, + }); + if (!checkId) { + throw new HttpError( + HttpStatusCode.NOT_FOUND, + "ไม่พบข้อมูลยุทธศาสตร์เป้าหมายตามแผนระดับ 2", + ); + } + development.strategyChild1PlannedId = checkId.strategyChild1Id; + development.strategyChild2PlannedId = checkId.id; + development.strategyChild3ActualId = _null; + development.strategyChild4ActualId = _null; + development.strategyChild5ActualId = _null; + break; + } + case 3: { + const checkId = await this.strategyChild3Repository.findOne({ + where: { id: requestBody.strategyChildPlannedId }, + }); + if (!checkId) { + throw new HttpError( + HttpStatusCode.NOT_FOUND, + "ไม่พบข้อมูลยุทธศาสตร์เป้าหมายตามแผนระดับ 2", + ); + } + development.strategyChild1PlannedId = checkId.strategyChild1Id; + development.strategyChild2PlannedId = checkId.strategyChild2Id; + development.strategyChild3PlannedId = checkId.id; + development.strategyChild4ActualId = _null; + development.strategyChild5ActualId = _null; + break; + } + case 4: { + const checkId = await this.strategyChild4Repository.findOne({ + where: { id: requestBody.strategyChildPlannedId }, + }); + if (!checkId) { + throw new HttpError( + HttpStatusCode.NOT_FOUND, + "ไม่พบข้อมูลยุทธศาสตร์เป้าหมายตามแผนระดับ 3", + ); + } + development.strategyChild1PlannedId = checkId.strategyChild1Id; + development.strategyChild2PlannedId = checkId.strategyChild2Id; + development.strategyChild3PlannedId = checkId.strategyChild3Id; + development.strategyChild4PlannedId = checkId.id; + development.strategyChild5ActualId = _null; + break; + } + case 5: { + const checkId = await this.strategyChild5Repository.findOne({ + where: { id: requestBody.strategyChildPlannedId }, + }); + if (!checkId) { + throw new HttpError( + HttpStatusCode.NOT_FOUND, + "ไม่พบข้อมูลยุทธศาสตร์เป้าหมายตามแผนระดับ 2", + ); + } + development.strategyChild1PlannedId = checkId.strategyChild1Id; + development.strategyChild2PlannedId = checkId.strategyChild2Id; + development.strategyChild3PlannedId = checkId.strategyChild3Id; + development.strategyChild4PlannedId = checkId.strategyChild4Id; + development.strategyChild5PlannedId = checkId.id; + break; + } + + default: + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลยุทธศาสตร์เป้าหมายตามแผน"); + } + switch (requestBody.strategyChildActualNode) { + case 1: { + const checkId = await this.strategyChild1Repository.findOne({ + where: { id: requestBody.strategyChildActualId }, + }); + if (!checkId) { + throw new HttpError( + HttpStatusCode.NOT_FOUND, + "ไม่พบข้อมูลยุทธศาสตร์เป้าหมายตามจริงระดับ 1", + ); + } + development.strategyChild1ActualId = checkId.id; + development.strategyChild2ActualId = _null; + development.strategyChild3ActualId = _null; + development.strategyChild4ActualId = _null; + development.strategyChild5ActualId = _null; + break; + } + case 2: { + const checkId = await this.strategyChild2Repository.findOne({ + where: { id: requestBody.strategyChildActualId }, + }); + if (!checkId) { + throw new HttpError( + HttpStatusCode.NOT_FOUND, + "ไม่พบข้อมูลยุทธศาสตร์เป้าหมายตามจริงระดับ 2", + ); + } + development.strategyChild1ActualId = checkId.strategyChild1Id; + development.strategyChild2ActualId = checkId.id; + development.strategyChild3ActualId = _null; + development.strategyChild4ActualId = _null; + development.strategyChild5ActualId = _null; + break; + } + case 3: { + const checkId = await this.strategyChild3Repository.findOne({ + where: { id: requestBody.strategyChildActualId }, + }); + if (!checkId) { + throw new HttpError( + HttpStatusCode.NOT_FOUND, + "ไม่พบข้อมูลยุทธศาสตร์เป้าหมายตามจริงระดับ 3", + ); + } + development.strategyChild1ActualId = checkId.strategyChild1Id; + development.strategyChild2ActualId = checkId.strategyChild2Id; + development.strategyChild3ActualId = checkId.id; + development.strategyChild4ActualId = _null; + development.strategyChild5ActualId = _null; + break; + } + case 4: { + const checkId = await this.strategyChild4Repository.findOne({ + where: { id: requestBody.strategyChildActualId }, + }); + if (!checkId) { + throw new HttpError( + HttpStatusCode.NOT_FOUND, + "ไม่พบข้อมูลยุทธศาสตร์เป้าหมายตามจริงระดับ 4", + ); + } + development.strategyChild1ActualId = checkId.strategyChild1Id; + development.strategyChild2ActualId = checkId.strategyChild2Id; + development.strategyChild3ActualId = checkId.strategyChild3Id; + development.strategyChild4ActualId = checkId.id; + development.strategyChild5ActualId = _null; + break; + } + case 5: { + const checkId = await this.strategyChild5Repository.findOne({ + where: { id: requestBody.strategyChildActualId }, + }); + if (!checkId) { + throw new HttpError( + HttpStatusCode.NOT_FOUND, + "ไม่พบข้อมูลยุทธศาสตร์เป้าหมายตามจริงระดับ 5", + ); + } + development.strategyChild1ActualId = checkId.strategyChild1Id; + development.strategyChild2ActualId = checkId.strategyChild2Id; + development.strategyChild3ActualId = checkId.strategyChild3Id; + development.strategyChild4ActualId = checkId.strategyChild4Id; + development.strategyChild5ActualId = checkId.id; + break; + } + + default: + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลยุทธศาสตร์เป้าหมายตามจริง"); + } Object.assign(development, requestBody); development.lastUpdateUserId = request.user.sub; development.lastUpdateFullName = request.user.name; @@ -988,6 +1356,16 @@ export class DevelopmentController extends Controller { "rootId", "orgRootShortName", "orgRevisionId", + "strategyChild1Planned", + "strategyChild2Planned", + "strategyChild3Planned", + "strategyChild4Planned", + "strategyChild5Planned", + "strategyChild1Actual", + "strategyChild2Actual", + "strategyChild3Actual", + "strategyChild4Actual", + "strategyChild5Actual", ], }); if (!getDevelopment) { @@ -1191,31 +1569,37 @@ export class DevelopmentController extends Controller { */ @Get("tab6/{id}") async GetDevelopemtTab6ById(@Path() id: string) { - const getDevelopment = await this.developmentRepository.findOne({ - where: { id: id }, - relations: [ - "developmentActualPeoples", - "developmentPlannedPeoples", - "developmentActualGoals", - "developmentPlannedGoals", - "developmentPlannedGoals.plannedGoalPositions", - "provinces", - // "provinces.developmentProvinces", - ], + const getDevelopment = await this.developmentHistoryRepository.find({ + where: { developmentId: id }, + relations: ["posLevel", "posType", "employeePosLevel", "employeePosType"], }); - if (!getDevelopment) { - throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงการ/หลักสูตรการฝึกอบรมนี้"); - } - let _getDevelopment: any = getDevelopment; - _getDevelopment.actualPeoples = getDevelopment.developmentActualPeoples; - _getDevelopment.plannedPeoples = getDevelopment.developmentPlannedPeoples; - _getDevelopment.actualGoals = getDevelopment.developmentActualGoals; - _getDevelopment.plannedGoals = getDevelopment.developmentPlannedGoals; - // _getDevelopment.provinces = getDevelopment.provinces.map(x=>x.developmentProvinces); - delete _getDevelopment.developmentActualPeoples; - delete _getDevelopment.developmentPlannedPeoples; - delete _getDevelopment.developmentActualGoals; - delete _getDevelopment.developmentPlannedGoals; + const _getDevelopment = getDevelopment.map((item) => ({ + id: item.id, + citizenId: item.citizenId, + fullName: item.prefix + item.firstName + " " + item.lastName, + position: item.position, + posType: + item.type == "OFFICER" + ? item.posType + ? item.posType.posTypeName + : null + : item.employeePosType + ? item.employeePosType.posTypeName + : null, + posLevel: + item.type == "OFFICER" + ? item.posLevel + ? item.posLevel.posLevelName + : null + : item.employeePosLevel + ? item.employeePosLevel.posLevelName + : null, + posExecutive: item.posExecutive, + root: item.root, + order: item.order, + dateOrder: item.dateOrder, + isDone: item.isDone, + })); return new HttpSuccess(_getDevelopment); } diff --git a/src/controllers/DevelopmentHistoryController.ts b/src/controllers/DevelopmentHistoryController.ts index eb5055e..787c300 100644 --- a/src/controllers/DevelopmentHistoryController.ts +++ b/src/controllers/DevelopmentHistoryController.ts @@ -185,6 +185,7 @@ export class DevelopmentOfficerHistoryController extends Controller { @Query("pageSize") pageSize: number = 10, @Query("keyword") keyword?: string, @Query("year") year?: number, + @Query("root") root?: number, ) { const type = "OFFICER"; const [development, total] = await AppDataSource.getRepository(DevelopmentHistory) @@ -192,14 +193,18 @@ export class DevelopmentOfficerHistoryController extends Controller { .leftJoinAndSelect("developmentHistory.development", "development") .leftJoinAndSelect("developmentHistory.posLevel", "posLevel") .leftJoinAndSelect("developmentHistory.posType", "posType") - .andWhere(year != 0 && year != null && year != undefined ? "development.year = :year" : "1=1", { year: year }) + .andWhere( + year != 0 && year != null && year != undefined ? "development.year = :year" : "1=1", + { year: year }, + ) + .andWhere(root != null && root != undefined ? "development.root = :root" : "1=1", { + root: root, + }) .andWhere("developmentHistory.type = :type", { type: type }) .andWhere( new Brackets((qb) => { qb.where( - keyword != null && keyword != "" - ? "developmentHistory.prefix LIKE :keyword" - : "1=1", + keyword != null && keyword != "" ? "developmentHistory.prefix LIKE :keyword" : "1=1", { keyword: `%${keyword}%`, }, @@ -237,25 +242,19 @@ export class DevelopmentOfficerHistoryController extends Controller { }, ) .orWhere( - keyword != null && keyword != "" - ? "development.projectName LIKE :keyword" - : "1=1", + keyword != null && keyword != "" ? "development.projectName LIKE :keyword" : "1=1", { keyword: `%${keyword}%`, }, ) .orWhere( - keyword != null && keyword != "" - ? "posType.posTypeName LIKE :keyword" - : "1=1", + keyword != null && keyword != "" ? "posType.posTypeName LIKE :keyword" : "1=1", { keyword: `%${keyword}%`, }, ) .orWhere( - keyword != null && keyword != "" - ? "posLevel.posLevelName LIKE :keyword" - : "1=1", + keyword != null && keyword != "" ? "posLevel.posLevelName LIKE :keyword" : "1=1", { keyword: `%${keyword}%`, }, @@ -266,10 +265,10 @@ export class DevelopmentOfficerHistoryController extends Controller { .skip((page - 1) * pageSize) .take(pageSize) .getManyAndCount(); - const formattedData = development.map(item => ({ + const formattedData = development.map((item) => ({ id: item.id, citizenId: item.citizenId, - fullName: item.prefix+item.firstName+" "+item.lastName, + fullName: item.prefix + item.firstName + " " + item.lastName, position: item.position, posType: item.posType ? item.posType.posTypeName : null, posLevel: item.posLevel ? item.posLevel.posLevelName : null, @@ -287,11 +286,11 @@ export class DevelopmentOfficerHistoryController extends Controller { * * @param {string} id Id โครงการ */ - @Get("{id}") + @Get("{id}") async GetDevelopemtHistoryById(@Path() id: string) { const type = "OFFICER"; const getDevelopment = await this.developmentHistoryRepository.findOne({ - relations: ["development","posLevel","posType"], + relations: ["development", "posLevel", "posType"], where: { id: id, type: type }, }); if (!getDevelopment) { @@ -306,7 +305,9 @@ export class DevelopmentOfficerHistoryController extends Controller { citizenId: getDevelopment.citizenId ? getDevelopment.citizenId : null, position: getDevelopment.position ? getDevelopment.position : null, posLevelId: getDevelopment.posLevelId ? getDevelopment.posLevelId : null, - posLevelName: getDevelopment.posLevel.posLevelName ? getDevelopment.posLevel.posLevelName : null, + posLevelName: getDevelopment.posLevel.posLevelName + ? getDevelopment.posLevel.posLevelName + : null, posTypeId: getDevelopment.posTypeId ? getDevelopment.posTypeId : null, posTypeName: getDevelopment.posType.posTypeName ? getDevelopment.posType.posTypeName : null, posExecutive: getDevelopment.posExecutive ? getDevelopment.posExecutive : null, @@ -314,17 +315,27 @@ export class DevelopmentOfficerHistoryController extends Controller { order: getDevelopment.order ? getDevelopment.order : null, dateOrder: getDevelopment.dateOrder ? getDevelopment.dateOrder : null, year: getDevelopment.development.year ? getDevelopment.development.year : null, - projectName: getDevelopment.development.projectName ? getDevelopment.development.projectName : null, + projectName: getDevelopment.development.projectName + ? getDevelopment.development.projectName + : null, dateStart: getDevelopment.development.dateStart ? getDevelopment.development.dateStart : null, dateEnd: getDevelopment.development.dateEnd ? getDevelopment.development.dateEnd : null, totalDate: getDevelopment.development.totalDate ? getDevelopment.development.totalDate : null, - addressAcademic: getDevelopment.development.addressAcademic ? getDevelopment.development.addressAcademic : null, - topicAcademic: getDevelopment.development.topicAcademic ? getDevelopment.development.topicAcademic : null, - dateStudyStart: getDevelopment.development.dateStudyStart ? getDevelopment.development.dateStudyStart : null, - dateStudyEnd: getDevelopment.development.dateStudyEnd ? getDevelopment.development.dateStudyEnd : null, + addressAcademic: getDevelopment.development.addressAcademic + ? getDevelopment.development.addressAcademic + : null, + topicAcademic: getDevelopment.development.topicAcademic + ? getDevelopment.development.topicAcademic + : null, + dateStudyStart: getDevelopment.development.dateStudyStart + ? getDevelopment.development.dateStudyStart + : null, + dateStudyEnd: getDevelopment.development.dateStudyEnd + ? getDevelopment.development.dateStudyEnd + : null, org: null, }; - + return new HttpSuccess(formattedData); } } diff --git a/src/controllers/DevelopmentScholarshipController.ts b/src/controllers/DevelopmentScholarshipController.ts index f305148..520135e 100644 --- a/src/controllers/DevelopmentScholarshipController.ts +++ b/src/controllers/DevelopmentScholarshipController.ts @@ -238,6 +238,7 @@ export class DevelopmentScholarshipController extends Controller { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลทุนการศึกษา/ฝึกอบรมนี้"); } const formattedData = { + root: getDevelopment.root ? getDevelopment.root : null, rank: getDevelopment.rank ? getDevelopment.rank : null, prefix: getDevelopment.prefix ? getDevelopment.prefix : null, firstName: getDevelopment.firstName ? getDevelopment.firstName : null, @@ -364,6 +365,7 @@ export class DevelopmentScholarshipController extends Controller { "graduatedDate", "isNoGraduated", "graduatedReason", + "root", ], }); if (!getDevelopment) { diff --git a/src/controllers/ReportController.ts b/src/controllers/ReportController.ts index dbd5be4..29a8c0d 100644 --- a/src/controllers/ReportController.ts +++ b/src/controllers/ReportController.ts @@ -26,6 +26,7 @@ import { import { PosType } from "../entities/PosType"; import { PosLevel } from "../entities/PosLevel"; import Extension from "../interfaces/extension"; +import { DevelopmentScholarship } from "../entities/DevelopmentScholarship"; @Route("api/v1/development/report") @Tags("Report") @Security("bearerAuth") @@ -34,6 +35,7 @@ export class ReportController extends Controller { private developmentRepository = AppDataSource.getRepository(Development); private posTypeRepository = AppDataSource.getRepository(PosType); private posLevelRepository = AppDataSource.getRepository(PosLevel); + private developmentScholarshipRepository = AppDataSource.getRepository(DevelopmentScholarship); /** * API Report รายการโครงการ/หลักสูตรการฝึกอบรมที่หน่วยงานของกรุงเทพมหานครเป็นผู้จัด @@ -64,19 +66,26 @@ export class ReportController extends Controller { * @summary DEV_0xx - Report รายการประวัติการฝึกอบรม/ดูงานของข้าราชการกรุงเทพมหานครสามัญ #xx * */ - @Get("history-officer/{year}") - async GetReportDevelopemtHistoryOfficer(@Query("year") year: number) { - const type = "OFFICER"; + @Post("history-officer") + async PostReportDevelopemtHistoryOfficer( + @Body() + body: { + year: number; + root: string; + }, + ) { const development = await AppDataSource.getRepository(DevelopmentHistory) .createQueryBuilder("developmentHistory") .leftJoinAndSelect("developmentHistory.posLevel", "posLevel") .leftJoinAndSelect("developmentHistory.posType", "posType") .leftJoinAndSelect("developmentHistory.development", "development") - .andWhere( - year != 0 && year != null && year != undefined ? "development.year = :year" : "1=1", - { year: year }, - ) - .andWhere("developmentHistory.type = :type", { type: type }) + .andWhere(body.year != 0 && body.year != null ? "development.year = :year" : "1=1", { + year: body.year, + }) + .andWhere(body.root != null ? "development.root = :root" : "1=1", { + root: body.root, + }) + .andWhere("developmentHistory.type = :type", { type: "OFFICER" }) .select([ "developmentHistory.citizenId", "developmentHistory.rank", @@ -89,6 +98,7 @@ export class ReportController extends Controller { "posLevel.posLevelName", "posType.posTypeName", "development.projectName", + "development.root", ]) .getMany(); @@ -101,6 +111,7 @@ export class ReportController extends Controller { posLevel: item.posLevel ? item.posLevel.posLevelName : null, posExecutive: item.posExecutive, projectName: item.development ? item.development.projectName : null, + root: item.root, })); return new HttpSuccess({ @@ -119,16 +130,26 @@ export class ReportController extends Controller { * * @param {number} year year ปี report */ - @Get("history-employee/{year}") - async GetReportDevelopemtHistoryEmployee(@Query("year") year: number = 2024) { - const type = "EMPLOYEE"; + @Post("history-employee") + async PostReportDevelopemtHistoryEmployee( + @Body() + body: { + year: number; + root: string; + }, + ) { const development = await AppDataSource.getRepository(DevelopmentHistory) .createQueryBuilder("developmentHistory") .leftJoinAndSelect("developmentHistory.employeePosLevel", "employeePosLevel") .leftJoinAndSelect("developmentHistory.employeePosType", "employeePosType") .leftJoinAndSelect("developmentHistory.development", "development") - .where("development.year = :year", { year }) - .andWhere("developmentHistory.type = :type", { type: type }) + .andWhere(body.year != 0 && body.year != null ? "development.year = :year" : "1=1", { + year: body.year, + }) + .andWhere(body.root != null ? "development.root = :root" : "1=1", { + root: body.root, + }) + .andWhere("developmentHistory.type = :type", { type: "EMPLOYEE" }) .select([ "developmentHistory.citizenId", "developmentHistory.position", @@ -140,6 +161,7 @@ export class ReportController extends Controller { "employeePosType.posTypeName", "employeePosType.posTypeShortName", "development.projectName", + "development.root", ]) .getMany(); @@ -154,6 +176,7 @@ export class ReportController extends Controller { " " + Extension.ToThaiNumber(item.employeePosLevel.posLevelName.toString()), projectName: item.development ? item.development.projectName : null, + root: item.root, })); return new HttpSuccess({ @@ -185,4 +208,86 @@ export class ReportController extends Controller { }, }); } + + /** + * API Report ข้าราชการฯที่ได้รับทุนการศึกษา/ฝึกอบรมใน detail + * + * @summary DEV_0xx - Report ข้าราชการฯที่ได้รับทุนการศึกษา/ฝึกอบรมใน detail #xx + * + * @param {string} id Id scholarship + */ + @Get("scholarship/{id}") + async GetReportDevelopemtScholarshipDetail(@Path() id: string) { + const getDevelopment = await this.developmentScholarshipRepository.findOne({ + where: { id: id }, + }); + if (!getDevelopment) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลทุนการศึกษา/ฝึกอบรมนี้"); + } + if (getDevelopment.scholarshipType != null) { + switch (getDevelopment.scholarshipType.trim().toUpperCase()) { + case "DOMESTICE": + getDevelopment.scholarshipType = "การศึกษาในประเทศ"; + break; + case "NOABROAD": + getDevelopment.scholarshipType = + "ฝึกอบรมในประเทศที่ส่งไปพัฒนากับหน่วยวงานภายนอก (หลักสูตรที่ไม่มีการไปต่างประเทศ)"; + break; + case "ABROAD": + getDevelopment.scholarshipType = + "ฝึกอบรมในประเทศที่ส่งไปพัฒนากับหน่วยวงานภายนอก (หลักสูตรที่มีการไปต่างประเทศ)"; + break; + case "EXECUTIVE": + getDevelopment.scholarshipType = + "ฝึกอบรมในประเทศที่ส่งไปพัฒนากับหน่วยวงานภายนอก (หลักสูตรประเภทนักบริหาร)"; + break; + default: + break; + } + } + + const formattedData = { + id: getDevelopment.id, + firstName: getDevelopment.firstName, + lastName: getDevelopment.lastName, + position: getDevelopment.position, + root: getDevelopment.root, + degreeLevel: getDevelopment.degreeLevel, + course: getDevelopment.course, + field: getDevelopment.field, + studyPlace: getDevelopment.studyPlace, + scholarshipType: getDevelopment.scholarshipType, + startDate: + getDevelopment.startDate == null + ? "" + : Extension.ToThaiNumber(Extension.ToThaiFullDate(getDevelopment.startDate)), + endDate: + getDevelopment.endDate == null + ? "" + : Extension.ToThaiNumber(Extension.ToThaiFullDate(getDevelopment.endDate)), + reportBackNo: + getDevelopment.reportBackNo == null + ? "" + : Extension.ToThaiNumber(getDevelopment.reportBackNo), + reportBackNoDate: + getDevelopment.reportBackNoDate == null + ? "" + : Extension.ToThaiNumber(Extension.ToThaiFullDate(getDevelopment.reportBackNoDate)), + governmentDate: + getDevelopment.governmentDate == null + ? "" + : Extension.ToThaiNumber(Extension.ToThaiFullDate(getDevelopment.governmentDate)), + graduatedDate: + getDevelopment.graduatedDate == null + ? "" + : Extension.ToThaiNumber(Extension.ToThaiFullDate(getDevelopment.graduatedDate)), + graduatedReason: getDevelopment.graduatedReason, + }; + + return new HttpSuccess({ + template: "repatriation", + reportName: "repatriation", + data: formattedData, + }); + } } diff --git a/src/entities/Development.ts b/src/entities/Development.ts index a708ece..dbbd06d 100644 --- a/src/entities/Development.ts +++ b/src/entities/Development.ts @@ -11,6 +11,11 @@ import { DevelopmentProjectTechniquePlanned } from "./DevelopmentProjectTechniqu import { CreateDevelopmentEvaluation, DevelopmentEvaluation } from "./DevelopmentEvaluation"; import { CreateDevelopmentAddress, DevelopmentAddress } from "./DevelopmentAddress"; import { DevelopmentProjectTechniqueActual } from "./DevelopmentProjectTechniqueActual"; +import { StrategyChild5 } from "./StrategyChild5"; +import { StrategyChild4 } from "./StrategyChild4"; +import { StrategyChild3 } from "./StrategyChild3"; +import { StrategyChild2 } from "./StrategyChild2"; +import { StrategyChild1 } from "./StrategyChild1"; @Entity("development") export class Development extends EntityBase { @@ -402,6 +407,116 @@ export class Development extends EntityBase { (developmentHistory: DevelopmentHistory) => developmentHistory.development, ) developmentHistorys: DevelopmentHistory[]; + + @Column({ + nullable: true, + length: 40, + comment: "คีย์นอก(FK)ของตาราง strategyChild1 เป้าหมายตามแผน", + default: null, + }) + strategyChild1PlannedId: string; + @ManyToOne(() => StrategyChild1, (strategyChild1) => strategyChild1.developmentPlanneds) + @JoinColumn({ name: "strategyChild1PlannedId" }) + strategyChild1Planned: StrategyChild1; + + @Column({ + nullable: true, + length: 40, + comment: "คีย์นอก(FK)ของตาราง strategyChild2 เป้าหมายตามแผน", + default: null, + }) + strategyChild2PlannedId: string; + @ManyToOne(() => StrategyChild2, (strategyChild2) => strategyChild2.developmentPlanneds) + @JoinColumn({ name: "strategyChild2PlannedId" }) + strategyChild2Planned: StrategyChild2; + + @Column({ + nullable: true, + length: 40, + comment: "คีย์นอก(FK)ของตาราง strategyChild3 เป้าหมายตามแผน", + default: null, + }) + strategyChild3PlannedId: string; + @ManyToOne(() => StrategyChild3, (strategyChild3) => strategyChild3.developmentPlanneds) + @JoinColumn({ name: "strategyChild3PlannedId" }) + strategyChild3Planned: StrategyChild3; + + @Column({ + nullable: true, + length: 40, + comment: "คีย์นอก(FK)ของตาราง strategyChild4 เป้าหมายตามแผน", + default: null, + }) + strategyChild4PlannedId: string; + @ManyToOne(() => StrategyChild4, (strategyChild4) => strategyChild4.developmentPlanneds) + @JoinColumn({ name: "strategyChild4PlannedId" }) + strategyChild4Planned: StrategyChild4; + + @Column({ + nullable: true, + length: 40, + comment: "คีย์นอก(FK)ของตาราง strategyChild5 เป้าหมายตามแผน", + default: null, + }) + strategyChild5PlannedId: string; + @ManyToOne(() => StrategyChild5, (strategyChild5) => strategyChild5.developmentPlanneds) + @JoinColumn({ name: "strategyChild5PlannedId" }) + strategyChild5Planned: StrategyChild5; + + @Column({ + nullable: true, + length: 40, + comment: "คีย์นอก(FK)ของตาราง strategyChild1 เป้าหมายตามจริง", + default: null, + }) + strategyChild1ActualId: string; + @ManyToOne(() => StrategyChild1, (strategyChild1) => strategyChild1.developmentActuals) + @JoinColumn({ name: "strategyChild1ActualId" }) + strategyChild1Actual: StrategyChild1; + + @Column({ + nullable: true, + length: 40, + comment: "คีย์นอก(FK)ของตาราง strategyChild2 เป้าหมายตามจริง", + default: null, + }) + strategyChild2ActualId: string; + @ManyToOne(() => StrategyChild2, (strategyChild2) => strategyChild2.developmentActuals) + @JoinColumn({ name: "strategyChild2ActualId" }) + strategyChild2Actual: StrategyChild2; + + @Column({ + nullable: true, + length: 40, + comment: "คีย์นอก(FK)ของตาราง strategyChild3 เป้าหมายตามจริง", + default: null, + }) + strategyChild3ActualId: string; + @ManyToOne(() => StrategyChild3, (strategyChild3) => strategyChild3.developmentActuals) + @JoinColumn({ name: "strategyChild3ActualId" }) + strategyChild3Actual: StrategyChild3; + + @Column({ + nullable: true, + length: 40, + comment: "คีย์นอก(FK)ของตาราง strategyChild4 เป้าหมายตามจริง", + default: null, + }) + strategyChild4ActualId: string; + @ManyToOne(() => StrategyChild4, (strategyChild4) => strategyChild4.developmentActuals) + @JoinColumn({ name: "strategyChild4ActualId" }) + strategyChild4Actual: StrategyChild4; + + @Column({ + nullable: true, + length: 40, + comment: "คีย์นอก(FK)ของตาราง strategyChild5 เป้าหมายตามจริง", + default: null, + }) + strategyChild5ActualId: string; + @ManyToOne(() => StrategyChild5, (strategyChild5) => strategyChild5.developmentActuals) + @JoinColumn({ name: "strategyChild5ActualId" }) + strategyChild5Actual: StrategyChild5; } export class CreateDevelopment { @Column() @@ -416,6 +531,14 @@ export class CreateDevelopment { orgRootShortName: string; @Column() orgRevisionId: string; + @Column() + strategyChildPlannedId: string; + @Column() + strategyChildPlannedNode: number; + @Column() + strategyChildActualId: string; + @Column() + strategyChildActualNode: number; } export class UpdateDevelopment1 { @@ -435,6 +558,14 @@ export class UpdateDevelopment1 { orgRootShortName: string; @Column() orgRevisionId: string; + @Column() + strategyChildPlannedId: string; + @Column() + strategyChildPlannedNode: number; + @Column() + strategyChildActualId: string; + @Column() + strategyChildActualNode: number; } export class UpdateDevelopment2_1 { @Column() diff --git a/src/entities/DevelopmentHistory.ts b/src/entities/DevelopmentHistory.ts index e8a25db..6e2ebca 100644 --- a/src/entities/DevelopmentHistory.ts +++ b/src/entities/DevelopmentHistory.ts @@ -8,6 +8,34 @@ import { EmployeePosLevel } from "./EmployeePosLevel"; @Entity("developmentHistory") export class DevelopmentHistory extends EntityBase { + @Column({ + nullable: true, + comment: "id หน่วยงาน", + default: null, + }) + rootId: string; + + @Column({ + nullable: true, + comment: "ชื่อหน่วยงาน", + default: null, + }) + root: string; + + @Column({ + nullable: true, + comment: "ชื่อย่ิหน่วยงาน", + default: null, + }) + orgRootShortName: string; + + @Column({ + nullable: true, + comment: "id revision", + default: null, + }) + orgRevisionId: string; + @Column({ nullable: true, comment: "ประเภทราชการ", @@ -142,6 +170,12 @@ export class DevelopmentHistory extends EntityBase { default: null, }) dateOrder: Date; + + @Column({ + comment: "บันทึกลงทะเบียนประวัติ", + default: false, + }) + isDone: boolean; } export class CreateDevelopmentHistory { @Column() diff --git a/src/entities/DevelopmentScholarship.ts b/src/entities/DevelopmentScholarship.ts index 1c850af..7ad4156 100644 --- a/src/entities/DevelopmentScholarship.ts +++ b/src/entities/DevelopmentScholarship.ts @@ -5,6 +5,34 @@ import { PosType } from "./PosType"; @Entity("developmentScholarship") export class DevelopmentScholarship extends EntityBase { + @Column({ + nullable: true, + comment: "id หน่วยงาน", + default: null, + }) + rootId: string; + + @Column({ + nullable: true, + comment: "ชื่อหน่วยงาน", + default: null, + }) + root: string; + + @Column({ + nullable: true, + comment: "ชื่อย่อหน่วยงาน", + default: null, + }) + orgRootShortName: string; + + @Column({ + nullable: true, + comment: "id revision", + default: null, + }) + orgRevisionId: string; + @Column({ nullable: true, comment: "id profile", @@ -213,7 +241,7 @@ export class DevelopmentScholarship extends EntityBase { @Column({ nullable: true, - type: "date", + type: "datetime", comment: "ลงวันที่(หนังสือ)", default: null, }) @@ -221,7 +249,7 @@ export class DevelopmentScholarship extends EntityBase { @Column({ nullable: true, - type: "date", + type: "datetime", comment: "หนังสืออนุมัติเมื่อวันที่", default: null, }) @@ -272,7 +300,7 @@ export class DevelopmentScholarship extends EntityBase { @Column({ nullable: true, - type: "date", + type: "datetime", comment: "ลงวันที่(เลขที่สัญญา)", default: null, }) @@ -288,7 +316,7 @@ export class DevelopmentScholarship extends EntityBase { @Column({ nullable: true, - type: "date", + type: "datetime", comment: "ลงวันที่(เลขที่หนังสือรายงานตัวกลับ)", default: null, }) @@ -296,7 +324,7 @@ export class DevelopmentScholarship extends EntityBase { @Column({ nullable: true, - type: "date", + type: "datetime", comment: "รายงานตัวกลับวันที่", default: null, }) @@ -482,6 +510,10 @@ export class DevelopmentScholarship extends EntityBase { graduatedReason: string; } export class CreateDevelopmentScholarship { + rootId: string | null; + root: string | null; + orgRootShortName: string | null; + orgRevisionId: string | null; profileId: string | null; rank?: string | null; prefix: string | null; @@ -537,6 +569,10 @@ export class CreateDevelopmentScholarship { } export class UpdateDevelopmentScholarship { + rootId: string | null; + root: string | null; + orgRootShortName: string | null; + orgRevisionId: string | null; profileId: string | null; rank?: string | null; prefix: string | null; diff --git a/src/entities/StrategyChild1.ts b/src/entities/StrategyChild1.ts index 0cd0ab4..05c56ea 100644 --- a/src/entities/StrategyChild1.ts +++ b/src/entities/StrategyChild1.ts @@ -4,7 +4,7 @@ import { StrategyChild2 } from "./StrategyChild2"; import { StrategyChild3 } from "./StrategyChild3"; import { StrategyChild4 } from "./StrategyChild4"; import { StrategyChild5 } from "./StrategyChild5"; - +import { Development } from "./Development"; @Entity("strategyChild1") export class StrategyChild1 extends EntityBase { @@ -28,6 +28,10 @@ export class StrategyChild1 extends EntityBase { @OneToMany(() => StrategyChild5, (strategyChild5) => strategyChild5.strategyChild1) strategyChild5s: StrategyChild5[]; + @OneToMany(() => Development, (development) => development.strategyChild1Planned) + developmentPlanneds: Development[]; + @OneToMany(() => Development, (development) => development.strategyChild1Actual) + developmentActuals: Development[]; } export class CreateStrategyChild1 { diff --git a/src/entities/StrategyChild2.ts b/src/entities/StrategyChild2.ts index fbc74ef..9425e59 100644 --- a/src/entities/StrategyChild2.ts +++ b/src/entities/StrategyChild2.ts @@ -4,7 +4,7 @@ import { StrategyChild1 } from "./StrategyChild1"; import { StrategyChild3 } from "./StrategyChild3"; import { StrategyChild4 } from "./StrategyChild4"; import { StrategyChild5 } from "./StrategyChild5"; - +import { Development } from "./Development"; @Entity("strategyChild2") export class StrategyChild2 extends EntityBase { @@ -21,7 +21,7 @@ export class StrategyChild2 extends EntityBase { comment: "คีย์นอก(FK)ของตาราง strategyChild1", }) strategyChild1Id: string; - + @ManyToOne(() => StrategyChild1, (strategyChild1) => strategyChild1.strategyChild2s) @JoinColumn({ name: "strategyChild1Id" }) strategyChild1: StrategyChild1; @@ -35,9 +35,11 @@ export class StrategyChild2 extends EntityBase { @OneToMany(() => StrategyChild5, (strategyChild5) => strategyChild5.strategyChild2) strategyChild5s: StrategyChild5[]; - - -} + @OneToMany(() => Development, (development) => development.strategyChild2Planned) + developmentPlanneds: Development[]; + @OneToMany(() => Development, (development) => development.strategyChild2Actual) + developmentActuals: Development[]; +} export class CreateStrategyChild2 { @Column() diff --git a/src/entities/StrategyChild3.ts b/src/entities/StrategyChild3.ts index 2166902..9698d0c 100644 --- a/src/entities/StrategyChild3.ts +++ b/src/entities/StrategyChild3.ts @@ -4,7 +4,7 @@ import { StrategyChild1 } from "./StrategyChild1"; import { StrategyChild2 } from "./StrategyChild2"; import { StrategyChild4 } from "./StrategyChild4"; import { StrategyChild5 } from "./StrategyChild5"; - +import { Development } from "./Development"; @Entity("strategyChild3") export class StrategyChild3 extends EntityBase { @@ -42,12 +42,16 @@ export class StrategyChild3 extends EntityBase { @OneToMany(() => StrategyChild5, (strategyChild5) => strategyChild5.strategyChild3) strategyChild5s: StrategyChild5[]; -} + @OneToMany(() => Development, (development) => development.strategyChild3Planned) + developmentPlanneds: Development[]; + @OneToMany(() => Development, (development) => development.strategyChild3Actual) + developmentActuals: Development[]; +} export class CreateStrategyChild3 { @Column() strategyChild3Name: string; - + @Column("uuid") strategyChild2Id: string; } diff --git a/src/entities/StrategyChild4.ts b/src/entities/StrategyChild4.ts index 290fd85..4382a0c 100644 --- a/src/entities/StrategyChild4.ts +++ b/src/entities/StrategyChild4.ts @@ -4,7 +4,7 @@ import { StrategyChild1 } from "./StrategyChild1"; import { StrategyChild2 } from "./StrategyChild2"; import { StrategyChild3 } from "./StrategyChild3"; import { StrategyChild5 } from "./StrategyChild5"; - +import { Development } from "./Development"; @Entity("strategyChild4") export class StrategyChild4 extends EntityBase { @@ -48,8 +48,12 @@ export class StrategyChild4 extends EntityBase { @OneToMany(() => StrategyChild5, (strategyChild5) => strategyChild5.strategyChild4) strategyChild5s: StrategyChild5[]; -} + @OneToMany(() => Development, (development) => development.strategyChild4Planned) + developmentPlanneds: Development[]; + @OneToMany(() => Development, (development) => development.strategyChild4Actual) + developmentActuals: Development[]; +} export class CreateStrategyChild4 { @Column() diff --git a/src/entities/StrategyChild5.ts b/src/entities/StrategyChild5.ts index 2fa84a4..987f21f 100644 --- a/src/entities/StrategyChild5.ts +++ b/src/entities/StrategyChild5.ts @@ -4,7 +4,7 @@ import { StrategyChild1 } from "./StrategyChild1"; import { StrategyChild2 } from "./StrategyChild2"; import { StrategyChild3 } from "./StrategyChild3"; import { StrategyChild4 } from "./StrategyChild4"; - +import { Development } from "./Development"; @Entity("strategyChild5") export class StrategyChild5 extends EntityBase { @@ -56,8 +56,11 @@ export class StrategyChild5 extends EntityBase { @JoinColumn({ name: "strategyChild4Id" }) strategyChild4: StrategyChild4; -} - + @OneToMany(() => Development, (development) => development.strategyChild5Planned) + developmentPlanneds: Development[]; + @OneToMany(() => Development, (development) => development.strategyChild5Actual) + developmentActuals: Development[]; +} export class CreateStrategyChild5 { @Column() diff --git a/src/migration/1712927871127-update_table_development_add_strategyChild.ts b/src/migration/1712927871127-update_table_development_add_strategyChild.ts new file mode 100644 index 0000000..69dda24 --- /dev/null +++ b/src/migration/1712927871127-update_table_development_add_strategyChild.ts @@ -0,0 +1,52 @@ +import { MigrationInterface, QueryRunner } from "typeorm"; + +export class UpdateTableDevelopmentAddStrategyChild1712927871127 implements MigrationInterface { + name = 'UpdateTableDevelopmentAddStrategyChild1712927871127' + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`development\` ADD \`strategyChild1PlannedId\` varchar(40) NULL COMMENT 'คีย์นอก(FK)ของตาราง strategyChild1 เป้าหมายตามแผน'`); + await queryRunner.query(`ALTER TABLE \`development\` ADD \`strategyChild2PlannedId\` varchar(40) NULL COMMENT 'คีย์นอก(FK)ของตาราง strategyChild2 เป้าหมายตามแผน'`); + await queryRunner.query(`ALTER TABLE \`development\` ADD \`strategyChild3PlannedId\` varchar(40) NULL COMMENT 'คีย์นอก(FK)ของตาราง strategyChild3 เป้าหมายตามแผน'`); + await queryRunner.query(`ALTER TABLE \`development\` ADD \`strategyChild4PlannedId\` varchar(40) NULL COMMENT 'คีย์นอก(FK)ของตาราง strategyChild4 เป้าหมายตามแผน'`); + await queryRunner.query(`ALTER TABLE \`development\` ADD \`strategyChild5PlannedId\` varchar(40) NULL COMMENT 'คีย์นอก(FK)ของตาราง strategyChild5 เป้าหมายตามแผน'`); + await queryRunner.query(`ALTER TABLE \`development\` ADD \`strategyChild1ActualId\` varchar(40) NULL COMMENT 'คีย์นอก(FK)ของตาราง strategyChild1 เป้าหมายตามจริง'`); + await queryRunner.query(`ALTER TABLE \`development\` ADD \`strategyChild2ActualId\` varchar(40) NULL COMMENT 'คีย์นอก(FK)ของตาราง strategyChild2 เป้าหมายตามจริง'`); + await queryRunner.query(`ALTER TABLE \`development\` ADD \`strategyChild3ActualId\` varchar(40) NULL COMMENT 'คีย์นอก(FK)ของตาราง strategyChild3 เป้าหมายตามจริง'`); + await queryRunner.query(`ALTER TABLE \`development\` ADD \`strategyChild4ActualId\` varchar(40) NULL COMMENT 'คีย์นอก(FK)ของตาราง strategyChild4 เป้าหมายตามจริง'`); + await queryRunner.query(`ALTER TABLE \`development\` ADD \`strategyChild5ActualId\` varchar(40) NULL COMMENT 'คีย์นอก(FK)ของตาราง strategyChild5 เป้าหมายตามจริง'`); + await queryRunner.query(`ALTER TABLE \`development\` ADD CONSTRAINT \`FK_10ff41d23b977cf8dce92e9b167\` FOREIGN KEY (\`strategyChild1PlannedId\`) REFERENCES \`strategyChild1\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`); + await queryRunner.query(`ALTER TABLE \`development\` ADD CONSTRAINT \`FK_593bc4c0cda43a2bee2928bda49\` FOREIGN KEY (\`strategyChild2PlannedId\`) REFERENCES \`strategyChild2\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`); + await queryRunner.query(`ALTER TABLE \`development\` ADD CONSTRAINT \`FK_231ce173640401d258c977aae79\` FOREIGN KEY (\`strategyChild3PlannedId\`) REFERENCES \`strategyChild3\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`); + await queryRunner.query(`ALTER TABLE \`development\` ADD CONSTRAINT \`FK_44fb0c37a11d7ad9b8ca98aaa08\` FOREIGN KEY (\`strategyChild4PlannedId\`) REFERENCES \`strategyChild4\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`); + await queryRunner.query(`ALTER TABLE \`development\` ADD CONSTRAINT \`FK_4cd86d57223a295e6de3c42cb61\` FOREIGN KEY (\`strategyChild5PlannedId\`) REFERENCES \`strategyChild5\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`); + await queryRunner.query(`ALTER TABLE \`development\` ADD CONSTRAINT \`FK_a54d96cd5fda35d92815f7f65eb\` FOREIGN KEY (\`strategyChild1ActualId\`) REFERENCES \`strategyChild1\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`); + await queryRunner.query(`ALTER TABLE \`development\` ADD CONSTRAINT \`FK_8a8b6b92dfd3f78d012300524df\` FOREIGN KEY (\`strategyChild2ActualId\`) REFERENCES \`strategyChild2\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`); + await queryRunner.query(`ALTER TABLE \`development\` ADD CONSTRAINT \`FK_9ee4f1c6a2f2c86760da928f01a\` FOREIGN KEY (\`strategyChild3ActualId\`) REFERENCES \`strategyChild3\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`); + await queryRunner.query(`ALTER TABLE \`development\` ADD CONSTRAINT \`FK_adf3d238b02f5806c9ed1e9b90b\` FOREIGN KEY (\`strategyChild4ActualId\`) REFERENCES \`strategyChild4\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`); + await queryRunner.query(`ALTER TABLE \`development\` ADD CONSTRAINT \`FK_f078e198298457e517c8d90e337\` FOREIGN KEY (\`strategyChild5ActualId\`) REFERENCES \`strategyChild5\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`); + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`development\` DROP FOREIGN KEY \`FK_f078e198298457e517c8d90e337\``); + await queryRunner.query(`ALTER TABLE \`development\` DROP FOREIGN KEY \`FK_adf3d238b02f5806c9ed1e9b90b\``); + await queryRunner.query(`ALTER TABLE \`development\` DROP FOREIGN KEY \`FK_9ee4f1c6a2f2c86760da928f01a\``); + await queryRunner.query(`ALTER TABLE \`development\` DROP FOREIGN KEY \`FK_8a8b6b92dfd3f78d012300524df\``); + await queryRunner.query(`ALTER TABLE \`development\` DROP FOREIGN KEY \`FK_a54d96cd5fda35d92815f7f65eb\``); + await queryRunner.query(`ALTER TABLE \`development\` DROP FOREIGN KEY \`FK_4cd86d57223a295e6de3c42cb61\``); + await queryRunner.query(`ALTER TABLE \`development\` DROP FOREIGN KEY \`FK_44fb0c37a11d7ad9b8ca98aaa08\``); + await queryRunner.query(`ALTER TABLE \`development\` DROP FOREIGN KEY \`FK_231ce173640401d258c977aae79\``); + await queryRunner.query(`ALTER TABLE \`development\` DROP FOREIGN KEY \`FK_593bc4c0cda43a2bee2928bda49\``); + await queryRunner.query(`ALTER TABLE \`development\` DROP FOREIGN KEY \`FK_10ff41d23b977cf8dce92e9b167\``); + await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`strategyChild5ActualId\``); + await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`strategyChild4ActualId\``); + await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`strategyChild3ActualId\``); + await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`strategyChild2ActualId\``); + await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`strategyChild1ActualId\``); + await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`strategyChild5PlannedId\``); + await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`strategyChild4PlannedId\``); + await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`strategyChild3PlannedId\``); + await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`strategyChild2PlannedId\``); + await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`strategyChild1PlannedId\``); + } + +} diff --git a/src/migration/1712930900458-update_table_development_add_strategyChild1.ts b/src/migration/1712930900458-update_table_development_add_strategyChild1.ts new file mode 100644 index 0000000..f96285a --- /dev/null +++ b/src/migration/1712930900458-update_table_development_add_strategyChild1.ts @@ -0,0 +1,22 @@ +import { MigrationInterface, QueryRunner } from "typeorm"; + +export class UpdateTableDevelopmentAddStrategyChild11712930900458 implements MigrationInterface { + name = 'UpdateTableDevelopmentAddStrategyChild11712930900458' + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`developmentHistory\` ADD \`rootId\` varchar(255) NULL COMMENT 'id หน่วยงาน'`); + await queryRunner.query(`ALTER TABLE \`developmentHistory\` ADD \`root\` varchar(255) NULL COMMENT 'ชื่อหน่วยงาน'`); + await queryRunner.query(`ALTER TABLE \`developmentHistory\` ADD \`orgRootShortName\` varchar(255) NULL COMMENT 'ชื่อย่ิหน่วยงาน'`); + await queryRunner.query(`ALTER TABLE \`developmentHistory\` ADD \`orgRevisionId\` varchar(255) NULL COMMENT 'id revision'`); + await queryRunner.query(`ALTER TABLE \`developmentHistory\` ADD \`isDone\` tinyint NOT NULL COMMENT 'บันทึกลงทะเบียนประวัติ' DEFAULT 0`); + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`developmentHistory\` DROP COLUMN \`isDone\``); + await queryRunner.query(`ALTER TABLE \`developmentHistory\` DROP COLUMN \`orgRevisionId\``); + await queryRunner.query(`ALTER TABLE \`developmentHistory\` DROP COLUMN \`orgRootShortName\``); + await queryRunner.query(`ALTER TABLE \`developmentHistory\` DROP COLUMN \`root\``); + await queryRunner.query(`ALTER TABLE \`developmentHistory\` DROP COLUMN \`rootId\``); + } + +} diff --git a/src/migration/1713012352435-update_table_developmentscholar_add_rootid.ts b/src/migration/1713012352435-update_table_developmentscholar_add_rootid.ts new file mode 100644 index 0000000..734ee75 --- /dev/null +++ b/src/migration/1713012352435-update_table_developmentscholar_add_rootid.ts @@ -0,0 +1,20 @@ +import { MigrationInterface, QueryRunner } from "typeorm"; + +export class UpdateTableDevelopmentscholarAddRootid1713012352435 implements MigrationInterface { + name = 'UpdateTableDevelopmentscholarAddRootid1713012352435' + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`developmentScholarship\` ADD \`rootId\` varchar(255) NULL COMMENT 'id หน่วยงาน'`); + await queryRunner.query(`ALTER TABLE \`developmentScholarship\` ADD \`root\` varchar(255) NULL COMMENT 'ชื่อหน่วยงาน'`); + await queryRunner.query(`ALTER TABLE \`developmentScholarship\` ADD \`orgRootShortName\` varchar(255) NULL COMMENT 'ชื่อย่อหน่วยงาน'`); + await queryRunner.query(`ALTER TABLE \`developmentScholarship\` ADD \`orgRevisionId\` varchar(255) NULL COMMENT 'id revision'`); + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`developmentScholarship\` DROP COLUMN \`orgRevisionId\``); + await queryRunner.query(`ALTER TABLE \`developmentScholarship\` DROP COLUMN \`orgRootShortName\``); + await queryRunner.query(`ALTER TABLE \`developmentScholarship\` DROP COLUMN \`root\``); + await queryRunner.query(`ALTER TABLE \`developmentScholarship\` DROP COLUMN \`rootId\``); + } + +} diff --git a/src/migration/1713014657464-update_table_developmentscholar_date_to_datetime.ts b/src/migration/1713014657464-update_table_developmentscholar_date_to_datetime.ts new file mode 100644 index 0000000..8e468ea --- /dev/null +++ b/src/migration/1713014657464-update_table_developmentscholar_date_to_datetime.ts @@ -0,0 +1,32 @@ +import { MigrationInterface, QueryRunner } from "typeorm"; + +export class UpdateTableDevelopmentscholarDateToDatetime1713014657464 implements MigrationInterface { + name = 'UpdateTableDevelopmentscholarDateToDatetime1713014657464' + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`developmentScholarship\` DROP COLUMN \`bookNoDate\``); + await queryRunner.query(`ALTER TABLE \`developmentScholarship\` ADD \`bookNoDate\` datetime NULL COMMENT 'ลงวันที่(หนังสือ)'`); + await queryRunner.query(`ALTER TABLE \`developmentScholarship\` DROP COLUMN \`bookApproveDate\``); + await queryRunner.query(`ALTER TABLE \`developmentScholarship\` ADD \`bookApproveDate\` datetime NULL COMMENT 'หนังสืออนุมัติเมื่อวันที่'`); + await queryRunner.query(`ALTER TABLE \`developmentScholarship\` DROP COLUMN \`contractDate\``); + await queryRunner.query(`ALTER TABLE \`developmentScholarship\` ADD \`contractDate\` datetime NULL COMMENT 'ลงวันที่(เลขที่สัญญา)'`); + await queryRunner.query(`ALTER TABLE \`developmentScholarship\` DROP COLUMN \`reportBackNoDate\``); + await queryRunner.query(`ALTER TABLE \`developmentScholarship\` ADD \`reportBackNoDate\` datetime NULL COMMENT 'ลงวันที่(เลขที่หนังสือรายงานตัวกลับ)'`); + await queryRunner.query(`ALTER TABLE \`developmentScholarship\` DROP COLUMN \`reportBackDate\``); + await queryRunner.query(`ALTER TABLE \`developmentScholarship\` ADD \`reportBackDate\` datetime NULL COMMENT 'รายงานตัวกลับวันที่'`); + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`developmentScholarship\` DROP COLUMN \`reportBackDate\``); + await queryRunner.query(`ALTER TABLE \`developmentScholarship\` ADD \`reportBackDate\` date NULL COMMENT 'รายงานตัวกลับวันที่'`); + await queryRunner.query(`ALTER TABLE \`developmentScholarship\` DROP COLUMN \`reportBackNoDate\``); + await queryRunner.query(`ALTER TABLE \`developmentScholarship\` ADD \`reportBackNoDate\` date NULL COMMENT 'ลงวันที่(เลขที่หนังสือรายงานตัวกลับ)'`); + await queryRunner.query(`ALTER TABLE \`developmentScholarship\` DROP COLUMN \`contractDate\``); + await queryRunner.query(`ALTER TABLE \`developmentScholarship\` ADD \`contractDate\` date NULL COMMENT 'ลงวันที่(เลขที่สัญญา)'`); + await queryRunner.query(`ALTER TABLE \`developmentScholarship\` DROP COLUMN \`bookApproveDate\``); + await queryRunner.query(`ALTER TABLE \`developmentScholarship\` ADD \`bookApproveDate\` date NULL COMMENT 'หนังสืออนุมัติเมื่อวันที่'`); + await queryRunner.query(`ALTER TABLE \`developmentScholarship\` DROP COLUMN \`bookNoDate\``); + await queryRunner.query(`ALTER TABLE \`developmentScholarship\` ADD \`bookNoDate\` date NULL COMMENT 'ลงวันที่(หนังสือ)'`); + } + +} From 422b0f3b87568f08ef52a58c0bef978cfa699866 Mon Sep 17 00:00:00 2001 From: Kittapath Date: Tue, 16 Apr 2024 07:50:17 +0700 Subject: [PATCH 049/250] =?UTF-8?q?=E0=B9=82=E0=B8=84=E0=B8=A3=E0=B8=87?= =?UTF-8?q?=E0=B8=AA=E0=B8=A3=E0=B9=89=E0=B8=B2=E0=B8=87=E0=B9=80=E0=B8=9E?= =?UTF-8?q?=E0=B8=B4=E0=B9=88=E0=B8=A1=E0=B8=AD=E0=B8=B1=E0=B8=9E=E0=B9=82?= =?UTF-8?q?=E0=B8=AB=E0=B8=A5=E0=B8=94=20user?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package-lock.json | 466 ++++++++++++++++-- package.json | 5 +- src/controllers/DevelopmentController.ts | 183 +++++-- src/entities/Development.ts | 2 +- src/entities/DevelopmentHistory.ts | 18 +- ..._table_developmentHistory_add_profileId.ts | 16 + ...ble_developmentHistory_add_trainingDays.ts | 16 + 7 files changed, 636 insertions(+), 70 deletions(-) create mode 100644 src/migration/1713163199894-update_table_developmentHistory_add_profileId.ts create mode 100644 src/migration/1713179439957-update_table_developmentHistory_add_trainingDays.ts diff --git a/package-lock.json b/package-lock.json index 3fd41e0..c77b04b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,12 +9,14 @@ "version": "1.0.0", "license": "ISC", "dependencies": { + "@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", @@ -22,7 +24,8 @@ "swagger-ui-express": "^5.0.0", "tsoa": "^6.0.1", "typeorm": "^0.3.19", - "typeorm-cli": "^1.0.7" + "typeorm-cli": "^1.0.7", + "xlsx": "^0.18.5" }, "devDependencies": { "@types/cors": "^2.8.17", @@ -89,6 +92,15 @@ "@jridgewell/sourcemap-codec": "^1.4.10" } }, + "node_modules/@lukeed/csprng": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/@lukeed/csprng/-/csprng-1.1.0.tgz", + "integrity": "sha512-Z7C/xXCiGWsg0KuKsHTKJxbWhpI3Vs5GwLfOean7MGyVFGqdRgBbAjOCh6u4bbjPc/8MJ2pZmK/0DLdCbivLDA==", + "peer": true, + "engines": { + "node": ">=8" + } + }, "node_modules/@lukeed/ms": { "version": "2.0.2", "resolved": "https://registry.npmjs.org/@lukeed/ms/-/ms-2.0.2.tgz", @@ -97,6 +109,145 @@ "node": ">=8" } }, + "node_modules/@nestjs/common": { + "version": "10.3.7", + "resolved": "https://registry.npmjs.org/@nestjs/common/-/common-10.3.7.tgz", + "integrity": "sha512-gKFtFzcJznrwsRYjtNZoPAvSOPYdNgxbTYoAyLTpoy393cIKgLmJTHu6ReH8/qIB9AaZLdGaFLkx98W/tFWFUw==", + "peer": true, + "dependencies": { + "iterare": "1.2.1", + "tslib": "2.6.2", + "uid": "2.0.2" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/nest" + }, + "peerDependencies": { + "class-transformer": "*", + "class-validator": "*", + "reflect-metadata": "^0.1.12 || ^0.2.0", + "rxjs": "^7.1.0" + }, + "peerDependenciesMeta": { + "class-transformer": { + "optional": true + }, + "class-validator": { + "optional": true + } + } + }, + "node_modules/@nestjs/core": { + "version": "10.3.7", + "resolved": "https://registry.npmjs.org/@nestjs/core/-/core-10.3.7.tgz", + "integrity": "sha512-hsdlnfiQ3kgqHL5k7js3CU0PV7hBJVi+LfFMgCkoagRxNMf67z0GFGeOV2jk5d65ssB19qdYsDa1MGVuEaoUpg==", + "hasInstallScript": true, + "peer": true, + "dependencies": { + "@nuxtjs/opencollective": "0.3.2", + "fast-safe-stringify": "2.1.1", + "iterare": "1.2.1", + "path-to-regexp": "3.2.0", + "tslib": "2.6.2", + "uid": "2.0.2" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/nest" + }, + "peerDependencies": { + "@nestjs/common": "^10.0.0", + "@nestjs/microservices": "^10.0.0", + "@nestjs/platform-express": "^10.0.0", + "@nestjs/websockets": "^10.0.0", + "reflect-metadata": "^0.1.12 || ^0.2.0", + "rxjs": "^7.1.0" + }, + "peerDependenciesMeta": { + "@nestjs/microservices": { + "optional": true + }, + "@nestjs/platform-express": { + "optional": true + }, + "@nestjs/websockets": { + "optional": true + } + } + }, + "node_modules/@nestjs/core/node_modules/path-to-regexp": { + "version": "3.2.0", + "resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-3.2.0.tgz", + "integrity": "sha512-jczvQbCUS7XmS7o+y1aEO9OBVFeZBQ1MDSEqmO7xSoPgOPoowY/SxLpZ6Vh97/8qHZOteiCKb7gkG9gA2ZUxJA==", + "peer": true + }, + "node_modules/@nestjs/platform-express": { + "version": "10.3.7", + "resolved": "https://registry.npmjs.org/@nestjs/platform-express/-/platform-express-10.3.7.tgz", + "integrity": "sha512-noNJ+PyIxQJLCKfuXz0tcQtlVAynfLIuKy62g70lEZ86UrIqSrZFqvWs/rFUgkbT6J8H7Rmv11hASOnX+7M2rA==", + "dependencies": { + "body-parser": "1.20.2", + "cors": "2.8.5", + "express": "4.19.2", + "multer": "1.4.4-lts.1", + "tslib": "2.6.2" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/nest" + }, + "peerDependencies": { + "@nestjs/common": "^10.0.0", + "@nestjs/core": "^10.0.0" + } + }, + "node_modules/@nestjs/platform-express/node_modules/mkdirp": { + "version": "0.5.6", + "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.6.tgz", + "integrity": "sha512-FP+p8RB8OWpF3YZBCrP5gtADmtXApB5AMLn+vdyA+PyxCjrCs00mjyUozssO33cwDeT3wNGdLxJ5M//YqtHAJw==", + "dependencies": { + "minimist": "^1.2.6" + }, + "bin": { + "mkdirp": "bin/cmd.js" + } + }, + "node_modules/@nestjs/platform-express/node_modules/multer": { + "version": "1.4.4-lts.1", + "resolved": "https://registry.npmjs.org/multer/-/multer-1.4.4-lts.1.tgz", + "integrity": "sha512-WeSGziVj6+Z2/MwQo3GvqzgR+9Uc+qt8SwHKh3gvNPiISKfsMfG4SvCOFYlxxgkXt7yIV2i1yczehm0EOKIxIg==", + "dependencies": { + "append-field": "^1.0.0", + "busboy": "^1.0.0", + "concat-stream": "^1.5.2", + "mkdirp": "^0.5.4", + "object-assign": "^4.1.1", + "type-is": "^1.6.4", + "xtend": "^4.0.0" + }, + "engines": { + "node": ">= 6.0.0" + } + }, + "node_modules/@nuxtjs/opencollective": { + "version": "0.3.2", + "resolved": "https://registry.npmjs.org/@nuxtjs/opencollective/-/opencollective-0.3.2.tgz", + "integrity": "sha512-um0xL3fO7Mf4fDxcqx9KryrB7zgRM5JSlvGN5AGkP6JLM5XEKyjeAiPbNxdXVXQ16isuAhYpvP88NgL2BGd6aA==", + "peer": true, + "dependencies": { + "chalk": "^4.1.0", + "consola": "^2.15.0", + "node-fetch": "^2.6.1" + }, + "bin": { + "opencollective": "bin/opencollective.js" + }, + "engines": { + "node": ">=8.0.0", + "npm": ">=5.0.0" + } + }, "node_modules/@one-ini/wasm": { "version": "0.1.1", "resolved": "https://registry.npmjs.org/@one-ini/wasm/-/wasm-0.1.1.tgz", @@ -365,6 +516,14 @@ "node": ">=0.4.0" } }, + "node_modules/adler-32": { + "version": "1.3.1", + "resolved": "https://registry.npmjs.org/adler-32/-/adler-32-1.3.1.tgz", + "integrity": "sha512-ynZ4w/nUUv5rrsR8UUGoe1VC9hZj6V5hU9Qw1HlMDJGEJw5S7TfTErWTjMys6M7vr0YWcPqs3qAr4ss0nDfP+A==", + "engines": { + "node": ">=0.8" + } + }, "node_modules/align-text": { "version": "0.1.4", "resolved": "https://registry.npmjs.org/align-text/-/align-text-0.1.4.tgz", @@ -437,6 +596,11 @@ "node": ">= 6.0.0" } }, + "node_modules/append-field": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/append-field/-/append-field-1.0.0.tgz", + "integrity": "sha512-klpgFSWLW1ZEs8svjfb7g4qWY0YS5imI82dTg+QahUvJ8YqAY0P10Uk8tTyh9ZGuYEZEMaeJYCF5BFuX552hsw==" + }, "node_modules/arg": { "version": "4.1.3", "resolved": "https://registry.npmjs.org/arg/-/arg-4.1.3.tgz", @@ -594,12 +758,12 @@ "integrity": "sha512-c98Bf3tPniI+scsdk237ku1Dc3ujXQTSgyiPUDEOe7tRkhrqridvh8klBv0HCEso1OLOYcHuCv/cS6DNxKH+ZA==" }, "node_modules/body-parser": { - "version": "1.20.1", - "resolved": "https://registry.npmjs.org/body-parser/-/body-parser-1.20.1.tgz", - "integrity": "sha512-jWi7abTbYwajOytWCQc37VulmWiRae5RyTpaCyDcS5/lMdtwSz5lOpDE67srw/HYe35f1z3fDQw+3txg7gNtWw==", + "version": "1.20.2", + "resolved": "https://registry.npmjs.org/body-parser/-/body-parser-1.20.2.tgz", + "integrity": "sha512-ml9pReCu3M61kGlqoTm2umSXTlRTuGTx0bfYj+uIUKKYycG5NtSbeetV3faSU6R7ajOPw0g/J1PvK4qNy7s5bA==", "dependencies": { "bytes": "3.1.2", - "content-type": "~1.0.4", + "content-type": "~1.0.5", "debug": "2.6.9", "depd": "2.0.0", "destroy": "1.2.0", @@ -607,7 +771,7 @@ "iconv-lite": "0.4.24", "on-finished": "2.4.1", "qs": "6.11.0", - "raw-body": "2.5.1", + "raw-body": "2.5.2", "type-is": "~1.6.18", "unpipe": "1.0.0" }, @@ -665,6 +829,17 @@ "resolved": "https://registry.npmjs.org/buffer-from/-/buffer-from-1.1.2.tgz", "integrity": "sha512-E+XQCRwSbaaiChtv6k6Dwgc+bx+Bs6vuKJHHl5kox/BaKbhiXzqQOwK4cO22yElGp2OCmjwVhT3HmxgyPGnJfQ==" }, + "node_modules/busboy": { + "version": "1.6.0", + "resolved": "https://registry.npmjs.org/busboy/-/busboy-1.6.0.tgz", + "integrity": "sha512-8SFQbg/0hQ9xy3UNTB0YEnsNBbWfhf7RtnzpL7TkBiTBRfrQ9Fxcnz7VJsleJpyp6rVLvXiuORqjlHi5q+PYuA==", + "dependencies": { + "streamsearch": "^1.1.0" + }, + "engines": { + "node": ">=10.16.0" + } + }, "node_modules/bytes": { "version": "3.1.2", "resolved": "https://registry.npmjs.org/bytes/-/bytes-3.1.2.tgz", @@ -706,6 +881,18 @@ "node": ">=0.10.0" } }, + "node_modules/cfb": { + "version": "1.2.2", + "resolved": "https://registry.npmjs.org/cfb/-/cfb-1.2.2.tgz", + "integrity": "sha512-KfdUZsSOw19/ObEWasvBP/Ac4reZvAGauZhs6S/gqNhXhI7cKwvlH7ulj+dOEYnca4bm4SGo8C1bTAQvnTjgQA==", + "dependencies": { + "adler-32": "~1.3.0", + "crc-32": "~1.2.0" + }, + "engines": { + "node": ">=0.8" + } + }, "node_modules/chalk": { "version": "4.1.2", "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz", @@ -962,6 +1149,14 @@ "url": "https://github.com/chalk/wrap-ansi?sponsor=1" } }, + "node_modules/codepage": { + "version": "1.15.0", + "resolved": "https://registry.npmjs.org/codepage/-/codepage-1.15.0.tgz", + "integrity": "sha512-3g6NUTPd/YtuuGrhMnOMRjFc+LJw/bnMp3+0r/Wcz3IXUuCosKRJvMphm5+Q+bvTVGcJJuRvVLuYba+WojaFaA==", + "engines": { + "node": ">=0.8" + } + }, "node_modules/color-convert": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz", @@ -1004,6 +1199,20 @@ "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", "integrity": "sha512-/Srv4dswyQNBfohGpz9o6Yb3Gz3SrUDqBH5rTuhGR7ahtlbYKnVxw2bCFMRljaA7EXHaXZ8wsHdodFvbkhKmqg==" }, + "node_modules/concat-stream": { + "version": "1.6.2", + "resolved": "https://registry.npmjs.org/concat-stream/-/concat-stream-1.6.2.tgz", + "integrity": "sha512-27HBghJxjiZtIk3Ycvn/4kbJk/1uZuJFfuPEns6LaEvpvG1f0hTea8lilrouyo9mVc2GWdcEZ8OLoGmSADlrCw==", + "engines": [ + "node >= 0.8" + ], + "dependencies": { + "buffer-from": "^1.0.0", + "inherits": "^2.0.3", + "readable-stream": "^2.2.2", + "typedarray": "^0.0.6" + } + }, "node_modules/config-chain": { "version": "1.1.13", "resolved": "https://registry.npmjs.org/config-chain/-/config-chain-1.1.13.tgz", @@ -1013,6 +1222,12 @@ "proto-list": "~1.2.1" } }, + "node_modules/consola": { + "version": "2.15.3", + "resolved": "https://registry.npmjs.org/consola/-/consola-2.15.3.tgz", + "integrity": "sha512-9vAdYbHj6x2fLKC4+oPH0kFzY/orMZyG2Aj+kNylHxKGJ/Ed4dpNyAQYwJOdqO4zdM7XpVHmyejQDcQHrnuXbw==", + "peer": true + }, "node_modules/content-disposition": { "version": "0.5.4", "resolved": "https://registry.npmjs.org/content-disposition/-/content-disposition-0.5.4.tgz", @@ -1033,9 +1248,9 @@ } }, "node_modules/cookie": { - "version": "0.5.0", - "resolved": "https://registry.npmjs.org/cookie/-/cookie-0.5.0.tgz", - "integrity": "sha512-YZ3GUyn/o8gfKJlnlX7g7xq4gyO6OSuhGPKaaGssGB2qgDUS0gPgtTvoyZLTt9Ab6dC4hfc9dV5arkvc/OCmrw==", + "version": "0.6.0", + "resolved": "https://registry.npmjs.org/cookie/-/cookie-0.6.0.tgz", + "integrity": "sha512-U71cyTamuh1CRNCfpGY6to28lxvNwPG4Guz/EVjgf3Jmzv0vlDp1atT9eS5dDjMYHucpHbWns6Lwf3BKz6svdw==", "engines": { "node": ">= 0.6" } @@ -1062,6 +1277,17 @@ "node": ">= 0.10" } }, + "node_modules/crc-32": { + "version": "1.2.2", + "resolved": "https://registry.npmjs.org/crc-32/-/crc-32-1.2.2.tgz", + "integrity": "sha512-ROmzCKrTnOwybPcJApAA6WBWij23HVfGVNKqqrZpuyZOHqK2CwHSvpGuyt/UNNvaIjEd8X5IFGp4Mh+Ie1IHJQ==", + "bin": { + "crc32": "bin/crc32.njs" + }, + "engines": { + "node": ">=0.8" + } + }, "node_modules/create-require": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/create-require/-/create-require-1.1.1.tgz", @@ -1425,16 +1651,16 @@ } }, "node_modules/express": { - "version": "4.18.2", - "resolved": "https://registry.npmjs.org/express/-/express-4.18.2.tgz", - "integrity": "sha512-5/PsL6iGPdfQ/lKM1UuielYgv3BUoJfz1aUwU9vHZ+J7gyvwdQXFEBIEIaxeGf0GIcreATNyBExtalisDbuMqQ==", + "version": "4.19.2", + "resolved": "https://registry.npmjs.org/express/-/express-4.19.2.tgz", + "integrity": "sha512-5T6nhjsT+EOMzuck8JjBHARTHfMht0POzlA60WV2pMD3gyXw2LZnZ+ueGdNxG+0calOJcWKbpFcuzLZ91YWq9Q==", "dependencies": { "accepts": "~1.3.8", "array-flatten": "1.1.1", - "body-parser": "1.20.1", + "body-parser": "1.20.2", "content-disposition": "0.5.4", "content-type": "~1.0.4", - "cookie": "0.5.0", + "cookie": "0.6.0", "cookie-signature": "1.0.6", "debug": "2.6.9", "depd": "2.0.0", @@ -1492,6 +1718,12 @@ "node": ">=16 <22" } }, + "node_modules/fast-safe-stringify": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/fast-safe-stringify/-/fast-safe-stringify-2.1.1.tgz", + "integrity": "sha512-W+KJc2dmILlPplD/H4K9l9LcAHAfPtP6BY84uVLXQ6Evcz9Lcg33Y2z1IVblT6xdY54PXYVHEv+0Wpq8Io6zkA==", + "peer": true + }, "node_modules/figures": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/figures/-/figures-2.0.0.tgz", @@ -1595,6 +1827,14 @@ "node": ">= 0.6" } }, + "node_modules/frac": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/frac/-/frac-1.1.2.tgz", + "integrity": "sha512-w/XBfkibaTl3YDqASwfDUqkna4Z2p9cFSr1aHDt0WoMTECnRfBOv2WArlZILlqgWlmdIlALXGpM2AOhEk5W3IA==", + "engines": { + "node": ">=0.8" + } + }, "node_modules/fresh": { "version": "0.5.2", "resolved": "https://registry.npmjs.org/fresh/-/fresh-0.5.2.tgz", @@ -2046,6 +2286,17 @@ "node": ">=4" } }, + "node_modules/inquirer/node_modules/rxjs": { + "version": "6.6.7", + "resolved": "https://registry.npmjs.org/rxjs/-/rxjs-6.6.7.tgz", + "integrity": "sha512-hTdwr+7yYNIT5n4AMYp85KA6yw2Va0FLa3Rguvbpa4W3I5xynaBZo41cM3XM+4Q6fRMj3sBYIR1VAmZMXYJvRQ==", + "dependencies": { + "tslib": "^1.9.0" + }, + "engines": { + "npm": ">=2.0.0" + } + }, "node_modules/inquirer/node_modules/string-width": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/string-width/-/string-width-2.1.1.tgz", @@ -2088,6 +2339,11 @@ "node": ">=6" } }, + "node_modules/inquirer/node_modules/tslib": { + "version": "1.14.1", + "resolved": "https://registry.npmjs.org/tslib/-/tslib-1.14.1.tgz", + "integrity": "sha512-Xni35NKzjgMrwevysHTCArtLDpPvye8zV/0E4EyYn43P7/7qvQwPh9BGkHewbMulVntbigmcT7rdX3BNo9wRJg==" + }, "node_modules/internal-slot": { "version": "1.0.6", "resolved": "https://registry.npmjs.org/internal-slot/-/internal-slot-1.0.6.tgz", @@ -2389,6 +2645,15 @@ "resolved": "https://registry.npmjs.org/isexe/-/isexe-2.0.0.tgz", "integrity": "sha512-RHxMLp9lnKHGHRng9QFhRCMbYAcVpn69smSGcq3f36xjgVVWThj4qqLbTLlq7Ssj8B+fIQ1EuCEGI2lKsyQeIw==" }, + "node_modules/iterare": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/iterare/-/iterare-1.2.1.tgz", + "integrity": "sha512-RKYVTCjAnRthyJes037NX/IiqeidgN1xc3j1RjFfECFp28A1GVwK9nA+i0rJPaHqSZwygLzRnFlzUuHFoWWy+Q==", + "peer": true, + "engines": { + "node": ">=6" + } + }, "node_modules/iterate-iterator": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/iterate-iterator/-/iterate-iterator-1.0.2.tgz", @@ -2692,6 +2957,34 @@ "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", "integrity": "sha512-Tpp60P6IUJDTuOq/5Z8cdskzJujfwqfOTkrwIwj7IRISpnkJnT6SyJ4PCPnGMoFjC9ddhal5KVIYtAt97ix05A==" }, + "node_modules/multer": { + "version": "1.4.5-lts.1", + "resolved": "https://registry.npmjs.org/multer/-/multer-1.4.5-lts.1.tgz", + "integrity": "sha512-ywPWvcDMeH+z9gQq5qYHCCy+ethsk4goepZ45GLD63fOu0YcNecQxi64nDs3qluZB+murG3/D4dJ7+dGctcCQQ==", + "dependencies": { + "append-field": "^1.0.0", + "busboy": "^1.0.0", + "concat-stream": "^1.5.2", + "mkdirp": "^0.5.4", + "object-assign": "^4.1.1", + "type-is": "^1.6.4", + "xtend": "^4.0.0" + }, + "engines": { + "node": ">= 6.0.0" + } + }, + "node_modules/multer/node_modules/mkdirp": { + "version": "0.5.6", + "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.6.tgz", + "integrity": "sha512-FP+p8RB8OWpF3YZBCrP5gtADmtXApB5AMLn+vdyA+PyxCjrCs00mjyUozssO33cwDeT3wNGdLxJ5M//YqtHAJw==", + "dependencies": { + "minimist": "^1.2.6" + }, + "bin": { + "mkdirp": "bin/cmd.js" + } + }, "node_modules/mute-stream": { "version": "0.0.7", "resolved": "https://registry.npmjs.org/mute-stream/-/mute-stream-0.0.7.tgz", @@ -2814,6 +3107,26 @@ "uuid": "dist/bin/uuid" } }, + "node_modules/node-fetch": { + "version": "2.7.0", + "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.7.0.tgz", + "integrity": "sha512-c4FRfUm/dbcWZ7U+1Wq0AwCyFL+3nt2bEw05wfxSz+DWpWsitgmSgYmy2dQdWyKC1694ELPqMs/YzUSNozLt8A==", + "peer": true, + "dependencies": { + "whatwg-url": "^5.0.0" + }, + "engines": { + "node": "4.x || >=6.0.0" + }, + "peerDependencies": { + "encoding": "^0.1.0" + }, + "peerDependenciesMeta": { + "encoding": { + "optional": true + } + } + }, "node_modules/nodemon": { "version": "3.0.3", "resolved": "https://registry.npmjs.org/nodemon/-/nodemon-3.0.3.tgz", @@ -3168,9 +3481,9 @@ } }, "node_modules/raw-body": { - "version": "2.5.1", - "resolved": "https://registry.npmjs.org/raw-body/-/raw-body-2.5.1.tgz", - "integrity": "sha512-qqJBtEyVgS0ZmPGdCFPWJ3FreoqvG4MVQln/kCgF7Olq95IbOp0/BWyMwbdtn4VTvkM8Y7khCQ2Xgk/tcrCXig==", + "version": "2.5.2", + "resolved": "https://registry.npmjs.org/raw-body/-/raw-body-2.5.2.tgz", + "integrity": "sha512-8zGqypfENjCIqGhgXToC8aB2r7YrBX+AQAfIPs/Mlk+BtPTztOvTS01NRW/3Eh60J+a48lt8qsCzirQ6loCVfA==", "dependencies": { "bytes": "3.1.2", "http-errors": "2.0.0", @@ -3291,21 +3604,14 @@ } }, "node_modules/rxjs": { - "version": "6.6.7", - "resolved": "https://registry.npmjs.org/rxjs/-/rxjs-6.6.7.tgz", - "integrity": "sha512-hTdwr+7yYNIT5n4AMYp85KA6yw2Va0FLa3Rguvbpa4W3I5xynaBZo41cM3XM+4Q6fRMj3sBYIR1VAmZMXYJvRQ==", + "version": "7.8.1", + "resolved": "https://registry.npmjs.org/rxjs/-/rxjs-7.8.1.tgz", + "integrity": "sha512-AA3TVj+0A2iuIoQkWEK/tqFjBq2j+6PO6Y0zJcvzLAFhEFIO3HL0vls9hWLncZbAAbK0mar7oZ4V079I/qPMxg==", + "peer": true, "dependencies": { - "tslib": "^1.9.0" - }, - "engines": { - "npm": ">=2.0.0" + "tslib": "^2.1.0" } }, - "node_modules/rxjs/node_modules/tslib": { - "version": "1.14.1", - "resolved": "https://registry.npmjs.org/tslib/-/tslib-1.14.1.tgz", - "integrity": "sha512-Xni35NKzjgMrwevysHTCArtLDpPvye8zV/0E4EyYn43P7/7qvQwPh9BGkHewbMulVntbigmcT7rdX3BNo9wRJg==" - }, "node_modules/safe-array-concat": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/safe-array-concat/-/safe-array-concat-1.1.0.tgz", @@ -3570,6 +3876,17 @@ "node": ">= 0.6" } }, + "node_modules/ssf": { + "version": "0.11.2", + "resolved": "https://registry.npmjs.org/ssf/-/ssf-0.11.2.tgz", + "integrity": "sha512-+idbmIXoYET47hH+d7dfm2epdOMUDjqcB4648sTZ+t2JwoyBFL/insLfB/racrDmsKB3diwsDA696pZMieAC5g==", + "dependencies": { + "frac": "~1.1.2" + }, + "engines": { + "node": ">=0.8" + } + }, "node_modules/statuses": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/statuses/-/statuses-2.0.1.tgz", @@ -3589,6 +3906,14 @@ "node": ">= 0.4" } }, + "node_modules/streamsearch": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/streamsearch/-/streamsearch-1.1.0.tgz", + "integrity": "sha512-Mcc5wHehp9aXz1ax6bZUyY5afg9u2rv5cqQI3mRrYkGC8rW2hM02jWuwjtL++LS5qinSyhj2QfLyNsuc+VsExg==", + "engines": { + "node": ">=10.0.0" + } + }, "node_modules/string_decoder": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.1.1.tgz", @@ -3899,6 +4224,12 @@ "nodetouch": "bin/nodetouch.js" } }, + "node_modules/tr46": { + "version": "0.0.3", + "resolved": "https://registry.npmjs.org/tr46/-/tr46-0.0.3.tgz", + "integrity": "sha512-N3WMsuqV66lT30CrXNbEjx4GEwlow3v6rr4mCcv6prnfwhS01rkgyFdjPNBYd9br7LpXV1+Emh01fHnq2Gdgrw==", + "peer": true + }, "node_modules/ts-node": { "version": "10.9.2", "resolved": "https://registry.npmjs.org/ts-node/-/ts-node-10.9.2.tgz", @@ -4036,6 +4367,11 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/typedarray": { + "version": "0.0.6", + "resolved": "https://registry.npmjs.org/typedarray/-/typedarray-0.0.6.tgz", + "integrity": "sha512-/aCDEGatGvZ2BIk+HmLf4ifCJFwvKFNb9/JeZPMulfgFracn9QFcAf5GO8B/mweUjSoblS5In0cWhqpfs/5PQA==" + }, "node_modules/typeorm": { "version": "0.3.19", "resolved": "https://registry.npmjs.org/typeorm/-/typeorm-0.3.19.tgz", @@ -4490,6 +4826,18 @@ "resolved": "https://registry.npmjs.org/uglify-to-browserify/-/uglify-to-browserify-1.0.2.tgz", "integrity": "sha512-vb2s1lYx2xBtUgy+ta+b2J/GLVUR+wmpINwHePmPRhOsIVCG2wDzKJ0n14GslH1BifsqVzSOwQhRaCAsZ/nI4Q==" }, + "node_modules/uid": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/uid/-/uid-2.0.2.tgz", + "integrity": "sha512-u3xV3X7uzvi5b1MncmZo3i2Aw222Zk1keqLA1YkHldREkAhAqi65wuPfe7lHx8H/Wzy+8CE7S7uS3jekIM5s8g==", + "peer": true, + "dependencies": { + "@lukeed/csprng": "^1.0.0" + }, + "engines": { + "node": ">=8" + } + }, "node_modules/unbox-primitive": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/unbox-primitive/-/unbox-primitive-1.0.2.tgz", @@ -4586,6 +4934,22 @@ "loose-envify": "^1.0.0" } }, + "node_modules/webidl-conversions": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-3.0.1.tgz", + "integrity": "sha512-2JAn3z8AR6rjK8Sm8orRC0h/bcl/DqL7tRPdGZ4I1CjdF+EaMLmYxBHyXuKL849eucPFhvBoxMsflfOb8kxaeQ==", + "peer": true + }, + "node_modules/whatwg-url": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/whatwg-url/-/whatwg-url-5.0.0.tgz", + "integrity": "sha512-saE57nupxk6v3HY35+jzBwYa0rKSy0XR8JSxZPwgLr7ys0IBzhGviA1/TUGJLmSVqs8pb9AnvICXEuOHLprYTw==", + "peer": true, + "dependencies": { + "tr46": "~0.0.3", + "webidl-conversions": "^3.0.0" + } + }, "node_modules/which": { "version": "2.0.2", "resolved": "https://registry.npmjs.org/which/-/which-2.0.2.tgz", @@ -4641,6 +5005,22 @@ "node": ">= 0.8.0" } }, + "node_modules/wmf": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/wmf/-/wmf-1.0.2.tgz", + "integrity": "sha512-/p9K7bEh0Dj6WbXg4JG0xvLQmIadrner1bi45VMJTfnbVHsc7yIajZyoSoK60/dtVBs12Fm6WkUI5/3WAVsNMw==", + "engines": { + "node": ">=0.8" + } + }, + "node_modules/word": { + "version": "0.3.0", + "resolved": "https://registry.npmjs.org/word/-/word-0.3.0.tgz", + "integrity": "sha512-OELeY0Q61OXpdUfTp+oweA/vtLVg5VDOXh+3he3PNzLGG/y0oylSOC1xRVj0+l4vQ3tj/bB1HVHv1ocXkQceFA==", + "engines": { + "node": ">=0.8" + } + }, "node_modules/wordwrap": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/wordwrap/-/wordwrap-1.0.0.tgz", @@ -4732,6 +5112,26 @@ "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", "integrity": "sha512-l4Sp/DRseor9wL6EvV2+TuQn63dMkPjZ/sp9XkghTEbV9KlPS1xUsZ3u7/IQO4wxtcFB4bgpQPRcR3QCvezPcQ==" }, + "node_modules/xlsx": { + "version": "0.18.5", + "resolved": "https://registry.npmjs.org/xlsx/-/xlsx-0.18.5.tgz", + "integrity": "sha512-dmg3LCjBPHZnQp5/F/+nnTa+miPJxUXB6vtk42YjBBKayDNagxGEeIdWApkYPOf3Z3pm3k62Knjzp7lMeTEtFQ==", + "dependencies": { + "adler-32": "~1.3.0", + "cfb": "~1.2.1", + "codepage": "~1.15.0", + "crc-32": "~1.2.1", + "ssf": "~0.11.2", + "wmf": "~1.0.1", + "word": "~0.3.0" + }, + "bin": { + "xlsx": "bin/xlsx.njs" + }, + "engines": { + "node": ">=0.8" + } + }, "node_modules/xml2js": { "version": "0.4.23", "resolved": "https://registry.npmjs.org/xml2js/-/xml2js-0.4.23.tgz", @@ -4752,6 +5152,14 @@ "node": ">=4.0" } }, + "node_modules/xtend": { + "version": "4.0.2", + "resolved": "https://registry.npmjs.org/xtend/-/xtend-4.0.2.tgz", + "integrity": "sha512-LKYU1iAXJXUgAXn9URjiu+MWhyUXHsvfp7mcuYm9dSUKK0/CjtrUwFAxD82/mCWbtLsGjFIad0wIsod4zrTAEQ==", + "engines": { + "node": ">=0.4" + } + }, "node_modules/y18n": { "version": "5.0.8", "resolved": "https://registry.npmjs.org/y18n/-/y18n-5.0.8.tgz", diff --git a/package.json b/package.json index b530886..939e3e5 100644 --- a/package.json +++ b/package.json @@ -27,12 +27,14 @@ "typescript": "^5.3.3" }, "dependencies": { + "@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", @@ -40,6 +42,7 @@ "swagger-ui-express": "^5.0.0", "tsoa": "^6.0.1", "typeorm": "^0.3.19", - "typeorm-cli": "^1.0.7" + "typeorm-cli": "^1.0.7", + "xlsx": "^0.18.5" } } diff --git a/src/controllers/DevelopmentController.ts b/src/controllers/DevelopmentController.ts index 50c7ef6..4e295ab 100644 --- a/src/controllers/DevelopmentController.ts +++ b/src/controllers/DevelopmentController.ts @@ -11,6 +11,7 @@ import { Path, Request, Query, + UploadedFile, } from "tsoa"; import { AppDataSource } from "../database/data-source"; import { In, Not } from "typeorm"; @@ -47,6 +48,10 @@ import { StrategyChild2 } from "../entities/StrategyChild2"; import { StrategyChild3 } from "../entities/StrategyChild3"; import { StrategyChild4 } from "../entities/StrategyChild4"; import { StrategyChild5 } from "../entities/StrategyChild5"; +import CallAPI from "../interfaces/call-api"; +import { UseInterceptors } from "@nestjs/common"; +import { FileInterceptor } from "@nestjs/platform-express"; +import * as xlsx from "xlsx"; @Route("api/v1/development/main") @Tags("Development") @@ -1572,13 +1577,21 @@ export class DevelopmentController extends Controller { const getDevelopment = await this.developmentHistoryRepository.find({ where: { developmentId: id }, relations: ["posLevel", "posType", "employeePosLevel", "employeePosType"], + order: { + isDone: "ASC", + citizenId: "ASC", + }, }); const _getDevelopment = getDevelopment.map((item) => ({ id: item.id, - citizenId: item.citizenId, + type: item.type, + idcard: item.citizenId, fullName: item.prefix + item.firstName + " " + item.lastName, + prefix: item.prefix, + firstName: item.firstName, + lastName: item.lastName, position: item.position, - posType: + posTypeName: item.type == "OFFICER" ? item.posType ? item.posType.posTypeName @@ -1586,7 +1599,7 @@ export class DevelopmentController extends Controller { : item.employeePosType ? item.employeePosType.posTypeName : null, - posLevel: + posLevelName: item.type == "OFFICER" ? item.posLevel ? item.posLevel.posLevelName @@ -1595,14 +1608,63 @@ export class DevelopmentController extends Controller { ? item.employeePosLevel.posLevelName : null, posExecutive: item.posExecutive, - root: item.root, - order: item.order, - dateOrder: item.dateOrder, + org: item.root, + trainingDays: item.trainingDays, + commandNumber: item.order, + commandDate: item.dateOrder, isDone: item.isDone, })); return new HttpSuccess(_getDevelopment); } + /** + * API รายละเอียดโครงการ/หลักสูตรการฝึกอบรม tab6 ส่งบันทึกทะเบียนประวัติ + * + * @summary DEV_00 - รายละเอียดโครงการ/หลักสูตรการฝึกอบรมtab6 ส่งบันทึกทะเบียนประวัติ # + * + * @param {string} id Id โครงการ + */ + @Get("tab6/done/{id}") + async GetDevelopemtTab6DoneById( + @Path() id: string, + @Request() request: { user: Record }, + ) { + const getDevelopment = await this.developmentHistoryRepository.find({ + where: { developmentId: id, isDone: false, type: "OFFICER" }, + relations: ["development"], + }); + await Promise.all( + getDevelopment.map(async (x) => { + const _data = Object.assign(new DevelopmentHistory(), x); + await new CallAPI() + .PostData(request, "org/profile/training", { + profileId: x.profileId, + name: x.development == null ? null : x.development.projectName, + topic: x.development == null ? null : x.development.topicAcademic, + yearly: x.development == null ? null : x.development.year, + place: x.development == null ? null : x.development.addressAcademic, + duration: x.development == null ? null : x.development.totalDate, + department: x.development == null ? null : x.development.root, + numberOrder: x.order, + dateOrder: x.dateOrder, + startDate: x.development == null ? null : x.development.dateStart, + endDate: x.development == null ? null : x.development.dateEnd, + isDate: true, + }) + .then((x) => { + _data.isDone = true; + }) + .catch((x) => { + _data.isDone = false; + }); + _data.lastUpdateUserId = request.user.sub; + _data.lastUpdateFullName = request.user.name; + await this.developmentHistoryRepository.save(_data); + }), + ); + return new HttpSuccess(getDevelopment); + } + /** * API list หน่วยงาน * @@ -1630,48 +1692,93 @@ export class DevelopmentController extends Controller { * * @param {string} id Id โครงการ */ - @Get("zxczxc/{id}") + @Post("tab6/{id}") + @UseInterceptors(FileInterceptor("file")) async UploadUserDevelopemtById( @Path() id: string, + @UploadedFile() file: Express.Multer.File, @Request() request: { user: Record }, ) { const getDevelopment = await this.developmentRepository.findOne({ where: { id: id }, - relations: ["developmentHistory"], + relations: { + developmentHistorys: true, + }, }); if (!getDevelopment) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงการ/หลักสูตรการฝึกอบรมนี้"); } - await this.developmentHistoryRepository.remove(getDevelopment.developmentHistorys); + const workbook = xlsx.read(file.buffer, { type: "buffer" }); + const sheetName = workbook.SheetNames[0]; // Assuming we're reading the first sheet + const sheet = workbook.Sheets[sheetName]; + const getDevelopments = xlsx.utils.sheet_to_json(sheet); - // await Promise.all( - // positions.map(async (x) => { - // const data = Object.assign(new DevelopmentHistory(), x); - // if (x.posTypeId != null) { - // const checkId = await this.posTypeRepository.findOne({ - // where: { id: x.posTypeId }, - // }); - // if (!checkId) { - // throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลประเภทตำแหน่ง"); - // } - // } - // if (x.posLevelId != null) { - // const checkId = await this.posLevelRepository.findOne({ - // where: { id: x.posLevelId }, - // }); - // if (!checkId) { - // throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลระดับตำแหน่ง"); - // } - // } - // data.developmentId = getDevelopment.id; - // data.createdUserId = request.user.sub; - // data.createdFullName = request.user.name; - // data.lastUpdateUserId = request.user.sub; - // data.lastUpdateFullName = request.user.name; - // await this.plannedGoalPositionRepository.save(data); - // }), - // ); - - return new HttpSuccess(); + await Promise.all( + getDevelopments.map(async (item: any) => { + if (item["รหัสประจำตัวประชาชน"] == undefined || item["รหัสประจำตัวประชาชน"].length != 13) + return; + const oldProfile = getDevelopment.developmentHistorys.find( + (x) => x.citizenId == item["รหัสประจำตัวประชาชน"], + ); + if (oldProfile != null) return; + if (item["ประเภท"] == undefined) return; + if (item["ประเภท"] == "ข้าราชการกรุงเทพมหานครสามัญ") { + await new CallAPI() + .GetData(request, `org/unauthorize/officer/citizen/${item["รหัสประจำตัวประชาชน"]}`) + .then(async (x: any) => { + let development = Object.assign(new DevelopmentHistory(), x); + development.order = + item["เลขที่คำสั่ง/เลขที่หนังสืออนุมัติ"] == undefined + ? null + : item["เลขที่คำสั่ง/เลขที่หนังสืออนุมัติ"]; + development.dateOrder = + item["คำสั่งลงวันที่/หนังสืออนุมัติลงวันที่"] == undefined + ? null + : new Date(item["คำสั่งลงวันที่/หนังสืออนุมัติลงวันที่"]); + development.trainingDays = + item["จำนวนวันที่อบรม"] == undefined ? null : item["จำนวนวันที่อบรม"]; + development.developmentId = id; + development.createdUserId = request.user.sub; + development.createdFullName = request.user.name; + development.lastUpdateUserId = request.user.sub; + development.lastUpdateFullName = request.user.name; + await this.developmentHistoryRepository.save(development); + }) + .catch((x) => { + return; + }); + } else { + await new CallAPI() + .GetData(request, `org/unauthorize/employee/citizen/${item["รหัสประจำตัวประชาชน"]}`) + .then(async (x: any) => { + let development = Object.assign(new DevelopmentHistory(), x); + development.order = + item["เลขที่คำสั่ง/เลขที่หนังสืออนุมัติ"] == undefined + ? null + : item["เลขที่คำสั่ง/เลขที่หนังสืออนุมัติ"]; + development.dateOrder = + item["คำสั่งลงวันที่/หนังสืออนุมัติลงวันที่"] == undefined + ? null + : new Date(item["คำสั่งลงวันที่/หนังสืออนุมัติลงวันที่"]); + development.trainingDays = + item["จำนวนวันที่อบรม"] == undefined ? null : item["จำนวนวันที่อบรม"]; + development.posLevelId = null; + development.posTypeId = null; + development.employeePosLevelId = x.posLevelId; + development.employeePosTypeId = x.posTypeId; + development.developmentId = id; + development.createdUserId = request.user.sub; + development.createdFullName = request.user.name; + development.lastUpdateUserId = request.user.sub; + development.lastUpdateFullName = request.user.name; + await this.developmentHistoryRepository.save(development); + }) + .catch((x) => { + return; + }); + } + }), + ); + return new HttpSuccess(getDevelopments); } } diff --git a/src/entities/Development.ts b/src/entities/Development.ts index dbbd06d..e56fe97 100644 --- a/src/entities/Development.ts +++ b/src/entities/Development.ts @@ -35,7 +35,7 @@ export class Development extends EntityBase { @Column({ nullable: true, - comment: "ชื่อย่ิหน่วยงาน", + comment: "ชื่อย่อหน่วยงาน", default: null, }) orgRootShortName: string; diff --git a/src/entities/DevelopmentHistory.ts b/src/entities/DevelopmentHistory.ts index 6e2ebca..c279e47 100644 --- a/src/entities/DevelopmentHistory.ts +++ b/src/entities/DevelopmentHistory.ts @@ -24,7 +24,7 @@ export class DevelopmentHistory extends EntityBase { @Column({ nullable: true, - comment: "ชื่อย่ิหน่วยงาน", + comment: "ชื่อย่อหน่วยงาน", default: null, }) orgRootShortName: string; @@ -36,6 +36,14 @@ export class DevelopmentHistory extends EntityBase { }) orgRevisionId: string; + @Column({ + nullable: true, + comment: "id profile", + length: 40, + default: null, + }) + profileId: string; + @Column({ nullable: true, comment: "ประเภทราชการ", @@ -155,6 +163,14 @@ export class DevelopmentHistory extends EntityBase { @JoinColumn({ name: "developmentId" }) development: Development; + @Column({ + nullable: true, + comment: "จำนวนวันที่อบรม", + default: null, + length: 255, + }) + trainingDays: string; + @Column({ nullable: true, comment: "เลขที่คำสั่ง/เลขที่หนังสืออนุมัติ", diff --git a/src/migration/1713163199894-update_table_developmentHistory_add_profileId.ts b/src/migration/1713163199894-update_table_developmentHistory_add_profileId.ts new file mode 100644 index 0000000..32b0753 --- /dev/null +++ b/src/migration/1713163199894-update_table_developmentHistory_add_profileId.ts @@ -0,0 +1,16 @@ +import { MigrationInterface, QueryRunner } from "typeorm"; + +export class UpdateTableDevelopmentHistoryAddProfileId1713163199894 implements MigrationInterface { + name = 'UpdateTableDevelopmentHistoryAddProfileId1713163199894' + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`developmentHistory\` ADD \`profileId\` varchar(40) NULL COMMENT 'id profile'`); + await queryRunner.query(`ALTER TABLE \`development\` CHANGE \`orgRootShortName\` \`orgRootShortName\` varchar(255) NULL COMMENT 'ชื่อย่อหน่วยงาน'`); + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`development\` CHANGE \`orgRootShortName\` \`orgRootShortName\` varchar(255) NULL COMMENT 'ชื่อย่ิหน่วยงาน'`); + await queryRunner.query(`ALTER TABLE \`developmentHistory\` DROP COLUMN \`profileId\``); + } + +} diff --git a/src/migration/1713179439957-update_table_developmentHistory_add_trainingDays.ts b/src/migration/1713179439957-update_table_developmentHistory_add_trainingDays.ts new file mode 100644 index 0000000..34f36e9 --- /dev/null +++ b/src/migration/1713179439957-update_table_developmentHistory_add_trainingDays.ts @@ -0,0 +1,16 @@ +import { MigrationInterface, QueryRunner } from "typeorm"; + +export class UpdateTableDevelopmentHistoryAddTrainingDays1713179439957 implements MigrationInterface { + name = 'UpdateTableDevelopmentHistoryAddTrainingDays1713179439957' + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`developmentHistory\` ADD \`trainingDays\` varchar(255) NULL COMMENT 'จำนวนวันที่อบรม'`); + await queryRunner.query(`ALTER TABLE \`developmentHistory\` CHANGE \`orgRootShortName\` \`orgRootShortName\` varchar(255) NULL COMMENT 'ชื่อย่อหน่วยงาน'`); + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`developmentHistory\` CHANGE \`orgRootShortName\` \`orgRootShortName\` varchar(255) NULL COMMENT 'ชื่อย่ิหน่วยงาน'`); + await queryRunner.query(`ALTER TABLE \`developmentHistory\` DROP COLUMN \`trainingDays\``); + } + +} From 5e2fcfdf055717b0b474cd339f56a3f75b4e8d9a Mon Sep 17 00:00:00 2001 From: AdisakKanthawilang Date: Wed, 17 Apr 2024 10:20:48 +0700 Subject: [PATCH 050/250] =?UTF-8?q?crud=20=E0=B8=9C=E0=B8=B1=E0=B8=87?= =?UTF-8?q?=E0=B8=A2=E0=B8=B8=E0=B8=97=E0=B8=98=E0=B8=A8=E0=B8=B2=E0=B8=AA?= =?UTF-8?q?=E0=B8=95=E0=B8=A3=E0=B9=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/StrategyController.ts | 332 ++++++++++++++++++++++++++ src/entities/StrategyChild5.ts | 2 +- 2 files changed, 333 insertions(+), 1 deletion(-) create mode 100644 src/controllers/StrategyController.ts diff --git a/src/controllers/StrategyController.ts b/src/controllers/StrategyController.ts new file mode 100644 index 0000000..858d8fe --- /dev/null +++ b/src/controllers/StrategyController.ts @@ -0,0 +1,332 @@ +import { + Body, + Controller, + Delete, + Example, + Get, + Patch, + Path, + Post, + Request, + Route, + Security, + Tags, +} from "tsoa"; +import { AppDataSource } from "../database/data-source"; +import { + CreateStrategyChild1, + StrategyChild1, + UpdateStrategyChild1, +} from "../entities/StrategyChild1"; +import { + CreateStrategyChild2, + StrategyChild2, + UpdateStrategyChild2, +} from "../entities/StrategyChild2"; +import { + CreateStrategyChild3, + StrategyChild3, + UpdateStrategyChild3, +} from "../entities/StrategyChild3"; +import { + CreateStrategyChild4, + StrategyChild4, + UpdateStrategyChild4, +} from "../entities/StrategyChild4"; +import { + CreateStrategyChild5, + StrategyChild5, + UpdateStrategyChild5, +} from "../entities/StrategyChild5"; +import HttpError from "../interfaces/http-error"; +import HttpStatus from "../interfaces/http-status"; +import HttpSuccess from "../interfaces/http-success"; +import { Check } from "typeorm"; + +@Route("api/v1/development/strategy") +@Tags("Strategy") +@Security("bearerAuth") +export class StrategyController extends Controller { + private strategy1Repo = AppDataSource.getRepository(StrategyChild1); + private strategy2Repo = AppDataSource.getRepository(StrategyChild2); + private strategy3Repo = AppDataSource.getRepository(StrategyChild3); + private strategy4Repo = AppDataSource.getRepository(StrategyChild4); + private strategy5Repo = AppDataSource.getRepository(StrategyChild5); + + @Get() + public async listStrategyChild1() { + const listStrategyChild1 = await this.strategy1Repo.find({ + relations: ["strategyChild2s", "strategyChild3s", "strategyChild4s", "strategyChild5s"], + }); + if (!listStrategyChild1) { + throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลยุทธศาสตร์"); + } + return new HttpSuccess(listStrategyChild1); + } + + @Post() + public async newStrategyChild( + @Request() request: { user: Record }, + @Body() + body: { + name: string; + levelnode: number; + idnode?: string | null; + }, + ) { + let strategyRepo: any; + let strategyChild: any; + let repoSave: any; + + switch (body.levelnode) { + case 0: + strategyRepo = this.strategy1Repo; + repoSave = this.strategy1Repo; + strategyChild = new StrategyChild1(); + strategyChild.strategyChild1Name = body.name; + break; + case 1: + strategyRepo = this.strategy1Repo; + repoSave = this.strategy2Repo; + strategyChild = new StrategyChild2(); + strategyChild.strategyChild2Name = body.name; + if(body.idnode){ + const chk1 = await this.strategy1Repo.findOne({ + where: { id: body.idnode }, + }) + if(chk1){ + strategyChild.strategyChild1Id = chk1.id + }else{ + throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลยุทธศาสตร์"); + } + } + break; + case 2: + strategyRepo = this.strategy2Repo; + repoSave = this.strategy3Repo; + strategyChild = new StrategyChild3(); + strategyChild.strategyChild3Name = body.name; + if(body.idnode){ + const chk2 = await this.strategy2Repo.findOne({ + where: { id: body.idnode }, + }) + if(chk2){ + strategyChild.strategyChild1Id = chk2.strategyChild1Id + strategyChild.strategyChild2Id = chk2.id + }else{ + throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลยุทธศาสตร์"); + } + } + break; + case 3: + strategyRepo = this.strategy3Repo; + repoSave = this.strategy4Repo; + strategyChild = new StrategyChild4(); + strategyChild.strategyChild4Name = body.name; + if(body.idnode){ + const chk3 = await this.strategy3Repo.findOne({ + where: { id: body.idnode }, + }) + if(chk3){ + strategyChild.strategyChild1Id = chk3.strategyChild1Id + strategyChild.strategyChild2Id = chk3.strategyChild2Id + strategyChild.strategyChild3Id = chk3.id + }else{ + throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลยุทธศาสตร์"); + } + } + break; + case 4: + strategyRepo = this.strategy4Repo; + repoSave = this.strategy5Repo; + strategyChild = new StrategyChild5(); + strategyChild.strategyChild5Name = body.name; + if(body.idnode){ + const chk4 = await this.strategy4Repo.findOne({ + where: { id: body.idnode }, + }) + if(chk4){ + strategyChild.strategyChild1Id = chk4.strategyChild1Id + strategyChild.strategyChild2Id = chk4.strategyChild2Id + strategyChild.strategyChild3Id = chk4.strategyChild3Id + strategyChild.strategyChild4Id = chk4.id + }else{ + throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลยุทธศาสตร์"); + } + } + break; + default: + throw new HttpError(HttpStatus.BAD_REQUEST, "levelnode ไม่ถูกต้อง"); + } + + strategyChild.createdUserId = request.user.sub; + strategyChild.createdFullName = request.user.name; + strategyChild.lastUpdateUserId = request.user.sub; + strategyChild.lastUpdateFullName = request.user.name; + + await repoSave.save(strategyChild); + + return new HttpSuccess(strategyChild.id); + } + + @Patch("{levelnode}/{idnode}") + public async editStrategyChild1( + @Request() request: { user: Record }, + @Body() + body: { + name: string; + levelnode: number; + idnode: string; + }, + ) { + let strategyRepo: any; + let strategyChild: any; + let repoSave: any; + + + switch (body.levelnode) { + + case 1: + strategyRepo = this.strategy1Repo; + strategyChild = await strategyRepo.findOne({ + where: { id: body.idnode }, + }) + if(!strategyChild){ + throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลยุทธศาสตร์"); + } + strategyChild.strategyChild1Name = body.name; + break; + case 2: + strategyRepo = this.strategy2Repo; + strategyChild = await strategyRepo.findOne({ + where: { id: body.idnode }, + }) + if(!strategyChild){ + throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลยุทธศาสตร์"); + } + repoSave = this.strategy2Repo; + break; + case 3: + strategyRepo = this.strategy3Repo; + strategyChild = await strategyRepo.findOne({ + where: { id: body.idnode }, + }) + if(!strategyChild){ + throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลยุทธศาสตร์"); + } + strategyChild.strategyChild3Name = body.name; + break; + case 4: + strategyRepo = this.strategy4Repo; + strategyChild = await strategyRepo.findOne({ + where: { id: body.idnode }, + }) + if(!strategyChild){ + throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลยุทธศาสตร์"); + } + strategyChild.strategyChild4Name = body.name; + break; + case 5: + strategyRepo = this.strategy5Repo; + strategyChild = await this.strategy5Repo.findOne({ + where: { id: body.idnode }, + }) + if(!strategyChild){ + throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลยุทธศาสตร์"); + } + strategyChild.strategyChild5Name = body.name; + break; + default: + throw new HttpError(HttpStatus.BAD_REQUEST, "levelnode ไม่ถูกต้อง"); + } + strategyChild.lastUpdateUserId = request.user.sub; + strategyChild.lastUpdateFullName = request.user.name; + + await strategyRepo.save(strategyChild); + + return new HttpSuccess(); + } + + @Delete("{levelnode}/{idnode}") + public async deleteStrategyChild( + @Request() request: { user: Record }, + @Body() + body: { + levelnode: number; + idnode: string; + },) { + let strategyRepo: any; + let data: any; + + switch (body.levelnode) { + case 1: + strategyRepo = this.strategy1Repo; + data = await strategyRepo.find({ + where: { id: body.idnode }, + }); + if(!data){ + throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลยุทธศาสตร์"); + } + await this.strategy5Repo.delete({ strategyChild1Id: body.idnode }); + await this.strategy4Repo.delete({ strategyChild1Id: body.idnode }); + await this.strategy3Repo.delete({ strategyChild1Id: body.idnode }); + await this.strategy2Repo.delete({ strategyChild1Id: body.idnode }); + await this.strategy1Repo.delete({ id : body.idnode }); + break; + case 2: + strategyRepo = this.strategy2Repo; + data = await strategyRepo.find({ + where: { id: body.idnode }, + }); + if(!data){ + throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลยุทธศาสตร์"); + } + await this.strategy5Repo.delete({ strategyChild2Id: body.idnode }); + await this.strategy4Repo.delete({ strategyChild2Id: body.idnode }); + await this.strategy3Repo.delete({ strategyChild2Id: body.idnode }); + await this.strategy2Repo.delete({ id : body.idnode }); + break; + case 3: + strategyRepo = this.strategy3Repo; + data = await strategyRepo.find({ + where: { id: body.idnode }, + }); + if(!data){ + throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลยุทธศาสตร์"); + } + await this.strategy5Repo.delete({ strategyChild3Id: body.idnode }); + await this.strategy4Repo.delete({ strategyChild3Id: body.idnode }); + await this.strategy3Repo.delete({ id: body.idnode }); + break; + case 4: + strategyRepo = this.strategy4Repo; + data = await strategyRepo.find({ + where: { id: body.idnode }, + }); + if(!data){ + throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลยุทธศาสตร์"); + } + await this.strategy5Repo.delete({ strategyChild4Id: body.idnode }); + await this.strategy4Repo.delete({ id: body.idnode }); + break; + case 5: + strategyRepo = this.strategy5Repo; + data = await strategyRepo.find({ + where: { id: body.idnode }, + }); + if(!data){ + throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลยุทธศาสตร์"); + } + await this.strategy5Repo.delete({ id: body.idnode }); + break; + default: + throw new HttpError(HttpStatus.BAD_REQUEST, "levelnode ไม่ถูกต้อง"); + } + + if (!data) { + throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); + } + + return new HttpSuccess(); + } +} diff --git a/src/entities/StrategyChild5.ts b/src/entities/StrategyChild5.ts index 2fa84a4..01d9c0e 100644 --- a/src/entities/StrategyChild5.ts +++ b/src/entities/StrategyChild5.ts @@ -10,7 +10,7 @@ import { StrategyChild4 } from "./StrategyChild4"; export class StrategyChild5 extends EntityBase { @Column({ nullable: true, - comment: "กลยุทธ์ที่", + comment: "กลยุทธ์ที่/เป้าประสงค์ที่", length: 255, default: null, }) From f3d2de51f7f717c70731b7cb0423e7d0ad7ba345 Mon Sep 17 00:00:00 2001 From: AdisakKanthawilang Date: Wed, 17 Apr 2024 10:40:11 +0700 Subject: [PATCH 051/250] fixparth --- src/controllers/StrategyController.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/controllers/StrategyController.ts b/src/controllers/StrategyController.ts index 858d8fe..e1715f4 100644 --- a/src/controllers/StrategyController.ts +++ b/src/controllers/StrategyController.ts @@ -169,7 +169,7 @@ export class StrategyController extends Controller { return new HttpSuccess(strategyChild.id); } - @Patch("{levelnode}/{idnode}") + @Patch() public async editStrategyChild1( @Request() request: { user: Record }, @Body() @@ -247,7 +247,7 @@ export class StrategyController extends Controller { return new HttpSuccess(); } - @Delete("{levelnode}/{idnode}") + @Delete() public async deleteStrategyChild( @Request() request: { user: Record }, @Body() From 428ac7b2b4567bca49800fce15ce8ed470a77802 Mon Sep 17 00:00:00 2001 From: Kittapath Date: Wed, 17 Apr 2024 13:42:26 +0700 Subject: [PATCH 052/250] no message --- .../DevelopmentScholarshipController.ts | 4 ++- src/entities/DevelopmentScholarship.ts | 35 ++++++++++++++----- ...-update_table_dev_add_governmentEndDate.ts | 22 ++++++++++++ ...update_table_dev_add_governmentEndDate1.ts | 14 ++++++++ 4 files changed, 66 insertions(+), 9 deletions(-) create mode 100644 src/migration/1713332483208-update_table_dev_add_governmentEndDate.ts create mode 100644 src/migration/1713334672151-update_table_dev_add_governmentEndDate1.ts diff --git a/src/controllers/DevelopmentScholarshipController.ts b/src/controllers/DevelopmentScholarshipController.ts index 520135e..830dced 100644 --- a/src/controllers/DevelopmentScholarshipController.ts +++ b/src/controllers/DevelopmentScholarshipController.ts @@ -360,10 +360,12 @@ export class DevelopmentScholarshipController extends Controller { "scholarshipYear", "scholarshipType", "fundType", + "bookNumber", + "bookDate", "governmentDate", + "governmentEndDate", "isGraduated", "graduatedDate", - "isNoGraduated", "graduatedReason", "root", ], diff --git a/src/entities/DevelopmentScholarship.ts b/src/entities/DevelopmentScholarship.ts index 7ad4156..0b5a3a8 100644 --- a/src/entities/DevelopmentScholarship.ts +++ b/src/entities/DevelopmentScholarship.ts @@ -474,14 +474,37 @@ export class DevelopmentScholarship extends EntityBase { }) isNoUseBudget: boolean; + @Column({ + nullable: true, + comment: "เลขที่หนังสือรายงานตัวกลับเข้าปฏิบัติราชการ", + default: null, + }) + bookNumber: string; + @Column({ nullable: true, type: "datetime", - comment: "กลับเข้ารับราชการตั้งแต่", + comment: " หนังสือรายงานตัวกลับเข้าปฏิบัติราชการลงวันที่", + default: null, + }) + bookDate: Date; + + @Column({ + nullable: true, + type: "datetime", + comment: "วันที่กลับเข้าปฏิบัติราชการ", default: null, }) governmentDate: Date; + @Column({ + nullable: true, + type: "datetime", + comment: "วันสิ้นสุดภาระผูกพัน", + default: null, + }) + governmentEndDate: Date; + @Column({ comment: "สำเร็จการศึกษาตามที่หลักสูตรกำหนด", default: false, @@ -496,12 +519,6 @@ export class DevelopmentScholarship extends EntityBase { }) graduatedDate: Date; - @Column({ - comment: "เสร็จสิ้นการศึกษาตามที่หลักสูตรกำหนดแล้วแต่ยังไม่สำเร็จการศึกษา", - default: false, - }) - isNoGraduated: boolean; - @Column({ nullable: true, comment: "เนื่องจาก", @@ -628,9 +645,11 @@ export class UpdateDevelopmentScholarship { } export class UpdateDevelopmentScholarshipUser { + bookNumber: string | null; + bookDate: Date | null; governmentDate: Date | null; + governmentEndDate: Date | null; isGraduated: boolean | null; graduatedDate: Date | null; - isNoGraduated: boolean | null; graduatedReason: string | null; } diff --git a/src/migration/1713332483208-update_table_dev_add_governmentEndDate.ts b/src/migration/1713332483208-update_table_dev_add_governmentEndDate.ts new file mode 100644 index 0000000..4b62df6 --- /dev/null +++ b/src/migration/1713332483208-update_table_dev_add_governmentEndDate.ts @@ -0,0 +1,22 @@ +import { MigrationInterface, QueryRunner } from "typeorm"; + +export class UpdateTableDevAddGovernmentEndDate1713332483208 implements MigrationInterface { + name = 'UpdateTableDevAddGovernmentEndDate1713332483208' + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`developmentScholarship\` ADD \`bookNumber\` varchar(255) NULL COMMENT 'เลขที่หนังสือรายงานตัวกลับเข้าปฏิบัติราชการ'`); + await queryRunner.query(`ALTER TABLE \`developmentScholarship\` ADD \`bookDate\` datetime NULL COMMENT ' หนังสือรายงานตัวกลับเข้าปฏิบัติราชการลงวันที่'`); + await queryRunner.query(`ALTER TABLE \`developmentScholarship\` ADD \`governmentEndDate\` datetime NULL COMMENT 'วันสิ้นสุดภาระผูกพัน'`); + await queryRunner.query(`ALTER TABLE \`developmentScholarship\` CHANGE \`governmentDate\` \`governmentDate\` datetime NULL COMMENT 'วันที่กลับเข้าปฏิบัติราชการ'`); + await queryRunner.query(`ALTER TABLE \`strategyChild5\` CHANGE \`strategyChild5Name\` \`strategyChild5Name\` varchar(255) NULL COMMENT 'กลยุทธ์ที่/เป้าประสงค์ที่'`); + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`strategyChild5\` CHANGE \`strategyChild5Name\` \`strategyChild5Name\` varchar(255) NULL COMMENT 'กลยุทธ์ที่'`); + await queryRunner.query(`ALTER TABLE \`developmentScholarship\` CHANGE \`governmentDate\` \`governmentDate\` datetime NULL COMMENT 'กลับเข้ารับราชการตั้งแต่'`); + await queryRunner.query(`ALTER TABLE \`developmentScholarship\` DROP COLUMN \`governmentEndDate\``); + await queryRunner.query(`ALTER TABLE \`developmentScholarship\` DROP COLUMN \`bookDate\``); + await queryRunner.query(`ALTER TABLE \`developmentScholarship\` DROP COLUMN \`bookNumber\``); + } + +} diff --git a/src/migration/1713334672151-update_table_dev_add_governmentEndDate1.ts b/src/migration/1713334672151-update_table_dev_add_governmentEndDate1.ts new file mode 100644 index 0000000..07d2359 --- /dev/null +++ b/src/migration/1713334672151-update_table_dev_add_governmentEndDate1.ts @@ -0,0 +1,14 @@ +import { MigrationInterface, QueryRunner } from "typeorm"; + +export class UpdateTableDevAddGovernmentEndDate11713334672151 implements MigrationInterface { + name = 'UpdateTableDevAddGovernmentEndDate11713334672151' + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`developmentScholarship\` DROP COLUMN \`isNoGraduated\``); + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`developmentScholarship\` ADD \`isNoGraduated\` tinyint NOT NULL COMMENT 'เสร็จสิ้นการศึกษาตามที่หลักสูตรกำหนดแล้วแต่ยังไม่สำเร็จการศึกษา' DEFAULT '0'`); + } + +} From 8a73302f6bfe99cc35f94d7e77b5b66099846983 Mon Sep 17 00:00:00 2001 From: AdisakKanthawilang Date: Wed, 17 Apr 2024 13:56:10 +0700 Subject: [PATCH 053/250] fix format get --- src/controllers/StrategyController.ts | 226 +++++++++++++++----------- 1 file changed, 127 insertions(+), 99 deletions(-) diff --git a/src/controllers/StrategyController.ts b/src/controllers/StrategyController.ts index e1715f4..f3194bc 100644 --- a/src/controllers/StrategyController.ts +++ b/src/controllers/StrategyController.ts @@ -52,16 +52,45 @@ export class StrategyController extends Controller { private strategy3Repo = AppDataSource.getRepository(StrategyChild3); private strategy4Repo = AppDataSource.getRepository(StrategyChild4); private strategy5Repo = AppDataSource.getRepository(StrategyChild5); - @Get() public async listStrategyChild1() { const listStrategyChild1 = await this.strategy1Repo.find({ - relations: ["strategyChild2s", "strategyChild3s", "strategyChild4s", "strategyChild5s"], - }); - if (!listStrategyChild1) { - throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลยุทธศาสตร์"); - } - return new HttpSuccess(listStrategyChild1); + relations: ["strategyChild2s", "strategyChild2s.strategyChild3s", "strategyChild2s.strategyChild3s.strategyChild4s", "strategyChild2s.strategyChild3s.strategyChild4s.strategyChild5s"], + }); + + if (!listStrategyChild1 || listStrategyChild1.length === 0) { + throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลยุทธศาสตร์"); + } + + const formattedData = listStrategyChild1.map(item => ({ + id: item.id, + level: 1, + name: item.strategyChild1Name, + children: item.strategyChild2s.map(child2 => ({ + id: child2.id, + level: 2, + name: child2.strategyChild2Name, + children: child2.strategyChild3s ? child2.strategyChild3s.map(child3 => ({ + id: child3.id, + level: 3, + name: child3.strategyChild3Name, + children: child3.strategyChild4s ? child3.strategyChild4s.map(child4 => ({ + id: child4.id, + level: 4, + name: child4.strategyChild4Name, + children: child4.strategyChild5s ? child4.strategyChild5s.map(child5 => ({ + id: child5.id, + level: 5, + name: child5.strategyChild5Name, + })) : [], + })) : [], + })) : [], + })), + })); + + + + return new HttpSuccess(formattedData); } @Post() @@ -90,15 +119,15 @@ export class StrategyController extends Controller { repoSave = this.strategy2Repo; strategyChild = new StrategyChild2(); strategyChild.strategyChild2Name = body.name; - if(body.idnode){ - const chk1 = await this.strategy1Repo.findOne({ + if (body.idnode) { + const chk1 = await this.strategy1Repo.findOne({ where: { id: body.idnode }, - }) - if(chk1){ - strategyChild.strategyChild1Id = chk1.id - }else{ - throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลยุทธศาสตร์"); - } + }); + if (chk1) { + strategyChild.strategyChild1Id = chk1.id; + } else { + throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลยุทธศาสตร์"); + } } break; case 2: @@ -106,16 +135,16 @@ export class StrategyController extends Controller { repoSave = this.strategy3Repo; strategyChild = new StrategyChild3(); strategyChild.strategyChild3Name = body.name; - if(body.idnode){ - const chk2 = await this.strategy2Repo.findOne({ - where: { id: body.idnode }, - }) - if(chk2){ - strategyChild.strategyChild1Id = chk2.strategyChild1Id - strategyChild.strategyChild2Id = chk2.id - }else{ - throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลยุทธศาสตร์"); - } + if (body.idnode) { + const chk2 = await this.strategy2Repo.findOne({ + where: { id: body.idnode }, + }); + if (chk2) { + strategyChild.strategyChild1Id = chk2.strategyChild1Id; + strategyChild.strategyChild2Id = chk2.id; + } else { + throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลยุทธศาสตร์"); + } } break; case 3: @@ -123,17 +152,17 @@ export class StrategyController extends Controller { repoSave = this.strategy4Repo; strategyChild = new StrategyChild4(); strategyChild.strategyChild4Name = body.name; - if(body.idnode){ - const chk3 = await this.strategy3Repo.findOne({ - where: { id: body.idnode }, - }) - if(chk3){ - strategyChild.strategyChild1Id = chk3.strategyChild1Id - strategyChild.strategyChild2Id = chk3.strategyChild2Id - strategyChild.strategyChild3Id = chk3.id - }else{ - throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลยุทธศาสตร์"); - } + if (body.idnode) { + const chk3 = await this.strategy3Repo.findOne({ + where: { id: body.idnode }, + }); + if (chk3) { + strategyChild.strategyChild1Id = chk3.strategyChild1Id; + strategyChild.strategyChild2Id = chk3.strategyChild2Id; + strategyChild.strategyChild3Id = chk3.id; + } else { + throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลยุทธศาสตร์"); + } } break; case 4: @@ -141,18 +170,18 @@ export class StrategyController extends Controller { repoSave = this.strategy5Repo; strategyChild = new StrategyChild5(); strategyChild.strategyChild5Name = body.name; - if(body.idnode){ - const chk4 = await this.strategy4Repo.findOne({ - where: { id: body.idnode }, - }) - if(chk4){ - strategyChild.strategyChild1Id = chk4.strategyChild1Id - strategyChild.strategyChild2Id = chk4.strategyChild2Id - strategyChild.strategyChild3Id = chk4.strategyChild3Id - strategyChild.strategyChild4Id = chk4.id - }else{ - throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลยุทธศาสตร์"); - } + if (body.idnode) { + const chk4 = await this.strategy4Repo.findOne({ + where: { id: body.idnode }, + }); + if (chk4) { + strategyChild.strategyChild1Id = chk4.strategyChild1Id; + strategyChild.strategyChild2Id = chk4.strategyChild2Id; + strategyChild.strategyChild3Id = chk4.strategyChild3Id; + strategyChild.strategyChild4Id = chk4.id; + } else { + throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลยุทธศาสตร์"); + } } break; default: @@ -183,57 +212,55 @@ export class StrategyController extends Controller { let strategyChild: any; let repoSave: any; - switch (body.levelnode) { - case 1: strategyRepo = this.strategy1Repo; strategyChild = await strategyRepo.findOne({ - where: { id: body.idnode }, - }) - if(!strategyChild){ - throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลยุทธศาสตร์"); - } + where: { id: body.idnode }, + }); + if (!strategyChild) { + throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลยุทธศาสตร์"); + } strategyChild.strategyChild1Name = body.name; break; case 2: strategyRepo = this.strategy2Repo; strategyChild = await strategyRepo.findOne({ - where: { id: body.idnode }, - }) - if(!strategyChild){ - throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลยุทธศาสตร์"); - } + where: { id: body.idnode }, + }); + if (!strategyChild) { + throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลยุทธศาสตร์"); + } repoSave = this.strategy2Repo; break; case 3: strategyRepo = this.strategy3Repo; strategyChild = await strategyRepo.findOne({ - where: { id: body.idnode }, - }) - if(!strategyChild){ - throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลยุทธศาสตร์"); - } + where: { id: body.idnode }, + }); + if (!strategyChild) { + throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลยุทธศาสตร์"); + } strategyChild.strategyChild3Name = body.name; break; case 4: strategyRepo = this.strategy4Repo; strategyChild = await strategyRepo.findOne({ - where: { id: body.idnode }, - }) - if(!strategyChild){ - throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลยุทธศาสตร์"); - } + where: { id: body.idnode }, + }); + if (!strategyChild) { + throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลยุทธศาสตร์"); + } strategyChild.strategyChild4Name = body.name; break; case 5: strategyRepo = this.strategy5Repo; strategyChild = await this.strategy5Repo.findOne({ - where: { id: body.idnode }, - }) - if(!strategyChild){ - throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลยุทธศาสตร์"); - } + where: { id: body.idnode }, + }); + if (!strategyChild) { + throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลยุทธศาสตร์"); + } strategyChild.strategyChild5Name = body.name; break; default: @@ -248,13 +275,14 @@ export class StrategyController extends Controller { } @Delete() - public async deleteStrategyChild( - @Request() request: { user: Record }, - @Body() - body: { - levelnode: number; - idnode: string; - },) { + public async deleteStrategyChild( + @Request() request: { user: Record }, + @Body() + body: { + levelnode: number; + idnode: string; + }, + ) { let strategyRepo: any; let data: any; @@ -262,37 +290,37 @@ export class StrategyController extends Controller { case 1: strategyRepo = this.strategy1Repo; data = await strategyRepo.find({ - where: { id: body.idnode }, + where: { id: body.idnode }, }); - if(!data){ - throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลยุทธศาสตร์"); + if (!data) { + throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลยุทธศาสตร์"); } await this.strategy5Repo.delete({ strategyChild1Id: body.idnode }); await this.strategy4Repo.delete({ strategyChild1Id: body.idnode }); await this.strategy3Repo.delete({ strategyChild1Id: body.idnode }); await this.strategy2Repo.delete({ strategyChild1Id: body.idnode }); - await this.strategy1Repo.delete({ id : body.idnode }); + await this.strategy1Repo.delete({ id: body.idnode }); break; case 2: strategyRepo = this.strategy2Repo; data = await strategyRepo.find({ - where: { id: body.idnode }, + where: { id: body.idnode }, }); - if(!data){ - throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลยุทธศาสตร์"); + if (!data) { + throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลยุทธศาสตร์"); } await this.strategy5Repo.delete({ strategyChild2Id: body.idnode }); await this.strategy4Repo.delete({ strategyChild2Id: body.idnode }); await this.strategy3Repo.delete({ strategyChild2Id: body.idnode }); - await this.strategy2Repo.delete({ id : body.idnode }); + await this.strategy2Repo.delete({ id: body.idnode }); break; case 3: strategyRepo = this.strategy3Repo; data = await strategyRepo.find({ - where: { id: body.idnode }, + where: { id: body.idnode }, }); - if(!data){ - throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลยุทธศาสตร์"); + if (!data) { + throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลยุทธศาสตร์"); } await this.strategy5Repo.delete({ strategyChild3Id: body.idnode }); await this.strategy4Repo.delete({ strategyChild3Id: body.idnode }); @@ -301,10 +329,10 @@ export class StrategyController extends Controller { case 4: strategyRepo = this.strategy4Repo; data = await strategyRepo.find({ - where: { id: body.idnode }, + where: { id: body.idnode }, }); - if(!data){ - throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลยุทธศาสตร์"); + if (!data) { + throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลยุทธศาสตร์"); } await this.strategy5Repo.delete({ strategyChild4Id: body.idnode }); await this.strategy4Repo.delete({ id: body.idnode }); @@ -312,10 +340,10 @@ export class StrategyController extends Controller { case 5: strategyRepo = this.strategy5Repo; data = await strategyRepo.find({ - where: { id: body.idnode }, + where: { id: body.idnode }, }); - if(!data){ - throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลยุทธศาสตร์"); + if (!data) { + throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลยุทธศาสตร์"); } await this.strategy5Repo.delete({ id: body.idnode }); break; From 893912b30422ae5966cf112a83528af15ba96b21 Mon Sep 17 00:00:00 2001 From: AdisakKanthawilang Date: Wed, 17 Apr 2024 14:18:05 +0700 Subject: [PATCH 054/250] fix bug --- src/controllers/StrategyController.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/controllers/StrategyController.ts b/src/controllers/StrategyController.ts index f3194bc..4f1c702 100644 --- a/src/controllers/StrategyController.ts +++ b/src/controllers/StrategyController.ts @@ -210,7 +210,6 @@ export class StrategyController extends Controller { ) { let strategyRepo: any; let strategyChild: any; - let repoSave: any; switch (body.levelnode) { case 1: @@ -231,7 +230,7 @@ export class StrategyController extends Controller { if (!strategyChild) { throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลยุทธศาสตร์"); } - repoSave = this.strategy2Repo; + strategyChild.strategyChild2Name = body.name; break; case 3: strategyRepo = this.strategy3Repo; From c87c3f8feff93bf842463833ad91482ac57cb871 Mon Sep 17 00:00:00 2001 From: Kittapath Date: Wed, 17 Apr 2024 14:26:37 +0700 Subject: [PATCH 055/250] =?UTF-8?q?=E0=B9=80=E0=B8=9E=E0=B8=B4=E0=B9=88?= =?UTF-8?q?=E0=B8=A1=E0=B8=88=E0=B8=B3=E0=B8=99=E0=B8=A7=E0=B8=99=E0=B8=A3?= =?UTF-8?q?=E0=B8=B8=E0=B9=88=E0=B8=99=E0=B8=95=E0=B8=B2=E0=B8=A1=E0=B9=81?= =?UTF-8?q?=E0=B8=9C=E0=B8=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/DevelopmentController.ts | 53 +++++++++++++++---- src/entities/Development.ts | 15 ++++-- ...update_table_dev_add_governmentEndDate2.ts | 18 +++++++ 3 files changed, 72 insertions(+), 14 deletions(-) create mode 100644 src/migration/1713338710965-update_table_dev_add_governmentEndDate2.ts diff --git a/src/controllers/DevelopmentController.ts b/src/controllers/DevelopmentController.ts index 4e295ab..08800b7 100644 --- a/src/controllers/DevelopmentController.ts +++ b/src/controllers/DevelopmentController.ts @@ -1394,8 +1394,13 @@ export class DevelopmentController extends Controller { "developmentActualPeoples", "developmentPlannedPeoples", "developmentActualGoals", + "developmentActualGoals.posTypeActual", + "developmentActualGoals.posLevelActual", + "developmentActualGoals", "developmentPlannedGoals", "developmentPlannedGoals.plannedGoalPositions", + "plannedGoalPositions.posTypePlanned", + "plannedGoalPositions.posLevelPlanned", ], }); if (!getDevelopment) { @@ -1422,19 +1427,44 @@ export class DevelopmentController extends Controller { actualGoals: getDevelopment.developmentActualGoals == null ? null - : getDevelopment.developmentActualGoals.sort((a, b) => - (a.groupTarget == null ? "" : a.groupTarget).localeCompare( - b.groupTarget == null ? "" : b.groupTarget, - ), - ), + : getDevelopment.developmentActualGoals + .sort((a, b) => + (a.groupTarget == null ? "" : a.groupTarget).localeCompare( + b.groupTarget == null ? "" : b.groupTarget, + ), + ) + .map((x) => ({ + groupTarget: x.groupTarget, + groupTargetSub: x.groupTargetSub, + position: x.position, + posTypeId: x.posTypeActualId, + posType: x.posTypeActual == null ? null : x.posTypeActual.posTypeName, + posLevelId: x.posLevelActualId, + posLevel: x.posLevelActual == null ? null : x.posLevelActual.posLevelName, + type: x.type, + amount: x.amount, + })), plannedGoals: getDevelopment.developmentPlannedGoals == null ? null - : getDevelopment.developmentPlannedGoals.sort((a, b) => - (a.groupTarget == null ? "" : a.groupTarget).localeCompare( - b.groupTarget == null ? "" : b.groupTarget, - ), - ), + : getDevelopment.developmentPlannedGoals + .sort((a, b) => + (a.groupTarget == null ? "" : a.groupTarget).localeCompare( + b.groupTarget == null ? "" : b.groupTarget, + ), + ) + .map((x) => ({ + groupTarget: x.groupTarget, + groupTargetSub: x.groupTargetSub, + position: x.plannedGoalPositions.map((y) => ({ + position: y.position, + posTypeId: y.posTypePlannedId, + posType: y.posTypePlanned == null ? null : y.posTypePlanned.posTypeName, + posLevelId: y.posLevelPlannedId, + posLevel: y.posLevelPlanned == null ? null : y.posLevelPlanned.posLevelName, + })), + amount: x.amount, + })), }; return new HttpSuccess(_getDevelopment); } @@ -1461,7 +1491,8 @@ export class DevelopmentController extends Controller { } let _getDevelopment: any = { developmentProjectTypes: getDevelopment.developmentProjectTypes.map((x) => x.name).sort(), - projectModal: getDevelopment.projectModal, + projectModalActual: getDevelopment.projectModalActual, + projectModalPlanned: getDevelopment.projectModalPlanned, isBackPlanned: getDevelopment.isBackPlanned, isHoldPlanned: getDevelopment.isHoldPlanned, projectDayBackPlanned: getDevelopment.projectDayBackPlanned, diff --git a/src/entities/Development.ts b/src/entities/Development.ts index e56fe97..1fcfc15 100644 --- a/src/entities/Development.ts +++ b/src/entities/Development.ts @@ -190,10 +190,17 @@ export class Development extends EntityBase { @Column({ nullable: true, - comment: "จำนวน(รุ่น)", + comment: "จำนวน(รุ่น)ตามแผน", default: null, }) - projectModal: number; + projectModalPlanned: number; + + @Column({ + nullable: true, + comment: "จำนวน(รุ่น)ตามจริง", + default: null, + }) + projectModalActual: number; ////////////////////////////////////////tab ผลประเมิน @OneToMany( @@ -583,7 +590,9 @@ export class UpdateDevelopment3 { @Column() developmentProjectTypes?: string[]; @Column() - projectModal?: number | null; + projectModalActual?: number | null; + @Column() + projectModalPlanned?: number | null; @Column() isBackPlanned?: boolean | null; @Column() diff --git a/src/migration/1713338710965-update_table_dev_add_governmentEndDate2.ts b/src/migration/1713338710965-update_table_dev_add_governmentEndDate2.ts new file mode 100644 index 0000000..a0f4111 --- /dev/null +++ b/src/migration/1713338710965-update_table_dev_add_governmentEndDate2.ts @@ -0,0 +1,18 @@ +import { MigrationInterface, QueryRunner } from "typeorm"; + +export class UpdateTableDevAddGovernmentEndDate21713338710965 implements MigrationInterface { + name = 'UpdateTableDevAddGovernmentEndDate21713338710965' + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`projectModal\``); + await queryRunner.query(`ALTER TABLE \`development\` ADD \`projectModalPlanned\` int NULL COMMENT 'จำนวน(รุ่น)ตามแผน'`); + await queryRunner.query(`ALTER TABLE \`development\` ADD \`projectModalActual\` int NULL COMMENT 'จำนวน(รุ่น)ตามจริง'`); + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`projectModalActual\``); + await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`projectModalPlanned\``); + await queryRunner.query(`ALTER TABLE \`development\` ADD \`projectModal\` int NULL COMMENT 'จำนวน(รุ่น)'`); + } + +} From 40c7a4675f2eafccac1c979e2b62d01fb96e4791 Mon Sep 17 00:00:00 2001 From: Kittapath Date: Wed, 17 Apr 2024 14:45:55 +0700 Subject: [PATCH 056/250] no message --- src/controllers/DevelopmentController.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/controllers/DevelopmentController.ts b/src/controllers/DevelopmentController.ts index 08800b7..4a17ecb 100644 --- a/src/controllers/DevelopmentController.ts +++ b/src/controllers/DevelopmentController.ts @@ -1399,8 +1399,8 @@ export class DevelopmentController extends Controller { "developmentActualGoals", "developmentPlannedGoals", "developmentPlannedGoals.plannedGoalPositions", - "plannedGoalPositions.posTypePlanned", - "plannedGoalPositions.posLevelPlanned", + "developmentPlannedGoals.plannedGoalPositions.posTypePlanned", + "developmentPlannedGoals.plannedGoalPositions.posLevelPlanned", ], }); if (!getDevelopment) { From d21704baaf0cb00055fe237587fa5443cc83d5b3 Mon Sep 17 00:00:00 2001 From: Kittapath Date: Wed, 17 Apr 2024 15:01:33 +0700 Subject: [PATCH 057/250] =?UTF-8?q?=E0=B9=80=E0=B8=9E=E0=B8=B4=E0=B9=88?= =?UTF-8?q?=E0=B8=A1=E0=B8=A7=E0=B8=B1=E0=B8=99=E0=B8=97=E0=B8=B5=E0=B9=88?= =?UTF-8?q?=E0=B8=AD=E0=B8=B1=E0=B8=9E=E0=B9=84=E0=B8=9F=E0=B8=A5=E0=B9=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/DevelopmentController.ts | 16 ++++-- .../DevelopmentEmployeeHistoryController.ts | 51 ++++++++++++------- .../DevelopmentHistoryController.ts | 2 + src/entities/DevelopmentHistory.ts | 24 +++++++++ ...23367-update_table_devhis_add_dateStart.ts | 16 ++++++ 5 files changed, 88 insertions(+), 21 deletions(-) create mode 100644 src/migration/1713340723367-update_table_devhis_add_dateStart.ts diff --git a/src/controllers/DevelopmentController.ts b/src/controllers/DevelopmentController.ts index 4a17ecb..cafa443 100644 --- a/src/controllers/DevelopmentController.ts +++ b/src/controllers/DevelopmentController.ts @@ -1643,6 +1643,8 @@ export class DevelopmentController extends Controller { trainingDays: item.trainingDays, commandNumber: item.order, commandDate: item.dateOrder, + dateStart: item.dateStart, + dateEnd: item.dateEnd, isDone: item.isDone, })); return new HttpSuccess(_getDevelopment); @@ -1674,12 +1676,12 @@ export class DevelopmentController extends Controller { topic: x.development == null ? null : x.development.topicAcademic, yearly: x.development == null ? null : x.development.year, place: x.development == null ? null : x.development.addressAcademic, - duration: x.development == null ? null : x.development.totalDate, + duration: x.trainingDays, department: x.development == null ? null : x.development.root, numberOrder: x.order, dateOrder: x.dateOrder, - startDate: x.development == null ? null : x.development.dateStart, - endDate: x.development == null ? null : x.development.dateEnd, + startDate: x.dateStart, + endDate: x.dateEnd, isDate: true, }) .then((x) => { @@ -1758,6 +1760,10 @@ export class DevelopmentController extends Controller { .GetData(request, `org/unauthorize/officer/citizen/${item["รหัสประจำตัวประชาชน"]}`) .then(async (x: any) => { let development = Object.assign(new DevelopmentHistory(), x); + development.dateStart = + item["วันที่เริ่มต้น"] == undefined ? null : item["วันที่เริ่มต้น"]; + development.dateEnd = + item["วันที่สิ้นสุด"] == undefined ? null : item["วันที่สิ้นสุด"]; development.order = item["เลขที่คำสั่ง/เลขที่หนังสืออนุมัติ"] == undefined ? null @@ -1783,6 +1789,10 @@ export class DevelopmentController extends Controller { .GetData(request, `org/unauthorize/employee/citizen/${item["รหัสประจำตัวประชาชน"]}`) .then(async (x: any) => { let development = Object.assign(new DevelopmentHistory(), x); + development.dateStart = + item["วันที่เริ่มต้น"] == undefined ? null : item["วันที่เริ่มต้น"]; + development.dateEnd = + item["วันที่สิ้นสุด"] == undefined ? null : item["วันที่สิ้นสุด"]; development.order = item["เลขที่คำสั่ง/เลขที่หนังสืออนุมัติ"] == undefined ? null diff --git a/src/controllers/DevelopmentEmployeeHistoryController.ts b/src/controllers/DevelopmentEmployeeHistoryController.ts index a5f8d6c..48ccdfd 100644 --- a/src/controllers/DevelopmentEmployeeHistoryController.ts +++ b/src/controllers/DevelopmentEmployeeHistoryController.ts @@ -200,14 +200,15 @@ export class DevelopmentEmployeeHistoryController extends Controller { .leftJoinAndSelect("developmentHistory.development", "development") .leftJoinAndSelect("developmentHistory.employeePosLevel", "employeePosLevel") .leftJoinAndSelect("developmentHistory.employeePosType", "employeePosType") - .andWhere(year != 0 && year != null && year != undefined ? "development.year = :year" : "1=1", { year: year }) + .andWhere( + year != 0 && year != null && year != undefined ? "development.year = :year" : "1=1", + { year: year }, + ) .andWhere("developmentHistory.type = :type", { type: type }) .andWhere( new Brackets((qb) => { qb.where( - keyword != null && keyword != "" - ? "developmentHistory.prefix LIKE :keyword" - : "1=1", + keyword != null && keyword != "" ? "developmentHistory.prefix LIKE :keyword" : "1=1", { keyword: `%${keyword}%`, }, @@ -245,9 +246,7 @@ export class DevelopmentEmployeeHistoryController extends Controller { }, ) .orWhere( - keyword != null && keyword != "" - ? "development.projectName LIKE :keyword" - : "1=1", + keyword != null && keyword != "" ? "development.projectName LIKE :keyword" : "1=1", { keyword: `%${keyword}%`, }, @@ -274,11 +273,11 @@ export class DevelopmentEmployeeHistoryController extends Controller { .skip((page - 1) * pageSize) .take(pageSize) .getManyAndCount(); - - const formattedData = development.map(item => ({ + + const formattedData = development.map((item) => ({ id: item.id, citizenId: item.citizenId, - fullName: item.prefix+item.firstName+" "+item.lastName, + fullName: item.prefix + item.firstName + " " + item.lastName, position: item.position, posType: item.employeePosType ? item.employeePosType.posTypeName : null, posLevel: item.employeePosLevel ? item.employeePosLevel.posLevelName : null, @@ -299,7 +298,7 @@ export class DevelopmentEmployeeHistoryController extends Controller { async GetDevelopemtHistoryById(@Path() id: string) { const type = "EMPLOYEE"; const getDevelopment = await this.developmentHistoryRepository.findOne({ - relations: ["development","employeePosLevel","employeePosType"], + relations: ["development", "employeePosLevel", "employeePosType"], where: { id: id, type: type }, }); if (!getDevelopment) { @@ -314,21 +313,37 @@ export class DevelopmentEmployeeHistoryController extends Controller { citizenId: getDevelopment.citizenId ? getDevelopment.citizenId : null, position: getDevelopment.position ? getDevelopment.position : null, posLevelId: getDevelopment.employeePosLevelId ? getDevelopment.employeePosLevelId : null, - posLevelName: getDevelopment.employeePosLevel.posLevelName ? getDevelopment.employeePosLevel.posLevelName : null, + posLevelName: getDevelopment.employeePosLevel.posLevelName + ? getDevelopment.employeePosLevel.posLevelName + : null, posTypeId: getDevelopment.employeePosTypeId ? getDevelopment.employeePosTypeId : null, - posTypeName: getDevelopment.employeePosType.posTypeName ? getDevelopment.employeePosType.posTypeName : null, + posTypeName: getDevelopment.employeePosType.posTypeName + ? getDevelopment.employeePosType.posTypeName + : null, developmentId: getDevelopment.developmentId ? getDevelopment.developmentId : null, order: getDevelopment.order ? getDevelopment.order : null, dateOrder: getDevelopment.dateOrder ? getDevelopment.dateOrder : null, + dateHisStart: getDevelopment.dateStart ? getDevelopment.dateStart : null, + dateHisEnd: getDevelopment.dateEnd ? getDevelopment.dateEnd : null, year: getDevelopment.development.year ? getDevelopment.development.year : null, - projectName: getDevelopment.development.projectName ? getDevelopment.development.projectName : null, + projectName: getDevelopment.development.projectName + ? getDevelopment.development.projectName + : null, dateStart: getDevelopment.development.dateStart ? getDevelopment.development.dateStart : null, dateEnd: getDevelopment.development.dateEnd ? getDevelopment.development.dateEnd : null, totalDate: getDevelopment.development.totalDate ? getDevelopment.development.totalDate : null, - addressAcademic: getDevelopment.development.addressAcademic ? getDevelopment.development.addressAcademic : null, - topicAcademic: getDevelopment.development.topicAcademic ? getDevelopment.development.topicAcademic : null, - dateStudyStart: getDevelopment.development.dateStudyStart ? getDevelopment.development.dateStudyStart : null, - dateStudyEnd: getDevelopment.development.dateStudyEnd ? getDevelopment.development.dateStudyEnd : null, + addressAcademic: getDevelopment.development.addressAcademic + ? getDevelopment.development.addressAcademic + : null, + topicAcademic: getDevelopment.development.topicAcademic + ? getDevelopment.development.topicAcademic + : null, + dateStudyStart: getDevelopment.development.dateStudyStart + ? getDevelopment.development.dateStudyStart + : null, + dateStudyEnd: getDevelopment.development.dateStudyEnd + ? getDevelopment.development.dateStudyEnd + : null, org: null, }; diff --git a/src/controllers/DevelopmentHistoryController.ts b/src/controllers/DevelopmentHistoryController.ts index 787c300..9f1fd7a 100644 --- a/src/controllers/DevelopmentHistoryController.ts +++ b/src/controllers/DevelopmentHistoryController.ts @@ -314,6 +314,8 @@ export class DevelopmentOfficerHistoryController extends Controller { developmentId: getDevelopment.developmentId ? getDevelopment.developmentId : null, order: getDevelopment.order ? getDevelopment.order : null, dateOrder: getDevelopment.dateOrder ? getDevelopment.dateOrder : null, + dateHisStart: getDevelopment.dateStart ? getDevelopment.dateStart : null, + dateHisEnd: getDevelopment.dateEnd ? getDevelopment.dateEnd : null, year: getDevelopment.development.year ? getDevelopment.development.year : null, projectName: getDevelopment.development.projectName ? getDevelopment.development.projectName diff --git a/src/entities/DevelopmentHistory.ts b/src/entities/DevelopmentHistory.ts index c279e47..33f0131 100644 --- a/src/entities/DevelopmentHistory.ts +++ b/src/entities/DevelopmentHistory.ts @@ -179,6 +179,22 @@ export class DevelopmentHistory extends EntityBase { }) order: string; + @Column({ + nullable: true, + type: "datetime", + comment: "วันที่เริ่มต้น", + default: null, + }) + dateStart: Date; + + @Column({ + nullable: true, + type: "datetime", + comment: "วันที่สิ้นสุด", + default: null, + }) + dateEnd: Date; + @Column({ nullable: true, type: "datetime", @@ -218,6 +234,10 @@ export class CreateDevelopmentHistory { order: string | null; @Column() dateOrder: Date | null; + @Column() + dateStart: Date | null; + @Column() + dateEnd: Date | null; } export class UpdateDevelopmentHistory { @@ -245,4 +265,8 @@ export class UpdateDevelopmentHistory { order: string | null; @Column() dateOrder: Date | null; + @Column() + dateStart: Date | null; + @Column() + dateEnd: Date | null; } diff --git a/src/migration/1713340723367-update_table_devhis_add_dateStart.ts b/src/migration/1713340723367-update_table_devhis_add_dateStart.ts new file mode 100644 index 0000000..1b3d4c7 --- /dev/null +++ b/src/migration/1713340723367-update_table_devhis_add_dateStart.ts @@ -0,0 +1,16 @@ +import { MigrationInterface, QueryRunner } from "typeorm"; + +export class UpdateTableDevhisAddDateStart1713340723367 implements MigrationInterface { + name = 'UpdateTableDevhisAddDateStart1713340723367' + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`developmentHistory\` ADD \`dateStart\` datetime NULL COMMENT 'วันที่เริ่มต้น'`); + await queryRunner.query(`ALTER TABLE \`developmentHistory\` ADD \`dateEnd\` datetime NULL COMMENT 'วันที่สิ้นสุด'`); + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`developmentHistory\` DROP COLUMN \`dateEnd\``); + await queryRunner.query(`ALTER TABLE \`developmentHistory\` DROP COLUMN \`dateStart\``); + } + +} From e9a6f004310a9a8e0783dfff442d00604a0a46b1 Mon Sep 17 00:00:00 2001 From: Kittapath Date: Wed, 17 Apr 2024 15:27:37 +0700 Subject: [PATCH 058/250] no message --- src/controllers/DevelopmentController.ts | 574 ++++++------------ src/entities/Development.ts | 16 +- src/entities/PlannedGoal.ts | 12 +- ...3341677475-update_table_devhis_add_type.ts | 14 + 4 files changed, 230 insertions(+), 386 deletions(-) create mode 100644 src/migration/1713341677475-update_table_devhis_add_type.ts diff --git a/src/controllers/DevelopmentController.ts b/src/controllers/DevelopmentController.ts index cafa443..1e115b1 100644 --- a/src/controllers/DevelopmentController.ts +++ b/src/controllers/DevelopmentController.ts @@ -109,188 +109,7 @@ export class DevelopmentController extends Controller { " มีอยู่ในระบบแล้ว", ); } - let _null: any = null; const development = Object.assign(new Development(), requestBody); - switch (requestBody.strategyChildPlannedNode) { - case 1: { - const checkId = await this.strategyChild1Repository.findOne({ - where: { id: requestBody.strategyChildPlannedId }, - }); - if (!checkId) { - throw new HttpError( - HttpStatusCode.NOT_FOUND, - "ไม่พบข้อมูลยุทธศาสตร์เป้าหมายตามแผนระดับ 1", - ); - } - development.strategyChild1PlannedId = checkId.id; - development.strategyChild2ActualId = _null; - development.strategyChild3ActualId = _null; - development.strategyChild4ActualId = _null; - development.strategyChild5ActualId = _null; - break; - } - case 2: { - const checkId = await this.strategyChild2Repository.findOne({ - where: { id: requestBody.strategyChildPlannedId }, - }); - if (!checkId) { - throw new HttpError( - HttpStatusCode.NOT_FOUND, - "ไม่พบข้อมูลยุทธศาสตร์เป้าหมายตามแผนระดับ 2", - ); - } - development.strategyChild1PlannedId = checkId.strategyChild1Id; - development.strategyChild2PlannedId = checkId.id; - development.strategyChild3ActualId = _null; - development.strategyChild4ActualId = _null; - development.strategyChild5ActualId = _null; - break; - } - case 3: { - const checkId = await this.strategyChild3Repository.findOne({ - where: { id: requestBody.strategyChildPlannedId }, - }); - if (!checkId) { - throw new HttpError( - HttpStatusCode.NOT_FOUND, - "ไม่พบข้อมูลยุทธศาสตร์เป้าหมายตามแผนระดับ 2", - ); - } - development.strategyChild1PlannedId = checkId.strategyChild1Id; - development.strategyChild2PlannedId = checkId.strategyChild2Id; - development.strategyChild3PlannedId = checkId.id; - development.strategyChild4ActualId = _null; - development.strategyChild5ActualId = _null; - break; - } - case 4: { - const checkId = await this.strategyChild4Repository.findOne({ - where: { id: requestBody.strategyChildPlannedId }, - }); - if (!checkId) { - throw new HttpError( - HttpStatusCode.NOT_FOUND, - "ไม่พบข้อมูลยุทธศาสตร์เป้าหมายตามแผนระดับ 3", - ); - } - development.strategyChild1PlannedId = checkId.strategyChild1Id; - development.strategyChild2PlannedId = checkId.strategyChild2Id; - development.strategyChild3PlannedId = checkId.strategyChild3Id; - development.strategyChild4PlannedId = checkId.id; - development.strategyChild5ActualId = _null; - break; - } - case 5: { - const checkId = await this.strategyChild5Repository.findOne({ - where: { id: requestBody.strategyChildPlannedId }, - }); - if (!checkId) { - throw new HttpError( - HttpStatusCode.NOT_FOUND, - "ไม่พบข้อมูลยุทธศาสตร์เป้าหมายตามแผนระดับ 2", - ); - } - development.strategyChild1PlannedId = checkId.strategyChild1Id; - development.strategyChild2PlannedId = checkId.strategyChild2Id; - development.strategyChild3PlannedId = checkId.strategyChild3Id; - development.strategyChild4PlannedId = checkId.strategyChild4Id; - development.strategyChild5PlannedId = checkId.id; - break; - } - - default: - throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลยุทธศาสตร์เป้าหมายตามแผน"); - } - switch (requestBody.strategyChildActualNode) { - case 1: { - const checkId = await this.strategyChild1Repository.findOne({ - where: { id: requestBody.strategyChildActualId }, - }); - if (!checkId) { - throw new HttpError( - HttpStatusCode.NOT_FOUND, - "ไม่พบข้อมูลยุทธศาสตร์เป้าหมายตามจริงระดับ 1", - ); - } - development.strategyChild1ActualId = checkId.id; - development.strategyChild2ActualId = _null; - development.strategyChild3ActualId = _null; - development.strategyChild4ActualId = _null; - development.strategyChild5ActualId = _null; - break; - } - case 2: { - const checkId = await this.strategyChild2Repository.findOne({ - where: { id: requestBody.strategyChildActualId }, - }); - if (!checkId) { - throw new HttpError( - HttpStatusCode.NOT_FOUND, - "ไม่พบข้อมูลยุทธศาสตร์เป้าหมายตามจริงระดับ 2", - ); - } - development.strategyChild1ActualId = checkId.strategyChild1Id; - development.strategyChild2ActualId = checkId.id; - development.strategyChild3ActualId = _null; - development.strategyChild4ActualId = _null; - development.strategyChild5ActualId = _null; - break; - } - case 3: { - const checkId = await this.strategyChild3Repository.findOne({ - where: { id: requestBody.strategyChildActualId }, - }); - if (!checkId) { - throw new HttpError( - HttpStatusCode.NOT_FOUND, - "ไม่พบข้อมูลยุทธศาสตร์เป้าหมายตามจริงระดับ 3", - ); - } - development.strategyChild1ActualId = checkId.strategyChild1Id; - development.strategyChild2ActualId = checkId.strategyChild2Id; - development.strategyChild3ActualId = checkId.id; - development.strategyChild4ActualId = _null; - development.strategyChild5ActualId = _null; - break; - } - case 4: { - const checkId = await this.strategyChild4Repository.findOne({ - where: { id: requestBody.strategyChildActualId }, - }); - if (!checkId) { - throw new HttpError( - HttpStatusCode.NOT_FOUND, - "ไม่พบข้อมูลยุทธศาสตร์เป้าหมายตามจริงระดับ 4", - ); - } - development.strategyChild1ActualId = checkId.strategyChild1Id; - development.strategyChild2ActualId = checkId.strategyChild2Id; - development.strategyChild3ActualId = checkId.strategyChild3Id; - development.strategyChild4ActualId = checkId.id; - development.strategyChild5ActualId = _null; - break; - } - case 5: { - const checkId = await this.strategyChild5Repository.findOne({ - where: { id: requestBody.strategyChildActualId }, - }); - if (!checkId) { - throw new HttpError( - HttpStatusCode.NOT_FOUND, - "ไม่พบข้อมูลยุทธศาสตร์เป้าหมายตามจริงระดับ 5", - ); - } - development.strategyChild1ActualId = checkId.strategyChild1Id; - development.strategyChild2ActualId = checkId.strategyChild2Id; - development.strategyChild3ActualId = checkId.strategyChild3Id; - development.strategyChild4ActualId = checkId.strategyChild4Id; - development.strategyChild5ActualId = checkId.id; - break; - } - - default: - throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลยุทธศาสตร์เป้าหมายตามจริง"); - } development.createdUserId = request.user.sub; development.createdFullName = request.user.name; development.lastUpdateUserId = request.user.sub; @@ -335,187 +154,6 @@ export class DevelopmentController extends Controller { " มีอยู่ในระบบแล้ว", ); } - let _null: any = null; - switch (requestBody.strategyChildPlannedNode) { - case 1: { - const checkId = await this.strategyChild1Repository.findOne({ - where: { id: requestBody.strategyChildPlannedId }, - }); - if (!checkId) { - throw new HttpError( - HttpStatusCode.NOT_FOUND, - "ไม่พบข้อมูลยุทธศาสตร์เป้าหมายตามแผนระดับ 1", - ); - } - development.strategyChild1PlannedId = checkId.id; - development.strategyChild2ActualId = _null; - development.strategyChild3ActualId = _null; - development.strategyChild4ActualId = _null; - development.strategyChild5ActualId = _null; - break; - } - case 2: { - const checkId = await this.strategyChild2Repository.findOne({ - where: { id: requestBody.strategyChildPlannedId }, - }); - if (!checkId) { - throw new HttpError( - HttpStatusCode.NOT_FOUND, - "ไม่พบข้อมูลยุทธศาสตร์เป้าหมายตามแผนระดับ 2", - ); - } - development.strategyChild1PlannedId = checkId.strategyChild1Id; - development.strategyChild2PlannedId = checkId.id; - development.strategyChild3ActualId = _null; - development.strategyChild4ActualId = _null; - development.strategyChild5ActualId = _null; - break; - } - case 3: { - const checkId = await this.strategyChild3Repository.findOne({ - where: { id: requestBody.strategyChildPlannedId }, - }); - if (!checkId) { - throw new HttpError( - HttpStatusCode.NOT_FOUND, - "ไม่พบข้อมูลยุทธศาสตร์เป้าหมายตามแผนระดับ 2", - ); - } - development.strategyChild1PlannedId = checkId.strategyChild1Id; - development.strategyChild2PlannedId = checkId.strategyChild2Id; - development.strategyChild3PlannedId = checkId.id; - development.strategyChild4ActualId = _null; - development.strategyChild5ActualId = _null; - break; - } - case 4: { - const checkId = await this.strategyChild4Repository.findOne({ - where: { id: requestBody.strategyChildPlannedId }, - }); - if (!checkId) { - throw new HttpError( - HttpStatusCode.NOT_FOUND, - "ไม่พบข้อมูลยุทธศาสตร์เป้าหมายตามแผนระดับ 3", - ); - } - development.strategyChild1PlannedId = checkId.strategyChild1Id; - development.strategyChild2PlannedId = checkId.strategyChild2Id; - development.strategyChild3PlannedId = checkId.strategyChild3Id; - development.strategyChild4PlannedId = checkId.id; - development.strategyChild5ActualId = _null; - break; - } - case 5: { - const checkId = await this.strategyChild5Repository.findOne({ - where: { id: requestBody.strategyChildPlannedId }, - }); - if (!checkId) { - throw new HttpError( - HttpStatusCode.NOT_FOUND, - "ไม่พบข้อมูลยุทธศาสตร์เป้าหมายตามแผนระดับ 2", - ); - } - development.strategyChild1PlannedId = checkId.strategyChild1Id; - development.strategyChild2PlannedId = checkId.strategyChild2Id; - development.strategyChild3PlannedId = checkId.strategyChild3Id; - development.strategyChild4PlannedId = checkId.strategyChild4Id; - development.strategyChild5PlannedId = checkId.id; - break; - } - - default: - throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลยุทธศาสตร์เป้าหมายตามแผน"); - } - switch (requestBody.strategyChildActualNode) { - case 1: { - const checkId = await this.strategyChild1Repository.findOne({ - where: { id: requestBody.strategyChildActualId }, - }); - if (!checkId) { - throw new HttpError( - HttpStatusCode.NOT_FOUND, - "ไม่พบข้อมูลยุทธศาสตร์เป้าหมายตามจริงระดับ 1", - ); - } - development.strategyChild1ActualId = checkId.id; - development.strategyChild2ActualId = _null; - development.strategyChild3ActualId = _null; - development.strategyChild4ActualId = _null; - development.strategyChild5ActualId = _null; - break; - } - case 2: { - const checkId = await this.strategyChild2Repository.findOne({ - where: { id: requestBody.strategyChildActualId }, - }); - if (!checkId) { - throw new HttpError( - HttpStatusCode.NOT_FOUND, - "ไม่พบข้อมูลยุทธศาสตร์เป้าหมายตามจริงระดับ 2", - ); - } - development.strategyChild1ActualId = checkId.strategyChild1Id; - development.strategyChild2ActualId = checkId.id; - development.strategyChild3ActualId = _null; - development.strategyChild4ActualId = _null; - development.strategyChild5ActualId = _null; - break; - } - case 3: { - const checkId = await this.strategyChild3Repository.findOne({ - where: { id: requestBody.strategyChildActualId }, - }); - if (!checkId) { - throw new HttpError( - HttpStatusCode.NOT_FOUND, - "ไม่พบข้อมูลยุทธศาสตร์เป้าหมายตามจริงระดับ 3", - ); - } - development.strategyChild1ActualId = checkId.strategyChild1Id; - development.strategyChild2ActualId = checkId.strategyChild2Id; - development.strategyChild3ActualId = checkId.id; - development.strategyChild4ActualId = _null; - development.strategyChild5ActualId = _null; - break; - } - case 4: { - const checkId = await this.strategyChild4Repository.findOne({ - where: { id: requestBody.strategyChildActualId }, - }); - if (!checkId) { - throw new HttpError( - HttpStatusCode.NOT_FOUND, - "ไม่พบข้อมูลยุทธศาสตร์เป้าหมายตามจริงระดับ 4", - ); - } - development.strategyChild1ActualId = checkId.strategyChild1Id; - development.strategyChild2ActualId = checkId.strategyChild2Id; - development.strategyChild3ActualId = checkId.strategyChild3Id; - development.strategyChild4ActualId = checkId.id; - development.strategyChild5ActualId = _null; - break; - } - case 5: { - const checkId = await this.strategyChild5Repository.findOne({ - where: { id: requestBody.strategyChildActualId }, - }); - if (!checkId) { - throw new HttpError( - HttpStatusCode.NOT_FOUND, - "ไม่พบข้อมูลยุทธศาสตร์เป้าหมายตามจริงระดับ 5", - ); - } - development.strategyChild1ActualId = checkId.strategyChild1Id; - development.strategyChild2ActualId = checkId.strategyChild2Id; - development.strategyChild3ActualId = checkId.strategyChild3Id; - development.strategyChild4ActualId = checkId.strategyChild4Id; - development.strategyChild5ActualId = checkId.id; - break; - } - - default: - throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลยุทธศาสตร์เป้าหมายตามจริง"); - } Object.assign(development, requestBody); development.lastUpdateUserId = request.user.sub; development.lastUpdateFullName = request.user.name; @@ -1000,6 +638,197 @@ export class DevelopmentController extends Controller { }), ); } + const _null: any = null; + if ( + requestBody.strategyChildPlannedNode != undefined && + requestBody.strategyChildPlannedNode != null + ) { + switch (requestBody.strategyChildPlannedNode) { + case 1: { + const checkId = await this.strategyChild1Repository.findOne({ + where: { id: requestBody.strategyChildPlannedId }, + }); + if (!checkId) { + throw new HttpError( + HttpStatusCode.NOT_FOUND, + "ไม่พบข้อมูลยุทธศาสตร์เป้าหมายตามแผนระดับ 1", + ); + } + development.strategyChild1PlannedId = checkId.id; + development.strategyChild2ActualId = _null; + development.strategyChild3ActualId = _null; + development.strategyChild4ActualId = _null; + development.strategyChild5ActualId = _null; + break; + } + case 2: { + const checkId = await this.strategyChild2Repository.findOne({ + where: { id: requestBody.strategyChildPlannedId }, + }); + if (!checkId) { + throw new HttpError( + HttpStatusCode.NOT_FOUND, + "ไม่พบข้อมูลยุทธศาสตร์เป้าหมายตามแผนระดับ 2", + ); + } + development.strategyChild1PlannedId = checkId.strategyChild1Id; + development.strategyChild2PlannedId = checkId.id; + development.strategyChild3ActualId = _null; + development.strategyChild4ActualId = _null; + development.strategyChild5ActualId = _null; + break; + } + case 3: { + const checkId = await this.strategyChild3Repository.findOne({ + where: { id: requestBody.strategyChildPlannedId }, + }); + if (!checkId) { + throw new HttpError( + HttpStatusCode.NOT_FOUND, + "ไม่พบข้อมูลยุทธศาสตร์เป้าหมายตามแผนระดับ 2", + ); + } + development.strategyChild1PlannedId = checkId.strategyChild1Id; + development.strategyChild2PlannedId = checkId.strategyChild2Id; + development.strategyChild3PlannedId = checkId.id; + development.strategyChild4ActualId = _null; + development.strategyChild5ActualId = _null; + break; + } + case 4: { + const checkId = await this.strategyChild4Repository.findOne({ + where: { id: requestBody.strategyChildPlannedId }, + }); + if (!checkId) { + throw new HttpError( + HttpStatusCode.NOT_FOUND, + "ไม่พบข้อมูลยุทธศาสตร์เป้าหมายตามแผนระดับ 3", + ); + } + development.strategyChild1PlannedId = checkId.strategyChild1Id; + development.strategyChild2PlannedId = checkId.strategyChild2Id; + development.strategyChild3PlannedId = checkId.strategyChild3Id; + development.strategyChild4PlannedId = checkId.id; + development.strategyChild5ActualId = _null; + break; + } + case 5: { + const checkId = await this.strategyChild5Repository.findOne({ + where: { id: requestBody.strategyChildPlannedId }, + }); + if (!checkId) { + throw new HttpError( + HttpStatusCode.NOT_FOUND, + "ไม่พบข้อมูลยุทธศาสตร์เป้าหมายตามแผนระดับ 2", + ); + } + development.strategyChild1PlannedId = checkId.strategyChild1Id; + development.strategyChild2PlannedId = checkId.strategyChild2Id; + development.strategyChild3PlannedId = checkId.strategyChild3Id; + development.strategyChild4PlannedId = checkId.strategyChild4Id; + development.strategyChild5PlannedId = checkId.id; + break; + } + + default: + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลยุทธศาสตร์เป้าหมายตามแผน"); + } + } + if ( + requestBody.strategyChildActualNode != undefined && + requestBody.strategyChildActualNode != null + ) { + switch (requestBody.strategyChildActualNode) { + case 1: { + const checkId = await this.strategyChild1Repository.findOne({ + where: { id: requestBody.strategyChildActualId }, + }); + if (!checkId) { + throw new HttpError( + HttpStatusCode.NOT_FOUND, + "ไม่พบข้อมูลยุทธศาสตร์เป้าหมายตามจริงระดับ 1", + ); + } + development.strategyChild1ActualId = checkId.id; + development.strategyChild2ActualId = _null; + development.strategyChild3ActualId = _null; + development.strategyChild4ActualId = _null; + development.strategyChild5ActualId = _null; + break; + } + case 2: { + const checkId = await this.strategyChild2Repository.findOne({ + where: { id: requestBody.strategyChildActualId }, + }); + if (!checkId) { + throw new HttpError( + HttpStatusCode.NOT_FOUND, + "ไม่พบข้อมูลยุทธศาสตร์เป้าหมายตามจริงระดับ 2", + ); + } + development.strategyChild1ActualId = checkId.strategyChild1Id; + development.strategyChild2ActualId = checkId.id; + development.strategyChild3ActualId = _null; + development.strategyChild4ActualId = _null; + development.strategyChild5ActualId = _null; + break; + } + case 3: { + const checkId = await this.strategyChild3Repository.findOne({ + where: { id: requestBody.strategyChildActualId }, + }); + if (!checkId) { + throw new HttpError( + HttpStatusCode.NOT_FOUND, + "ไม่พบข้อมูลยุทธศาสตร์เป้าหมายตามจริงระดับ 3", + ); + } + development.strategyChild1ActualId = checkId.strategyChild1Id; + development.strategyChild2ActualId = checkId.strategyChild2Id; + development.strategyChild3ActualId = checkId.id; + development.strategyChild4ActualId = _null; + development.strategyChild5ActualId = _null; + break; + } + case 4: { + const checkId = await this.strategyChild4Repository.findOne({ + where: { id: requestBody.strategyChildActualId }, + }); + if (!checkId) { + throw new HttpError( + HttpStatusCode.NOT_FOUND, + "ไม่พบข้อมูลยุทธศาสตร์เป้าหมายตามจริงระดับ 4", + ); + } + development.strategyChild1ActualId = checkId.strategyChild1Id; + development.strategyChild2ActualId = checkId.strategyChild2Id; + development.strategyChild3ActualId = checkId.strategyChild3Id; + development.strategyChild4ActualId = checkId.id; + development.strategyChild5ActualId = _null; + break; + } + case 5: { + const checkId = await this.strategyChild5Repository.findOne({ + where: { id: requestBody.strategyChildActualId }, + }); + if (!checkId) { + throw new HttpError( + HttpStatusCode.NOT_FOUND, + "ไม่พบข้อมูลยุทธศาสตร์เป้าหมายตามจริงระดับ 5", + ); + } + development.strategyChild1ActualId = checkId.strategyChild1Id; + development.strategyChild2ActualId = checkId.strategyChild2Id; + development.strategyChild3ActualId = checkId.strategyChild3Id; + development.strategyChild4ActualId = checkId.strategyChild4Id; + development.strategyChild5ActualId = checkId.id; + break; + } + + default: + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลยุทธศาสตร์เป้าหมายตามจริง"); + } + } return new HttpSuccess(development.id); } @@ -1361,16 +1190,6 @@ export class DevelopmentController extends Controller { "rootId", "orgRootShortName", "orgRevisionId", - "strategyChild1Planned", - "strategyChild2Planned", - "strategyChild3Planned", - "strategyChild4Planned", - "strategyChild5Planned", - "strategyChild1Actual", - "strategyChild2Actual", - "strategyChild3Actual", - "strategyChild4Actual", - "strategyChild5Actual", ], }); if (!getDevelopment) { @@ -1456,6 +1275,7 @@ export class DevelopmentController extends Controller { .map((x) => ({ groupTarget: x.groupTarget, groupTargetSub: x.groupTargetSub, + type: x.type, position: x.plannedGoalPositions.map((y) => ({ position: y.position, posTypeId: y.posTypePlannedId, @@ -1509,6 +1329,16 @@ export class DevelopmentController extends Controller { developmentProjectTechniqueActuals: getDevelopment.developmentProjectTechniqueActuals .map((x) => x.name) .sort(), + strategyChild1Planned: getDevelopment.strategyChild1Planned, + strategyChild2Planned: getDevelopment.strategyChild2Planned, + strategyChild3Planned: getDevelopment.strategyChild3Planned, + strategyChild4Planned: getDevelopment.strategyChild4Planned, + strategyChild5Planned: getDevelopment.strategyChild5Planned, + strategyChild1Actual: getDevelopment.strategyChild1Actual, + strategyChild2Actual: getDevelopment.strategyChild2Actual, + strategyChild3Actual: getDevelopment.strategyChild3Actual, + strategyChild4Actual: getDevelopment.strategyChild4Actual, + strategyChild5Actual: getDevelopment.strategyChild5Actual, }; return new HttpSuccess(_getDevelopment); } diff --git a/src/entities/Development.ts b/src/entities/Development.ts index 1fcfc15..efafab1 100644 --- a/src/entities/Development.ts +++ b/src/entities/Development.ts @@ -538,14 +538,6 @@ export class CreateDevelopment { orgRootShortName: string; @Column() orgRevisionId: string; - @Column() - strategyChildPlannedId: string; - @Column() - strategyChildPlannedNode: number; - @Column() - strategyChildActualId: string; - @Column() - strategyChildActualNode: number; } export class UpdateDevelopment1 { @@ -617,6 +609,14 @@ export class UpdateDevelopment3 { projectNigthHoldActual?: number | null; @Column() developmentProjectTechniqueActuals?: string[]; + @Column() + strategyChildPlannedId?: string; + @Column() + strategyChildPlannedNode?: number; + @Column() + strategyChildActualId?: string; + @Column() + strategyChildActualNode?: number; } export class UpdateDevelopment4 { // @Column() diff --git a/src/entities/PlannedGoal.ts b/src/entities/PlannedGoal.ts index ec70ffe..4e070fb 100644 --- a/src/entities/PlannedGoal.ts +++ b/src/entities/PlannedGoal.ts @@ -48,12 +48,12 @@ export class PlannedGoal extends EntityBase { // @JoinColumn({ name: "posLevelPlannedId" }) // posLevelPlanned: PosLevel; - // @Column({ - // nullable: true, - // comment: "ประเภท(กลุ่มอาชีพ คุณสมบัติ)", - // default: null, - // }) - // type: string; + @Column({ + nullable: true, + comment: "ประเภท(กลุ่มอาชีพ คุณสมบัติ)", + default: null, + }) + type: string; @Column({ nullable: true, diff --git a/src/migration/1713341677475-update_table_devhis_add_type.ts b/src/migration/1713341677475-update_table_devhis_add_type.ts new file mode 100644 index 0000000..3446563 --- /dev/null +++ b/src/migration/1713341677475-update_table_devhis_add_type.ts @@ -0,0 +1,14 @@ +import { MigrationInterface, QueryRunner } from "typeorm"; + +export class UpdateTableDevhisAddType1713341677475 implements MigrationInterface { + name = 'UpdateTableDevhisAddType1713341677475' + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`plannedGoal\` ADD \`type\` varchar(255) NULL COMMENT 'ประเภท(กลุ่มอาชีพ คุณสมบัติ)'`); + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`plannedGoal\` DROP COLUMN \`type\``); + } + +} From 9bb920f0d93c2aacbfa1419c3773af8f27883453 Mon Sep 17 00:00:00 2001 From: Kittapath Date: Wed, 17 Apr 2024 15:37:14 +0700 Subject: [PATCH 059/250] no message --- src/controllers/DevelopmentController.ts | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/controllers/DevelopmentController.ts b/src/controllers/DevelopmentController.ts index 1e115b1..6fbafd9 100644 --- a/src/controllers/DevelopmentController.ts +++ b/src/controllers/DevelopmentController.ts @@ -1329,16 +1329,16 @@ export class DevelopmentController extends Controller { developmentProjectTechniqueActuals: getDevelopment.developmentProjectTechniqueActuals .map((x) => x.name) .sort(), - strategyChild1Planned: getDevelopment.strategyChild1Planned, - strategyChild2Planned: getDevelopment.strategyChild2Planned, - strategyChild3Planned: getDevelopment.strategyChild3Planned, - strategyChild4Planned: getDevelopment.strategyChild4Planned, - strategyChild5Planned: getDevelopment.strategyChild5Planned, - strategyChild1Actual: getDevelopment.strategyChild1Actual, - strategyChild2Actual: getDevelopment.strategyChild2Actual, - strategyChild3Actual: getDevelopment.strategyChild3Actual, - strategyChild4Actual: getDevelopment.strategyChild4Actual, - strategyChild5Actual: getDevelopment.strategyChild5Actual, + strategyChild1Planned: getDevelopment.strategyChild1PlannedId, + strategyChild2Planned: getDevelopment.strategyChild2PlannedId, + strategyChild3Planned: getDevelopment.strategyChild3PlannedId, + strategyChild4Planned: getDevelopment.strategyChild4PlannedId, + strategyChild5Planned: getDevelopment.strategyChild5PlannedId, + strategyChild1Actual: getDevelopment.strategyChild1ActualId, + strategyChild2Actual: getDevelopment.strategyChild2ActualId, + strategyChild3Actual: getDevelopment.strategyChild3ActualId, + strategyChild4Actual: getDevelopment.strategyChild4ActualId, + strategyChild5Actual: getDevelopment.strategyChild5ActualId, }; return new HttpSuccess(_getDevelopment); } From 9f6443813c280e287a02df4c2ae7320f7fadd875 Mon Sep 17 00:00:00 2001 From: AdisakKanthawilang Date: Wed, 17 Apr 2024 15:37:27 +0700 Subject: [PATCH 060/250] fix --- src/controllers/StrategyController.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/controllers/StrategyController.ts b/src/controllers/StrategyController.ts index 4f1c702..7d24c27 100644 --- a/src/controllers/StrategyController.ts +++ b/src/controllers/StrategyController.ts @@ -56,6 +56,7 @@ export class StrategyController extends Controller { public async listStrategyChild1() { const listStrategyChild1 = await this.strategy1Repo.find({ relations: ["strategyChild2s", "strategyChild2s.strategyChild3s", "strategyChild2s.strategyChild3s.strategyChild4s", "strategyChild2s.strategyChild3s.strategyChild4s.strategyChild5s"], + order: { createdAt: "ASC" }, }); if (!listStrategyChild1 || listStrategyChild1.length === 0) { From 83f92fc38c8dfeff809e8c76e7ba1ffea92a90ba Mon Sep 17 00:00:00 2001 From: AdisakKanthawilang Date: Wed, 17 Apr 2024 17:04:37 +0700 Subject: [PATCH 061/250] fix bug --- src/controllers/DevelopmentController.ts | 286 ++++++++++++----------- src/entities/Development.ts | 8 +- 2 files changed, 159 insertions(+), 135 deletions(-) diff --git a/src/controllers/DevelopmentController.ts b/src/controllers/DevelopmentController.ts index 6fbafd9..0c8c908 100644 --- a/src/controllers/DevelopmentController.ts +++ b/src/controllers/DevelopmentController.ts @@ -588,7 +588,7 @@ export class DevelopmentController extends Controller { }); development.lastUpdateUserId = request.user.sub; development.lastUpdateFullName = request.user.name; - await this.developmentRepository.save(development); + await this.developmentProjectTypeRepository.remove(development.developmentProjectTypes); await this.developmentProjectTechniquePlannedRepository.remove( development.developmentProjectTechniquePlanneds, @@ -645,88 +645,98 @@ export class DevelopmentController extends Controller { ) { switch (requestBody.strategyChildPlannedNode) { case 1: { - const checkId = await this.strategyChild1Repository.findOne({ - where: { id: requestBody.strategyChildPlannedId }, - }); - if (!checkId) { - throw new HttpError( - HttpStatusCode.NOT_FOUND, - "ไม่พบข้อมูลยุทธศาสตร์เป้าหมายตามแผนระดับ 1", - ); + if (requestBody.strategyChildPlannedId) { + const checkId = await this.strategyChild1Repository.findOne({ + where: { id: requestBody.strategyChildPlannedId }, + }); + if (!checkId) { + throw new HttpError( + HttpStatusCode.NOT_FOUND, + "ไม่พบข้อมูลยุทธศาสตร์เป้าหมายตามแผนระดับ 1", + ); + } + development.strategyChild1PlannedId = checkId.id; + development.strategyChild2PlannedId = _null; + development.strategyChild3PlannedId = _null; + development.strategyChild4PlannedId = _null; + development.strategyChild5PlannedId = _null; } - development.strategyChild1PlannedId = checkId.id; - development.strategyChild2ActualId = _null; - development.strategyChild3ActualId = _null; - development.strategyChild4ActualId = _null; - development.strategyChild5ActualId = _null; break; } case 2: { - const checkId = await this.strategyChild2Repository.findOne({ - where: { id: requestBody.strategyChildPlannedId }, - }); - if (!checkId) { - throw new HttpError( - HttpStatusCode.NOT_FOUND, - "ไม่พบข้อมูลยุทธศาสตร์เป้าหมายตามแผนระดับ 2", - ); + if (requestBody.strategyChildPlannedId) { + const checkId = await this.strategyChild2Repository.findOne({ + where: { id: requestBody.strategyChildPlannedId }, + }); + if (!checkId) { + throw new HttpError( + HttpStatusCode.NOT_FOUND, + "ไม่พบข้อมูลยุทธศาสตร์เป้าหมายตามแผนระดับ 2", + ); + } + development.strategyChild1PlannedId = checkId.strategyChild1Id; + development.strategyChild2PlannedId = checkId.id; + development.strategyChild3PlannedId = _null; + development.strategyChild4PlannedId = _null; + development.strategyChild5PlannedId = _null; } - development.strategyChild1PlannedId = checkId.strategyChild1Id; - development.strategyChild2PlannedId = checkId.id; - development.strategyChild3ActualId = _null; - development.strategyChild4ActualId = _null; - development.strategyChild5ActualId = _null; break; } case 3: { - const checkId = await this.strategyChild3Repository.findOne({ - where: { id: requestBody.strategyChildPlannedId }, - }); - if (!checkId) { - throw new HttpError( - HttpStatusCode.NOT_FOUND, - "ไม่พบข้อมูลยุทธศาสตร์เป้าหมายตามแผนระดับ 2", - ); + if (requestBody.strategyChildPlannedId) { + const checkId = await this.strategyChild3Repository.findOne({ + where: { id: requestBody.strategyChildPlannedId }, + }); + if (!checkId) { + throw new HttpError( + HttpStatusCode.NOT_FOUND, + "ไม่พบข้อมูลยุทธศาสตร์เป้าหมายตามแผนระดับ 2", + ); + } + development.strategyChild1PlannedId = checkId.strategyChild1Id; + development.strategyChild2PlannedId = checkId.strategyChild2Id; + development.strategyChild3PlannedId = checkId.id; + development.strategyChild4PlannedId = _null; + development.strategyChild5PlannedId = _null; } - development.strategyChild1PlannedId = checkId.strategyChild1Id; - development.strategyChild2PlannedId = checkId.strategyChild2Id; - development.strategyChild3PlannedId = checkId.id; - development.strategyChild4ActualId = _null; - development.strategyChild5ActualId = _null; break; } case 4: { - const checkId = await this.strategyChild4Repository.findOne({ - where: { id: requestBody.strategyChildPlannedId }, - }); - if (!checkId) { - throw new HttpError( - HttpStatusCode.NOT_FOUND, - "ไม่พบข้อมูลยุทธศาสตร์เป้าหมายตามแผนระดับ 3", - ); + if (requestBody.strategyChildPlannedId) { + const checkId = await this.strategyChild4Repository.findOne({ + where: { id: requestBody.strategyChildPlannedId }, + }); + if (!checkId) { + throw new HttpError( + HttpStatusCode.NOT_FOUND, + "ไม่พบข้อมูลยุทธศาสตร์เป้าหมายตามแผนระดับ 3", + ); + } + development.strategyChild1PlannedId = checkId.strategyChild1Id; + development.strategyChild2PlannedId = checkId.strategyChild2Id; + development.strategyChild3PlannedId = checkId.strategyChild3Id; + development.strategyChild4PlannedId = checkId.id; + development.strategyChild5PlannedId = _null; } - development.strategyChild1PlannedId = checkId.strategyChild1Id; - development.strategyChild2PlannedId = checkId.strategyChild2Id; - development.strategyChild3PlannedId = checkId.strategyChild3Id; - development.strategyChild4PlannedId = checkId.id; - development.strategyChild5ActualId = _null; break; } case 5: { - const checkId = await this.strategyChild5Repository.findOne({ - where: { id: requestBody.strategyChildPlannedId }, - }); - if (!checkId) { - throw new HttpError( - HttpStatusCode.NOT_FOUND, - "ไม่พบข้อมูลยุทธศาสตร์เป้าหมายตามแผนระดับ 2", - ); + if (requestBody.strategyChildPlannedId) { + const checkId = await this.strategyChild5Repository.findOne({ + where: { id: requestBody.strategyChildPlannedId }, + }); + if (!checkId) { + throw new HttpError( + HttpStatusCode.NOT_FOUND, + "ไม่พบข้อมูลยุทธศาสตร์เป้าหมายตามแผนระดับ 2", + ); + } + development.strategyChild1PlannedId = checkId.strategyChild1Id; + development.strategyChild2PlannedId = checkId.strategyChild2Id; + development.strategyChild3PlannedId = checkId.strategyChild3Id; + development.strategyChild4PlannedId = checkId.strategyChild4Id; + development.strategyChild5PlannedId = checkId.id; } - development.strategyChild1PlannedId = checkId.strategyChild1Id; - development.strategyChild2PlannedId = checkId.strategyChild2Id; - development.strategyChild3PlannedId = checkId.strategyChild3Id; - development.strategyChild4PlannedId = checkId.strategyChild4Id; - development.strategyChild5PlannedId = checkId.id; break; } @@ -740,88 +750,98 @@ export class DevelopmentController extends Controller { ) { switch (requestBody.strategyChildActualNode) { case 1: { - const checkId = await this.strategyChild1Repository.findOne({ - where: { id: requestBody.strategyChildActualId }, - }); - if (!checkId) { - throw new HttpError( - HttpStatusCode.NOT_FOUND, - "ไม่พบข้อมูลยุทธศาสตร์เป้าหมายตามจริงระดับ 1", - ); + if (requestBody.strategyChildActualId) { + const checkId = await this.strategyChild1Repository.findOne({ + where: { id: requestBody.strategyChildActualId }, + }); + if (!checkId) { + throw new HttpError( + HttpStatusCode.NOT_FOUND, + "ไม่พบข้อมูลยุทธศาสตร์เป้าหมายตามจริงระดับ 1", + ); + } + development.strategyChild1ActualId = checkId.id; + development.strategyChild2ActualId = _null; + development.strategyChild3ActualId = _null; + development.strategyChild4ActualId = _null; + development.strategyChild5ActualId = _null; } - development.strategyChild1ActualId = checkId.id; - development.strategyChild2ActualId = _null; - development.strategyChild3ActualId = _null; - development.strategyChild4ActualId = _null; - development.strategyChild5ActualId = _null; break; } case 2: { - const checkId = await this.strategyChild2Repository.findOne({ - where: { id: requestBody.strategyChildActualId }, - }); - if (!checkId) { - throw new HttpError( - HttpStatusCode.NOT_FOUND, - "ไม่พบข้อมูลยุทธศาสตร์เป้าหมายตามจริงระดับ 2", - ); + if (requestBody.strategyChildActualId) { + const checkId = await this.strategyChild2Repository.findOne({ + where: { id: requestBody.strategyChildActualId }, + }); + if (!checkId) { + throw new HttpError( + HttpStatusCode.NOT_FOUND, + "ไม่พบข้อมูลยุทธศาสตร์เป้าหมายตามจริงระดับ 2", + ); + } + development.strategyChild1ActualId = checkId.strategyChild1Id; + development.strategyChild2ActualId = checkId.id; + development.strategyChild3ActualId = _null; + development.strategyChild4ActualId = _null; + development.strategyChild5ActualId = _null; } - development.strategyChild1ActualId = checkId.strategyChild1Id; - development.strategyChild2ActualId = checkId.id; - development.strategyChild3ActualId = _null; - development.strategyChild4ActualId = _null; - development.strategyChild5ActualId = _null; break; } case 3: { - const checkId = await this.strategyChild3Repository.findOne({ - where: { id: requestBody.strategyChildActualId }, - }); - if (!checkId) { - throw new HttpError( - HttpStatusCode.NOT_FOUND, - "ไม่พบข้อมูลยุทธศาสตร์เป้าหมายตามจริงระดับ 3", - ); + if (requestBody.strategyChildActualId) { + const checkId = await this.strategyChild3Repository.findOne({ + where: { id: requestBody.strategyChildActualId }, + }); + if (!checkId) { + throw new HttpError( + HttpStatusCode.NOT_FOUND, + "ไม่พบข้อมูลยุทธศาสตร์เป้าหมายตามจริงระดับ 3", + ); + } + development.strategyChild1ActualId = checkId.strategyChild1Id; + development.strategyChild2ActualId = checkId.strategyChild2Id; + development.strategyChild3ActualId = checkId.id; + development.strategyChild4ActualId = _null; + development.strategyChild5ActualId = _null; } - development.strategyChild1ActualId = checkId.strategyChild1Id; - development.strategyChild2ActualId = checkId.strategyChild2Id; - development.strategyChild3ActualId = checkId.id; - development.strategyChild4ActualId = _null; - development.strategyChild5ActualId = _null; break; } case 4: { - const checkId = await this.strategyChild4Repository.findOne({ - where: { id: requestBody.strategyChildActualId }, - }); - if (!checkId) { - throw new HttpError( - HttpStatusCode.NOT_FOUND, - "ไม่พบข้อมูลยุทธศาสตร์เป้าหมายตามจริงระดับ 4", - ); + if (requestBody.strategyChildActualId) { + const checkId = await this.strategyChild4Repository.findOne({ + where: { id: requestBody.strategyChildActualId }, + }); + if (!checkId) { + throw new HttpError( + HttpStatusCode.NOT_FOUND, + "ไม่พบข้อมูลยุทธศาสตร์เป้าหมายตามจริงระดับ 4", + ); + } + development.strategyChild1ActualId = checkId.strategyChild1Id; + development.strategyChild2ActualId = checkId.strategyChild2Id; + development.strategyChild3ActualId = checkId.strategyChild3Id; + development.strategyChild4ActualId = checkId.id; + development.strategyChild5ActualId = _null; } - development.strategyChild1ActualId = checkId.strategyChild1Id; - development.strategyChild2ActualId = checkId.strategyChild2Id; - development.strategyChild3ActualId = checkId.strategyChild3Id; - development.strategyChild4ActualId = checkId.id; - development.strategyChild5ActualId = _null; break; } case 5: { - const checkId = await this.strategyChild5Repository.findOne({ - where: { id: requestBody.strategyChildActualId }, - }); - if (!checkId) { - throw new HttpError( - HttpStatusCode.NOT_FOUND, - "ไม่พบข้อมูลยุทธศาสตร์เป้าหมายตามจริงระดับ 5", - ); + if (requestBody.strategyChildActualId) { + const checkId = await this.strategyChild5Repository.findOne({ + where: { id: requestBody.strategyChildActualId }, + }); + if (!checkId) { + throw new HttpError( + HttpStatusCode.NOT_FOUND, + "ไม่พบข้อมูลยุทธศาสตร์เป้าหมายตามจริงระดับ 5", + ); + } + development.strategyChild1ActualId = checkId.strategyChild1Id; + development.strategyChild2ActualId = checkId.strategyChild2Id; + development.strategyChild3ActualId = checkId.strategyChild3Id; + development.strategyChild4ActualId = checkId.strategyChild4Id; + development.strategyChild5ActualId = checkId.id; } - development.strategyChild1ActualId = checkId.strategyChild1Id; - development.strategyChild2ActualId = checkId.strategyChild2Id; - development.strategyChild3ActualId = checkId.strategyChild3Id; - development.strategyChild4ActualId = checkId.strategyChild4Id; - development.strategyChild5ActualId = checkId.id; break; } @@ -829,6 +849,7 @@ export class DevelopmentController extends Controller { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลยุทธศาสตร์เป้าหมายตามจริง"); } } + await this.developmentRepository.save(development); return new HttpSuccess(development.id); } @@ -1253,6 +1274,7 @@ export class DevelopmentController extends Controller { ), ) .map((x) => ({ + id: x.id, groupTarget: x.groupTarget, groupTargetSub: x.groupTargetSub, position: x.position, @@ -1273,10 +1295,12 @@ export class DevelopmentController extends Controller { ), ) .map((x) => ({ + id: x.id, groupTarget: x.groupTarget, groupTargetSub: x.groupTargetSub, type: x.type, position: x.plannedGoalPositions.map((y) => ({ + id: y.id, position: y.position, posTypeId: y.posTypePlannedId, posType: y.posTypePlanned == null ? null : y.posTypePlanned.posTypeName, diff --git a/src/entities/Development.ts b/src/entities/Development.ts index efafab1..898b86a 100644 --- a/src/entities/Development.ts +++ b/src/entities/Development.ts @@ -610,13 +610,13 @@ export class UpdateDevelopment3 { @Column() developmentProjectTechniqueActuals?: string[]; @Column() - strategyChildPlannedId?: string; + strategyChildPlannedId?: string | null; @Column() - strategyChildPlannedNode?: number; + strategyChildPlannedNode?: number | null; @Column() - strategyChildActualId?: string; + strategyChildActualId?: string | null; @Column() - strategyChildActualNode?: number; + strategyChildActualNode?: number | null; } export class UpdateDevelopment4 { // @Column() From d9c98f4f255b11f43554bdb096592d310f86f21e Mon Sep 17 00:00:00 2001 From: Kittapath Date: Wed, 17 Apr 2024 17:31:07 +0700 Subject: [PATCH 062/250] no message --- src/controllers/DevelopmentController.ts | 2 +- .../DevelopmentEmployeeHistoryController.ts | 89 ++++++++++++----- .../DevelopmentHistoryController.ts | 98 +++++++++++++------ .../DevelopmentScholarshipController.ts | 4 +- src/entities/DevelopmentHistory.ts | 7 ++ src/entities/DevelopmentScholarship.ts | 9 ++ ...13347839774-update_table_devhis_add_org.ts | 16 +++ 7 files changed, 169 insertions(+), 56 deletions(-) create mode 100644 src/migration/1713347839774-update_table_devhis_add_org.ts diff --git a/src/controllers/DevelopmentController.ts b/src/controllers/DevelopmentController.ts index 6fbafd9..b1f71a4 100644 --- a/src/controllers/DevelopmentController.ts +++ b/src/controllers/DevelopmentController.ts @@ -1469,7 +1469,7 @@ export class DevelopmentController extends Controller { ? item.employeePosLevel.posLevelName : null, posExecutive: item.posExecutive, - org: item.root, + org: item.org, trainingDays: item.trainingDays, commandNumber: item.order, commandDate: item.dateOrder, diff --git a/src/controllers/DevelopmentEmployeeHistoryController.ts b/src/controllers/DevelopmentEmployeeHistoryController.ts index 48ccdfd..8c587ef 100644 --- a/src/controllers/DevelopmentEmployeeHistoryController.ts +++ b/src/controllers/DevelopmentEmployeeHistoryController.ts @@ -35,6 +35,34 @@ export class DevelopmentEmployeeHistoryController extends Controller { private posTypeRepository = AppDataSource.getRepository(EmployeePosType); private posLevelRepository = AppDataSource.getRepository(EmployeePosLevel); + /** + * API list หน่วยงาน + * + * @summary DEV_00 - list หน่วยงาน # + * + */ + @Get("org/{year}") + async GetOrgDevelopemt(@Path() year: number) { + const type = "EMPLOYEE"; + const getOrg = await this.developmentHistoryRepository + .createQueryBuilder("developmentHistory") + .leftJoinAndSelect("developmentHistory.development", "development") + .andWhere("developmentHistory.root IS NOT NULL") + .andWhere(year > 0 ? "development.year LIKE :year" : "1=1", { + year: `${year.toString()}`, + }) + .andWhere("developmentHistory.type LIKE :type", { + type: `${type}`, + }) + .select("developmentHistory.root") + .groupBy("developmentHistory.root") + .getRawMany(); + if (getOrg.length > 0) { + return new HttpSuccess(getOrg.map((x) => x.developmentHistory_root)); + } + return new HttpSuccess(getOrg); + } + /** * API เพิ่มประวัติการฝึกอบรม/ดูงาน * @@ -187,12 +215,16 @@ export class DevelopmentEmployeeHistoryController extends Controller { * @summary DEV_009 - รายการประวัติการฝึกอบรม/ดูงาน #9 * */ - @Get() + @Post("filter") async GetDevelopmentHistoryLists( - @Query("page") page: number = 1, - @Query("pageSize") pageSize: number = 10, - @Query("keyword") keyword?: string, - @Query("year") year?: number, + @Body() + body: { + page: number; + pageSize: number; + keyword?: string; + year?: number; + root: string | null; + }, ) { const type = "EMPLOYEE"; const [development, total] = await AppDataSource.getRepository(DevelopmentHistory) @@ -201,77 +233,84 @@ export class DevelopmentEmployeeHistoryController extends Controller { .leftJoinAndSelect("developmentHistory.employeePosLevel", "employeePosLevel") .leftJoinAndSelect("developmentHistory.employeePosType", "employeePosType") .andWhere( - year != 0 && year != null && year != undefined ? "development.year = :year" : "1=1", - { year: year }, + body.year != 0 && body.year != null && body.year != undefined + ? "development.year = :year" + : "1=1", + { year: body.year }, ) + .andWhere(body.root != null ? "developmentHistory.root = :root" : "1=1", { root: body.root }) .andWhere("developmentHistory.type = :type", { type: type }) .andWhere( new Brackets((qb) => { qb.where( - keyword != null && keyword != "" ? "developmentHistory.prefix LIKE :keyword" : "1=1", + body.keyword != null && body.keyword != "" + ? "developmentHistory.prefix LIKE :keyword" + : "1=1", { - keyword: `%${keyword}%`, + keyword: `%${body.keyword}%`, }, ) .orWhere( - keyword != null && keyword != "" + body.keyword != null && body.keyword != "" ? "developmentHistory.firstName LIKE :keyword" : "1=1", { - keyword: `%${keyword}%`, + keyword: `%${body.keyword}%`, }, ) .orWhere( - keyword != null && keyword != "" + body.keyword != null && body.keyword != "" ? "developmentHistory.lastName LIKE :keyword" : "1=1", { - keyword: `%${keyword}%`, + keyword: `%${body.keyword}%`, }, ) .orWhere( - keyword != null && keyword != "" + body.keyword != null && body.keyword != "" ? "developmentHistory.position LIKE :keyword" : "1=1", { - keyword: `%${keyword}%`, + keyword: `%${body.keyword}%`, }, ) .orWhere( - keyword != null && keyword != "" + body.keyword != null && body.keyword != "" ? "developmentHistory.position LIKE :keyword" : "1=1", { - keyword: `%${keyword}%`, + keyword: `%${body.keyword}%`, }, ) .orWhere( - keyword != null && keyword != "" ? "development.projectName LIKE :keyword" : "1=1", + body.keyword != null && body.keyword != "" + ? "development.projectName LIKE :keyword" + : "1=1", { - keyword: `%${keyword}%`, + keyword: `%${body.keyword}%`, }, ) .orWhere( - keyword != null && keyword != "" + body.keyword != null && body.keyword != "" ? "employeePosType.posTypeName LIKE :keyword" : "1=1", { - keyword: `%${keyword}%`, + keyword: `%${body.keyword}%`, }, ) .orWhere( - keyword != null && keyword != "" + body.keyword != null && body.keyword != "" ? "employeePosLevel.posLevelName LIKE :keyword" : "1=1", { - keyword: `%${keyword}%`, + keyword: `%${body.keyword}%`, }, ); }), ) .orderBy("developmentHistory.createdAt", "DESC") - .skip((page - 1) * pageSize) - .take(pageSize) + .skip((body.page - 1) * body.pageSize) + .take(body.pageSize) .getManyAndCount(); const formattedData = development.map((item) => ({ diff --git a/src/controllers/DevelopmentHistoryController.ts b/src/controllers/DevelopmentHistoryController.ts index 9f1fd7a..476c201 100644 --- a/src/controllers/DevelopmentHistoryController.ts +++ b/src/controllers/DevelopmentHistoryController.ts @@ -35,6 +35,34 @@ export class DevelopmentOfficerHistoryController extends Controller { private posTypeRepository = AppDataSource.getRepository(PosType); private posLevelRepository = AppDataSource.getRepository(PosLevel); + /** + * API list หน่วยงาน + * + * @summary DEV_00 - list หน่วยงาน # + * + */ + @Get("org/{year}") + async GetOrgDevelopemt(@Path() year: number) { + const type = "OFFICER"; + const getOrg = await this.developmentHistoryRepository + .createQueryBuilder("developmentHistory") + .leftJoinAndSelect("developmentHistory.development", "development") + .andWhere("developmentHistory.root IS NOT NULL") + .andWhere(year > 0 ? "development.year LIKE :year" : "1=1", { + year: `${year.toString()}`, + }) + .andWhere("developmentHistory.type LIKE :type", { + type: `${type}`, + }) + .select("developmentHistory.root") + .groupBy("developmentHistory.root") + .getRawMany(); + if (getOrg.length > 0) { + return new HttpSuccess(getOrg.map((x) => x.developmentHistory_root)); + } + return new HttpSuccess(getOrg); + } + /** * API เพิ่มประวัติการฝึกอบรม/ดูงาน * @@ -179,13 +207,16 @@ export class DevelopmentOfficerHistoryController extends Controller { * @summary DEV_009 - รายการประวัติการฝึกอบรม/ดูงาน #9 * */ - @Get() + @Post("filter") async GetDevelopmentHistoryLists( - @Query("page") page: number = 1, - @Query("pageSize") pageSize: number = 10, - @Query("keyword") keyword?: string, - @Query("year") year?: number, - @Query("root") root?: number, + @Body() + body: { + page: number; + pageSize: number; + keyword?: string; + year?: number; + root: string | null; + }, ) { const type = "OFFICER"; const [development, total] = await AppDataSource.getRepository(DevelopmentHistory) @@ -194,76 +225,87 @@ export class DevelopmentOfficerHistoryController extends Controller { .leftJoinAndSelect("developmentHistory.posLevel", "posLevel") .leftJoinAndSelect("developmentHistory.posType", "posType") .andWhere( - year != 0 && year != null && year != undefined ? "development.year = :year" : "1=1", - { year: year }, + body.year != 0 && body.year != null && body.year != undefined + ? "development.year = :year" + : "1=1", + { year: body.year }, ) - .andWhere(root != null && root != undefined ? "development.root = :root" : "1=1", { - root: root, + .andWhere(body.root != null && body.root != undefined ? "development.root = :root" : "1=1", { + root: body.root, }) + .andWhere(body.root != null ? "developmentHistory.root = :root" : "1=1", { root: body.root }) .andWhere("developmentHistory.type = :type", { type: type }) .andWhere( new Brackets((qb) => { qb.where( - keyword != null && keyword != "" ? "developmentHistory.prefix LIKE :keyword" : "1=1", + body.keyword != null && body.keyword != "" + ? "developmentHistory.prefix LIKE :keyword" + : "1=1", { - keyword: `%${keyword}%`, + keyword: `%${body.keyword}%`, }, ) .orWhere( - keyword != null && keyword != "" + body.keyword != null && body.keyword != "" ? "developmentHistory.firstName LIKE :keyword" : "1=1", { - keyword: `%${keyword}%`, + keyword: `%${body.keyword}%`, }, ) .orWhere( - keyword != null && keyword != "" + body.keyword != null && body.keyword != "" ? "developmentHistory.lastName LIKE :keyword" : "1=1", { - keyword: `%${keyword}%`, + keyword: `%${body.keyword}%`, }, ) .orWhere( - keyword != null && keyword != "" + body.keyword != null && body.keyword != "" ? "developmentHistory.position LIKE :keyword" : "1=1", { - keyword: `%${keyword}%`, + keyword: `%${body.keyword}%`, }, ) .orWhere( - keyword != null && keyword != "" + body.keyword != null && body.keyword != "" ? "developmentHistory.position LIKE :keyword" : "1=1", { - keyword: `%${keyword}%`, + keyword: `%${body.keyword}%`, }, ) .orWhere( - keyword != null && keyword != "" ? "development.projectName LIKE :keyword" : "1=1", + body.keyword != null && body.keyword != "" + ? "development.projectName LIKE :keyword" + : "1=1", { - keyword: `%${keyword}%`, + keyword: `%${body.keyword}%`, }, ) .orWhere( - keyword != null && keyword != "" ? "posType.posTypeName LIKE :keyword" : "1=1", + body.keyword != null && body.keyword != "" + ? "posType.posTypeName LIKE :keyword" + : "1=1", { - keyword: `%${keyword}%`, + keyword: `%${body.keyword}%`, }, ) .orWhere( - keyword != null && keyword != "" ? "posLevel.posLevelName LIKE :keyword" : "1=1", + body.keyword != null && body.keyword != "" + ? "posLevel.posLevelName LIKE :keyword" + : "1=1", { - keyword: `%${keyword}%`, + keyword: `%${body.keyword}%`, }, ); }), ) .orderBy("developmentHistory.createdAt", "DESC") - .skip((page - 1) * pageSize) - .take(pageSize) + .skip((body.page - 1) * body.pageSize) + .take(body.pageSize) .getManyAndCount(); const formattedData = development.map((item) => ({ id: item.id, diff --git a/src/controllers/DevelopmentScholarshipController.ts b/src/controllers/DevelopmentScholarshipController.ts index 830dced..c85f7a4 100644 --- a/src/controllers/DevelopmentScholarshipController.ts +++ b/src/controllers/DevelopmentScholarshipController.ts @@ -238,7 +238,7 @@ export class DevelopmentScholarshipController extends Controller { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลทุนการศึกษา/ฝึกอบรมนี้"); } const formattedData = { - root: getDevelopment.root ? getDevelopment.root : null, + org: getDevelopment.org ? getDevelopment.org : null, rank: getDevelopment.rank ? getDevelopment.rank : null, prefix: getDevelopment.prefix ? getDevelopment.prefix : null, firstName: getDevelopment.firstName ? getDevelopment.firstName : null, @@ -367,7 +367,7 @@ export class DevelopmentScholarshipController extends Controller { "isGraduated", "graduatedDate", "graduatedReason", - "root", + "org", ], }); if (!getDevelopment) { diff --git a/src/entities/DevelopmentHistory.ts b/src/entities/DevelopmentHistory.ts index 33f0131..12e9ee5 100644 --- a/src/entities/DevelopmentHistory.ts +++ b/src/entities/DevelopmentHistory.ts @@ -22,6 +22,13 @@ export class DevelopmentHistory extends EntityBase { }) root: string; + @Column({ + nullable: true, + comment: "ชื่อหน่วยงานที่สังกัด", + default: null, + }) + org: string; + @Column({ nullable: true, comment: "ชื่อย่อหน่วยงาน", diff --git a/src/entities/DevelopmentScholarship.ts b/src/entities/DevelopmentScholarship.ts index 0b5a3a8..99b3d23 100644 --- a/src/entities/DevelopmentScholarship.ts +++ b/src/entities/DevelopmentScholarship.ts @@ -19,6 +19,13 @@ export class DevelopmentScholarship extends EntityBase { }) root: string; + @Column({ + nullable: true, + comment: "ชื่อหน่วยงานที่สังกัด", + default: null, + }) + org: string; + @Column({ nullable: true, comment: "ชื่อย่อหน่วยงาน", @@ -529,6 +536,7 @@ export class DevelopmentScholarship extends EntityBase { export class CreateDevelopmentScholarship { rootId: string | null; root: string | null; + org: string | null; orgRootShortName: string | null; orgRevisionId: string | null; profileId: string | null; @@ -588,6 +596,7 @@ export class CreateDevelopmentScholarship { export class UpdateDevelopmentScholarship { rootId: string | null; root: string | null; + org: string | null; orgRootShortName: string | null; orgRevisionId: string | null; profileId: string | null; diff --git a/src/migration/1713347839774-update_table_devhis_add_org.ts b/src/migration/1713347839774-update_table_devhis_add_org.ts new file mode 100644 index 0000000..029260d --- /dev/null +++ b/src/migration/1713347839774-update_table_devhis_add_org.ts @@ -0,0 +1,16 @@ +import { MigrationInterface, QueryRunner } from "typeorm"; + +export class UpdateTableDevhisAddOrg1713347839774 implements MigrationInterface { + name = 'UpdateTableDevhisAddOrg1713347839774' + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`developmentHistory\` ADD \`org\` varchar(255) NULL COMMENT 'ชื่อหน่วยงานที่สังกัด'`); + await queryRunner.query(`ALTER TABLE \`developmentScholarship\` ADD \`org\` varchar(255) NULL COMMENT 'ชื่อหน่วยงานที่สังกัด'`); + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`developmentScholarship\` DROP COLUMN \`org\``); + await queryRunner.query(`ALTER TABLE \`developmentHistory\` DROP COLUMN \`org\``); + } + +} From ddc0e85e3e31218028791bb149b44e40a58a8241 Mon Sep 17 00:00:00 2001 From: Kittapath Date: Wed, 17 Apr 2024 22:34:21 +0700 Subject: [PATCH 063/250] =?UTF-8?q?=E0=B9=82=E0=B8=84=E0=B8=A3=E0=B8=87?= =?UTF-8?q?=E0=B8=81=E0=B8=B2=E0=B8=A3=E0=B9=80=E0=B8=9E=E0=B8=B4=E0=B9=88?= =?UTF-8?q?=E0=B8=A1=E0=B8=84=E0=B9=89=E0=B8=99=E0=B8=AB=E0=B8=B2=E0=B8=AB?= =?UTF-8?q?=E0=B8=99=E0=B9=88=E0=B8=A7=E0=B8=A2=E0=B8=87=E0=B8=B2=E0=B8=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/DevelopmentController.ts | 120 +++++++++++++++--- .../DevelopmentEmployeeHistoryController.ts | 73 +++++------ .../DevelopmentHistoryController.ts | 69 +++++----- src/entities/Development.ts | 98 ++++++++++++-- ...13366798329-update_table_dev_add_child1.ts | 40 ++++++ 5 files changed, 297 insertions(+), 103 deletions(-) create mode 100644 src/migration/1713366798329-update_table_dev_add_child1.ts diff --git a/src/controllers/DevelopmentController.ts b/src/controllers/DevelopmentController.ts index 9133c71..2b61162 100644 --- a/src/controllers/DevelopmentController.ts +++ b/src/controllers/DevelopmentController.ts @@ -110,6 +110,29 @@ export class DevelopmentController extends Controller { ); } const development = Object.assign(new Development(), requestBody); + await new CallAPI() + .PostData(request, "org/find/all", { + node: requestBody.node, + nodeId: requestBody.nodeId, + }) + .then((x) => { + development.root = x.root; + development.rootId = x.rootId; + development.rootShortName = x.rootShortName; + development.child1 = x.child1; + development.child1Id = x.child1Id; + development.child1ShortName = x.child1ShortName; + development.child2 = x.child2; + development.child2Id = x.child2Id; + development.child2ShortName = x.child2ShortName; + development.child3 = x.child3; + development.child3Id = x.child3Id; + development.child3ShortName = x.child3ShortName; + development.child4 = x.child4; + development.child4Id = x.child4Id; + development.child4ShortName = x.child4ShortName; + }) + .catch((x) => {}); development.createdUserId = request.user.sub; development.createdFullName = request.user.name; development.lastUpdateUserId = request.user.sub; @@ -155,6 +178,29 @@ export class DevelopmentController extends Controller { ); } Object.assign(development, requestBody); + await new CallAPI() + .PostData(request, "org/find/all", { + node: requestBody.node, + nodeId: requestBody.nodeId, + }) + .then((x) => { + development.root = x.root; + development.rootId = x.rootId; + development.rootShortName = x.rootShortName; + development.child1 = x.child1; + development.child1Id = x.child1Id; + development.child1ShortName = x.child1ShortName; + development.child2 = x.child2; + development.child2Id = x.child2Id; + development.child2ShortName = x.child2ShortName; + development.child3 = x.child3; + development.child3Id = x.child3Id; + development.child3ShortName = x.child3ShortName; + development.child4 = x.child4; + development.child4Id = x.child4Id; + development.child4ShortName = x.child4ShortName; + }) + .catch((x) => {}); development.lastUpdateUserId = request.user.sub; development.lastUpdateFullName = request.user.name; await this.developmentRepository.save(development); @@ -1122,7 +1168,8 @@ export class DevelopmentController extends Controller { @Query("pageSize") pageSize: number = 10, @Query("year") year: number, @Query("status") status: string, - @Query("root") root?: string | null, + @Query("nodeId") nodeId?: string | null, + @Query("node") node?: number | null, @Query("keyword") keyword?: string, ) { const [development, total] = await AppDataSource.getRepository(Development) @@ -1130,16 +1177,38 @@ export class DevelopmentController extends Controller { .andWhere(year > 0 ? "development.year LIKE :year" : "1=1", { year: `${year.toString()}`, }) - .andWhere(root != undefined && root != null ? "development.root LIKE :root" : "1=1", { - root: `${root}`, - }) + .andWhere( + node != undefined && node != null + ? node == 4 + ? "development.child4Id LIKE :nodeId" + : node == 3 + ? "development.child3Id LIKE :nodeId" + : node == 2 + ? "development.child2Id LIKE :nodeId" + : node == 1 + ? "development.child1Id LIKE :nodeId" + : "development.rootId LIKE :nodeId" + : "1=1", + { + nodeId: `${nodeId}`, + }, + ) .andWhere(status != undefined ? "development.status LIKE :status" : "1=1", { status: `%${status}%`, }) .andWhere(keyword != undefined ? "development.projectName LIKE :keyword" : "1=1", { keyword: `%${keyword}%`, }) - .select(["development.id", "development.projectName", "development.year", "development.root"]) + .select([ + "development.id", + "development.projectName", + "development.year", + "development.root", + "development.child1", + "development.child2", + "development.child3", + "development.child4", + ]) .orderBy("development.year", "DESC") .orderBy("development.createdAt", "DESC") .skip((page - 1) * pageSize) @@ -1201,22 +1270,39 @@ export class DevelopmentController extends Controller { async GetDevelopemtTab1ById(@Path() id: string) { const getDevelopment = await this.developmentRepository.findOne({ where: { id: id }, - select: [ - "id", - "year", - "projectName", - "reason", - "objective", - "root", - "rootId", - "orgRootShortName", - "orgRevisionId", - ], }); if (!getDevelopment) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงการ/หลักสูตรการฝึกอบรมนี้"); } - return new HttpSuccess(getDevelopment); + let node = null; + let nodeId = null; + if (getDevelopment.child4Id != null) { + node = 4; + nodeId = getDevelopment.child4Id; + } else if (getDevelopment.child3Id != null) { + node = 3; + nodeId = getDevelopment.child3Id; + } else if (getDevelopment.child2Id != null) { + node = 2; + nodeId = getDevelopment.child2Id; + } else if (getDevelopment.child1Id != null) { + node = 1; + nodeId = getDevelopment.child1Id; + } else if (getDevelopment.rootId != null) { + node = 0; + nodeId = getDevelopment.rootId; + } + + const formattedData = { + id: getDevelopment.id, + year: getDevelopment.year, + projectName: getDevelopment.projectName, + reason: getDevelopment.reason, + objective: getDevelopment.objective, + node: node, + nodeId: nodeId, + }; + return new HttpSuccess(formattedData); } /** diff --git a/src/controllers/DevelopmentEmployeeHistoryController.ts b/src/controllers/DevelopmentEmployeeHistoryController.ts index 8c587ef..5af4ebf 100644 --- a/src/controllers/DevelopmentEmployeeHistoryController.ts +++ b/src/controllers/DevelopmentEmployeeHistoryController.ts @@ -345,45 +345,40 @@ export class DevelopmentEmployeeHistoryController extends Controller { } const formattedData = { - rank: getDevelopment.rank ? getDevelopment.rank : null, - prefix: getDevelopment.prefix ? getDevelopment.prefix : null, - firstName: getDevelopment.firstName ? getDevelopment.firstName : null, - lastName: getDevelopment.lastName ? getDevelopment.lastName : null, - citizenId: getDevelopment.citizenId ? getDevelopment.citizenId : null, - position: getDevelopment.position ? getDevelopment.position : null, - posLevelId: getDevelopment.employeePosLevelId ? getDevelopment.employeePosLevelId : null, - posLevelName: getDevelopment.employeePosLevel.posLevelName - ? getDevelopment.employeePosLevel.posLevelName - : null, - posTypeId: getDevelopment.employeePosTypeId ? getDevelopment.employeePosTypeId : null, - posTypeName: getDevelopment.employeePosType.posTypeName - ? getDevelopment.employeePosType.posTypeName - : null, - developmentId: getDevelopment.developmentId ? getDevelopment.developmentId : null, - order: getDevelopment.order ? getDevelopment.order : null, - dateOrder: getDevelopment.dateOrder ? getDevelopment.dateOrder : null, - dateHisStart: getDevelopment.dateStart ? getDevelopment.dateStart : null, - dateHisEnd: getDevelopment.dateEnd ? getDevelopment.dateEnd : null, - year: getDevelopment.development.year ? getDevelopment.development.year : null, - projectName: getDevelopment.development.projectName - ? getDevelopment.development.projectName - : null, - dateStart: getDevelopment.development.dateStart ? getDevelopment.development.dateStart : null, - dateEnd: getDevelopment.development.dateEnd ? getDevelopment.development.dateEnd : null, - totalDate: getDevelopment.development.totalDate ? getDevelopment.development.totalDate : null, - addressAcademic: getDevelopment.development.addressAcademic - ? getDevelopment.development.addressAcademic - : null, - topicAcademic: getDevelopment.development.topicAcademic - ? getDevelopment.development.topicAcademic - : null, - dateStudyStart: getDevelopment.development.dateStudyStart - ? getDevelopment.development.dateStudyStart - : null, - dateStudyEnd: getDevelopment.development.dateStudyEnd - ? getDevelopment.development.dateStudyEnd - : null, - org: null, + rank: getDevelopment.rank, + org: getDevelopment.org, + prefix: getDevelopment.prefix, + firstName: getDevelopment.firstName, + lastName: getDevelopment.lastName, + citizenId: getDevelopment.citizenId, + position: getDevelopment.position, + posLevelId: getDevelopment.employeePosLevelId, + posLevelName: + getDevelopment.employeePosLevel != null + ? getDevelopment.employeePosLevel.posLevelName + : null, + posTypeId: getDevelopment.employeePosTypeId, + posTypeName: + getDevelopment.employeePosType != null ? getDevelopment.employeePosType.posTypeName : null, + developmentId: getDevelopment.developmentId, + order: getDevelopment.order, + dateOrder: getDevelopment.dateOrder, + dateHisStart: getDevelopment.dateStart, + dateHisEnd: getDevelopment.dateEnd, + year: getDevelopment.development != null ? getDevelopment.development.year : null, + projectName: + getDevelopment.development != null ? getDevelopment.development.projectName : null, + dateStart: getDevelopment.development != null ? getDevelopment.development.dateStart : null, + dateEnd: getDevelopment.development != null ? getDevelopment.development.dateEnd : null, + totalDate: getDevelopment.development != null ? getDevelopment.development.totalDate : null, + addressAcademic: + getDevelopment.development != null ? getDevelopment.development.addressAcademic : null, + topicAcademic: + getDevelopment.development != null ? getDevelopment.development.topicAcademic : null, + dateStudyStart: + getDevelopment.development != null ? getDevelopment.development.dateStudyStart : null, + dateStudyEnd: + getDevelopment.development != null ? getDevelopment.development.dateStudyEnd : null, }; return new HttpSuccess(formattedData); diff --git a/src/controllers/DevelopmentHistoryController.ts b/src/controllers/DevelopmentHistoryController.ts index 476c201..8ba2d90 100644 --- a/src/controllers/DevelopmentHistoryController.ts +++ b/src/controllers/DevelopmentHistoryController.ts @@ -340,44 +340,37 @@ export class DevelopmentOfficerHistoryController extends Controller { } const formattedData = { - rank: getDevelopment.rank ? getDevelopment.rank : null, - prefix: getDevelopment.prefix ? getDevelopment.prefix : null, - firstName: getDevelopment.firstName ? getDevelopment.firstName : null, - lastName: getDevelopment.lastName ? getDevelopment.lastName : null, - citizenId: getDevelopment.citizenId ? getDevelopment.citizenId : null, - position: getDevelopment.position ? getDevelopment.position : null, - posLevelId: getDevelopment.posLevelId ? getDevelopment.posLevelId : null, - posLevelName: getDevelopment.posLevel.posLevelName - ? getDevelopment.posLevel.posLevelName - : null, - posTypeId: getDevelopment.posTypeId ? getDevelopment.posTypeId : null, - posTypeName: getDevelopment.posType.posTypeName ? getDevelopment.posType.posTypeName : null, - posExecutive: getDevelopment.posExecutive ? getDevelopment.posExecutive : null, - developmentId: getDevelopment.developmentId ? getDevelopment.developmentId : null, - order: getDevelopment.order ? getDevelopment.order : null, - dateOrder: getDevelopment.dateOrder ? getDevelopment.dateOrder : null, - dateHisStart: getDevelopment.dateStart ? getDevelopment.dateStart : null, - dateHisEnd: getDevelopment.dateEnd ? getDevelopment.dateEnd : null, - year: getDevelopment.development.year ? getDevelopment.development.year : null, - projectName: getDevelopment.development.projectName - ? getDevelopment.development.projectName - : null, - dateStart: getDevelopment.development.dateStart ? getDevelopment.development.dateStart : null, - dateEnd: getDevelopment.development.dateEnd ? getDevelopment.development.dateEnd : null, - totalDate: getDevelopment.development.totalDate ? getDevelopment.development.totalDate : null, - addressAcademic: getDevelopment.development.addressAcademic - ? getDevelopment.development.addressAcademic - : null, - topicAcademic: getDevelopment.development.topicAcademic - ? getDevelopment.development.topicAcademic - : null, - dateStudyStart: getDevelopment.development.dateStudyStart - ? getDevelopment.development.dateStudyStart - : null, - dateStudyEnd: getDevelopment.development.dateStudyEnd - ? getDevelopment.development.dateStudyEnd - : null, - org: null, + rank: getDevelopment.rank, + org: getDevelopment.org, + prefix: getDevelopment.prefix, + firstName: getDevelopment.firstName, + lastName: getDevelopment.lastName, + citizenId: getDevelopment.citizenId, + position: getDevelopment.position, + posLevelId: getDevelopment.posLevelId, + posLevelName: getDevelopment.posLevel != null ? getDevelopment.posLevel.posLevelName : null, + posTypeId: getDevelopment.posTypeId, + posTypeName: getDevelopment.posType != null ? getDevelopment.posType.posTypeName : null, + posExecutive: getDevelopment.posExecutive, + developmentId: getDevelopment.developmentId, + order: getDevelopment.order, + dateOrder: getDevelopment.dateOrder, + dateHisStart: getDevelopment.dateStart, + dateHisEnd: getDevelopment.dateEnd, + year: getDevelopment.development != null ? getDevelopment.development.year : null, + projectName: + getDevelopment.development != null ? getDevelopment.development.projectName : null, + dateStart: getDevelopment.development != null ? getDevelopment.development.dateStart : null, + dateEnd: getDevelopment.development != null ? getDevelopment.development.dateEnd : null, + totalDate: getDevelopment.development != null ? getDevelopment.development.totalDate : null, + addressAcademic: + getDevelopment.development != null ? getDevelopment.development.addressAcademic : null, + topicAcademic: + getDevelopment.development != null ? getDevelopment.development.topicAcademic : null, + dateStudyStart: + getDevelopment.development != null ? getDevelopment.development.dateStudyStart : null, + dateStudyEnd: + getDevelopment.development != null ? getDevelopment.development.dateStudyEnd : null, }; return new HttpSuccess(formattedData); diff --git a/src/entities/Development.ts b/src/entities/Development.ts index 898b86a..0a90a6e 100644 --- a/src/entities/Development.ts +++ b/src/entities/Development.ts @@ -38,7 +38,91 @@ export class Development extends EntityBase { comment: "ชื่อย่อหน่วยงาน", default: null, }) - orgRootShortName: string; + rootShortName: string; + + @Column({ + nullable: true, + comment: "id หน่วยงาน child1", + default: null, + }) + child1Id: string; + + @Column({ + nullable: true, + comment: "ชื่อหน่วยงาน child1", + default: null, + }) + child1: string; + + @Column({ + nullable: true, + comment: "ชื่อย่อหน่วยงาน child1", + default: null, + }) + child1ShortName: string; + + @Column({ + nullable: true, + comment: "id หน่วยงาน child2", + default: null, + }) + child2Id: string; + + @Column({ + nullable: true, + comment: "ชื่อหน่วยงาน child2", + default: null, + }) + child2: string; + + @Column({ + nullable: true, + comment: "ชื่อย่อหน่วยงาน child2", + default: null, + }) + child2ShortName: string; + + @Column({ + nullable: true, + comment: "id หน่วยงาน child3", + default: null, + }) + child3Id: string; + + @Column({ + nullable: true, + comment: "ชื่อหน่วยงาน child3", + default: null, + }) + child3: string; + + @Column({ + nullable: true, + comment: "ชื่อย่อหน่วยงาน child3", + default: null, + }) + child3ShortName: string; + + @Column({ + nullable: true, + comment: "id หน่วยงาน child4", + default: null, + }) + child4Id: string; + + @Column({ + nullable: true, + comment: "ชื่อหน่วยงาน child4", + default: null, + }) + child4: string; + + @Column({ + nullable: true, + comment: "ชื่อย่อหน่วยงาน child4", + default: null, + }) + child4ShortName: string; @Column({ nullable: true, @@ -531,11 +615,9 @@ export class CreateDevelopment { @Column() projectName: string; @Column() - root: string; + node: number; @Column() - rootId: string; - @Column() - orgRootShortName: string; + nodeId: string; @Column() orgRevisionId: string; } @@ -550,11 +632,9 @@ export class UpdateDevelopment1 { @Column() objective: string | null; @Column() - root: string; + node: number; @Column() - rootId: string; - @Column() - orgRootShortName: string; + nodeId: string; @Column() orgRevisionId: string; @Column() diff --git a/src/migration/1713366798329-update_table_dev_add_child1.ts b/src/migration/1713366798329-update_table_dev_add_child1.ts new file mode 100644 index 0000000..ff3817b --- /dev/null +++ b/src/migration/1713366798329-update_table_dev_add_child1.ts @@ -0,0 +1,40 @@ +import { MigrationInterface, QueryRunner } from "typeorm"; + +export class UpdateTableDevAddChild11713366798329 implements MigrationInterface { + name = 'UpdateTableDevAddChild11713366798329' + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`orgRootShortName\``); + await queryRunner.query(`ALTER TABLE \`development\` ADD \`rootShortName\` varchar(255) NULL COMMENT 'ชื่อย่อหน่วยงาน'`); + await queryRunner.query(`ALTER TABLE \`development\` ADD \`child1Id\` varchar(255) NULL COMMENT 'id หน่วยงาน child1'`); + await queryRunner.query(`ALTER TABLE \`development\` ADD \`child1\` varchar(255) NULL COMMENT 'ชื่อหน่วยงาน child1'`); + await queryRunner.query(`ALTER TABLE \`development\` ADD \`child1ShortName\` varchar(255) NULL COMMENT 'ชื่อย่อหน่วยงาน child1'`); + await queryRunner.query(`ALTER TABLE \`development\` ADD \`child2Id\` varchar(255) NULL COMMENT 'id หน่วยงาน child2'`); + await queryRunner.query(`ALTER TABLE \`development\` ADD \`child2\` varchar(255) NULL COMMENT 'ชื่อหน่วยงาน child2'`); + await queryRunner.query(`ALTER TABLE \`development\` ADD \`child2ShortName\` varchar(255) NULL COMMENT 'ชื่อย่อหน่วยงาน child2'`); + await queryRunner.query(`ALTER TABLE \`development\` ADD \`child3Id\` varchar(255) NULL COMMENT 'id หน่วยงาน child3'`); + await queryRunner.query(`ALTER TABLE \`development\` ADD \`child3\` varchar(255) NULL COMMENT 'ชื่อหน่วยงาน child3'`); + await queryRunner.query(`ALTER TABLE \`development\` ADD \`child3ShortName\` varchar(255) NULL COMMENT 'ชื่อย่อหน่วยงาน child3'`); + await queryRunner.query(`ALTER TABLE \`development\` ADD \`child4Id\` varchar(255) NULL COMMENT 'id หน่วยงาน child4'`); + await queryRunner.query(`ALTER TABLE \`development\` ADD \`child4\` varchar(255) NULL COMMENT 'ชื่อหน่วยงาน child4'`); + await queryRunner.query(`ALTER TABLE \`development\` ADD \`child4ShortName\` varchar(255) NULL COMMENT 'ชื่อย่อหน่วยงาน child4'`); + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`child4ShortName\``); + await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`child4\``); + await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`child4Id\``); + await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`child3ShortName\``); + await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`child3\``); + await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`child3Id\``); + await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`child2ShortName\``); + await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`child2\``); + await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`child2Id\``); + await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`child1ShortName\``); + await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`child1\``); + await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`child1Id\``); + await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`rootShortName\``); + await queryRunner.query(`ALTER TABLE \`development\` ADD \`orgRootShortName\` varchar(255) NULL COMMENT 'ชื่อย่อหน่วยงาน'`); + } + +} From 4b5c82f74444a646824e5baa1b23fb78e235c024 Mon Sep 17 00:00:00 2001 From: AdisakKanthawilang Date: Thu, 18 Apr 2024 11:47:24 +0700 Subject: [PATCH 064/250] fix function update --- src/entities/Development.ts | 8 -------- 1 file changed, 8 deletions(-) diff --git a/src/entities/Development.ts b/src/entities/Development.ts index 0a90a6e..11d24d2 100644 --- a/src/entities/Development.ts +++ b/src/entities/Development.ts @@ -637,14 +637,6 @@ export class UpdateDevelopment1 { nodeId: string; @Column() orgRevisionId: string; - @Column() - strategyChildPlannedId: string; - @Column() - strategyChildPlannedNode: number; - @Column() - strategyChildActualId: string; - @Column() - strategyChildActualNode: number; } export class UpdateDevelopment2_1 { @Column() From 9b0b51ea3629b068e8c87d498e761a57bfface42 Mon Sep 17 00:00:00 2001 From: Kittapath Date: Thu, 18 Apr 2024 13:51:34 +0700 Subject: [PATCH 065/250] no message --- src/controllers/DevelopmentController.ts | 84 ++++++++++++------------ 1 file changed, 42 insertions(+), 42 deletions(-) diff --git a/src/controllers/DevelopmentController.ts b/src/controllers/DevelopmentController.ts index 2b61162..3cd0bc0 100644 --- a/src/controllers/DevelopmentController.ts +++ b/src/controllers/DevelopmentController.ts @@ -642,48 +642,6 @@ export class DevelopmentController extends Controller { await this.developmentProjectTechniqueActualRepository.remove( development.developmentProjectTechniqueActuals, ); - if (requestBody.developmentProjectTypes != null) { - await Promise.all( - requestBody.developmentProjectTypes.map(async (x) => { - let data = new DevelopmentProjectType(); - data.name = x; - data.createdUserId = request.user.sub; - data.createdFullName = request.user.name; - data.lastUpdateUserId = request.user.sub; - data.lastUpdateFullName = request.user.name; - data.developmentId = development.id; - await this.developmentProjectTypeRepository.save(data); - }), - ); - } - if (requestBody.developmentProjectTechniquePlanneds != null) { - await Promise.all( - requestBody.developmentProjectTechniquePlanneds.map(async (x) => { - let data = new DevelopmentProjectTechniquePlanned(); - data.name = x; - data.createdUserId = request.user.sub; - data.createdFullName = request.user.name; - data.lastUpdateUserId = request.user.sub; - data.lastUpdateFullName = request.user.name; - data.developmentId = development.id; - await this.developmentProjectTechniquePlannedRepository.save(data); - }), - ); - } - if (requestBody.developmentProjectTechniqueActuals != null) { - await Promise.all( - requestBody.developmentProjectTechniqueActuals.map(async (x) => { - let data = new DevelopmentProjectTechniquePlanned(); - data.name = x; - data.createdUserId = request.user.sub; - data.createdFullName = request.user.name; - data.lastUpdateUserId = request.user.sub; - data.lastUpdateFullName = request.user.name; - data.developmentId = development.id; - await this.developmentProjectTechniqueActualRepository.save(data); - }), - ); - } const _null: any = null; if ( requestBody.strategyChildPlannedNode != undefined && @@ -896,6 +854,48 @@ export class DevelopmentController extends Controller { } } await this.developmentRepository.save(development); + if (requestBody.developmentProjectTypes != null) { + await Promise.all( + requestBody.developmentProjectTypes.map(async (x) => { + let data = new DevelopmentProjectType(); + data.name = x; + data.createdUserId = request.user.sub; + data.createdFullName = request.user.name; + data.lastUpdateUserId = request.user.sub; + data.lastUpdateFullName = request.user.name; + data.developmentId = development.id; + await this.developmentProjectTypeRepository.save(data); + }), + ); + } + if (requestBody.developmentProjectTechniquePlanneds != null) { + await Promise.all( + requestBody.developmentProjectTechniquePlanneds.map(async (x) => { + let data = new DevelopmentProjectTechniquePlanned(); + data.name = x; + data.createdUserId = request.user.sub; + data.createdFullName = request.user.name; + data.lastUpdateUserId = request.user.sub; + data.lastUpdateFullName = request.user.name; + data.developmentId = development.id; + await this.developmentProjectTechniquePlannedRepository.save(data); + }), + ); + } + if (requestBody.developmentProjectTechniqueActuals != null) { + await Promise.all( + requestBody.developmentProjectTechniqueActuals.map(async (x) => { + let data = new DevelopmentProjectTechniquePlanned(); + data.name = x; + data.createdUserId = request.user.sub; + data.createdFullName = request.user.name; + data.lastUpdateUserId = request.user.sub; + data.lastUpdateFullName = request.user.name; + data.developmentId = development.id; + await this.developmentProjectTechniqueActualRepository.save(data); + }), + ); + } return new HttpSuccess(development.id); } From e8094726f0d6f3324939ee49ea950e3cc934ae17 Mon Sep 17 00:00:00 2001 From: Kittapath Date: Thu, 18 Apr 2024 14:28:26 +0700 Subject: [PATCH 066/250] =?UTF-8?q?filter=20=E0=B8=9B=E0=B8=A3=E0=B8=B0?= =?UTF-8?q?=E0=B8=A7=E0=B8=B1=E0=B8=95=E0=B8=B4=E0=B8=AB=E0=B8=99=E0=B9=88?= =?UTF-8?q?=E0=B8=A7=E0=B8=A2=E0=B8=87=E0=B8=B2=E0=B8=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/DevelopmentEmployeeHistoryController.ts | 7 ++++++- src/controllers/DevelopmentHistoryController.ts | 9 ++++++--- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/controllers/DevelopmentEmployeeHistoryController.ts b/src/controllers/DevelopmentEmployeeHistoryController.ts index 5af4ebf..6d6dadc 100644 --- a/src/controllers/DevelopmentEmployeeHistoryController.ts +++ b/src/controllers/DevelopmentEmployeeHistoryController.ts @@ -238,7 +238,12 @@ export class DevelopmentEmployeeHistoryController extends Controller { : "1=1", { year: body.year }, ) - .andWhere(body.root != null ? "developmentHistory.root = :root" : "1=1", { root: body.root }) + .andWhere( + body.root != null && body.root != undefined ? "developmentHistory.rootId = :root" : "1=1", + { + root: body.root, + }, + ) .andWhere("developmentHistory.type = :type", { type: type }) .andWhere( new Brackets((qb) => { diff --git a/src/controllers/DevelopmentHistoryController.ts b/src/controllers/DevelopmentHistoryController.ts index 8ba2d90..cee2aee 100644 --- a/src/controllers/DevelopmentHistoryController.ts +++ b/src/controllers/DevelopmentHistoryController.ts @@ -230,9 +230,12 @@ export class DevelopmentOfficerHistoryController extends Controller { : "1=1", { year: body.year }, ) - .andWhere(body.root != null && body.root != undefined ? "development.root = :root" : "1=1", { - root: body.root, - }) + .andWhere( + body.root != null && body.root != undefined ? "development.rootId = :root" : "1=1", + { + root: body.root, + }, + ) .andWhere(body.root != null ? "developmentHistory.root = :root" : "1=1", { root: body.root }) .andWhere("developmentHistory.type = :type", { type: type }) .andWhere( From 1685ad224cb4479abf16eb56fb9c102b23cbd62d Mon Sep 17 00:00:00 2001 From: AdisakKanthawilang Date: Thu, 18 Apr 2024 14:50:49 +0700 Subject: [PATCH 067/250] fix bug --- src/controllers/DevelopmentController.ts | 54 +++++++++++++++++++++++- 1 file changed, 53 insertions(+), 1 deletion(-) diff --git a/src/controllers/DevelopmentController.ts b/src/controllers/DevelopmentController.ts index 3cd0bc0..16d62bd 100644 --- a/src/controllers/DevelopmentController.ts +++ b/src/controllers/DevelopmentController.ts @@ -109,6 +109,7 @@ export class DevelopmentController extends Controller { " มีอยู่ในระบบแล้ว", ); } + const development = Object.assign(new Development(), requestBody); await new CallAPI() .PostData(request, "org/find/all", { @@ -132,11 +133,15 @@ export class DevelopmentController extends Controller { development.child4Id = x.child4Id; development.child4ShortName = x.child4ShortName; }) - .catch((x) => {}); + .catch((error) => { + console.error("Error calling API:", error); + }); + development.createdUserId = request.user.sub; development.createdFullName = request.user.name; development.lastUpdateUserId = request.user.sub; development.lastUpdateFullName = request.user.name; + await this.developmentRepository.save(development); return new HttpSuccess(development.id); } @@ -203,6 +208,53 @@ export class DevelopmentController extends Controller { .catch((x) => {}); development.lastUpdateUserId = request.user.sub; development.lastUpdateFullName = request.user.name; + const _null: any = null; + switch (requestBody.node) { + case 0: { + development.child1 = _null; + development.child1Id = _null; + development.child1ShortName = _null; + development.child2 = _null; + development.child2Id = _null; + development.child2ShortName = _null; + development.child3 = _null; + development.child3Id = _null; + development.child3ShortName = _null; + development.child4 = _null; + development.child4Id = _null; + development.child4ShortName = _null; + break; + } + case 1: { + development.child2 = _null; + development.child2Id = _null; + development.child2ShortName = _null; + development.child3 = _null; + development.child3Id = _null; + development.child3ShortName = _null; + development.child4 = _null; + development.child4Id = _null; + development.child4ShortName = _null; + break; + } + case 2: { + development.child3 = _null; + development.child3Id = _null; + development.child3ShortName = _null; + development.child4 = _null; + development.child4Id = _null; + development.child4ShortName = _null; + break; + } + case 3: { + development.child4 = _null; + development.child4Id = _null; + development.child4ShortName = _null; + break; + } + default: + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงการ/หลักสูตรการฝึกอบรม"); + } await this.developmentRepository.save(development); return new HttpSuccess(development.id); } From 109bea3fc841845278e555108ed9a0b0717fd90c Mon Sep 17 00:00:00 2001 From: Kittapath Date: Thu, 18 Apr 2024 15:57:03 +0700 Subject: [PATCH 068/250] =?UTF-8?q?=E0=B9=81=E0=B8=81=E0=B9=89api=E0=B8=A2?= =?UTF-8?q?=E0=B8=B4=E0=B8=87=E0=B9=84=E0=B8=9B=E0=B8=82=E0=B9=89=E0=B8=B2?= =?UTF-8?q?=E0=B8=87=E0=B8=99=E0=B8=AD=E0=B8=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/DevelopmentController.ts | 12 ++++++------ src/interfaces/call-api.ts | 4 ++-- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/controllers/DevelopmentController.ts b/src/controllers/DevelopmentController.ts index 16d62bd..660ec50 100644 --- a/src/controllers/DevelopmentController.ts +++ b/src/controllers/DevelopmentController.ts @@ -141,7 +141,7 @@ export class DevelopmentController extends Controller { development.createdFullName = request.user.name; development.lastUpdateUserId = request.user.sub; development.lastUpdateFullName = request.user.name; - + await this.developmentRepository.save(development); return new HttpSuccess(development.id); } @@ -247,13 +247,13 @@ export class DevelopmentController extends Controller { break; } case 3: { - development.child4 = _null; - development.child4Id = _null; - development.child4ShortName = _null; + development.child4 = _null; + development.child4Id = _null; + development.child4ShortName = _null; break; } - default: - throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงการ/หลักสูตรการฝึกอบรม"); + default: + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงการ/หลักสูตรการฝึกอบรม"); } await this.developmentRepository.save(development); return new HttpSuccess(development.id); diff --git a/src/interfaces/call-api.ts b/src/interfaces/call-api.ts index 8608230..4cbd1a5 100644 --- a/src/interfaces/call-api.ts +++ b/src/interfaces/call-api.ts @@ -21,7 +21,7 @@ class CallAPI { try { const response = await axios.get(url, { headers: { - Authorization: `Bearer ${token}`, + Authorization: `${token}`, "Content-Type": "application/json", }, }); @@ -37,7 +37,7 @@ class CallAPI { try { const response = await axios.post(url, sendData, { headers: { - Authorization: `Bearer ${token}`, + Authorization: `${token}`, "Content-Type": "application/json", }, }); From a84027415037baca4bfbad69f876f96074d11d63 Mon Sep 17 00:00:00 2001 From: Kittapath Date: Thu, 18 Apr 2024 16:17:37 +0700 Subject: [PATCH 069/250] =?UTF-8?q?=E0=B9=80=E0=B8=9E=E0=B8=B4=E0=B9=88?= =?UTF-8?q?=E0=B8=A1=E0=B8=9F=E0=B8=B4=E0=B8=A7=E0=B8=AB=E0=B8=99=E0=B9=88?= =?UTF-8?q?=E0=B8=A7=E0=B8=A2=E0=B8=87=E0=B8=B2=E0=B8=99=E0=B8=9C=E0=B8=B9?= =?UTF-8?q?=E0=B9=89=E0=B8=84=E0=B9=89=E0=B8=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DevelopmentEmployeeHistoryController.ts | 2 +- .../DevelopmentHistoryController.ts | 9 ++-- .../DevelopmentScholarshipController.ts | 13 ++++++ src/entities/DevelopmentScholarship.ts | 45 +++++++++++++++++++ ...pdate_table_devscholar_add_guarantorOrg.ts | 22 +++++++++ 5 files changed, 84 insertions(+), 7 deletions(-) create mode 100644 src/migration/1713431125506-update_table_devscholar_add_guarantorOrg.ts diff --git a/src/controllers/DevelopmentEmployeeHistoryController.ts b/src/controllers/DevelopmentEmployeeHistoryController.ts index 6d6dadc..9534b7f 100644 --- a/src/controllers/DevelopmentEmployeeHistoryController.ts +++ b/src/controllers/DevelopmentEmployeeHistoryController.ts @@ -239,7 +239,7 @@ export class DevelopmentEmployeeHistoryController extends Controller { { year: body.year }, ) .andWhere( - body.root != null && body.root != undefined ? "developmentHistory.rootId = :root" : "1=1", + body.root != null && body.root != undefined ? "developmentHistory.root = :root" : "1=1", { root: body.root, }, diff --git a/src/controllers/DevelopmentHistoryController.ts b/src/controllers/DevelopmentHistoryController.ts index cee2aee..8ba2d90 100644 --- a/src/controllers/DevelopmentHistoryController.ts +++ b/src/controllers/DevelopmentHistoryController.ts @@ -230,12 +230,9 @@ export class DevelopmentOfficerHistoryController extends Controller { : "1=1", { year: body.year }, ) - .andWhere( - body.root != null && body.root != undefined ? "development.rootId = :root" : "1=1", - { - root: body.root, - }, - ) + .andWhere(body.root != null && body.root != undefined ? "development.root = :root" : "1=1", { + root: body.root, + }) .andWhere(body.root != null ? "developmentHistory.root = :root" : "1=1", { root: body.root }) .andWhere("developmentHistory.type = :type", { type: type }) .andWhere( diff --git a/src/controllers/DevelopmentScholarshipController.ts b/src/controllers/DevelopmentScholarshipController.ts index c85f7a4..9af4a2e 100644 --- a/src/controllers/DevelopmentScholarshipController.ts +++ b/src/controllers/DevelopmentScholarshipController.ts @@ -238,7 +238,11 @@ export class DevelopmentScholarshipController extends Controller { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลทุนการศึกษา/ฝึกอบรมนี้"); } const formattedData = { + rootId: getDevelopment.rootId ? getDevelopment.rootId : null, + root: getDevelopment.root ? getDevelopment.root : null, org: getDevelopment.org ? getDevelopment.org : null, + orgRootShortName: getDevelopment.orgRootShortName ? getDevelopment.orgRootShortName : null, + orgRevisionId: getDevelopment.orgRevisionId ? getDevelopment.orgRevisionId : null, rank: getDevelopment.rank ? getDevelopment.rank : null, prefix: getDevelopment.prefix ? getDevelopment.prefix : null, firstName: getDevelopment.firstName ? getDevelopment.firstName : null, @@ -252,6 +256,15 @@ export class DevelopmentScholarshipController extends Controller { : null, posTypeId: getDevelopment.posTypeId ? getDevelopment.posTypeId : null, posTypeName: getDevelopment.posType?.posTypeName ? getDevelopment.posType?.posTypeName : null, + guarantorRootId: getDevelopment.guarantorRootId ? getDevelopment.guarantorRootId : null, + guarantorRoot: getDevelopment.guarantorRoot ? getDevelopment.guarantorRoot : null, + guarantorOrg: getDevelopment.guarantorOrg ? getDevelopment.guarantorOrg : null, + guarantorOrgRootShortName: getDevelopment.guarantorOrgRootShortName + ? getDevelopment.guarantorOrgRootShortName + : null, + guarantorOrgRevisionId: getDevelopment.guarantorOrgRevisionId + ? getDevelopment.guarantorOrgRevisionId + : null, guarantorRank: getDevelopment.guarantorRank ? getDevelopment.guarantorRank : null, guarantorPrefix: getDevelopment.guarantorPrefix ? getDevelopment.guarantorPrefix : null, guarantorFirstName: getDevelopment.guarantorFirstName diff --git a/src/entities/DevelopmentScholarship.ts b/src/entities/DevelopmentScholarship.ts index 99b3d23..efa05ba 100644 --- a/src/entities/DevelopmentScholarship.ts +++ b/src/entities/DevelopmentScholarship.ts @@ -137,6 +137,41 @@ export class DevelopmentScholarship extends EntityBase { @JoinColumn({ name: "posTypeId" }) posType: PosType; + @Column({ + nullable: true, + comment: "id หน่วยงาน", + default: null, + }) + guarantorRootId: string; + + @Column({ + nullable: true, + comment: "ชื่อหน่วยงาน", + default: null, + }) + guarantorRoot: string; + + @Column({ + nullable: true, + comment: "ชื่อหน่วยงานที่สังกัด", + default: null, + }) + guarantorOrg: string; + + @Column({ + nullable: true, + comment: "ชื่อย่อหน่วยงาน", + default: null, + }) + guarantorOrgRootShortName: string; + + @Column({ + nullable: true, + comment: "id revision", + default: null, + }) + guarantorOrgRevisionId: string; + @Column({ nullable: true, comment: "ยศ(ผู้ค้ำ)", @@ -549,6 +584,11 @@ export class CreateDevelopmentScholarship { posExecutive: string | null; posLevelId: string | null; posTypeId: string | null; + guarantorRootId: string | null; + guarantorRoot: string | null; + guarantorOrg: string | null; + guarantorOrgRootShortName: string | null; + guarantorOrgRevisionId: string | null; guarantorRank?: string | null; guarantorPrefix: string | null; guarantorFirstName: string | null; @@ -609,6 +649,11 @@ export class UpdateDevelopmentScholarship { posExecutive: string | null; posLevelId: string | null; posTypeId: string | null; + guarantorRootId?: string | null; + guarantorRoot?: string | null; + guarantorOrg?: string | null; + guarantorOrgRootShortName?: string | null; + guarantorOrgRevisionId?: string | null; guarantorRank?: string | null; guarantorPrefix: string | null; guarantorFirstName: string | null; diff --git a/src/migration/1713431125506-update_table_devscholar_add_guarantorOrg.ts b/src/migration/1713431125506-update_table_devscholar_add_guarantorOrg.ts new file mode 100644 index 0000000..7d2ff87 --- /dev/null +++ b/src/migration/1713431125506-update_table_devscholar_add_guarantorOrg.ts @@ -0,0 +1,22 @@ +import { MigrationInterface, QueryRunner } from "typeorm"; + +export class UpdateTableDevscholarAddGuarantorOrg1713431125506 implements MigrationInterface { + name = 'UpdateTableDevscholarAddGuarantorOrg1713431125506' + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`developmentScholarship\` ADD \`guarantorRootId\` varchar(255) NULL COMMENT 'id หน่วยงาน'`); + await queryRunner.query(`ALTER TABLE \`developmentScholarship\` ADD \`guarantorRoot\` varchar(255) NULL COMMENT 'ชื่อหน่วยงาน'`); + await queryRunner.query(`ALTER TABLE \`developmentScholarship\` ADD \`guarantorOrg\` varchar(255) NULL COMMENT 'ชื่อหน่วยงานที่สังกัด'`); + await queryRunner.query(`ALTER TABLE \`developmentScholarship\` ADD \`guarantorOrgRootShortName\` varchar(255) NULL COMMENT 'ชื่อย่อหน่วยงาน'`); + await queryRunner.query(`ALTER TABLE \`developmentScholarship\` ADD \`guarantorOrgRevisionId\` varchar(255) NULL COMMENT 'id revision'`); + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`developmentScholarship\` DROP COLUMN \`guarantorOrgRevisionId\``); + await queryRunner.query(`ALTER TABLE \`developmentScholarship\` DROP COLUMN \`guarantorOrgRootShortName\``); + await queryRunner.query(`ALTER TABLE \`developmentScholarship\` DROP COLUMN \`guarantorOrg\``); + await queryRunner.query(`ALTER TABLE \`developmentScholarship\` DROP COLUMN \`guarantorRoot\``); + await queryRunner.query(`ALTER TABLE \`developmentScholarship\` DROP COLUMN \`guarantorRootId\``); + } + +} From 87c7452fa59d14db755dd2e946717aa743b7184e Mon Sep 17 00:00:00 2001 From: Kittapath Date: Fri, 19 Apr 2024 09:28:57 +0700 Subject: [PATCH 070/250] =?UTF-8?q?kpi=20=E0=B9=81=E0=B8=9A=E0=B8=9A?= =?UTF-8?q?=E0=B9=81=E0=B8=9C=E0=B8=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DevelopmentScholarshipController.ts | 34 ++- src/controllers/ReportController.ts | 6 +- src/controllers/StrategyController.ts | 201 +++++++++++++++--- 3 files changed, 194 insertions(+), 47 deletions(-) diff --git a/src/controllers/DevelopmentScholarshipController.ts b/src/controllers/DevelopmentScholarshipController.ts index 9af4a2e..ab59272 100644 --- a/src/controllers/DevelopmentScholarshipController.ts +++ b/src/controllers/DevelopmentScholarshipController.ts @@ -343,18 +343,30 @@ export class DevelopmentScholarshipController extends Controller { * @param {string} profileId profileId ข้าราชการฯที่ได้รับทุนการศึกษา */ @Get("user/{profileId}") - async GetDevelopemtScholarshipUserById(@Path() profileId: string) { - const getDevelopment = await this.developmentScholarshipRepository.find({ - where: { profileId: profileId }, - }); - const formattedData = getDevelopment.map((item) => ({ - id: item.id, - scholarshipYear: item.scholarshipYear, - scholarshipType: item.scholarshipType, - fundType: item.fundType, - })); + async GetDevelopemtScholarshipUserById( + @Path() profileId: string, + @Query("type") type?: string | null, + @Query("year") year?: number | null, + ) { + const getDevelopment = await AppDataSource.getRepository(DevelopmentScholarship) + .createQueryBuilder("developmentScholarship") + .andWhere("developmentScholarship.profileId = :profileId", { profileId: profileId }) + .andWhere( + year !== 0 && year != null && year != undefined + ? "developmentScholarship.scholarshipYear = :scholarshipYear" + : "1=1", + { scholarshipYear: year }, + ) + .andWhere( + type != null && type != undefined + ? "developmentScholarship.scholarshipType = :scholarshipType" + : "1=1", + { scholarshipType: type }, + ) + .select(["id", "scholarshipYear", "scholarshipYear", "scholarshipType", "fundType"]) + .getRawMany(); - return new HttpSuccess(formattedData); + return new HttpSuccess(getDevelopment); } /** diff --git a/src/controllers/ReportController.ts b/src/controllers/ReportController.ts index 29a8c0d..6becec6 100644 --- a/src/controllers/ReportController.ts +++ b/src/controllers/ReportController.ts @@ -251,12 +251,16 @@ export class ReportController extends Controller { firstName: getDevelopment.firstName, lastName: getDevelopment.lastName, position: getDevelopment.position, - root: getDevelopment.root, + org: getDevelopment.org, degreeLevel: getDevelopment.degreeLevel, course: getDevelopment.course, field: getDevelopment.field, studyPlace: getDevelopment.studyPlace, scholarshipType: getDevelopment.scholarshipType, + bookNoDate: + getDevelopment.bookNoDate == null + ? "" + : Extension.ToThaiNumber(Extension.ToThaiFullDate(getDevelopment.bookNoDate)), startDate: getDevelopment.startDate == null ? "" diff --git a/src/controllers/StrategyController.ts b/src/controllers/StrategyController.ts index 7d24c27..1ab6468 100644 --- a/src/controllers/StrategyController.ts +++ b/src/controllers/StrategyController.ts @@ -55,41 +55,50 @@ export class StrategyController extends Controller { @Get() public async listStrategyChild1() { const listStrategyChild1 = await this.strategy1Repo.find({ - relations: ["strategyChild2s", "strategyChild2s.strategyChild3s", "strategyChild2s.strategyChild3s.strategyChild4s", "strategyChild2s.strategyChild3s.strategyChild4s.strategyChild5s"], - order: { createdAt: "ASC" }, - }); - - if (!listStrategyChild1 || listStrategyChild1.length === 0) { - throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลยุทธศาสตร์"); - } - - const formattedData = listStrategyChild1.map(item => ({ - id: item.id, - level: 1, - name: item.strategyChild1Name, - children: item.strategyChild2s.map(child2 => ({ - id: child2.id, - level: 2, - name: child2.strategyChild2Name, - children: child2.strategyChild3s ? child2.strategyChild3s.map(child3 => ({ - id: child3.id, - level: 3, - name: child3.strategyChild3Name, - children: child3.strategyChild4s ? child3.strategyChild4s.map(child4 => ({ - id: child4.id, - level: 4, - name: child4.strategyChild4Name, - children: child4.strategyChild5s ? child4.strategyChild5s.map(child5 => ({ - id: child5.id, - level: 5, - name: child5.strategyChild5Name, - })) : [], - })) : [], - })) : [], - })), - })); - - + relations: [ + "strategyChild2s", + "strategyChild2s.strategyChild3s", + "strategyChild2s.strategyChild3s.strategyChild4s", + "strategyChild2s.strategyChild3s.strategyChild4s.strategyChild5s", + ], + order: { createdAt: "ASC" }, + }); + + if (!listStrategyChild1 || listStrategyChild1.length === 0) { + throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลยุทธศาสตร์"); + } + + const formattedData = listStrategyChild1.map((item) => ({ + id: item.id, + level: 1, + name: item.strategyChild1Name, + children: item.strategyChild2s.map((child2) => ({ + id: child2.id, + level: 2, + name: child2.strategyChild2Name, + children: child2.strategyChild3s + ? child2.strategyChild3s.map((child3) => ({ + id: child3.id, + level: 3, + name: child3.strategyChild3Name, + children: child3.strategyChild4s + ? child3.strategyChild4s.map((child4) => ({ + id: child4.id, + level: 4, + name: child4.strategyChild4Name, + children: child4.strategyChild5s + ? child4.strategyChild5s.map((child5) => ({ + id: child5.id, + level: 5, + name: child5.strategyChild5Name, + })) + : [], + })) + : [], + })) + : [], + })), + })); return new HttpSuccess(formattedData); } @@ -357,4 +366,126 @@ export class StrategyController extends Controller { return new HttpSuccess(); } + + /** + * API เช็ค node detail + * + * @summary เช็ค node detail (ADMIN) + * + */ + @Post("find/all") + async findNodeAllDetail(@Body() requestBody: { strategy: number; strategyId: string }) { + switch (requestBody.strategy) { + case 1: { + const data = await this.strategy1Repo.findOne({ + where: { id: requestBody.strategyId }, + }); + if (data == null) { + throw new HttpError(HttpStatus.NOT_FOUND, "not found rootId."); + } + return new HttpSuccess({ + strategyChild1Id: data.id, + strategyChild1: data.strategyChild1Name, + }); + } + case 2: { + const data = await this.strategy2Repo.findOne({ + where: { id: requestBody.strategyId }, + relations: { + strategyChild1: true, + }, + }); + if (data == null) { + throw new HttpError(HttpStatus.NOT_FOUND, "not found child1."); + } + return new HttpSuccess({ + strategyChild1Id: data.strategyChild1Id, + strategyChild1: + data.strategyChild1 == null ? null : data.strategyChild1.strategyChild1Name, + strategyChild2Id: data.id, + strategyChild2: data.strategyChild2Name, + }); + } + case 3: { + const data = await this.strategy3Repo.findOne({ + where: { id: requestBody.strategyId }, + relations: { + strategyChild1: true, + strategyChild2: true, + }, + }); + if (data == null) { + throw new HttpError(HttpStatus.NOT_FOUND, "not found child2."); + } + return new HttpSuccess({ + strategyChild1Id: data.strategyChild1Id, + strategyChild1: + data.strategyChild1 == null ? null : data.strategyChild1.strategyChild1Name, + strategyChild2Id: data.strategyChild2Id, + strategyChild2: + data.strategyChild2 == null ? null : data.strategyChild2.strategyChild2Name, + strategyChild3Id: data.id, + strategyChild3: data.strategyChild3Name, + }); + } + case 4: { + const data = await this.strategy4Repo.findOne({ + where: { id: requestBody.strategyId }, + relations: { + strategyChild1: true, + strategyChild2: true, + strategyChild3: true, + }, + }); + if (data == null) { + throw new HttpError(HttpStatus.NOT_FOUND, "not found child3."); + } + return new HttpSuccess({ + strategyChild1Id: data.strategyChild1Id, + strategyChild1: + data.strategyChild1 == null ? null : data.strategyChild1.strategyChild1Name, + strategyChild2Id: data.strategyChild2Id, + strategyChild2: + data.strategyChild2 == null ? null : data.strategyChild2.strategyChild2Name, + strategyChild3Id: data.strategyChild3Id, + strategyChild3: + data.strategyChild3 == null ? null : data.strategyChild3.strategyChild3Name, + strategyChild4Id: data.id, + strategyChild4: data.strategyChild4Name, + }); + } + case 5: { + const data = await this.strategy5Repo.findOne({ + where: { id: requestBody.strategyId }, + relations: { + strategyChild1: true, + strategyChild2: true, + strategyChild3: true, + strategyChild4: true, + }, + }); + if (data == null) { + throw new HttpError(HttpStatus.NOT_FOUND, "not found child4."); + } + return new HttpSuccess({ + strategyChild1Id: data.strategyChild1Id, + strategyChild1: + data.strategyChild1 == null ? null : data.strategyChild1.strategyChild1Name, + strategyChild2Id: data.strategyChild2Id, + strategyChild2: + data.strategyChild2 == null ? null : data.strategyChild2.strategyChild2Name, + strategyChild3Id: data.strategyChild3Id, + strategyChild3: + data.strategyChild3 == null ? null : data.strategyChild3.strategyChild3Name, + strategyChild4Id: data.strategyChild4Id, + strategyChild4: + data.strategyChild4 == null ? null : data.strategyChild4.strategyChild4Name, + strategyChild5Id: data.id, + strategyChild5: data.strategyChild5Name, + }); + } + default: + throw new HttpError(HttpStatus.NOT_FOUND, "not found type: " + requestBody.strategy); + } + } } From e1640d210404adac67a9fae3b340c28b430e9476 Mon Sep 17 00:00:00 2001 From: Kittapath Date: Fri, 26 Apr 2024 10:18:20 +0700 Subject: [PATCH 071/250] =?UTF-8?q?=E0=B9=80=E0=B8=9E=E0=B8=B4=E0=B9=88?= =?UTF-8?q?=E0=B8=A1=20node=20id?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/DevelopmentController.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/controllers/DevelopmentController.ts b/src/controllers/DevelopmentController.ts index 660ec50..5ce3fb1 100644 --- a/src/controllers/DevelopmentController.ts +++ b/src/controllers/DevelopmentController.ts @@ -1353,6 +1353,11 @@ export class DevelopmentController extends Controller { objective: getDevelopment.objective, node: node, nodeId: nodeId, + root: getDevelopment.rootId, + child1: getDevelopment.child1Id, + child2: getDevelopment.child2Id, + child3: getDevelopment.child3Id, + child4: getDevelopment.child4Id, }; return new HttpSuccess(formattedData); } From 8fe55d661defcc5cb2a44ff4da59ef215ab641a8 Mon Sep 17 00:00:00 2001 From: AdisakKanthawilang Date: Fri, 26 Apr 2024 16:07:09 +0700 Subject: [PATCH 072/250] add orgRevisionId --- src/controllers/DevelopmentController.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/controllers/DevelopmentController.ts b/src/controllers/DevelopmentController.ts index 660ec50..dd4e4bf 100644 --- a/src/controllers/DevelopmentController.ts +++ b/src/controllers/DevelopmentController.ts @@ -1347,6 +1347,7 @@ export class DevelopmentController extends Controller { const formattedData = { id: getDevelopment.id, + revisionId: getDevelopment.orgRevisionId, year: getDevelopment.year, projectName: getDevelopment.projectName, reason: getDevelopment.reason, From 47c275ef0499c1a012c7d1a061d34e238d4202f7 Mon Sep 17 00:00:00 2001 From: AdisakKanthawilang Date: Mon, 29 Apr 2024 14:51:12 +0700 Subject: [PATCH 073/250] add field year --- src/controllers/DevelopmentEmployeeHistoryController.ts | 1 + src/controllers/DevelopmentHistoryController.ts | 1 + 2 files changed, 2 insertions(+) diff --git a/src/controllers/DevelopmentEmployeeHistoryController.ts b/src/controllers/DevelopmentEmployeeHistoryController.ts index 9534b7f..56dd7fd 100644 --- a/src/controllers/DevelopmentEmployeeHistoryController.ts +++ b/src/controllers/DevelopmentEmployeeHistoryController.ts @@ -323,6 +323,7 @@ export class DevelopmentEmployeeHistoryController extends Controller { citizenId: item.citizenId, fullName: item.prefix + item.firstName + " " + item.lastName, position: item.position, + year: item.development.year, posType: item.employeePosType ? item.employeePosType.posTypeName : null, posLevel: item.employeePosLevel ? item.employeePosLevel.posLevelName : null, projectName: item.development.projectName, diff --git a/src/controllers/DevelopmentHistoryController.ts b/src/controllers/DevelopmentHistoryController.ts index 8ba2d90..5b8aeb8 100644 --- a/src/controllers/DevelopmentHistoryController.ts +++ b/src/controllers/DevelopmentHistoryController.ts @@ -312,6 +312,7 @@ export class DevelopmentOfficerHistoryController extends Controller { citizenId: item.citizenId, fullName: item.prefix + item.firstName + " " + item.lastName, position: item.position, + year: item.development.year, posType: item.posType ? item.posType.posTypeName : null, posLevel: item.posLevel ? item.posLevel.posLevelName : null, posExecutive: item.posExecutive, From 71c547c5c6ae4047416f1eef1290443ca59d93a0 Mon Sep 17 00:00:00 2001 From: Bright Date: Tue, 30 Apr 2024 11:48:23 +0700 Subject: [PATCH 074/250] =?UTF-8?q?=E0=B9=80=E0=B8=9E=E0=B8=B4=E0=B9=88?= =?UTF-8?q?=E0=B8=A1=E0=B8=9F=E0=B8=B4=E0=B8=A5=E0=B8=94=E0=B9=8C=E0=B9=80?= =?UTF-8?q?=E0=B8=82=E0=B9=89=E0=B8=B2=20report?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/ReportController.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/controllers/ReportController.ts b/src/controllers/ReportController.ts index 6becec6..4ba6f07 100644 --- a/src/controllers/ReportController.ts +++ b/src/controllers/ReportController.ts @@ -286,6 +286,8 @@ export class ReportController extends Controller { ? "" : Extension.ToThaiNumber(Extension.ToThaiFullDate(getDevelopment.graduatedDate)), graduatedReason: getDevelopment.graduatedReason, + useOfficialTime: getDevelopment.useOfficialTime, + isGraduated: getDevelopment.isGraduated }; return new HttpSuccess({ From d129fd7a47432496268b887e4c48baf73953149c Mon Sep 17 00:00:00 2001 From: Bright Date: Tue, 30 Apr 2024 13:16:11 +0700 Subject: [PATCH 075/250] =?UTF-8?q?=E0=B9=80=E0=B8=9E=E0=B8=B4=E0=B9=88?= =?UTF-8?q?=E0=B8=A1=E0=B8=84=E0=B9=89=E0=B8=99=E0=B8=AB=E0=B8=B2=E0=B8=94?= =?UTF-8?q?=E0=B9=89=E0=B8=A7=E0=B8=A2=E0=B9=80=E0=B8=A5=E0=B8=82=E0=B8=9A?= =?UTF-8?q?=E0=B8=B1=E0=B8=95=E0=B8=A3=E0=B8=9B=E0=B8=A3=E0=B8=B0=E0=B8=8A?= =?UTF-8?q?=E0=B8=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/DevelopmentScholarshipController.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/controllers/DevelopmentScholarshipController.ts b/src/controllers/DevelopmentScholarshipController.ts index ab59272..c9ba84b 100644 --- a/src/controllers/DevelopmentScholarshipController.ts +++ b/src/controllers/DevelopmentScholarshipController.ts @@ -174,6 +174,14 @@ export class DevelopmentScholarshipController extends Controller { keyword: `%${keyword}%`, }, ) + .orWhere( + keyword != null && keyword != "" + ? "developmentScholarship.citizenId LIKE :keyword" + : "1=1", + { + keyword: `%${keyword}%`, + }, + ) .orWhere( keyword != null && keyword != "" ? "developmentScholarship.position LIKE :keyword" From 5d98acafdb0d691111af87a4c0ac6e0b17749ad7 Mon Sep 17 00:00:00 2001 From: Kittapath Date: Tue, 30 Apr 2024 13:19:44 +0700 Subject: [PATCH 076/250] no message --- src/controllers/DevelopmentController.ts | 25 +++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/src/controllers/DevelopmentController.ts b/src/controllers/DevelopmentController.ts index e6dc3ce..af89e3d 100644 --- a/src/controllers/DevelopmentController.ts +++ b/src/controllers/DevelopmentController.ts @@ -1751,7 +1751,26 @@ export class DevelopmentController extends Controller { const oldProfile = getDevelopment.developmentHistorys.find( (x) => x.citizenId == item["รหัสประจำตัวประชาชน"], ); - if (oldProfile != null) return; + if (oldProfile != null) { + if (oldProfile.isDone == true) return; + item.dateStart = item["วันที่เริ่มต้น"] == undefined ? null : item["วันที่เริ่มต้น"]; + item.dateEnd = item["วันที่สิ้นสุด"] == undefined ? null : item["วันที่สิ้นสุด"]; + item.order = + item["เลขที่คำสั่ง/เลขที่หนังสืออนุมัติ"] == undefined + ? null + : item["เลขที่คำสั่ง/เลขที่หนังสืออนุมัติ"]; + item.dateOrder = + item["คำสั่งลงวันที่/หนังสืออนุมัติลงวันที่"] == undefined + ? null + : new Date(item["คำสั่งลงวันที่/หนังสืออนุมัติลงวันที่"]); + item.trainingDays = item["จำนวนวันที่อบรม"] == undefined ? null : item["จำนวนวันที่อบรม"]; + item.createdUserId = request.user.sub; + item.createdFullName = request.user.name; + item.lastUpdateUserId = request.user.sub; + item.lastUpdateFullName = request.user.name; + await this.developmentHistoryRepository.save(item); + return; + } if (item["ประเภท"] == undefined) return; if (item["ประเภท"] == "ข้าราชการกรุงเทพมหานครสามัญ") { await new CallAPI() @@ -1772,6 +1791,10 @@ export class DevelopmentController extends Controller { : new Date(item["คำสั่งลงวันที่/หนังสืออนุมัติลงวันที่"]); development.trainingDays = item["จำนวนวันที่อบรม"] == undefined ? null : item["จำนวนวันที่อบรม"]; + development.posLevelId = x.posLevelId; + development.posTypeId = x.posTypeId; + development.employeePosLevelId = null; + development.employeePosTypeId = null; development.developmentId = id; development.createdUserId = request.user.sub; development.createdFullName = request.user.name; From d101cbca4a0d82ca449dbca0c53958592502c4cb Mon Sep 17 00:00:00 2001 From: Kittapath Date: Tue, 30 Apr 2024 14:14:51 +0700 Subject: [PATCH 077/250] no message --- src/controllers/DevelopmentController.ts | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/src/controllers/DevelopmentController.ts b/src/controllers/DevelopmentController.ts index af89e3d..0c7ade7 100644 --- a/src/controllers/DevelopmentController.ts +++ b/src/controllers/DevelopmentController.ts @@ -1748,27 +1748,29 @@ export class DevelopmentController extends Controller { getDevelopments.map(async (item: any) => { if (item["รหัสประจำตัวประชาชน"] == undefined || item["รหัสประจำตัวประชาชน"].length != 13) return; - const oldProfile = getDevelopment.developmentHistorys.find( + const oldProfile: any = getDevelopment.developmentHistorys.find( (x) => x.citizenId == item["รหัสประจำตัวประชาชน"], ); if (oldProfile != null) { if (oldProfile.isDone == true) return; - item.dateStart = item["วันที่เริ่มต้น"] == undefined ? null : item["วันที่เริ่มต้น"]; - item.dateEnd = item["วันที่สิ้นสุด"] == undefined ? null : item["วันที่สิ้นสุด"]; - item.order = + oldProfile.dateStart = + item["วันที่เริ่มต้น"] == undefined ? null : item["วันที่เริ่มต้น"]; + oldProfile.dateEnd = item["วันที่สิ้นสุด"] == undefined ? null : item["วันที่สิ้นสุด"]; + oldProfile.order = item["เลขที่คำสั่ง/เลขที่หนังสืออนุมัติ"] == undefined ? null : item["เลขที่คำสั่ง/เลขที่หนังสืออนุมัติ"]; - item.dateOrder = + oldProfile.dateOrder = item["คำสั่งลงวันที่/หนังสืออนุมัติลงวันที่"] == undefined ? null : new Date(item["คำสั่งลงวันที่/หนังสืออนุมัติลงวันที่"]); - item.trainingDays = item["จำนวนวันที่อบรม"] == undefined ? null : item["จำนวนวันที่อบรม"]; - item.createdUserId = request.user.sub; - item.createdFullName = request.user.name; - item.lastUpdateUserId = request.user.sub; - item.lastUpdateFullName = request.user.name; - await this.developmentHistoryRepository.save(item); + oldProfile.trainingDays = + item["จำนวนวันที่อบรม"] == undefined ? null : item["จำนวนวันที่อบรม"]; + oldProfile.createdUserId = request.user.sub; + oldProfile.createdFullName = request.user.name; + oldProfile.lastUpdateUserId = request.user.sub; + oldProfile.lastUpdateFullName = request.user.name; + await this.developmentHistoryRepository.save(oldProfile); return; } if (item["ประเภท"] == undefined) return; From 00df943de500a574f5c3d91a823357bbf587a1fd Mon Sep 17 00:00:00 2001 From: Kittapath Date: Fri, 3 May 2024 17:38:39 +0700 Subject: [PATCH 078/250] =?UTF-8?q?=E0=B8=9A=E0=B8=B1=E0=B8=99=E0=B8=97?= =?UTF-8?q?=E0=B8=B6=E0=B8=81=E0=B8=81=E0=B8=B2=E0=B8=A3=E0=B8=A8=E0=B8=B6?= =?UTF-8?q?=E0=B8=81=E0=B8=A9=E0=B8=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DevelopmentScholarshipController.ts | 63 +++++++++++-------- 1 file changed, 37 insertions(+), 26 deletions(-) diff --git a/src/controllers/DevelopmentScholarshipController.ts b/src/controllers/DevelopmentScholarshipController.ts index c9ba84b..b0ed458 100644 --- a/src/controllers/DevelopmentScholarshipController.ts +++ b/src/controllers/DevelopmentScholarshipController.ts @@ -218,6 +218,7 @@ export class DevelopmentScholarshipController extends Controller { .getManyAndCount(); const formattedData = development.map((item) => ({ id: item.id, + year: item.scholarshipYear, citizenId: item.citizenId, fullName: item.prefix + item.firstName + " " + item.lastName, position: item.position, @@ -461,51 +462,61 @@ export class DevelopmentScholarshipController extends Controller { getDevelopment.status = _status; getDevelopment.lastUpdateUserId = request.user.sub; getDevelopment.lastUpdateFullName = request.user.name; + let scholarshipType = ""; if (_status == "GRADUATE") { if (getDevelopment.scholarshipType != null) { switch (getDevelopment.scholarshipType.trim().toUpperCase()) { case "DOMESTICE": - getDevelopment.scholarshipType = "การศึกษาในประเทศ"; + scholarshipType = "การศึกษาในประเทศ"; break; case "NOABROAD": - getDevelopment.scholarshipType = + scholarshipType = "ฝึกอบรมในประเทศที่ส่งไปพัฒนากับหน่วยวงานภายนอก (หลักสูตรที่ไม่มีการไปต่างประเทศ)"; break; case "ABROAD": - getDevelopment.scholarshipType = + scholarshipType = "ฝึกอบรมในประเทศที่ส่งไปพัฒนากับหน่วยวงานภายนอก (หลักสูตรที่มีการไปต่างประเทศ)"; break; case "EXECUTIVE": - getDevelopment.scholarshipType = + scholarshipType = "ฝึกอบรมในประเทศที่ส่งไปพัฒนากับหน่วยวงานภายนอก (หลักสูตรประเภทนักบริหาร)"; break; default: break; } } - let profileEdu = await new CallAPI().PostData(request, "org/profile/educations", { - profileId: getDevelopment.profileId, - institute: getDevelopment.educationalInstitution, - startDate: getDevelopment.startDate, - endDate: getDevelopment.endDate, - finishDate: null, - isEducation: false, - degree: null, - field: getDevelopment.field, - fundName: getDevelopment.scholarshipType, - gpa: null, - country: getDevelopment.studyCountry, - other: null, - duration: getDevelopment.totalPeriod, - durationYear: 0, - note: null, - educationLevel: getDevelopment.degreeLevel, - educationLevelId: null, - isDate: false, - positionPath: null, - positionPathId: null, - }); + let profileEdu = await new CallAPI() + .PostData(request, "org/profile/educations", { + profileId: getDevelopment.profileId, + institute: getDevelopment.educationalInstitution, + startDate: getDevelopment.startDate, + endDate: getDevelopment.endDate, + finishDate: null, + isEducation: false, + degree: null, + field: getDevelopment.field, + fundName: scholarshipType, + gpa: null, + country: getDevelopment.studyCountry, + other: null, + duration: getDevelopment.totalPeriod, + durationYear: 0, + note: null, + educationLevel: getDevelopment.degreeLevel, + educationLevelId: null, + isDate: false, + positionPath: null, + positionPathId: null, + }) + .then(async (x) => { + await this.developmentScholarshipRepository.save(getDevelopment); + }) + .catch((error) => { + console.error("ไม่สามารถบันทึกลงทะเบียนประวัติได้"); + }); } else if (_status == "NOTGRADUATE") { + getDevelopment.status = _status; + await this.developmentScholarshipRepository.save(getDevelopment); } else { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบสถานะนี้ในระบบ"); } From 422510dbe3000a1475484de40315576a029d7cbf Mon Sep 17 00:00:00 2001 From: Bright Date: Fri, 17 May 2024 10:05:15 +0700 Subject: [PATCH 079/250] =?UTF-8?q?=E0=B9=80=E0=B8=9E=E0=B8=B4=E0=B9=88?= =?UTF-8?q?=E0=B8=A1=E0=B8=9F=E0=B8=B4=E0=B8=A5=E0=B8=94=E0=B9=8C=20totalP?= =?UTF-8?q?eriod?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/ReportController.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/controllers/ReportController.ts b/src/controllers/ReportController.ts index 4ba6f07..71ad0f1 100644 --- a/src/controllers/ReportController.ts +++ b/src/controllers/ReportController.ts @@ -287,7 +287,11 @@ export class ReportController extends Controller { : Extension.ToThaiNumber(Extension.ToThaiFullDate(getDevelopment.graduatedDate)), graduatedReason: getDevelopment.graduatedReason, useOfficialTime: getDevelopment.useOfficialTime, - isGraduated: getDevelopment.isGraduated + isGraduated: getDevelopment.isGraduated, + totalPeriod: + getDevelopment.totalPeriod == null || getDevelopment.totalPeriod == "" + ? "" + : Extension.ToThaiNumber(getDevelopment.totalPeriod), }; return new HttpSuccess({ From eb41d529c72d6e389cd10092fdd9782552fef190 Mon Sep 17 00:00:00 2001 From: AdisakKanthawilang Date: Mon, 20 May 2024 13:17:11 +0700 Subject: [PATCH 080/250] fix --- src/controllers/StrategyController.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/controllers/StrategyController.ts b/src/controllers/StrategyController.ts index 1ab6468..5d815e1 100644 --- a/src/controllers/StrategyController.ts +++ b/src/controllers/StrategyController.ts @@ -64,9 +64,9 @@ export class StrategyController extends Controller { order: { createdAt: "ASC" }, }); - if (!listStrategyChild1 || listStrategyChild1.length === 0) { - throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลยุทธศาสตร์"); - } + // if (!listStrategyChild1 || listStrategyChild1.length === 0) { + // throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลยุทธศาสตร์"); + // } const formattedData = listStrategyChild1.map((item) => ({ id: item.id, From 2584d26d6c0e5d4860212712ecbd63f606e430ec Mon Sep 17 00:00:00 2001 From: AnandaTon Date: Tue, 21 May 2024 11:11:33 +0700 Subject: [PATCH 081/250] =?UTF-8?q?=E0=B9=81=E0=B8=81=E0=B9=89=E0=B9=84?= =?UTF-8?q?=E0=B8=82=E0=B9=83=E0=B8=AB=E0=B9=89=E0=B9=80=E0=B8=9E=E0=B8=B4?= =?UTF-8?q?=E0=B9=88=E0=B8=A1=E0=B8=82=E0=B9=89=E0=B8=AD=E0=B8=84=E0=B8=A7?= =?UTF-8?q?=E0=B8=B2=E0=B8=A1=E0=B8=A2=E0=B8=B2=E0=B8=A7=E0=B9=84=E0=B8=94?= =?UTF-8?q?=E0=B9=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/entities/Development.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/entities/Development.ts b/src/entities/Development.ts index 11d24d2..1bad0b7 100644 --- a/src/entities/Development.ts +++ b/src/entities/Development.ts @@ -156,6 +156,7 @@ export class Development extends EntityBase { nullable: true, comment: "หลักการและเหตุผล", default: null, + type: "text", }) reason: string; @@ -163,6 +164,7 @@ export class Development extends EntityBase { nullable: true, comment: "วัตถุประสงค์", default: null, + type: "text", }) objective: string; From bd9b8b41838bc790c0bca8195f0db338c4018f68 Mon Sep 17 00:00:00 2001 From: Kittapath Date: Tue, 21 May 2024 12:55:17 +0700 Subject: [PATCH 082/250] migrate --- ...6270845115-update_table_dev_reason_text.ts | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 src/migration/1716270845115-update_table_dev_reason_text.ts diff --git a/src/migration/1716270845115-update_table_dev_reason_text.ts b/src/migration/1716270845115-update_table_dev_reason_text.ts new file mode 100644 index 0000000..ca35c0c --- /dev/null +++ b/src/migration/1716270845115-update_table_dev_reason_text.ts @@ -0,0 +1,20 @@ +import { MigrationInterface, QueryRunner } from "typeorm"; + +export class UpdateTableDevReasonText1716270845115 implements MigrationInterface { + name = 'UpdateTableDevReasonText1716270845115' + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`reason\``); + await queryRunner.query(`ALTER TABLE \`development\` ADD \`reason\` text NULL COMMENT 'หลักการและเหตุผล'`); + await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`objective\``); + await queryRunner.query(`ALTER TABLE \`development\` ADD \`objective\` text NULL COMMENT 'วัตถุประสงค์'`); + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`objective\``); + await queryRunner.query(`ALTER TABLE \`development\` ADD \`objective\` varchar(255) NULL COMMENT 'วัตถุประสงค์'`); + await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`reason\``); + await queryRunner.query(`ALTER TABLE \`development\` ADD \`reason\` varchar(255) NULL COMMENT 'หลักการและเหตุผล'`); + } + +} From a56d469736fafd1f56e98b1e851f48346a26e6c7 Mon Sep 17 00:00:00 2001 From: AnandaTon Date: Tue, 21 May 2024 15:19:20 +0700 Subject: [PATCH 083/250] =?UTF-8?q?=E0=B9=80=E0=B8=9E=E0=B8=B4=E0=B9=88?= =?UTF-8?q?=E0=B8=A1=E0=B9=80=E0=B8=87=E0=B8=B7=E0=B9=88=E0=B8=AD=E0=B8=99?= =?UTF-8?q?=E0=B9=84=E0=B8=82=20type?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/DevelopmentController.ts | 68 ++++++++++++++++-------- 1 file changed, 47 insertions(+), 21 deletions(-) diff --git a/src/controllers/DevelopmentController.ts b/src/controllers/DevelopmentController.ts index 0c7ade7..bc35a79 100644 --- a/src/controllers/DevelopmentController.ts +++ b/src/controllers/DevelopmentController.ts @@ -1667,27 +1667,53 @@ export class DevelopmentController extends Controller { await Promise.all( getDevelopment.map(async (x) => { const _data = Object.assign(new DevelopmentHistory(), x); - await new CallAPI() - .PostData(request, "org/profile/training", { - profileId: x.profileId, - name: x.development == null ? null : x.development.projectName, - topic: x.development == null ? null : x.development.topicAcademic, - yearly: x.development == null ? null : x.development.year, - place: x.development == null ? null : x.development.addressAcademic, - duration: x.trainingDays, - department: x.development == null ? null : x.development.root, - numberOrder: x.order, - dateOrder: x.dateOrder, - startDate: x.dateStart, - endDate: x.dateEnd, - isDate: true, - }) - .then((x) => { - _data.isDone = true; - }) - .catch((x) => { - _data.isDone = false; - }); + + if (x.type === "OFFICER") { + await new CallAPI() + .PostData(request, "org/profile/training", { + profileId: x.profileId, + name: x.development == null ? null : x.development.projectName, + topic: x.development == null ? null : x.development.topicAcademic, + yearly: x.development == null ? null : x.development.year, + place: x.development == null ? null : x.development.addressAcademic, + duration: x.trainingDays, + department: x.development == null ? null : x.development.root, + numberOrder: x.order, + dateOrder: x.dateOrder, + startDate: x.dateStart, + endDate: x.dateEnd, + isDate: true, + }) + .then((x) => { + _data.isDone = true; + }) + .catch((x) => { + _data.isDone = false; + }); + } else if (x.type === "EMPLOYEE") { + await new CallAPI() + .PostData(request, "org/profile/training", { + profileId: x.profileId, + name: x.development == null ? null : x.development.projectName, + topic: x.development == null ? null : x.development.topicAcademic, + yearly: x.development == null ? null : x.development.year, + place: x.development == null ? null : x.development.addressAcademic, + duration: x.trainingDays, + department: x.development == null ? null : x.development.root, + numberOrder: x.order, + dateOrder: x.dateOrder, + startDate: x.dateStart, + endDate: x.dateEnd, + isDate: true, + }) + .then((x) => { + _data.isDone = true; + }) + .catch((x) => { + _data.isDone = false; + }); + } + _data.lastUpdateUserId = request.user.sub; _data.lastUpdateFullName = request.user.name; await this.developmentHistoryRepository.save(_data); From d310c3384e6c990d8ec7742f149de1381ef9b46b Mon Sep 17 00:00:00 2001 From: AdisakKanthawilang Date: Tue, 21 May 2024 15:40:03 +0700 Subject: [PATCH 084/250] fix filter --- src/controllers/DevelopmentEmployeeHistoryController.ts | 7 +------ src/controllers/DevelopmentHistoryController.ts | 7 ++++--- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/src/controllers/DevelopmentEmployeeHistoryController.ts b/src/controllers/DevelopmentEmployeeHistoryController.ts index 56dd7fd..c35b617 100644 --- a/src/controllers/DevelopmentEmployeeHistoryController.ts +++ b/src/controllers/DevelopmentEmployeeHistoryController.ts @@ -238,12 +238,7 @@ export class DevelopmentEmployeeHistoryController extends Controller { : "1=1", { year: body.year }, ) - .andWhere( - body.root != null && body.root != undefined ? "developmentHistory.root = :root" : "1=1", - { - root: body.root, - }, - ) + .andWhere(body.root != null ? "developmentHistory.root = :root" : "1=1", { root: body.root }) .andWhere("developmentHistory.type = :type", { type: type }) .andWhere( new Brackets((qb) => { diff --git a/src/controllers/DevelopmentHistoryController.ts b/src/controllers/DevelopmentHistoryController.ts index 5b8aeb8..b19c1bf 100644 --- a/src/controllers/DevelopmentHistoryController.ts +++ b/src/controllers/DevelopmentHistoryController.ts @@ -230,9 +230,9 @@ export class DevelopmentOfficerHistoryController extends Controller { : "1=1", { year: body.year }, ) - .andWhere(body.root != null && body.root != undefined ? "development.root = :root" : "1=1", { - root: body.root, - }) + // .andWhere(body.root != null && body.root != undefined ? "development.root = :root" : "1=1", { + // root: body.root, + // }) .andWhere(body.root != null ? "developmentHistory.root = :root" : "1=1", { root: body.root }) .andWhere("developmentHistory.type = :type", { type: type }) .andWhere( @@ -313,6 +313,7 @@ export class DevelopmentOfficerHistoryController extends Controller { fullName: item.prefix + item.firstName + " " + item.lastName, position: item.position, year: item.development.year, + root: item.development.root,//test posType: item.posType ? item.posType.posTypeName : null, posLevel: item.posLevel ? item.posLevel.posLevelName : null, posExecutive: item.posExecutive, From a428f59d9d80a861bba627faf84f587e40056b1e Mon Sep 17 00:00:00 2001 From: AnandaTon Date: Tue, 21 May 2024 16:50:51 +0700 Subject: [PATCH 085/250] =?UTF-8?q?=E0=B9=81=E0=B8=81=E0=B9=89=E0=B9=84?= =?UTF-8?q?=E0=B8=82=20path=20profile=20Employee=20traning?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/DevelopmentController.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/controllers/DevelopmentController.ts b/src/controllers/DevelopmentController.ts index bc35a79..3a18860 100644 --- a/src/controllers/DevelopmentController.ts +++ b/src/controllers/DevelopmentController.ts @@ -1692,8 +1692,8 @@ export class DevelopmentController extends Controller { }); } else if (x.type === "EMPLOYEE") { await new CallAPI() - .PostData(request, "org/profile/training", { - profileId: x.profileId, + .PostData(request, "org/profile-employee/training", { + profileEmployeeId: x.profileId, name: x.development == null ? null : x.development.projectName, topic: x.development == null ? null : x.development.topicAcademic, yearly: x.development == null ? null : x.development.year, From fe6c92674badf0443415c3d0a4dd8b61ab6dfcd0 Mon Sep 17 00:00:00 2001 From: AnandaTon Date: Tue, 21 May 2024 18:17:47 +0700 Subject: [PATCH 086/250] Update DevelopmentController.ts --- src/controllers/DevelopmentController.ts | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/controllers/DevelopmentController.ts b/src/controllers/DevelopmentController.ts index 3a18860..e4c765f 100644 --- a/src/controllers/DevelopmentController.ts +++ b/src/controllers/DevelopmentController.ts @@ -1661,14 +1661,13 @@ export class DevelopmentController extends Controller { @Request() request: { user: Record }, ) { const getDevelopment = await this.developmentHistoryRepository.find({ - where: { developmentId: id, isDone: false, type: "OFFICER" }, + where: { developmentId: id, isDone: false }, relations: ["development"], }); await Promise.all( getDevelopment.map(async (x) => { const _data = Object.assign(new DevelopmentHistory(), x); - - if (x.type === "OFFICER") { + if (x.type == "OFFICER") { await new CallAPI() .PostData(request, "org/profile/training", { profileId: x.profileId, @@ -1690,7 +1689,10 @@ export class DevelopmentController extends Controller { .catch((x) => { _data.isDone = false; }); - } else if (x.type === "EMPLOYEE") { + } else if (x.type == "EMPLOYEE") { + console.log( + "000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", + ); await new CallAPI() .PostData(request, "org/profile-employee/training", { profileEmployeeId: x.profileId, From 37f8b4c0bf0308367817400ba034641a634a8561 Mon Sep 17 00:00:00 2001 From: Kittapath Date: Tue, 21 May 2024 18:24:27 +0700 Subject: [PATCH 087/250] no message --- src/controllers/DevelopmentController.ts | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/controllers/DevelopmentController.ts b/src/controllers/DevelopmentController.ts index e4c765f..8768eae 100644 --- a/src/controllers/DevelopmentController.ts +++ b/src/controllers/DevelopmentController.ts @@ -1690,9 +1690,6 @@ export class DevelopmentController extends Controller { _data.isDone = false; }); } else if (x.type == "EMPLOYEE") { - console.log( - "000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", - ); await new CallAPI() .PostData(request, "org/profile-employee/training", { profileEmployeeId: x.profileId, From 28bb5e224669297cb135a93016cad26a5841c13c Mon Sep 17 00:00:00 2001 From: Kittapath Date: Tue, 11 Jun 2024 11:59:13 +0700 Subject: [PATCH 088/250] =?UTF-8?q?=E0=B9=81=E0=B8=81=E0=B9=89=20build?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/release.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index c358c91..255820c 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -8,7 +8,7 @@ on: env: REGISTRY: docker.frappet.com IMAGE_NAME: ehr/bma-ehr-development-service - DEPLOY_HOST: 49.0.91.80 + DEPLOY_HOST: frappet.com COMPOSE_PATH: /home/frappet/docker/bma/bma-ehr-development 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 From 72a045fcfce18ad2a5ec83ac234470aacfb88157 Mon Sep 17 00:00:00 2001 From: Kittapath Date: Sun, 30 Jun 2024 20:50:39 +0700 Subject: [PATCH 089/250] add profilio --- src/controllers/PortfolioController.ts | 162 ++++++++++++++++++ src/entities/Portfolio.ts | 25 +++ src/middlewares/user.ts | 13 ++ .../1719477296897-add_table_Portfolio.ts | 14 ++ 4 files changed, 214 insertions(+) create mode 100644 src/controllers/PortfolioController.ts create mode 100644 src/entities/Portfolio.ts create mode 100644 src/middlewares/user.ts create mode 100644 src/migration/1719477296897-add_table_Portfolio.ts diff --git a/src/controllers/PortfolioController.ts b/src/controllers/PortfolioController.ts new file mode 100644 index 0000000..51f4eec --- /dev/null +++ b/src/controllers/PortfolioController.ts @@ -0,0 +1,162 @@ +import { + Controller, + Post, + Put, + Delete, + Route, + Security, + Tags, + Body, + Path, + Request, + SuccessResponse, + Response, + Get, +} from "tsoa"; +import { AppDataSource } from "../database/data-source"; +import HttpSuccess from "../interfaces/http-success"; +import HttpStatusCode from "../interfaces/http-status"; +import HttpError from "../interfaces/http-error"; +import { Not } from "typeorm"; +import { CreatePortfolio, Portfolio } from "../entities/Portfolio"; +import { RequestWithUser } from "../middlewares/user"; + +@Route("api/v1/development/portfolio") +@Tags("Portfolio") +@Security("bearerAuth") +@Response( + HttpStatusCode.INTERNAL_SERVER_ERROR, + "เกิดข้อผิดพลาด ไม่สามารถแสดงรายการได้ กรุณาลองใหม่ในภายหลัง", +) +@SuccessResponse(HttpStatusCode.OK, "สำเร็จ") +export class PortfolioController extends Controller { + private portfolioRepository = AppDataSource.getRepository(Portfolio); + + /** + * API list รายการผลงาน + * + * @summary ORG_058 - CRUD ผลงาน (ADMIN) #62 + * + */ + @Get() + async GetResult(@Request() request: RequestWithUser) { + const _portfolio = await this.portfolioRepository.find({ + where: { createdUserId: request.user.sub }, + select: [ + "id", + "name", + "detail", + "createdAt", + "lastUpdatedAt", + "createdFullName", + "lastUpdateFullName", + ], + order: { name: "ASC" }, + }); + return new HttpSuccess(_portfolio); + } + + /** + * API รายละเอียดรายการผลงาน + * + * @summary ORG_058 - CRUD ผลงาน (ADMIN) #62 + * + * @param {string} id Id ผลงาน + */ + @Get("{id}") + async GetById(@Path() id: string, @Request() request: RequestWithUser) { + const _portfolio = await this.portfolioRepository.findOne({ + where: { id: id, createdUserId: request.user.sub }, + select: ["id", "name", "detail"], + }); + if (!_portfolio) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลผลงานนี้"); + } + + return new HttpSuccess(_portfolio); + } + + /** + * API สร้างรายการ body ผลงาน + * + * @summary ORG_058 - CRUD ผลงาน (ADMIN) #62 + * + */ + @Post() + async Post( + @Body() + requestBody: CreatePortfolio, + @Request() request: RequestWithUser, + ) { + const _portfolio = Object.assign(new Portfolio(), requestBody); + if (!_portfolio) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลผลงานนี้"); + } + + const checkName = await this.portfolioRepository.findOne({ + where: { name: requestBody.name, createdUserId: request.user.sub }, + }); + + if (checkName) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ชื่อนี้มีอยู่ในระบบแล้ว"); + } + + _portfolio.createdUserId = request.user.sub; + _portfolio.createdFullName = request.user.name; + _portfolio.lastUpdateUserId = request.user.sub; + _portfolio.lastUpdateFullName = request.user.name; + await this.portfolioRepository.save(_portfolio); + return new HttpSuccess(_portfolio.id); + } + + /** + * API แก้ไขรายการ body ผลงาน + * + * @summary ORG_058 - CRUD ผลงาน (ADMIN) #62 + * + * @param {string} id Id ผลงาน + */ + @Put("{id}") + async Put( + @Path() id: string, + @Body() + requestBody: CreatePortfolio, + @Request() request: RequestWithUser, + ) { + const _portfolio = await this.portfolioRepository.findOne({ where: { id: id } }); + if (!_portfolio) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลผลงานนี้"); + } + const checkName = await this.portfolioRepository.findOne({ + where: { id: Not(id), name: requestBody.name, createdUserId: request.user.sub }, + }); + if (checkName) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ชื่อนี้มีอยู่ในระบบแล้ว"); + } + + _portfolio.lastUpdateUserId = request.user.sub; + _portfolio.lastUpdateFullName = request.user.name; + Object.assign(_portfolio, requestBody); + await this.portfolioRepository.save(_portfolio); + return new HttpSuccess(_portfolio.id); + } + + /** + * API ลบรายการผลงาน + * + * @summary ORG_058 - CRUD ผลงาน (ADMIN) #62 + * + * @param {string} id Id ผลงาน + */ + @Delete("{id}") + async Delete(@Path() id: string, @Request() request: RequestWithUser) { + const _delPortfolio = await this.portfolioRepository.findOne({ + where: { id: id, createdUserId: request.user.sub }, + }); + if (!_delPortfolio) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลผลงานนี้"); + } + await this.portfolioRepository.delete(_delPortfolio.id); + return new HttpSuccess(); + } +} diff --git a/src/entities/Portfolio.ts b/src/entities/Portfolio.ts new file mode 100644 index 0000000..acff01a --- /dev/null +++ b/src/entities/Portfolio.ts @@ -0,0 +1,25 @@ +import { Entity, Column } from "typeorm"; +import { EntityBase } from "./base/Base"; + +@Entity("portfolio") +export class Portfolio extends EntityBase { + @Column({ + nullable: true, + comment: "ชื่อเอกสาร/ผลงาน", + default: null, + }) + name: string; + + @Column({ + nullable: true, + comment: "รายละเอียดเอกสาร/ผลงาน", + default: null, + }) + detail: string; +} +export class CreatePortfolio { + @Column() + name: string; + @Column() + detail: string | null; +} diff --git a/src/middlewares/user.ts b/src/middlewares/user.ts new file mode 100644 index 0000000..a35cdc4 --- /dev/null +++ b/src/middlewares/user.ts @@ -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[]; + }; +}; diff --git a/src/migration/1719477296897-add_table_Portfolio.ts b/src/migration/1719477296897-add_table_Portfolio.ts new file mode 100644 index 0000000..e904ba2 --- /dev/null +++ b/src/migration/1719477296897-add_table_Portfolio.ts @@ -0,0 +1,14 @@ +import { MigrationInterface, QueryRunner } from "typeorm"; + +export class AddTablePortfolio1719477296897 implements MigrationInterface { + name = 'AddTablePortfolio1719477296897' + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(`CREATE TABLE \`portfolio\` (\`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', \`name\` varchar(255) NULL COMMENT 'ชื่อเอกสาร/ผลงาน', \`detail\` varchar(255) NULL COMMENT 'รายละเอียดเอกสาร/ผลงาน', PRIMARY KEY (\`id\`)) ENGINE=InnoDB`); + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(`DROP TABLE \`portfolio\``); + } + +} From 2e2a4336c12ab19a3cb2067fd1b34b4005e9170b Mon Sep 17 00:00:00 2001 From: AdisakKanthawilang Date: Mon, 1 Jul 2024 11:42:34 +0700 Subject: [PATCH 090/250] =?UTF-8?q?=E0=B8=9B=E0=B8=A3=E0=B8=B1=E0=B8=9A?= =?UTF-8?q?=E0=B8=9F=E0=B8=B4=E0=B8=A7=20detail=20=E0=B9=80=E0=B8=9B?= =?UTF-8?q?=E0=B9=87=E0=B8=99=20longText?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/entities/Portfolio.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/entities/Portfolio.ts b/src/entities/Portfolio.ts index acff01a..074dd08 100644 --- a/src/entities/Portfolio.ts +++ b/src/entities/Portfolio.ts @@ -11,6 +11,7 @@ export class Portfolio extends EntityBase { name: string; @Column({ + type: "longtext", nullable: true, comment: "รายละเอียดเอกสาร/ผลงาน", default: null, From fdd9c510cca5ace3e326b96dc1c2a907dada3ce7 Mon Sep 17 00:00:00 2001 From: Bright Date: Fri, 5 Jul 2024 14:42:48 +0700 Subject: [PATCH 091/250] migrate --- src/migration/1720165194013-update_field.ts | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 src/migration/1720165194013-update_field.ts diff --git a/src/migration/1720165194013-update_field.ts b/src/migration/1720165194013-update_field.ts new file mode 100644 index 0000000..aa53008 --- /dev/null +++ b/src/migration/1720165194013-update_field.ts @@ -0,0 +1,16 @@ +import { MigrationInterface, QueryRunner } from "typeorm"; + +export class UpdateField1720165194013 implements MigrationInterface { + name = 'UpdateField1720165194013' + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`portfolio\` DROP COLUMN \`detail\``); + await queryRunner.query(`ALTER TABLE \`portfolio\` ADD \`detail\` longtext NULL COMMENT 'รายละเอียดเอกสาร/ผลงาน'`); + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`portfolio\` DROP COLUMN \`detail\``); + await queryRunner.query(`ALTER TABLE \`portfolio\` ADD \`detail\` varchar(255) NULL COMMENT 'รายละเอียดเอกสาร/ผลงาน'`); + } + +} From eac232edcc1d717ff64125a9b171c69a74f3a24c Mon Sep 17 00:00:00 2001 From: Kittapath Date: Fri, 5 Jul 2024 17:36:19 +0700 Subject: [PATCH 092/250] =?UTF-8?q?=E0=B9=81=E0=B8=81=E0=B9=89=E0=B8=AB?= =?UTF-8?q?=E0=B8=A1=E0=B8=B2=E0=B8=A2=E0=B9=80=E0=B8=AB=E0=B8=95=E0=B8=B8?= =?UTF-8?q?=E0=B8=9E=E0=B8=B1=E0=B8=92=E0=B8=99=E0=B8=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/DevelopmentController.ts | 2 ++ src/entities/Development.ts | 18 +++++++++++++++++ .../DevelopmentProjectTechniqueActual.ts | 4 +++- .../DevelopmentProjectTechniquePlanned.ts | 4 +++- src/migration/1720174912913-add_table_dev1.ts | 16 +++++++++++++++ src/migration/1720175549705-add_table_dev2.ts | 20 +++++++++++++++++++ 6 files changed, 62 insertions(+), 2 deletions(-) create mode 100644 src/migration/1720174912913-add_table_dev1.ts create mode 100644 src/migration/1720175549705-add_table_dev2.ts diff --git a/src/controllers/DevelopmentController.ts b/src/controllers/DevelopmentController.ts index 8768eae..891082c 100644 --- a/src/controllers/DevelopmentController.ts +++ b/src/controllers/DevelopmentController.ts @@ -1494,6 +1494,8 @@ export class DevelopmentController extends Controller { projectDayBackActual: getDevelopment.projectDayBackActual, projectDayHoldActual: getDevelopment.projectDayHoldActual, projectNigthHoldActual: getDevelopment.projectNigthHoldActual, + reasonActual: getDevelopment.reasonActual, + reasonPlanned: getDevelopment.reasonPlanned, developmentProjectTechniqueActuals: getDevelopment.developmentProjectTechniqueActuals .map((x) => x.name) .sort(), diff --git a/src/entities/Development.ts b/src/entities/Development.ts index 1bad0b7..f41987d 100644 --- a/src/entities/Development.ts +++ b/src/entities/Development.ts @@ -260,6 +260,13 @@ export class Development extends EntityBase { }) projectNigthHoldActual: number; + @Column({ + nullable: true, + comment: "รายละเอียดอื่นๆ แผน", + default: null, + }) + reasonPlanned: string; + @OneToMany( () => DevelopmentProjectTechniquePlanned, (developmentProjectTechniquePlanned: DevelopmentProjectTechniquePlanned) => @@ -267,6 +274,13 @@ export class Development extends EntityBase { ) developmentProjectTechniquePlanneds: DevelopmentProjectTechniquePlanned[]; + @Column({ + nullable: true, + comment: "รายละเอียดอื่นๆ จริง", + default: null, + }) + reasonActual: string; + @OneToMany( () => DevelopmentProjectTechniqueActual, (developmentProjectTechniqueActual: DevelopmentProjectTechniqueActual) => @@ -672,6 +686,8 @@ export class UpdateDevelopment3 { @Column() developmentProjectTechniquePlanneds?: string[]; @Column() + reasonPlanned?: string; + @Column() isBackActual?: boolean | null; @Column() isHoldActual?: boolean | null; @@ -684,6 +700,8 @@ export class UpdateDevelopment3 { @Column() developmentProjectTechniqueActuals?: string[]; @Column() + reasonActual?: string; + @Column() strategyChildPlannedId?: string | null; @Column() strategyChildPlannedNode?: number | null; diff --git a/src/entities/DevelopmentProjectTechniqueActual.ts b/src/entities/DevelopmentProjectTechniqueActual.ts index a437e00..0fa3b08 100644 --- a/src/entities/DevelopmentProjectTechniqueActual.ts +++ b/src/entities/DevelopmentProjectTechniqueActual.ts @@ -12,7 +12,9 @@ export class DevelopmentProjectTechniqueActual extends EntityBase { // ACADEMIC_SEMINAR = การสัมมนาทางวิชาการ // WORKSHOP = การสัมมนาเชิงปฏิบัติการ // SPECIAL_LECTURE = การบรรยายพิเศษ + // LECTURE = การบรรยาย // STUDY_TRAINING = การฝึกศึกษา + // OTHER = อื่น nullable: true, comment: "เทคนิควิธีการที่ใช้ในการพัฒนา", default: null, @@ -35,5 +37,5 @@ export class DevelopmentProjectTechniqueActual extends EntityBase { } export class CreateDevelopmentProjectTechniqueActual { @Column() - name: number; + name: string; } diff --git a/src/entities/DevelopmentProjectTechniquePlanned.ts b/src/entities/DevelopmentProjectTechniquePlanned.ts index bb8d3dc..7ba3c7c 100644 --- a/src/entities/DevelopmentProjectTechniquePlanned.ts +++ b/src/entities/DevelopmentProjectTechniquePlanned.ts @@ -12,7 +12,9 @@ export class DevelopmentProjectTechniquePlanned extends EntityBase { // ACADEMIC_SEMINAR = การสัมมนาทางวิชาการ // WORKSHOP = การสัมมนาเชิงปฏิบัติการ // SPECIAL_LECTURE = การบรรยายพิเศษ + // LECTURE = การบรรยาย // STUDY_TRAINING = การฝึกศึกษา + // OTHER = อื่น nullable: true, comment: "เทคนิควิธีการที่ใช้ในการพัฒนา", default: null, @@ -35,5 +37,5 @@ export class DevelopmentProjectTechniquePlanned extends EntityBase { } export class CreateDevelopmentProjectTechniquePlanned { @Column() - name: number; + name: string; } diff --git a/src/migration/1720174912913-add_table_dev1.ts b/src/migration/1720174912913-add_table_dev1.ts new file mode 100644 index 0000000..9b89534 --- /dev/null +++ b/src/migration/1720174912913-add_table_dev1.ts @@ -0,0 +1,16 @@ +import { MigrationInterface, QueryRunner } from "typeorm"; + +export class AddTableDev11720174912913 implements MigrationInterface { + name = 'AddTableDev11720174912913' + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`developmentProjectTechniquePlanned\` ADD \`detail\` varchar(255) NULL COMMENT 'รายละเอียด'`); + await queryRunner.query(`ALTER TABLE \`developmentProjectTechniqueActual\` ADD \`detail\` varchar(255) NULL COMMENT 'รายละเอียด'`); + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`developmentProjectTechniqueActual\` DROP COLUMN \`detail\``); + await queryRunner.query(`ALTER TABLE \`developmentProjectTechniquePlanned\` DROP COLUMN \`detail\``); + } + +} diff --git a/src/migration/1720175549705-add_table_dev2.ts b/src/migration/1720175549705-add_table_dev2.ts new file mode 100644 index 0000000..4204f05 --- /dev/null +++ b/src/migration/1720175549705-add_table_dev2.ts @@ -0,0 +1,20 @@ +import { MigrationInterface, QueryRunner } from "typeorm"; + +export class AddTableDev21720175549705 implements MigrationInterface { + name = 'AddTableDev21720175549705' + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`developmentProjectTechniquePlanned\` DROP COLUMN \`detail\``); + await queryRunner.query(`ALTER TABLE \`developmentProjectTechniqueActual\` DROP COLUMN \`detail\``); + await queryRunner.query(`ALTER TABLE \`development\` ADD \`reasonPlanned\` varchar(255) NULL COMMENT 'รายละเอียดอื่นๆ แผน'`); + await queryRunner.query(`ALTER TABLE \`development\` ADD \`reasonActual\` varchar(255) NULL COMMENT 'รายละเอียดอื่นๆ จริง'`); + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`reasonActual\``); + await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`reasonPlanned\``); + await queryRunner.query(`ALTER TABLE \`developmentProjectTechniqueActual\` ADD \`detail\` varchar(255) NULL COMMENT 'รายละเอียด'`); + await queryRunner.query(`ALTER TABLE \`developmentProjectTechniquePlanned\` ADD \`detail\` varchar(255) NULL COMMENT 'รายละเอียด'`); + } + +} From 9975f2c607c2196bba367b3a385169ac08015f0f Mon Sep 17 00:00:00 2001 From: Kittapath Date: Tue, 9 Jul 2024 00:03:36 +0700 Subject: [PATCH 093/250] =?UTF-8?q?=E0=B9=81=E0=B8=81=E0=B9=89env?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/release.yaml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 255820c..55da994 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -9,7 +9,8 @@ env: REGISTRY: docker.frappet.com IMAGE_NAME: ehr/bma-ehr-development-service DEPLOY_HOST: frappet.com - COMPOSE_PATH: /home/frappet/docker/bma/bma-ehr-development + COMPOSE_PATH: /home/frappet/docker/bma-ehr + # COMPOSE_PATH: /home/frappet/docker/bma/bma-ehr-development 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 release-test: From a984acb6834b1a523a9824d2d58d284c082adf94 Mon Sep 17 00:00:00 2001 From: Kittapath Date: Tue, 9 Jul 2024 17:03:24 +0700 Subject: [PATCH 094/250] =?UTF-8?q?=E0=B9=81=E0=B8=81=E0=B9=89=20env?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/release.yaml | 4 ++-- src/interfaces/call-api.ts | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 55da994..0c083cc 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -9,8 +9,8 @@ env: REGISTRY: docker.frappet.com IMAGE_NAME: ehr/bma-ehr-development-service DEPLOY_HOST: frappet.com - COMPOSE_PATH: /home/frappet/docker/bma-ehr - # COMPOSE_PATH: /home/frappet/docker/bma/bma-ehr-development + # COMPOSE_PATH: /home/frappet/docker/bma-ehr + COMPOSE_PATH: /home/frappet/docker/bma/bma-ehr-development 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 release-test: diff --git a/src/interfaces/call-api.ts b/src/interfaces/call-api.ts index 4cbd1a5..d6498fa 100644 --- a/src/interfaces/call-api.ts +++ b/src/interfaces/call-api.ts @@ -17,7 +17,7 @@ class CallAPI { //Get public async GetData(request: any, @Path() path: any) { const token = request.headers.authorization; - const url = process.env.API + path; + const url = process.env.API_URL + path; try { const response = await axios.get(url, { headers: { @@ -33,7 +33,7 @@ class CallAPI { //Post public async PostData(request: any, @Path() path: any, sendData: any) { const token = request.headers.authorization; - const url = process.env.API + path; + const url = process.env.API_URL + path; try { const response = await axios.post(url, sendData, { headers: { From a842962db191fcb82342924c21832f4d4a8824c7 Mon Sep 17 00:00:00 2001 From: Methapon2001 <61303214+Methapon2001@users.noreply.github.com> Date: Wed, 10 Jul 2024 09:42:23 +0700 Subject: [PATCH 095/250] feat: add elasticsearch --- package-lock.json | 94 +++++++++++++++++++++++++++++++++++++++++++++++ package.json | 1 + 2 files changed, 95 insertions(+) diff --git a/package-lock.json b/package-lock.json index c77b04b..349ccc2 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,6 +9,7 @@ "version": "1.0.0", "license": "ISC", "dependencies": { + "@elastic/elasticsearch": "^8.14.0", "@nestjs/platform-express": "^10.3.7", "@tsoa/runtime": "^6.0.0", "axios": "^1.6.8", @@ -51,6 +52,66 @@ "node": ">=12" } }, + "node_modules/@elastic/elasticsearch": { + "version": "8.14.0", + "resolved": "https://registry.npmjs.org/@elastic/elasticsearch/-/elasticsearch-8.14.0.tgz", + "integrity": "sha512-MGrgCI4y+Ozssf5Q2IkVJlqt5bUMnKIICG2qxeOfrJNrVugMCBCAQypyesmSSocAtNm8IX3LxfJ3jQlFHmKe2w==", + "license": "Apache-2.0", + "dependencies": { + "@elastic/transport": "^8.6.0", + "tslib": "^2.4.0" + }, + "engines": { + "node": ">=18" + } + }, + "node_modules/@elastic/transport": { + "version": "8.7.0", + "resolved": "https://registry.npmjs.org/@elastic/transport/-/transport-8.7.0.tgz", + "integrity": "sha512-IqXT7a8DZPJtqP2qmX1I2QKmxYyN27kvSW4g6pInESE1SuGwZDp2FxHJ6W2kwmYOJwQdAt+2aWwzXO5jHo9l4A==", + "license": "Apache-2.0", + "dependencies": { + "@opentelemetry/api": "1.x", + "debug": "^4.3.4", + "hpagent": "^1.0.0", + "ms": "^2.1.3", + "secure-json-parse": "^2.4.0", + "tslib": "^2.4.0", + "undici": "^6.12.0" + }, + "engines": { + "node": ">=18" + } + }, + "node_modules/@elastic/transport/node_modules/debug": { + "version": "4.3.5", + "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.5.tgz", + "integrity": "sha512-pt0bNEmneDIvdL1Xsd9oDQ/wrQRkXDT4AUWlNZNPKvW5x/jyO9VFXkJUP07vQ2upmw5PlaITaPKc31jK13V+jg==", + "license": "MIT", + "dependencies": { + "ms": "2.1.2" + }, + "engines": { + "node": ">=6.0" + }, + "peerDependenciesMeta": { + "supports-color": { + "optional": true + } + } + }, + "node_modules/@elastic/transport/node_modules/debug/node_modules/ms": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", + "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==", + "license": "MIT" + }, + "node_modules/@elastic/transport/node_modules/ms": { + "version": "2.1.3", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz", + "integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==", + "license": "MIT" + }, "node_modules/@isaacs/cliui": { "version": "8.0.2", "resolved": "https://registry.npmjs.org/@isaacs/cliui/-/cliui-8.0.2.tgz", @@ -253,6 +314,15 @@ "resolved": "https://registry.npmjs.org/@one-ini/wasm/-/wasm-0.1.1.tgz", "integrity": "sha512-XuySG1E38YScSJoMlqovLru4KTUNSjgVTIjyh7qMX6aNN5HY5Ct5LhRJdxO79JtTzKfzV/bnWpz+zquYrISsvw==" }, + "node_modules/@opentelemetry/api": { + "version": "1.9.0", + "resolved": "https://registry.npmjs.org/@opentelemetry/api/-/api-1.9.0.tgz", + "integrity": "sha512-3giAOQvZiH5F9bMlMiv8+GSPMeqg0dbaeo58/0SlA9sxSqZhnUtxzX9/2FzyhS9sWQf5S0GJE0AKBrFqjpeYcg==", + "license": "Apache-2.0", + "engines": { + "node": ">=8.0.0" + } + }, "node_modules/@pkgjs/parseargs": { "version": "0.11.0", "resolved": "https://registry.npmjs.org/@pkgjs/parseargs/-/parseargs-0.11.0.tgz", @@ -2140,6 +2210,15 @@ "node": "*" } }, + "node_modules/hpagent": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/hpagent/-/hpagent-1.2.0.tgz", + "integrity": "sha512-A91dYTeIB6NoXG+PxTQpCCDDnfHsW9kc06Lvpu1TEe9gnd6ZFeiBoRO9JvzEv6xK7EX97/dUE8g/vBMTqTS3CA==", + "license": "MIT", + "engines": { + "node": ">=14" + } + }, "node_modules/http-errors": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/http-errors/-/http-errors-2.0.0.tgz", @@ -3674,6 +3753,12 @@ "resolved": "https://registry.npmjs.org/sax/-/sax-1.3.0.tgz", "integrity": "sha512-0s+oAmw9zLl1V1cS9BtZN7JAd0cW5e0QH4W3LWEK6a4LaLEA2OTpGYWDY+6XasBLtz6wkm3u1xRw95mRuJ59WA==" }, + "node_modules/secure-json-parse": { + "version": "2.7.0", + "resolved": "https://registry.npmjs.org/secure-json-parse/-/secure-json-parse-2.7.0.tgz", + "integrity": "sha512-6aU+Rwsezw7VR8/nyvKTx8QpWH9FrcYiXXlqC4z5d5XQBDRqtbfsRjnwGyqbi3gddNtWHuEk9OANUotL26qKUw==", + "license": "BSD-3-Clause" + }, "node_modules/semver": { "version": "7.5.4", "resolved": "https://registry.npmjs.org/semver/-/semver-7.5.4.tgz", @@ -4858,6 +4943,15 @@ "integrity": "sha512-WxONCrssBM8TSPRqN5EmsjVrsv4A8X12J4ArBiiayv3DyyG3ZlIg6yysuuSYdZsVz3TKcTg2fd//Ujd4CHV1iA==", "dev": true }, + "node_modules/undici": { + "version": "6.19.2", + "resolved": "https://registry.npmjs.org/undici/-/undici-6.19.2.tgz", + "integrity": "sha512-JfjKqIauur3Q6biAtHJ564e3bWa8VvT+7cSiOJHFbX4Erv6CLGDpg8z+Fmg/1OI/47RA+GI2QZaF48SSaLvyBA==", + "license": "MIT", + "engines": { + "node": ">=18.17" + } + }, "node_modules/undici-types": { "version": "5.26.5", "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-5.26.5.tgz", diff --git a/package.json b/package.json index 939e3e5..67445e7 100644 --- a/package.json +++ b/package.json @@ -27,6 +27,7 @@ "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", From f3161ab757f6052983309909f9b0e37fe800090b Mon Sep 17 00:00:00 2001 From: Methapon2001 <61303214+Methapon2001@users.noreply.github.com> Date: Wed, 10 Jul 2024 09:47:04 +0700 Subject: [PATCH 096/250] feat: add log middleware --- src/middlewares/logs.ts | 73 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 src/middlewares/logs.ts diff --git a/src/middlewares/logs.ts b/src/middlewares/logs.ts new file mode 100644 index 0000000..8c992dd --- /dev/null +++ b/src/middlewares/logs.ts @@ -0,0 +1,73 @@ +import { NextFunction, Request, Response } from "express"; +import { Client } from "@elastic/elasticsearch"; + +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 = { + 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().toString(); + const start = performance.now(); + + req.app.locals.logData = {}; + + res.on("finish", () => { + if (!req.url.startsWith("/api/")) return; + + const level = LOG_LEVEL_MAP[process.env.LOG_LEVEL ?? "info"] || 1; + + if (level === 1 && res.statusCode < 500) return; + if (level === 2 && res.statusCode < 400) return; + if (level === 3 && res.statusCode < 200) return; + + const obj = { + logType: res.statusCode >= 500 ? "error" : res.statusCode >= 400 ? "warning" : "info", + systemName: "BMA_EHR_DEVELOPMENT", + startTimeStamp: timestamp, + endTimeStamp: new Date().toString(), + processTime: performance.now() - start, + host: req.hostname, + method: req.method, + endpoint: req.url, + responseCode: res.statusCode === 304 ? 200 : res.statusCode, + responseDescription: data?.code, + 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; From 4dc342d018aa9bbd26eac3090154019f02b5d14a Mon Sep 17 00:00:00 2001 From: Kittapath Date: Wed, 10 Jul 2024 10:45:01 +0700 Subject: [PATCH 097/250] no message --- src/controllers/DevelopmentController.ts | 12 ++++++------ src/controllers/DevelopmentScholarshipController.ts | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/controllers/DevelopmentController.ts b/src/controllers/DevelopmentController.ts index 891082c..8cbb1ec 100644 --- a/src/controllers/DevelopmentController.ts +++ b/src/controllers/DevelopmentController.ts @@ -112,7 +112,7 @@ export class DevelopmentController extends Controller { const development = Object.assign(new Development(), requestBody); await new CallAPI() - .PostData(request, "org/find/all", { + .PostData(request, "/org/find/all", { node: requestBody.node, nodeId: requestBody.nodeId, }) @@ -184,7 +184,7 @@ export class DevelopmentController extends Controller { } Object.assign(development, requestBody); await new CallAPI() - .PostData(request, "org/find/all", { + .PostData(request, "/org/find/all", { node: requestBody.node, nodeId: requestBody.nodeId, }) @@ -1671,7 +1671,7 @@ export class DevelopmentController extends Controller { const _data = Object.assign(new DevelopmentHistory(), x); if (x.type == "OFFICER") { await new CallAPI() - .PostData(request, "org/profile/training", { + .PostData(request, "/org/profile/training", { profileId: x.profileId, name: x.development == null ? null : x.development.projectName, topic: x.development == null ? null : x.development.topicAcademic, @@ -1693,7 +1693,7 @@ export class DevelopmentController extends Controller { }); } else if (x.type == "EMPLOYEE") { await new CallAPI() - .PostData(request, "org/profile-employee/training", { + .PostData(request, "/org/profile-employee/training", { profileEmployeeId: x.profileId, name: x.development == null ? null : x.development.projectName, topic: x.development == null ? null : x.development.topicAcademic, @@ -1803,7 +1803,7 @@ export class DevelopmentController extends Controller { if (item["ประเภท"] == undefined) return; if (item["ประเภท"] == "ข้าราชการกรุงเทพมหานครสามัญ") { await new CallAPI() - .GetData(request, `org/unauthorize/officer/citizen/${item["รหัสประจำตัวประชาชน"]}`) + .GetData(request, `/org/unauthorize/officer/citizen/${item["รหัสประจำตัวประชาชน"]}`) .then(async (x: any) => { let development = Object.assign(new DevelopmentHistory(), x); development.dateStart = @@ -1836,7 +1836,7 @@ export class DevelopmentController extends Controller { }); } else { await new CallAPI() - .GetData(request, `org/unauthorize/employee/citizen/${item["รหัสประจำตัวประชาชน"]}`) + .GetData(request, `/org/unauthorize/employee/citizen/${item["รหัสประจำตัวประชาชน"]}`) .then(async (x: any) => { let development = Object.assign(new DevelopmentHistory(), x); development.dateStart = diff --git a/src/controllers/DevelopmentScholarshipController.ts b/src/controllers/DevelopmentScholarshipController.ts index b0ed458..b403675 100644 --- a/src/controllers/DevelopmentScholarshipController.ts +++ b/src/controllers/DevelopmentScholarshipController.ts @@ -486,7 +486,7 @@ export class DevelopmentScholarshipController extends Controller { } } let profileEdu = await new CallAPI() - .PostData(request, "org/profile/educations", { + .PostData(request, "/org/profile/educations", { profileId: getDevelopment.profileId, institute: getDevelopment.educationalInstitution, startDate: getDevelopment.startDate, From ee1a1238ebe3d6cc86a5e0cd7d68cab213aac853 Mon Sep 17 00:00:00 2001 From: Methapon2001 <61303214+Methapon2001@users.noreply.github.com> Date: Thu, 11 Jul 2024 10:29:40 +0700 Subject: [PATCH 098/250] feat: add user data to log --- src/middlewares/auth.ts | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/middlewares/auth.ts b/src/middlewares/auth.ts index e81aa15..edb59b5 100644 --- a/src/middlewares/auth.ts +++ b/src/middlewares/auth.ts @@ -7,11 +7,7 @@ import HttpStatus from "../interfaces/http-status"; 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 -) { +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.", ); @@ -57,6 +53,9 @@ export async function expressAuthentication( break; } + request.app.locals.logData.userId = payload.sub; + request.app.locals.logData.user = payload.preferred_username; + return payload; } From 0d26d2d7a83ff93175e4cb50ab6c82805ecef20a Mon Sep 17 00:00:00 2001 From: Methapon2001 <61303214+Methapon2001@users.noreply.github.com> Date: Thu, 11 Jul 2024 10:54:03 +0700 Subject: [PATCH 099/250] fix: change to string instead (or else cannot be search) --- src/middlewares/logs.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/middlewares/logs.ts b/src/middlewares/logs.ts index 8c992dd..461a13f 100644 --- a/src/middlewares/logs.ts +++ b/src/middlewares/logs.ts @@ -54,7 +54,7 @@ async function logMiddleware(req: Request, res: Response, next: NextFunction) { host: req.hostname, method: req.method, endpoint: req.url, - responseCode: res.statusCode === 304 ? 200 : res.statusCode, + responseCode: String(res.statusCode === 304 ? 200 : res.statusCode), responseDescription: data?.code, input: (level === 4 && JSON.stringify(req.body, null, 2)) || undefined, output: (level === 4 && JSON.stringify(data, null, 2)) || undefined, From 21d70dd3f5c1ec5319291e2662c2d40297060eb2 Mon Sep 17 00:00:00 2001 From: Methapon2001 <61303214+Methapon2001@users.noreply.github.com> Date: Thu, 11 Jul 2024 10:58:18 +0700 Subject: [PATCH 100/250] feat: enable log --- src/app.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/app.ts b/src/app.ts index 6efbcf9..2580fda 100644 --- a/src/app.ts +++ b/src/app.ts @@ -8,6 +8,7 @@ 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(); @@ -21,6 +22,7 @@ async function main() { ); 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)); From a6c1df903c24a8d4d62d690331afac7b3d189690 Mon Sep 17 00:00:00 2001 From: Methapon2001 <61303214+Methapon2001@users.noreply.github.com> Date: Thu, 11 Jul 2024 11:05:29 +0700 Subject: [PATCH 101/250] fix: log data type --- src/middlewares/logs.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/middlewares/logs.ts b/src/middlewares/logs.ts index 461a13f..ff3cf9f 100644 --- a/src/middlewares/logs.ts +++ b/src/middlewares/logs.ts @@ -31,7 +31,7 @@ async function logMiddleware(req: Request, res: Response, next: NextFunction) { return originalJson.call(this, v); }; - const timestamp = new Date().toString(); + const timestamp = new Date().toISOString(); const start = performance.now(); req.app.locals.logData = {}; @@ -49,7 +49,7 @@ async function logMiddleware(req: Request, res: Response, next: NextFunction) { logType: res.statusCode >= 500 ? "error" : res.statusCode >= 400 ? "warning" : "info", systemName: "BMA_EHR_DEVELOPMENT", startTimeStamp: timestamp, - endTimeStamp: new Date().toString(), + endTimeStamp: new Date().toISOString(), processTime: performance.now() - start, host: req.hostname, method: req.method, From 94226de1684df518694160fa645ff3ef6030f85b Mon Sep 17 00:00:00 2001 From: Methapon2001 <61303214+Methapon2001@users.noreply.github.com> Date: Thu, 11 Jul 2024 12:04:32 +0700 Subject: [PATCH 102/250] Revert "feat: enable log" This reverts commit 21d70dd3f5c1ec5319291e2662c2d40297060eb2. --- src/app.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/app.ts b/src/app.ts index 2580fda..6efbcf9 100644 --- a/src/app.ts +++ b/src/app.ts @@ -8,7 +8,6 @@ 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(); @@ -22,7 +21,6 @@ async function main() { ); 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)); From f8e1f9ab9d2d1273e7bc54bec3db4fa78e8262f5 Mon Sep 17 00:00:00 2001 From: Methapon2001 <61303214+Methapon2001@users.noreply.github.com> Date: Thu, 11 Jul 2024 12:10:11 +0700 Subject: [PATCH 103/250] fix: error --- src/middlewares/auth.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/middlewares/auth.ts b/src/middlewares/auth.ts index edb59b5..d3c8c88 100644 --- a/src/middlewares/auth.ts +++ b/src/middlewares/auth.ts @@ -53,8 +53,8 @@ export async function expressAuthentication( break; } - request.app.locals.logData.userId = payload.sub; - request.app.locals.logData.user = payload.preferred_username; + // request.app.locals.logData.userId = payload.sub; + // request.app.locals.logData.user = payload.preferred_username; return payload; } From 272de6c4558f5d040300772a5708fe5e05d5445c Mon Sep 17 00:00:00 2001 From: Methapon2001 <61303214+Methapon2001@users.noreply.github.com> Date: Mon, 15 Jul 2024 16:45:40 +0700 Subject: [PATCH 104/250] feat: add log --- src/middlewares/auth.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/middlewares/auth.ts b/src/middlewares/auth.ts index d3c8c88..2c939d3 100644 --- a/src/middlewares/auth.ts +++ b/src/middlewares/auth.ts @@ -52,9 +52,13 @@ export async function expressAuthentication( if (process.env.AUTH_PUBLIC_KEY) payload = await verifyOffline(token); break; } + if (!request.app.locals.logData) { + request.app.locals.logData = {}; + } - // request.app.locals.logData.userId = payload.sub; - // request.app.locals.logData.user = payload.preferred_username; + request.app.locals.logData.userId = payload.sub; + request.app.locals.logData.userName = payload.name; + request.app.locals.logData.user = payload.preferred_username; return payload; } From 5ca06267d313d4486bd5179f7c6e49fda5884155 Mon Sep 17 00:00:00 2001 From: Methapon2001 <61303214+Methapon2001@users.noreply.github.com> Date: Mon, 15 Jul 2024 16:45:48 +0700 Subject: [PATCH 105/250] Reapply "feat: enable log" This reverts commit 94226de1684df518694160fa645ff3ef6030f85b. --- src/app.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/app.ts b/src/app.ts index 6efbcf9..2580fda 100644 --- a/src/app.ts +++ b/src/app.ts @@ -8,6 +8,7 @@ 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(); @@ -21,6 +22,7 @@ async function main() { ); 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)); From 08f8c598ac29a5d1c8b150253f9ae14305c7bd5a Mon Sep 17 00:00:00 2001 From: Methapon2001 <61303214+Methapon2001@users.noreply.github.com> Date: Mon, 15 Jul 2024 16:46:46 +0700 Subject: [PATCH 106/250] feat: change system name --- src/middlewares/logs.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/middlewares/logs.ts b/src/middlewares/logs.ts index ff3cf9f..1e6e16a 100644 --- a/src/middlewares/logs.ts +++ b/src/middlewares/logs.ts @@ -47,7 +47,7 @@ async function logMiddleware(req: Request, res: Response, next: NextFunction) { const obj = { logType: res.statusCode >= 500 ? "error" : res.statusCode >= 400 ? "warning" : "info", - systemName: "BMA_EHR_DEVELOPMENT", + systemName: "development", startTimeStamp: timestamp, endTimeStamp: new Date().toISOString(), processTime: performance.now() - start, From 3e686addec93e60bcf1f1dafc1e72a47ee239ac0 Mon Sep 17 00:00:00 2001 From: Kittapath Date: Mon, 15 Jul 2024 21:27:38 +0700 Subject: [PATCH 107/250] =?UTF-8?q?=E0=B9=80=E0=B8=9E=E0=B8=B4=E0=B9=88?= =?UTF-8?q?=E0=B8=A1=20=E0=B8=A3=E0=B8=B2=E0=B8=A2=E0=B8=A5=E0=B8=B0?= =?UTF-8?q?=E0=B9=80=E0=B8=AD=E0=B8=B5=E0=B8=A2=E0=B8=94=E0=B8=AD=E0=B8=B7?= =?UTF-8?q?=E0=B9=88=E0=B8=99=E0=B9=86=2070=20=E0=B8=88=E0=B8=A3=E0=B8=B4?= =?UTF-8?q?=E0=B8=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/DevelopmentController.ts | 8 +++- src/entities/Development.ts | 48 +++++++++++++++++++++--- 2 files changed, 48 insertions(+), 8 deletions(-) diff --git a/src/controllers/DevelopmentController.ts b/src/controllers/DevelopmentController.ts index 8cbb1ec..fd98192 100644 --- a/src/controllers/DevelopmentController.ts +++ b/src/controllers/DevelopmentController.ts @@ -1494,8 +1494,12 @@ export class DevelopmentController extends Controller { projectDayBackActual: getDevelopment.projectDayBackActual, projectDayHoldActual: getDevelopment.projectDayHoldActual, projectNigthHoldActual: getDevelopment.projectNigthHoldActual, - reasonActual: getDevelopment.reasonActual, - reasonPlanned: getDevelopment.reasonPlanned, + reasonActual70: getDevelopment.reasonActual70, + reasonActual20: getDevelopment.reasonActual20, + reasonActual10: getDevelopment.reasonActual10, + reasonPlanned70: getDevelopment.reasonPlanned70, + reasonPlanned20: getDevelopment.reasonPlanned20, + reasonPlanned10: getDevelopment.reasonPlanned10, developmentProjectTechniqueActuals: getDevelopment.developmentProjectTechniqueActuals .map((x) => x.name) .sort(), diff --git a/src/entities/Development.ts b/src/entities/Development.ts index f41987d..f65b06e 100644 --- a/src/entities/Development.ts +++ b/src/entities/Development.ts @@ -262,10 +262,24 @@ export class Development extends EntityBase { @Column({ nullable: true, - comment: "รายละเอียดอื่นๆ แผน", + comment: "รายละเอียดอื่นๆ 70 แผน", default: null, }) - reasonPlanned: string; + reasonPlanned70: string; + + @Column({ + nullable: true, + comment: "รายละเอียดอื่นๆ 20 แผน", + default: null, + }) + reasonPlanned20: string; + + @Column({ + nullable: true, + comment: "รายละเอียดอื่นๆ 10 แผน", + default: null, + }) + reasonPlanned10: string; @OneToMany( () => DevelopmentProjectTechniquePlanned, @@ -276,10 +290,24 @@ export class Development extends EntityBase { @Column({ nullable: true, - comment: "รายละเอียดอื่นๆ จริง", + comment: "รายละเอียดอื่นๆ 70 จริง", default: null, }) - reasonActual: string; + reasonActual70: string; + + @Column({ + nullable: true, + comment: "รายละเอียดอื่นๆ 20 จริง", + default: null, + }) + reasonActual20: string; + + @Column({ + nullable: true, + comment: "รายละเอียดอื่นๆ 10 จริง", + default: null, + }) + reasonActual10: string; @OneToMany( () => DevelopmentProjectTechniqueActual, @@ -686,7 +714,11 @@ export class UpdateDevelopment3 { @Column() developmentProjectTechniquePlanneds?: string[]; @Column() - reasonPlanned?: string; + reasonPlanned70?: string; + @Column() + reasonPlanned20?: string; + @Column() + reasonPlanned10?: string; @Column() isBackActual?: boolean | null; @Column() @@ -700,7 +732,11 @@ export class UpdateDevelopment3 { @Column() developmentProjectTechniqueActuals?: string[]; @Column() - reasonActual?: string; + reasonActual70?: string; + @Column() + reasonActual20?: string; + @Column() + reasonActual10?: string; @Column() strategyChildPlannedId?: string | null; @Column() From 3cb55d582cea00887d7bd55bf4e93bcc5fd59a7d Mon Sep 17 00:00:00 2001 From: Kittapath Date: Mon, 15 Jul 2024 21:29:38 +0700 Subject: [PATCH 108/250] migrate --- ...734191-add_table_dev_add_reasonActual70.ts | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 src/migration/1721053734191-add_table_dev_add_reasonActual70.ts diff --git a/src/migration/1721053734191-add_table_dev_add_reasonActual70.ts b/src/migration/1721053734191-add_table_dev_add_reasonActual70.ts new file mode 100644 index 0000000..09d2fff --- /dev/null +++ b/src/migration/1721053734191-add_table_dev_add_reasonActual70.ts @@ -0,0 +1,28 @@ +import { MigrationInterface, QueryRunner } from "typeorm"; + +export class AddTableDevAddReasonActual701721053734191 implements MigrationInterface { + name = 'AddTableDevAddReasonActual701721053734191' + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`reasonPlanned\``); + await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`reasonActual\``); + await queryRunner.query(`ALTER TABLE \`development\` ADD \`reasonPlanned70\` varchar(255) NULL COMMENT 'รายละเอียดอื่นๆ 70 แผน'`); + await queryRunner.query(`ALTER TABLE \`development\` ADD \`reasonPlanned20\` varchar(255) NULL COMMENT 'รายละเอียดอื่นๆ 20 แผน'`); + await queryRunner.query(`ALTER TABLE \`development\` ADD \`reasonPlanned10\` varchar(255) NULL COMMENT 'รายละเอียดอื่นๆ 10 แผน'`); + await queryRunner.query(`ALTER TABLE \`development\` ADD \`reasonActual70\` varchar(255) NULL COMMENT 'รายละเอียดอื่นๆ 70 จริง'`); + await queryRunner.query(`ALTER TABLE \`development\` ADD \`reasonActual20\` varchar(255) NULL COMMENT 'รายละเอียดอื่นๆ 20 จริง'`); + await queryRunner.query(`ALTER TABLE \`development\` ADD \`reasonActual10\` varchar(255) NULL COMMENT 'รายละเอียดอื่นๆ 10 จริง'`); + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`reasonActual10\``); + await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`reasonActual20\``); + await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`reasonActual70\``); + await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`reasonPlanned10\``); + await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`reasonPlanned20\``); + await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`reasonPlanned70\``); + await queryRunner.query(`ALTER TABLE \`development\` ADD \`reasonActual\` varchar(255) NULL COMMENT 'รายละเอียดอื่นๆ จริง'`); + await queryRunner.query(`ALTER TABLE \`development\` ADD \`reasonPlanned\` varchar(255) NULL COMMENT 'รายละเอียดอื่นๆ แผน'`); + } + +} From a746f8947bf71bab3ce35e355645739526f87410 Mon Sep 17 00:00:00 2001 From: Bright Date: Wed, 17 Jul 2024 10:19:25 +0700 Subject: [PATCH 109/250] =?UTF-8?q?Fix=20Checkbox=20=E0=B9=84=E0=B8=A1?= =?UTF-8?q?=E0=B9=88=E0=B9=81=E0=B8=AA=E0=B8=94=E0=B8=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/ReportController.ts | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/controllers/ReportController.ts b/src/controllers/ReportController.ts index 71ad0f1..d2ed50a 100644 --- a/src/controllers/ReportController.ts +++ b/src/controllers/ReportController.ts @@ -287,7 +287,16 @@ export class ReportController extends Controller { : Extension.ToThaiNumber(Extension.ToThaiFullDate(getDevelopment.graduatedDate)), graduatedReason: getDevelopment.graduatedReason, useOfficialTime: getDevelopment.useOfficialTime, + useOffTime: getDevelopment.useOfficialTime == true + ? "🗹 ใช้ ☐ ไม่ใช้" + : "☐ ใช้ 🗹 ไม่ใช้", isGraduated: getDevelopment.isGraduated, + isG1: getDevelopment.isGraduated == true + ? "🗹" + : "☐", + isG2: getDevelopment.isGraduated == true + ? "☐" + : "🗹", totalPeriod: getDevelopment.totalPeriod == null || getDevelopment.totalPeriod == "" ? "" From d45d18e59218841f3b83262cc69d8444ad705d3a Mon Sep 17 00:00:00 2001 From: Kittapath Date: Wed, 17 Jul 2024 12:47:36 +0700 Subject: [PATCH 110/250] edit report error --- src/controllers/ReportController.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/controllers/ReportController.ts b/src/controllers/ReportController.ts index 71ad0f1..3b17ce0 100644 --- a/src/controllers/ReportController.ts +++ b/src/controllers/ReportController.ts @@ -46,9 +46,9 @@ export class ReportController extends Controller { */ @Get("main/{type}") async GetReportDevelopemtMain(@Path() type: string) { - const _type = type.trim().toUpperCase(); + // const _type = type.trim().toUpperCase(); const formattedData = { - org: _type, + org: "_type", }; return new HttpSuccess({ @@ -288,10 +288,10 @@ export class ReportController extends Controller { graduatedReason: getDevelopment.graduatedReason, useOfficialTime: getDevelopment.useOfficialTime, isGraduated: getDevelopment.isGraduated, - totalPeriod: + totalPeriod: getDevelopment.totalPeriod == null || getDevelopment.totalPeriod == "" - ? "" - : Extension.ToThaiNumber(getDevelopment.totalPeriod), + ? "" + : Extension.ToThaiNumber(getDevelopment.totalPeriod), }; return new HttpSuccess({ From 3fb7770344f2c6dd0c32c9155c74d78d7ada81a6 Mon Sep 17 00:00:00 2001 From: Bright Date: Wed, 17 Jul 2024 13:19:20 +0700 Subject: [PATCH 111/250] no message --- src/controllers/ReportController.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/controllers/ReportController.ts b/src/controllers/ReportController.ts index 3ae7e04..6df295e 100644 --- a/src/controllers/ReportController.ts +++ b/src/controllers/ReportController.ts @@ -44,8 +44,8 @@ export class ReportController extends Controller { * * @param {string} type type ประเภท report */ - @Get("main/{type}") - async GetReportDevelopemtMain(@Path() type: string) { + @Get("main") + async GetReportDevelopemtMain(/*@Path() type: string*/) { // const _type = type.trim().toUpperCase(); const formattedData = { org: "_type", From 4b34fc20b86bd76c6ee99a59e7e6d4b9b96a9c77 Mon Sep 17 00:00:00 2001 From: Bright Date: Wed, 17 Jul 2024 13:58:37 +0700 Subject: [PATCH 112/250] no message --- src/controllers/ReportController.ts | 17 ++++++++++------- src/interfaces/extension.ts | 10 ++++++++++ 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/src/controllers/ReportController.ts b/src/controllers/ReportController.ts index 6df295e..e1bbd9b 100644 --- a/src/controllers/ReportController.ts +++ b/src/controllers/ReportController.ts @@ -260,15 +260,15 @@ export class ReportController extends Controller { bookNoDate: getDevelopment.bookNoDate == null ? "" - : Extension.ToThaiNumber(Extension.ToThaiFullDate(getDevelopment.bookNoDate)), + : Extension.ToThaiNumber(Extension.ToThaiFullDate3(getDevelopment.bookNoDate)), startDate: getDevelopment.startDate == null ? "" - : Extension.ToThaiNumber(Extension.ToThaiFullDate(getDevelopment.startDate)), + : Extension.ToThaiNumber(Extension.ToThaiFullDate3(getDevelopment.startDate)), endDate: getDevelopment.endDate == null ? "" - : Extension.ToThaiNumber(Extension.ToThaiFullDate(getDevelopment.endDate)), + : Extension.ToThaiNumber(Extension.ToThaiFullDate3(getDevelopment.endDate)), reportBackNo: getDevelopment.reportBackNo == null ? "" @@ -276,16 +276,19 @@ export class ReportController extends Controller { reportBackNoDate: getDevelopment.reportBackNoDate == null ? "" - : Extension.ToThaiNumber(Extension.ToThaiFullDate(getDevelopment.reportBackNoDate)), + : Extension.ToThaiNumber(Extension.ToThaiFullDate3(getDevelopment.reportBackNoDate)), governmentDate: getDevelopment.governmentDate == null ? "" - : Extension.ToThaiNumber(Extension.ToThaiFullDate(getDevelopment.governmentDate)), + : Extension.ToThaiNumber(Extension.ToThaiFullDate3(getDevelopment.governmentDate)), graduatedDate: getDevelopment.graduatedDate == null ? "" - : Extension.ToThaiNumber(Extension.ToThaiFullDate(getDevelopment.graduatedDate)), - graduatedReason: getDevelopment.graduatedReason, + : Extension.ToThaiNumber(Extension.ToThaiFullDate3(getDevelopment.graduatedDate)), + graduatedReason: + getDevelopment.graduatedReason == null + ? "" + : getDevelopment.graduatedReason, useOfficialTime: getDevelopment.useOfficialTime, useOffTime: getDevelopment.useOfficialTime == true ? "🗹 ใช้ ☐ ไม่ใช้" : "☐ ใช้ 🗹 ไม่ใช้", isGraduated: getDevelopment.isGraduated, diff --git a/src/interfaces/extension.ts b/src/interfaces/extension.ts index 1355587..5de8bd4 100644 --- a/src/interfaces/extension.ts +++ b/src/interfaces/extension.ts @@ -67,6 +67,16 @@ class Extension { ); } + 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 sumObjectValues(array: any, propertyName: any) { let sum = 0; for (let i = 0; i < array.length; i++) { From 1c9cb7ea7819b10aaa3c40df5994f3b2c159f234 Mon Sep 17 00:00:00 2001 From: AdisakKanthawilang Date: Thu, 25 Jul 2024 17:06:42 +0700 Subject: [PATCH 113/250] log --- src/controllers/DevelopmentController.ts | 545 +++++++++++++++--- .../DevelopmentEmployeeHistoryController.ts | 30 +- .../DevelopmentHistoryController.ts | 30 +- .../DevelopmentScholarshipController.ts | 101 +++- src/controllers/PortfolioController.ts | 22 +- src/controllers/StrategyController.ts | 23 +- src/database/data-source.ts | 29 +- src/interfaces/call-api.ts | 37 ++ src/interfaces/utils.ts | 35 ++ src/middlewares/error.ts | 6 + src/middlewares/logs.ts | 5 +- 11 files changed, 741 insertions(+), 122 deletions(-) create mode 100644 src/interfaces/utils.ts diff --git a/src/controllers/DevelopmentController.ts b/src/controllers/DevelopmentController.ts index fd98192..52a87bc 100644 --- a/src/controllers/DevelopmentController.ts +++ b/src/controllers/DevelopmentController.ts @@ -52,6 +52,8 @@ import CallAPI from "../interfaces/call-api"; import { UseInterceptors } from "@nestjs/common"; import { FileInterceptor } from "@nestjs/platform-express"; import * as xlsx from "xlsx"; +import { addLogSequence, setLogDataDiff } from "../interfaces/utils"; +import { RequestWithUser } from "../middlewares/user"; @Route("api/v1/development/main") @Tags("Development") @@ -91,7 +93,7 @@ export class DevelopmentController extends Controller { @Post() async CreateDevelopment( @Body() requestBody: CreateDevelopment, - @Request() request: { user: Record }, + @Request() request: RequestWithUser, ) { const chk_name = await this.developmentRepository.find({ where: { @@ -141,8 +143,12 @@ export class DevelopmentController extends Controller { development.createdFullName = request.user.name; development.lastUpdateUserId = request.user.sub; development.lastUpdateFullName = request.user.name; - - await this.developmentRepository.save(development); + addLogSequence(request, { + action: "database", + status: "success", + description: "Store Development.", + }); + await this.developmentRepository.save(development, { data: request }); return new HttpSuccess(development.id); } @@ -157,8 +163,13 @@ export class DevelopmentController extends Controller { async UpdateDevelopmentTab1( @Path() id: string, @Body() requestBody: UpdateDevelopment1, - @Request() request: { user: Record }, + @Request() request: RequestWithUser, ) { + // addLogSequence(request, { + // action: "database", + // status: "success", + // description: "Get Development.", + // }); const development = await this.developmentRepository.findOne({ where: { id }, }); @@ -182,6 +193,7 @@ export class DevelopmentController extends Controller { " มีอยู่ในระบบแล้ว", ); } + const before = structuredClone(development); Object.assign(development, requestBody); await new CallAPI() .PostData(request, "/org/find/all", { @@ -255,7 +267,13 @@ export class DevelopmentController extends Controller { default: throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงการ/หลักสูตรการฝึกอบรม"); } - await this.developmentRepository.save(development); + addLogSequence(request, { + action: "database", + status: "success", + description: "Store Development.", + }); + await this.developmentRepository.save(development, { data: request }); + setLogDataDiff(request, { before, after: development }); return new HttpSuccess(development.id); } @@ -270,8 +288,13 @@ export class DevelopmentController extends Controller { async CreateDevelopmenttab2_1( @Path() id: string, @Body() requestBody: CreatePlannedGoal, - @Request() request: { user: Record }, + @Request() request: RequestWithUser, ) { + // addLogSequence(request, { + // action: "database", + // status: "success", + // description: "Get Development.", + // }); const development = await this.developmentRepository.findOne({ where: { id }, }); @@ -284,7 +307,12 @@ export class DevelopmentController extends Controller { data.lastUpdateUserId = request.user.sub; data.lastUpdateFullName = request.user.name; data.developmentPlannedGoalId = development.id; - await this.plannedGoalRepository.save(data); + addLogSequence(request, { + action: "database", + status: "success", + description: "Store Development.", + }); + await this.plannedGoalRepository.save(data, { data: request }); await Promise.all( requestBody.positions.map(async (x) => { @@ -305,12 +333,19 @@ export class DevelopmentController extends Controller { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลระดับตำแหน่ง"); } } + const before = structuredClone(development); _data.createdUserId = request.user.sub; _data.createdFullName = request.user.name; _data.lastUpdateUserId = request.user.sub; _data.lastUpdateFullName = request.user.name; _data.plannedGoalId = data.id; - await this.plannedGoalPositionRepository.save(_data); + addLogSequence(request, { + action: "database", + status: "success", + description: "Store Development.", + }); + await this.plannedGoalPositionRepository.save(_data, { data: request }); + setLogDataDiff(request, { before, after: development }); }), ); return new HttpSuccess(data.id); @@ -327,21 +362,33 @@ export class DevelopmentController extends Controller { async CreateDevelopmenttab2_2( @Path() id: string, @Body() requestBody: CreatePlannedPeople, - @Request() request: { user: Record }, + @Request() request: RequestWithUser, ) { + // addLogSequence(request, { + // action: "database", + // status: "success", + // description: "Get Development.", + // }); const development = await this.developmentRepository.findOne({ where: { id }, }); if (!development) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงการ/หลักสูตรการฝึกอบรมนี้"); } + const before = structuredClone(development); const data = Object.assign(new PlannedPeople(), requestBody); data.createdUserId = request.user.sub; data.createdFullName = request.user.name; data.lastUpdateUserId = request.user.sub; data.lastUpdateFullName = request.user.name; data.developmentPlannedPeopleId = development.id; - await this.plannedPeopleRepository.save(data); + addLogSequence(request, { + action: "database", + status: "success", + description: "Store Development.", + }); + await this.plannedPeopleRepository.save(data, { data: request }); + setLogDataDiff(request, { before, after: development }); return new HttpSuccess(data.id); } @@ -356,8 +403,13 @@ export class DevelopmentController extends Controller { async CreateDevelopmenttab2_3( @Path() id: string, @Body() requestBody: CreateActualGoal, - @Request() request: { user: Record }, + @Request() request: RequestWithUser, ) { + // addLogSequence(request, { + // action: "database", + // status: "success", + // description: "Get Development.", + // }); const development = await this.developmentRepository.findOne({ where: { id }, }); @@ -365,6 +417,11 @@ export class DevelopmentController extends Controller { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงการ/หลักสูตรการฝึกอบรมนี้"); } if (requestBody.posTypeActualId != null) { + // addLogSequence(request, { + // action: "database", + // status: "success", + // description: "Get Position Type.", + // }); const checkId = await this.posTypeRepository.findOne({ where: { id: requestBody.posTypeActualId }, }); @@ -373,6 +430,11 @@ export class DevelopmentController extends Controller { } } if (requestBody.posLevelActualId != null) { + // addLogSequence(request, { + // action: "database", + // status: "success", + // description: "Get Position Level.", + // }); const checkId = await this.posLevelRepository.findOne({ where: { id: requestBody.posLevelActualId }, }); @@ -380,13 +442,20 @@ export class DevelopmentController extends Controller { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลระดับตำแหน่ง"); } } + const before = structuredClone(development); const data = Object.assign(new ActualGoal(), requestBody); data.createdUserId = request.user.sub; data.createdFullName = request.user.name; data.lastUpdateUserId = request.user.sub; data.lastUpdateFullName = request.user.name; data.developmentActualGoalId = development.id; - await this.actualGoalRepository.save(data); + addLogSequence(request, { + action: "database", + status: "success", + description: "Store ActualGoal.", + }); + await this.actualGoalRepository.save(data, { data: request }); + setLogDataDiff(request, { before, after: development }); return new HttpSuccess(data.id); } @@ -401,21 +470,33 @@ export class DevelopmentController extends Controller { async CreateDevelopmenttab2_4( @Path() id: string, @Body() requestBody: CreateActualPeople, - @Request() request: { user: Record }, + @Request() request: RequestWithUser, ) { + // addLogSequence(request, { + // action: "database", + // status: "success", + // description: "Get Development.", + // }); const development = await this.developmentRepository.findOne({ where: { id }, }); if (!development) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงการ/หลักสูตรการฝึกอบรมนี้"); } + const before = structuredClone(development); const data = Object.assign(new ActualPeople(), requestBody); data.createdUserId = request.user.sub; data.createdFullName = request.user.name; data.lastUpdateUserId = request.user.sub; data.lastUpdateFullName = request.user.name; data.developmentActualPeopleId = development.id; - await this.actualPeopleRepository.save(data); + addLogSequence(request, { + action: "database", + status: "success", + description: "Store ActualPeople.", + }); + await this.actualPeopleRepository.save(data, { data: request }); + setLogDataDiff(request, { before, after: development }); return new HttpSuccess(data.id); } @@ -430,8 +511,13 @@ export class DevelopmentController extends Controller { async UpdateDevelopmenttab2_1( @Path() id: string, @Body() requestBody: CreatePlannedGoal, - @Request() request: { user: Record }, + @Request() request: RequestWithUser, ) { + // addLogSequence(request, { + // action: "database", + // status: "success", + // description: "Get Development.", + // }); const development = await this.plannedGoalRepository.findOne({ where: { id }, relations: { @@ -441,13 +527,25 @@ export class DevelopmentController extends Controller { if (!development) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงการ/หลักสูตรการฝึกอบรมนี้"); } - - await this.plannedGoalPositionRepository.remove(development.plannedGoalPositions); + const before = structuredClone(development); + addLogSequence(request, { + action: "remove", + status: "success", + description: "Remove data in the field on the PlannedGoalPosition.", + }); + await this.plannedGoalPositionRepository.remove(development.plannedGoalPositions, { + data: request, + }); Object.assign(development, { ...requestBody, positions: [] }); development.lastUpdateUserId = request.user.sub; development.lastUpdateFullName = request.user.name; - await this.plannedGoalRepository.save(development); - + addLogSequence(request, { + action: "database", + status: "success", + description: "Store PlannedGoal.", + }); + await this.plannedGoalRepository.save(development, { data: request }); + setLogDataDiff(request, { before, after: development }); if (requestBody.positions != null) { await Promise.all( requestBody.positions.map(async (x) => { @@ -473,7 +571,16 @@ export class DevelopmentController extends Controller { _data.lastUpdateUserId = request.user.sub; _data.lastUpdateFullName = request.user.name; _data.plannedGoalId = development.id; - await this.plannedGoalPositionRepository.save(_data); + addLogSequence(request, { + action: "database", + status: "success", + description: "Store Planned Goal Position.", + }); + await this.plannedGoalPositionRepository.save(_data, { + data: { + request: request, + }, + }); }), ); } @@ -491,18 +598,30 @@ export class DevelopmentController extends Controller { async UpdateDevelopmenttab2_2( @Path() id: string, @Body() requestBody: CreatePlannedPeople, - @Request() request: { user: Record }, + @Request() request: RequestWithUser, ) { + // addLogSequence(request, { + // action: "database", + // status: "success", + // description: "Get Development.", + // }); const development = await this.plannedPeopleRepository.findOne({ where: { id }, }); if (!development) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงการ/หลักสูตรการฝึกอบรมนี้"); } + const before = structuredClone(development); Object.assign(development, requestBody); development.lastUpdateUserId = request.user.sub; development.lastUpdateFullName = request.user.name; - await this.plannedPeopleRepository.save(development); + addLogSequence(request, { + action: "database", + status: "success", + description: "Store PlannedPeople.", + }); + await this.plannedPeopleRepository.save(development, { data: request }); + setLogDataDiff(request, { before, after: development }); return new HttpSuccess(development.id); } @@ -517,8 +636,13 @@ export class DevelopmentController extends Controller { async UpdateDevelopmenttab2_3( @Path() id: string, @Body() requestBody: CreateActualGoal, - @Request() request: { user: Record }, + @Request() request: RequestWithUser, ) { + // addLogSequence(request, { + // action: "database", + // status: "success", + // description: "Get Development.", + // }); const development = await this.actualGoalRepository.findOne({ where: { id }, }); @@ -526,6 +650,11 @@ export class DevelopmentController extends Controller { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงการ/หลักสูตรการฝึกอบรมนี้"); } if (requestBody.posTypeActualId != null) { + // addLogSequence(request, { + // action: "database", + // status: "success", + // description: "Get Position Type.", + // }); const checkId = await this.posTypeRepository.findOne({ where: { id: requestBody.posTypeActualId }, }); @@ -534,6 +663,11 @@ export class DevelopmentController extends Controller { } } if (requestBody.posLevelActualId != null) { + // addLogSequence(request, { + // action: "database", + // status: "success", + // description: "Get Position Level.", + // }); const checkId = await this.posLevelRepository.findOne({ where: { id: requestBody.posLevelActualId }, }); @@ -541,10 +675,17 @@ export class DevelopmentController extends Controller { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลระดับตำแหน่ง"); } } + const before = structuredClone(development); Object.assign(development, requestBody); development.lastUpdateUserId = request.user.sub; development.lastUpdateFullName = request.user.name; - await this.actualGoalRepository.save(development); + addLogSequence(request, { + action: "database", + status: "success", + description: "Store ActualGoal.", + }); + await this.actualGoalRepository.save(development, { data: request }); + setLogDataDiff(request, { before, after: development }); return new HttpSuccess(development.id); } @@ -559,18 +700,30 @@ export class DevelopmentController extends Controller { async UpdateDevelopmenttab2_4( @Path() id: string, @Body() requestBody: CreateActualPeople, - @Request() request: { user: Record }, + @Request() request: RequestWithUser, ) { + // addLogSequence(request, { + // action: "database", + // status: "success", + // description: "Get Development.", + // }); const development = await this.actualPeopleRepository.findOne({ where: { id }, }); if (!development) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงการ/หลักสูตรการฝึกอบรมนี้"); } + const before = structuredClone(development); Object.assign(development, requestBody); development.lastUpdateUserId = request.user.sub; development.lastUpdateFullName = request.user.name; - await this.actualPeopleRepository.save(development); + addLogSequence(request, { + action: "database", + status: "success", + description: "Store ActualPeople.", + }); + await this.actualPeopleRepository.save(development, { data: request }); + setLogDataDiff(request, { before, after: development }); return new HttpSuccess(development.id); } @@ -582,7 +735,12 @@ export class DevelopmentController extends Controller { * @param {string} id Id รายการ */ @Delete("tab2_1/{id}") - async DeleteDevelopmenttab2_1(@Path() id: string) { + async DeleteDevelopmenttab2_1(@Path() id: string, @Request() request: RequestWithUser) { + // addLogSequence(request, { + // action: "database", + // status: "success", + // description: "Get Development.", + // }); const development = await this.plannedGoalRepository.findOne({ where: { id }, }); @@ -592,8 +750,18 @@ export class DevelopmentController extends Controller { const _development = await this.plannedGoalPositionRepository.find({ where: { plannedGoalId: id }, }); - await this.plannedGoalPositionRepository.remove(_development); - await this.plannedGoalRepository.remove(development); + addLogSequence(request, { + action: "remove", + status: "success", + description: "Remove data in PlannedGoalPosition.", + }); + await this.plannedGoalPositionRepository.remove(_development, { data: request }); + addLogSequence(request, { + action: "remove", + status: "success", + description: "Remove data in PlannedGoal.", + }); + await this.plannedGoalRepository.remove(development, { data: request }); return new HttpSuccess(development.id); } @@ -605,14 +773,24 @@ export class DevelopmentController extends Controller { * @param {string} id Id รายการ */ @Delete("tab2_2/{id}") - async DeleteDevelopmenttab2_2(@Path() id: string) { + async DeleteDevelopmenttab2_2(@Path() id: string, @Request() request: RequestWithUser) { + // addLogSequence(request, { + // action: "database", + // status: "success", + // description: "Get Development.", + // }); const development = await this.plannedPeopleRepository.findOne({ where: { id }, }); if (!development) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลผู้เกี่ยวข้องเป้าหมายตามแผน"); } - await this.plannedPeopleRepository.remove(development); + addLogSequence(request, { + action: "remove", + status: "success", + description: "Remove data in PlannedPeople.", + }); + await this.plannedPeopleRepository.remove(development, { data: request }); return new HttpSuccess(development.id); } @@ -624,14 +802,24 @@ export class DevelopmentController extends Controller { * @param {string} id Id รายการ */ @Delete("tab2_3/{id}") - async DeleteDevelopmenttab2_3(@Path() id: string) { + async DeleteDevelopmenttab2_3(@Path() id: string, @Request() request: RequestWithUser) { + // addLogSequence(request, { + // action: "database", + // status: "success", + // description: "Get Development.", + // }); const development = await this.actualGoalRepository.findOne({ where: { id }, }); if (!development) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลกลุ่มเป้าหมายตามจริง"); } - await this.actualGoalRepository.remove(development); + addLogSequence(request, { + action: "remove", + status: "success", + description: "Remove data in ActualGoal.", + }); + await this.actualGoalRepository.remove(development, { data: request }); return new HttpSuccess(development.id); } @@ -643,14 +831,24 @@ export class DevelopmentController extends Controller { * @param {string} id Id รายการ */ @Delete("tab2_4/{id}") - async DeleteDevelopmenttab2_4(@Path() id: string) { + async DeleteDevelopmenttab2_4(@Path() id: string, @Request() request: RequestWithUser) { + // addLogSequence(request, { + // action: "database", + // status: "success", + // description: "Get Development.", + // }); const development = await this.actualPeopleRepository.findOne({ where: { id }, }); if (!development) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลผู้เกี่ยวข้องเป้าหมายตามจริง"); } - await this.actualPeopleRepository.remove(development); + addLogSequence(request, { + action: "remove", + status: "success", + description: "Remove data in ActualPeople.", + }); + await this.actualPeopleRepository.remove(development, { data: request }); return new HttpSuccess(development.id); } @@ -665,8 +863,13 @@ export class DevelopmentController extends Controller { async UpdateDevelopmentTab3( @Path() id: string, @Body() requestBody: UpdateDevelopment3, - @Request() request: { user: Record }, + @Request() request: RequestWithUser, ) { + // addLogSequence(request, { + // action: "database", + // status: "success", + // description: "Get Development.", + // }); const development = await this.developmentRepository.findOne({ where: { id }, relations: { @@ -686,13 +889,35 @@ export class DevelopmentController extends Controller { }); development.lastUpdateUserId = request.user.sub; development.lastUpdateFullName = request.user.name; - - await this.developmentProjectTypeRepository.remove(development.developmentProjectTypes); + addLogSequence(request, { + action: "remove", + status: "success", + description: "Remove data in DevelopmentProjectType.", + }); + await this.developmentProjectTypeRepository.remove(development.developmentProjectTypes, { + data: request, + }); + addLogSequence(request, { + action: "remove", + status: "success", + description: "Remove data in DevelopmentProjectTechniquePlanned.", + }); await this.developmentProjectTechniquePlannedRepository.remove( development.developmentProjectTechniquePlanneds, + { + data: request, + } ); + addLogSequence(request, { + action: "remove", + status: "success", + description: "Remove data in DevelopmentProjectTechniqueActual.", + }); await this.developmentProjectTechniqueActualRepository.remove( development.developmentProjectTechniqueActuals, + { + data: request, + } ); const _null: any = null; if ( @@ -905,7 +1130,12 @@ export class DevelopmentController extends Controller { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลยุทธศาสตร์เป้าหมายตามจริง"); } } - await this.developmentRepository.save(development); + addLogSequence(request, { + action: "database", + status: "success", + description: "Store Development.", + }); + await this.developmentRepository.save(development, { data: request }); if (requestBody.developmentProjectTypes != null) { await Promise.all( requestBody.developmentProjectTypes.map(async (x) => { @@ -916,7 +1146,12 @@ export class DevelopmentController extends Controller { data.lastUpdateUserId = request.user.sub; data.lastUpdateFullName = request.user.name; data.developmentId = development.id; - await this.developmentProjectTypeRepository.save(data); + addLogSequence(request, { + action: "database", + status: "success", + description: "Store DevelopmentProjectType.", + }); + await this.developmentProjectTypeRepository.save(data, { data: request }); }), ); } @@ -930,7 +1165,12 @@ export class DevelopmentController extends Controller { data.lastUpdateUserId = request.user.sub; data.lastUpdateFullName = request.user.name; data.developmentId = development.id; - await this.developmentProjectTechniquePlannedRepository.save(data); + addLogSequence(request, { + action: "database", + status: "success", + description: "Store DevelopmentProjectTechniquePlanned.", + }); + await this.developmentProjectTechniquePlannedRepository.save(data, { data: request }); }), ); } @@ -944,7 +1184,12 @@ export class DevelopmentController extends Controller { data.lastUpdateUserId = request.user.sub; data.lastUpdateFullName = request.user.name; data.developmentId = development.id; - await this.developmentProjectTechniqueActualRepository.save(data); + addLogSequence(request, { + action: "database", + status: "success", + description: "Store DevelopmentProjectTechniqueActual.", + }); + await this.developmentProjectTechniqueActualRepository.save(data, { data: request }); }), ); } @@ -962,18 +1207,30 @@ export class DevelopmentController extends Controller { async UpdateDevelopmentTab4( @Path() id: string, @Body() requestBody: UpdateDevelopment4, - @Request() request: { user: Record }, + @Request() request: RequestWithUser, ) { + // addLogSequence(request, { + // action: "database", + // status: "success", + // description: "Get Development.", + // }); const development = await this.developmentRepository.findOne({ where: { id }, }); if (!development) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงการ/หลักสูตรการฝึกอบรมนี้"); } + const before = structuredClone(development); Object.assign(development, requestBody); development.lastUpdateUserId = request.user.sub; development.lastUpdateFullName = request.user.name; - await this.developmentRepository.save(development); + addLogSequence(request, { + action: "database", + status: "success", + description: "Store Development.", + }); + await this.developmentRepository.save(development, { data: request }); + setLogDataDiff(request, { before, after: development }); return new HttpSuccess(development.id); } @@ -988,21 +1245,33 @@ export class DevelopmentController extends Controller { async CreateDevelopmenttab4_1( @Path() id: string, @Body() requestBody: CreateDevelopmentEvaluation, - @Request() request: { user: Record }, + @Request() request: RequestWithUser, ) { + // addLogSequence(request, { + // action: "database", + // status: "success", + // description: "Get Development.", + // }); const development = await this.developmentRepository.findOne({ where: { id }, }); if (!development) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงการ/หลักสูตรการฝึกอบรมนี้"); } + const before = structuredClone(development); const data = Object.assign(new DevelopmentEvaluation(), requestBody); data.createdUserId = request.user.sub; data.createdFullName = request.user.name; data.lastUpdateUserId = request.user.sub; data.lastUpdateFullName = request.user.name; data.developmentId = development.id; - await this.developmentEvaluationRepository.save(data); + addLogSequence(request, { + action: "database", + status: "success", + description: "Store DevelopmentEvaluation.", + }); + await this.developmentEvaluationRepository.save(data, { data: request }); + setLogDataDiff(request, { before, after: development }); return new HttpSuccess(data.id); } @@ -1014,14 +1283,24 @@ export class DevelopmentController extends Controller { * @param {string} id Id รายการ */ @Delete("tab4_1/{id}") - async DeleteDevelopmenttab4_1(@Path() id: string) { + async DeleteDevelopmenttab4_1(@Path() id: string, @Request() request: RequestWithUser) { + // addLogSequence(request, { + // action: "database", + // status: "success", + // description: "Get Development Evaluation By ID.", + // }); const development = await this.developmentEvaluationRepository.findOne({ where: { id }, }); if (!development) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลผู้เกี่ยวข้องเป้าหมายตามแผน"); } - await this.developmentEvaluationRepository.remove(development); + addLogSequence(request, { + action: "remove", + status: "success", + description: "Remove Development Evaluation By ID.", + }); + await this.developmentEvaluationRepository.remove(development, { data: request }); return new HttpSuccess(development.id); } @@ -1036,7 +1315,7 @@ export class DevelopmentController extends Controller { async UpdateDevelopmenttab4_1( @Path() id: string, @Body() requestBody: CreateDevelopmentEvaluation, - @Request() request: { user: Record }, + @Request() request: RequestWithUser, ) { const development = await this.developmentEvaluationRepository.findOne({ where: { id }, @@ -1047,7 +1326,7 @@ export class DevelopmentController extends Controller { Object.assign(development, requestBody); development.lastUpdateUserId = request.user.sub; development.lastUpdateFullName = request.user.name; - await this.developmentEvaluationRepository.save(development); + await this.developmentEvaluationRepository.save(development, { data: request }); return new HttpSuccess(development.id); } @@ -1062,7 +1341,7 @@ export class DevelopmentController extends Controller { async UpdateDevelopmentTab5( @Path() id: string, @Body() requestBody: UpdateDevelopment5, - @Request() request: { user: Record }, + @Request() request: RequestWithUser, ) { const development = await this.developmentRepository.findOne({ where: { id }, @@ -1083,9 +1362,20 @@ export class DevelopmentController extends Controller { Object.assign(development, { ...requestBody, developmentAddresss: [] }); development.lastUpdateUserId = request.user.sub; development.lastUpdateFullName = request.user.name; - await this.developmentRepository.save(development); - - await this.developmentAddresssRepository.remove(development.developmentAddresss); + addLogSequence(request, { + action: "database", + status: "success", + description: "Store Development.", + }); + await this.developmentRepository.save(development, { data: request }); + addLogSequence(request, { + action: "remove", + status: "success", + description: "Remove DevelopmentAddresss.", + }); + await this.developmentAddresssRepository.remove(development.developmentAddresss, { + data: request, + }); await Promise.all( requestBody.developmentAddresss.map(async (x) => { const data = Object.assign(new DevelopmentAddress(), x); @@ -1100,7 +1390,12 @@ export class DevelopmentController extends Controller { data.createdFullName = request.user.name; data.lastUpdateUserId = request.user.sub; data.lastUpdateFullName = request.user.name; - await this.developmentAddresssRepository.save(data); + addLogSequence(request, { + action: "database", + status: "success", + description: "Store DevelopmentAddresss.", + }); + await this.developmentAddresssRepository.save(data, { data: request }); }), ); @@ -1163,7 +1458,7 @@ export class DevelopmentController extends Controller { * @param {string} id Id รายการ */ @Delete("{id}") - async DeleteDevelopment(@Path() id: string) { + async DeleteDevelopment(@Path() id: string , @Request () request: RequestWithUser) { const development = await this.developmentRepository.findOne({ where: { id }, relations: { @@ -1189,22 +1484,93 @@ export class DevelopmentController extends Controller { const plannedGoalPosition = await this.plannedGoalPositionRepository.find({ where: { plannedGoalId: In(development.developmentPlannedGoals.map((x) => x.id)) }, }); - await this.plannedGoalPositionRepository.remove(plannedGoalPosition); + addLogSequence(request, { + action: "remove", + status: "success", + description: "Remove PlannedGoalPosition.", + }); + await this.plannedGoalPositionRepository.remove(plannedGoalPosition, { data: request }); } - await this.actualPeopleRepository.remove(development.developmentActualPeoples); - await this.plannedPeopleRepository.remove(development.developmentPlannedPeoples); - await this.actualGoalRepository.remove(development.developmentActualGoals); - await this.plannedGoalRepository.remove(development.developmentPlannedGoals); - await this.developmentProjectTypeRepository.remove(development.developmentProjectTypes); + addLogSequence(request, { + action: "remove", + status: "success", + description: "Remove ActualPeople.", + }); + await this.actualPeopleRepository.remove(development.developmentActualPeoples, { + data: request, + }); + addLogSequence(request, { + action: "remove", + status: "success", + description: "Remove PlannedPeople.", + }); + await this.plannedPeopleRepository.remove(development.developmentPlannedPeoples, { + data: request, + }); + addLogSequence(request, { + action: "remove", + status: "success", + description: "Remove ActualGoal.", + }); + await this.actualGoalRepository.remove(development.developmentActualGoals, { data: request }); + addLogSequence(request, { + action: "remove", + status: "success", + description: "Remove PlannedGoal.", + }); + await this.plannedGoalRepository.remove(development.developmentPlannedGoals, { data: request }); + addLogSequence(request, { + action: "remove", + status: "success", + description: "Remove DevelopmentProjectType.", + }); + await this.developmentProjectTypeRepository.remove(development.developmentProjectTypes, { + data: request, + }); + addLogSequence(request, { + action: "remove", + status: "success", + description: "Remove DevelopmentProjectTechniquePlanned.", + }); await this.developmentProjectTechniquePlannedRepository.remove( development.developmentProjectTechniquePlanneds, + { + data: request, + }, ); + addLogSequence(request, { + action: "remove", + status: "success", + description: "Remove DevelopmentProjectTechniqueActuals.", + }); await this.developmentProjectTechniqueActualRepository.remove( development.developmentProjectTechniqueActuals, + { + data: request, + }, ); - await this.developmentEvaluationRepository.remove(development.developmentEvaluations); - await this.developmentAddresssRepository.remove(development.developmentAddresss); - await this.developmentRepository.remove(development); + addLogSequence(request, { + action: "remove", + status: "success", + description: "Remove DevelopmentEvaluation.", + }); + await this.developmentEvaluationRepository.remove(development.developmentEvaluations, { + data: request, + }); + addLogSequence(request, { + action: "remove", + status: "success", + description: "Remove DevelopmentAddresss.", + }); + await this.developmentAddresssRepository.remove(development.developmentAddresss, { + data: request, + }); + addLogSequence(request, { + action: "remove", + status: "success", + description: "Remove Development.", + }); + await this.developmentRepository.remove(development, { data: request }); return new HttpSuccess(); } @@ -1278,10 +1644,7 @@ export class DevelopmentController extends Controller { * @param {string} id Id โครงการ */ @Get("finish/{id}") - async FinishDevelopemtById( - @Path() id: string, - @Request() request: { user: Record }, - ) { + async FinishDevelopemtById(@Path() id: string, @Request() request: RequestWithUser) { const getDevelopment = await this.developmentRepository.findOne({ where: { id: id }, }); @@ -1291,7 +1654,12 @@ export class DevelopmentController extends Controller { getDevelopment.status = "FINISH"; getDevelopment.lastUpdateUserId = request.user.sub; getDevelopment.lastUpdateFullName = request.user.name; - await this.developmentRepository.save(getDevelopment); + addLogSequence(request, { + action: "database", + status: "success", + description: "Store Development.", + }); + await this.developmentRepository.save(getDevelopment, { data: request }); return new HttpSuccess(getDevelopment); } @@ -1662,10 +2030,7 @@ export class DevelopmentController extends Controller { * @param {string} id Id โครงการ */ @Get("tab6/done/{id}") - async GetDevelopemtTab6DoneById( - @Path() id: string, - @Request() request: { user: Record }, - ) { + async GetDevelopemtTab6DoneById(@Path() id: string, @Request() request: RequestWithUser) { const getDevelopment = await this.developmentHistoryRepository.find({ where: { developmentId: id, isDone: false }, relations: ["development"], @@ -1721,7 +2086,12 @@ export class DevelopmentController extends Controller { _data.lastUpdateUserId = request.user.sub; _data.lastUpdateFullName = request.user.name; - await this.developmentHistoryRepository.save(_data); + addLogSequence(request, { + action: "database", + status: "success", + description: "Store DevelopmentHistory.", + }); + await this.developmentHistoryRepository.save(_data, { data: request }); }), ); return new HttpSuccess(getDevelopment); @@ -1734,7 +2104,7 @@ export class DevelopmentController extends Controller { * */ @Get("org/root") - async GetOrgDevelopemt(@Request() request: { user: Record }) { + async GetOrgDevelopemt() { const getOrg = await this.developmentRepository .createQueryBuilder("development") .select("development.root") @@ -1759,7 +2129,7 @@ export class DevelopmentController extends Controller { async UploadUserDevelopemtById( @Path() id: string, @UploadedFile() file: Express.Multer.File, - @Request() request: { user: Record }, + @Request() request: RequestWithUser, ) { const getDevelopment = await this.developmentRepository.findOne({ where: { id: id }, @@ -1801,7 +2171,12 @@ export class DevelopmentController extends Controller { oldProfile.createdFullName = request.user.name; oldProfile.lastUpdateUserId = request.user.sub; oldProfile.lastUpdateFullName = request.user.name; - await this.developmentHistoryRepository.save(oldProfile); + addLogSequence(request, { + action: "database", + status: "success", + description: "Store DevelopmentHistory.", + }); + await this.developmentHistoryRepository.save(oldProfile, { data: request }); return; } if (item["ประเภท"] == undefined) return; @@ -1833,7 +2208,12 @@ export class DevelopmentController extends Controller { development.createdFullName = request.user.name; development.lastUpdateUserId = request.user.sub; development.lastUpdateFullName = request.user.name; - await this.developmentHistoryRepository.save(development); + addLogSequence(request, { + action: "database", + status: "success", + description: "Store DevelopmentHistory.", + }); + await this.developmentHistoryRepository.save(development, { data: request }); }) .catch((x) => { return; @@ -1866,7 +2246,12 @@ export class DevelopmentController extends Controller { development.createdFullName = request.user.name; development.lastUpdateUserId = request.user.sub; development.lastUpdateFullName = request.user.name; - await this.developmentHistoryRepository.save(development); + addLogSequence(request, { + action: "database", + status: "success", + description: "Store DevelopmentHistory.", + }); + await this.developmentHistoryRepository.save(development, { data: request }); }) .catch((x) => { return; diff --git a/src/controllers/DevelopmentEmployeeHistoryController.ts b/src/controllers/DevelopmentEmployeeHistoryController.ts index c35b617..731dd80 100644 --- a/src/controllers/DevelopmentEmployeeHistoryController.ts +++ b/src/controllers/DevelopmentEmployeeHistoryController.ts @@ -25,6 +25,8 @@ import { } from "../entities/DevelopmentHistory"; import { EmployeePosType } from "../entities/EmployeePosType"; import { EmployeePosLevel } from "../entities/EmployeePosLevel"; +import { RequestWithUser } from "../middlewares/user"; +import { addLogSequence } from "../interfaces/utils"; @Route("api/v1/development/history/employee") @Tags("DevelopmentEmployeeHistory") @@ -72,7 +74,7 @@ export class DevelopmentEmployeeHistoryController extends Controller { @Post() async CreateDevelopmentHistory( @Body() requestBody: CreateDevelopmentHistory, - @Request() request: { user: Record }, + @Request() request: RequestWithUser, ) { const type = "EMPLOYEE"; const chk_name = await this.developmentHistoryRepository.find({ @@ -119,7 +121,12 @@ export class DevelopmentEmployeeHistoryController extends Controller { development.createdFullName = request.user.name; development.lastUpdateUserId = request.user.sub; development.lastUpdateFullName = request.user.name; - await this.developmentHistoryRepository.save(development); + addLogSequence(request, { + action: "database", + status: "success", + description: "Store DevelopmentHistory.", + }); + await this.developmentHistoryRepository.save(development, { data: request }); return new HttpSuccess(development.id); } @@ -134,7 +141,7 @@ export class DevelopmentEmployeeHistoryController extends Controller { async UpdateDevelopmentHistory( @Path() id: string, @Body() requestBody: UpdateDevelopmentHistory, - @Request() request: { user: Record }, + @Request() request: RequestWithUser, ) { const type = "EMPLOYEE"; const development = await this.developmentHistoryRepository.findOne({ @@ -184,7 +191,12 @@ export class DevelopmentEmployeeHistoryController extends Controller { development.posLevelId = null; development.lastUpdateUserId = request.user.sub; development.lastUpdateFullName = request.user.name; - await this.developmentHistoryRepository.save(development); + addLogSequence(request, { + action: "database", + status: "success", + description: "Store DevelopmentHistory.", + }); + await this.developmentHistoryRepository.save(development, { data: request }); return new HttpSuccess(development.id); } @@ -196,7 +208,7 @@ export class DevelopmentEmployeeHistoryController extends Controller { * @param {string} id Id โครงการ */ @Delete("{id}") - async DeleteDevelopmentHistory(@Path() id: string) { + async DeleteDevelopmentHistory(@Path() id: string,@Request () request: RequestWithUser) { const type = "EMPLOYEE"; const development = await this.developmentHistoryRepository.findOne({ where: { id: id, type: type }, @@ -204,8 +216,12 @@ export class DevelopmentEmployeeHistoryController extends Controller { if (!development) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลประวัติการฝึกอบรม/ดูงานนี้"); } - - await this.developmentHistoryRepository.remove(development); + addLogSequence(request, { + action: "remove", + status: "success", + description: "Remove DevelopmentHistory.", + }); + await this.developmentHistoryRepository.remove(development, { data: request }); return new HttpSuccess(); } diff --git a/src/controllers/DevelopmentHistoryController.ts b/src/controllers/DevelopmentHistoryController.ts index b19c1bf..ae476b5 100644 --- a/src/controllers/DevelopmentHistoryController.ts +++ b/src/controllers/DevelopmentHistoryController.ts @@ -25,6 +25,8 @@ import { } from "../entities/DevelopmentHistory"; import { PosType } from "../entities/PosType"; import { PosLevel } from "../entities/PosLevel"; +import { RequestWithUser } from "../middlewares/user"; +import { addLogSequence } from "../interfaces/utils"; @Route("api/v1/development/history/officer") @Tags("DevelopmentOfficerHistory") @@ -72,7 +74,7 @@ export class DevelopmentOfficerHistoryController extends Controller { @Post() async CreateDevelopmentHistory( @Body() requestBody: CreateDevelopmentHistory, - @Request() request: { user: Record }, + @Request() request: RequestWithUser, ) { const type = "OFFICER"; const chk_name = await this.developmentHistoryRepository.find({ @@ -115,7 +117,12 @@ export class DevelopmentOfficerHistoryController extends Controller { development.createdFullName = request.user.name; development.lastUpdateUserId = request.user.sub; development.lastUpdateFullName = request.user.name; - await this.developmentHistoryRepository.save(development); + addLogSequence(request, { + action: "database", + status: "success", + description: "Store DevelopmentHistory.", + }); + await this.developmentHistoryRepository.save(development, { data: request }); return new HttpSuccess(development.id); } @@ -130,7 +137,7 @@ export class DevelopmentOfficerHistoryController extends Controller { async UpdateDevelopmentHistory( @Path() id: string, @Body() requestBody: UpdateDevelopmentHistory, - @Request() request: { user: Record }, + @Request() request: RequestWithUser, ) { const type = "OFFICER"; const development = await this.developmentHistoryRepository.findOne({ @@ -176,7 +183,12 @@ export class DevelopmentOfficerHistoryController extends Controller { development.type = type; development.lastUpdateUserId = request.user.sub; development.lastUpdateFullName = request.user.name; - await this.developmentHistoryRepository.save(development); + addLogSequence(request, { + action: "database", + status: "success", + description: "Store DevelopmentHistory.", + }); + await this.developmentHistoryRepository.save(development, { data: request }); return new HttpSuccess(development.id); } @@ -188,7 +200,7 @@ export class DevelopmentOfficerHistoryController extends Controller { * @param {string} id Id โครงการ */ @Delete("{id}") - async DeleteDevelopmentHistory(@Path() id: string) { + async DeleteDevelopmentHistory(@Path() id: string, @Request() request: RequestWithUser) { const type = "OFFICER"; const development = await this.developmentHistoryRepository.findOne({ where: { id: id, type: type }, @@ -196,8 +208,12 @@ export class DevelopmentOfficerHistoryController extends Controller { if (!development) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลประวัติการฝึกอบรม/ดูงานนี้"); } - - await this.developmentHistoryRepository.remove(development); + addLogSequence(request, { + action: "database", + status: "success", + description: "Store DevelopmentHistory.", + }); + await this.developmentHistoryRepository.remove(development, { data: request }); return new HttpSuccess(); } diff --git a/src/controllers/DevelopmentScholarshipController.ts b/src/controllers/DevelopmentScholarshipController.ts index b403675..b4bcbb4 100644 --- a/src/controllers/DevelopmentScholarshipController.ts +++ b/src/controllers/DevelopmentScholarshipController.ts @@ -26,6 +26,9 @@ import { import { PosType } from "../entities/PosType"; import { PosLevel } from "../entities/PosLevel"; import CallAPI from "../interfaces/call-api"; +import { RequestWithUser } from "../middlewares/user"; +import { addLogSequence, setLogDataDiff } from "../interfaces/utils"; +import { request } from "axios"; @Route("api/v1/development/scholarship") @Tags("DevelopmentScholarship") @@ -44,9 +47,14 @@ export class DevelopmentScholarshipController extends Controller { @Post() async CreateDevelopmentScholarship( @Body() requestBody: CreateDevelopmentScholarship, - @Request() request: { user: Record }, + @Request() request: RequestWithUser, ) { if (requestBody.posTypeId != null) { + // addLogSequence(request, { + // action: "database", + // status: "success", + // description: "Get Position Type.", + // }); const checkId = await this.posTypeRepository.findOne({ where: { id: requestBody.posTypeId }, }); @@ -55,6 +63,11 @@ export class DevelopmentScholarshipController extends Controller { } } if (requestBody.posLevelId != null) { + // addLogSequence(request, { + // action: "database", + // status: "success", + // description: "Get Position Level.", + // }); const checkId = await this.posLevelRepository.findOne({ where: { id: requestBody.posLevelId }, }); @@ -68,7 +81,12 @@ export class DevelopmentScholarshipController extends Controller { development.createdFullName = request.user.name; development.lastUpdateUserId = request.user.sub; development.lastUpdateFullName = request.user.name; - await this.developmentScholarshipRepository.save(development); + addLogSequence(request, { + action: "database", + status: "success", + description: "Store Development Scholarship.", + }); + await this.developmentScholarshipRepository.save(development, { data: request }); return new HttpSuccess(development.id); } @@ -83,8 +101,13 @@ export class DevelopmentScholarshipController extends Controller { async UpdateDevelopmentScholarship( @Path() id: string, @Body() requestBody: UpdateDevelopmentScholarship, - @Request() request: { user: Record }, + @Request() request: RequestWithUser, ) { + // addLogSequence(request, { + // action: "database", + // status: "success", + // description: "Get Development Scholarship.", + // }); const development = await this.developmentScholarshipRepository.findOne({ where: { id: id }, }); @@ -92,6 +115,11 @@ export class DevelopmentScholarshipController extends Controller { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลทุนการศึกษา/ฝึกอบรมนี้"); } if (requestBody.posTypeId != null) { + // addLogSequence(request, { + // action: "database", + // status: "success", + // description: "Get Position Type.", + // }); const checkId = await this.posTypeRepository.findOne({ where: { id: requestBody.posTypeId }, }); @@ -100,6 +128,11 @@ export class DevelopmentScholarshipController extends Controller { } } if (requestBody.posLevelId != null) { + // addLogSequence(request, { + // action: "database", + // status: "success", + // description: "Get Position Level.", + // }); const checkId = await this.posLevelRepository.findOne({ where: { id: requestBody.posLevelId }, }); @@ -107,10 +140,17 @@ export class DevelopmentScholarshipController extends Controller { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลระดับตำแหน่ง"); } } + const before = structuredClone(development); Object.assign(development, requestBody); development.lastUpdateUserId = request.user.sub; development.lastUpdateFullName = request.user.name; - await this.developmentScholarshipRepository.save(development); + addLogSequence(request, { + action: "database", + status: "success", + description: "Store DevelopmentScholarship.", + }); + await this.developmentScholarshipRepository.save(development, { data: request }); + setLogDataDiff(request, { before, after: development }); return new HttpSuccess(development.id); } @@ -122,15 +162,24 @@ export class DevelopmentScholarshipController extends Controller { * @param {string} id Id ข้าราชการฯที่ได้รับทุนการศึกษา */ @Delete("{id}") - async DeleteDevelopmentScholarship(@Path() id: string) { + async DeleteDevelopmentScholarship(@Path() id: string, @Request() request: RequestWithUser) { + // addLogSequence(request, { + // action: "database", + // status: "success", + // description: "Get Development Scholarship", + // }); const development = await this.developmentScholarshipRepository.findOne({ where: { id: id }, }); if (!development) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลทุนการศึกษา/ฝึกอบรมนี้"); } - - await this.developmentScholarshipRepository.remove(development); + addLogSequence(request, { + action: "remove", + status: "success", + description: "Remove Development Scholarship By ID.", + }); + await this.developmentScholarshipRepository.remove(development, { data: request }); return new HttpSuccess(); } @@ -422,19 +471,30 @@ export class DevelopmentScholarshipController extends Controller { async UpdateDevelopemtScholarshipUserById( @Path() id: string, @Body() requestBody: UpdateDevelopmentScholarshipUser, - @Request() request: { user: Record }, + @Request() request: RequestWithUser, ) { + // addLogSequence(request, { + // action: "database", + // status: "success", + // description: "Get Development Scholarship.", + // }); const getDevelopment = await this.developmentScholarshipRepository.findOne({ where: { id: id }, }); if (!getDevelopment) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลทุนการศึกษา/ฝึกอบรมนี้"); } + const before = structuredClone(getDevelopment); Object.assign(getDevelopment, requestBody); getDevelopment.lastUpdateUserId = request.user.sub; getDevelopment.lastUpdateFullName = request.user.name; - await this.developmentScholarshipRepository.save(getDevelopment); - + addLogSequence(request, { + action: "database", + status: "success", + description: "Store DevelopmentScholarship.", + }); + await this.developmentScholarshipRepository.save(getDevelopment, { data: request }); + setLogDataDiff(request, { before, after: getDevelopment }); return new HttpSuccess(getDevelopment.id); } @@ -450,8 +510,13 @@ export class DevelopmentScholarshipController extends Controller { async ChangeStatusDevelopemtScholarshipById( @Path() id: string, @Path() status: string, - @Request() request: { user: Record }, + @Request() request: RequestWithUser, ) { + // addLogSequence(request, { + // action: "database", + // status: "success", + // description: "Get Development Scholarship.", + // }); const getDevelopment = await this.developmentScholarshipRepository.findOne({ where: { id: id }, }); @@ -465,6 +530,11 @@ export class DevelopmentScholarshipController extends Controller { let scholarshipType = ""; if (_status == "GRADUATE") { if (getDevelopment.scholarshipType != null) { + // addLogSequence(request, { + // action: "database", + // status: "success", + // description: "Change Status Development Scholarship.", + // }); switch (getDevelopment.scholarshipType.trim().toUpperCase()) { case "DOMESTICE": scholarshipType = "การศึกษาในประเทศ"; @@ -509,14 +579,19 @@ export class DevelopmentScholarshipController extends Controller { positionPathId: null, }) .then(async (x) => { - await this.developmentScholarshipRepository.save(getDevelopment); + await this.developmentScholarshipRepository.save(getDevelopment, { data: request }); }) .catch((error) => { console.error("ไม่สามารถบันทึกลงทะเบียนประวัติได้"); }); } else if (_status == "NOTGRADUATE") { getDevelopment.status = _status; - await this.developmentScholarshipRepository.save(getDevelopment); + addLogSequence(request, { + action: "database", + status: "success", + description: "Change Status Development Scholarship.", + }); + await this.developmentScholarshipRepository.save(getDevelopment, { data: request }); } else { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบสถานะนี้ในระบบ"); } diff --git a/src/controllers/PortfolioController.ts b/src/controllers/PortfolioController.ts index 51f4eec..17b1522 100644 --- a/src/controllers/PortfolioController.ts +++ b/src/controllers/PortfolioController.ts @@ -20,6 +20,7 @@ import HttpError from "../interfaces/http-error"; import { Not } from "typeorm"; import { CreatePortfolio, Portfolio } from "../entities/Portfolio"; import { RequestWithUser } from "../middlewares/user"; +import { addLogSequence } from "../interfaces/utils"; @Route("api/v1/development/portfolio") @Tags("Portfolio") @@ -105,7 +106,12 @@ export class PortfolioController extends Controller { _portfolio.createdFullName = request.user.name; _portfolio.lastUpdateUserId = request.user.sub; _portfolio.lastUpdateFullName = request.user.name; - await this.portfolioRepository.save(_portfolio); + addLogSequence(request, { + action: "database", + status: "success", + description: "Store Portfolio.", + }); + await this.portfolioRepository.save(_portfolio, { data: request }); return new HttpSuccess(_portfolio.id); } @@ -137,7 +143,12 @@ export class PortfolioController extends Controller { _portfolio.lastUpdateUserId = request.user.sub; _portfolio.lastUpdateFullName = request.user.name; Object.assign(_portfolio, requestBody); - await this.portfolioRepository.save(_portfolio); + addLogSequence(request, { + action: "database", + status: "success", + description: "Store Portfolio.", + }); + await this.portfolioRepository.save(_portfolio, { data: request }); return new HttpSuccess(_portfolio.id); } @@ -156,7 +167,12 @@ export class PortfolioController extends Controller { if (!_delPortfolio) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลผลงานนี้"); } - await this.portfolioRepository.delete(_delPortfolio.id); + addLogSequence(request, { + action: "database", + status: "success", + description: "Store Portfolio.", + }); + await this.portfolioRepository.delete(_delPortfolio.id), { data: request }; return new HttpSuccess(); } } diff --git a/src/controllers/StrategyController.ts b/src/controllers/StrategyController.ts index 5d815e1..1231641 100644 --- a/src/controllers/StrategyController.ts +++ b/src/controllers/StrategyController.ts @@ -42,6 +42,8 @@ import HttpError from "../interfaces/http-error"; import HttpStatus from "../interfaces/http-status"; import HttpSuccess from "../interfaces/http-success"; import { Check } from "typeorm"; +import { addLogSequence } from "../interfaces/utils"; +import { RequestWithUser } from "../middlewares/user"; @Route("api/v1/development/strategy") @Tags("Strategy") @@ -105,7 +107,7 @@ export class StrategyController extends Controller { @Post() public async newStrategyChild( - @Request() request: { user: Record }, + @Request() request: RequestWithUser, @Body() body: { name: string; @@ -202,15 +204,19 @@ export class StrategyController extends Controller { strategyChild.createdFullName = request.user.name; strategyChild.lastUpdateUserId = request.user.sub; strategyChild.lastUpdateFullName = request.user.name; - - await repoSave.save(strategyChild); + addLogSequence(request, { + action: "database", + status: "success", + description: "Store Strategy.", + }); + await repoSave.save(strategyChild, { data: request }); return new HttpSuccess(strategyChild.id); } @Patch() public async editStrategyChild1( - @Request() request: { user: Record }, + @Request() request: RequestWithUser, @Body() body: { name: string; @@ -278,14 +284,19 @@ export class StrategyController extends Controller { strategyChild.lastUpdateUserId = request.user.sub; strategyChild.lastUpdateFullName = request.user.name; - await strategyRepo.save(strategyChild); + addLogSequence(request, { + action: "remove", + status: "success", + description: "Edit Strategy by ID.", + }); + await strategyRepo.save(strategyChild, { data: request }); return new HttpSuccess(); } @Delete() public async deleteStrategyChild( - @Request() request: { user: Record }, + @Request() request: RequestWithUser, @Body() body: { levelnode: number; diff --git a/src/database/data-source.ts b/src/database/data-source.ts index 7c70f52..f594f1e 100644 --- a/src/database/data-source.ts +++ b/src/database/data-source.ts @@ -1,6 +1,28 @@ import "dotenv/config"; import "reflect-metadata"; -import { DataSource } from "typeorm"; +import { DataSource, LogLevel, LogMessage } from "typeorm"; +import { Logger } from "typeorm"; +import { QueryRunner } from "typeorm/browser"; +import { RequestWithUser } from "../middlewares/user"; + +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 | 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", @@ -11,7 +33,7 @@ export const AppDataSource = new DataSource({ password: process.env.DB_PASSWORD, connectorPackage: "mysql2", synchronize: false, - logging: true, + logging: ["query", "error"], entities: process.env.NODE_ENV !== "production" ? ["src/entities/**/*.ts"] @@ -21,7 +43,6 @@ export const AppDataSource = new DataSource({ ? ["src/migration/**/*.ts"] : ["dist/migration/**/*{.ts,.js}"], subscribers: [], + logger: new MyCustomLogger(), }); -// console.log(AppDataSource); -// export default database; diff --git a/src/interfaces/call-api.ts b/src/interfaces/call-api.ts index d6498fa..7060fd6 100644 --- a/src/interfaces/call-api.ts +++ b/src/interfaces/call-api.ts @@ -12,6 +12,7 @@ import { Path, } from "tsoa"; import axios from "axios"; +import { addLogSequence } from "./utils"; class CallAPI { //Get @@ -25,8 +26,26 @@ class CallAPI { "Content-Type": "application/json", }, }); + addLogSequence(request, { + action: "request", + status: "success", + description: JSON.stringify(response.data.result), + request: { + method: "GET", + url: url, + }, + }); return response.data.result; } catch (error) { + addLogSequence(request, { + action: "request", + status: "error", + description: JSON.stringify(error), + request: { + method: "GET", + url: url, + }, + }); throw error; } } @@ -41,8 +60,26 @@ class CallAPI { "Content-Type": "application/json", }, }); + addLogSequence(request, { + action: "request", + status: "success", + description: JSON.stringify(response.data.result), + request: { + method: "POST", + url: url, + }, + }); return response.data.result; } catch (error) { + addLogSequence(request, { + action: "request", + status: "error", + description: JSON.stringify(error), + request: { + method: "POST", + url: url, + }, + }); throw error; } } diff --git a/src/interfaces/utils.ts b/src/interfaces/utils.ts new file mode 100644 index 0000000..a6bf98d --- /dev/null +++ b/src/interfaces/utils.ts @@ -0,0 +1,35 @@ +import { RequestWithUser } from "../middlewares/user"; + +export type DataDiff = { + before: any; + after: any; +}; + +export type LogSequence = { + action: string; + status: "success" | "error"; + description: string; + query?: string; + request?: { + method: "GET" | "POST" | "PUT" | "DELETE" | "PATCH"; + url: 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; +} diff --git a/src/middlewares/error.ts b/src/middlewares/error.ts index b010f0a..f8d0b56 100644 --- a/src/middlewares/error.ts +++ b/src/middlewares/error.ts @@ -4,6 +4,12 @@ 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, diff --git a/src/middlewares/logs.ts b/src/middlewares/logs.ts index 1e6e16a..e5acc5b 100644 --- a/src/middlewares/logs.ts +++ b/src/middlewares/logs.ts @@ -39,7 +39,7 @@ async function logMiddleware(req: Request, res: Response, next: NextFunction) { res.on("finish", () => { if (!req.url.startsWith("/api/")) return; - const level = LOG_LEVEL_MAP[process.env.LOG_LEVEL ?? "info"] || 1; + 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; @@ -47,6 +47,7 @@ async function logMiddleware(req: Request, res: Response, next: NextFunction) { const obj = { logType: res.statusCode >= 500 ? "error" : res.statusCode >= 400 ? "warning" : "info", + ip: req.ip, systemName: "development", startTimeStamp: timestamp, endTimeStamp: new Date().toISOString(), @@ -55,7 +56,7 @@ async function logMiddleware(req: Request, res: Response, next: NextFunction) { method: req.method, endpoint: req.url, responseCode: String(res.statusCode === 304 ? 200 : res.statusCode), - responseDescription: data?.code, + 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, From f6ee60eab9536722b3018ce795ce12293abdda01 Mon Sep 17 00:00:00 2001 From: AdisakKanthawilang Date: Thu, 25 Jul 2024 17:31:01 +0700 Subject: [PATCH 114/250] fix --- src/controllers/DevelopmentController.ts | 5 +++++ src/database/data-source.ts | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/controllers/DevelopmentController.ts b/src/controllers/DevelopmentController.ts index 52a87bc..edeee82 100644 --- a/src/controllers/DevelopmentController.ts +++ b/src/controllers/DevelopmentController.ts @@ -1326,6 +1326,11 @@ export class DevelopmentController extends Controller { Object.assign(development, requestBody); development.lastUpdateUserId = request.user.sub; development.lastUpdateFullName = request.user.name; + addLogSequence(request, { + action: "database", + status: "success", + description: "Store DevelopmentEvaluation.", + }); await this.developmentEvaluationRepository.save(development, { data: request }); return new HttpSuccess(development.id); } diff --git a/src/database/data-source.ts b/src/database/data-source.ts index f594f1e..1eee170 100644 --- a/src/database/data-source.ts +++ b/src/database/data-source.ts @@ -10,7 +10,7 @@ export class MyCustomLogger implements Logger { logQuery(query: string, parameters?: any[], queryRunner?: QueryRunner): void { const req = queryRunner?.data as RequestWithUser | undefined; - const logData = req?.app?.locals.logData?.sequence.at(-1); + const logData = req?.app?.locals.logData?.sequence?.at(-1); if (logData && !logData.query) logData.query = []; if (logData) logData.query.push( From cc26192b6597b6ad1e457ccafe6ee3d7e5c47ee9 Mon Sep 17 00:00:00 2001 From: AdisakKanthawilang Date: Thu, 25 Jul 2024 17:39:58 +0700 Subject: [PATCH 115/250] fix tab5 --- src/controllers/DevelopmentController.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/controllers/DevelopmentController.ts b/src/controllers/DevelopmentController.ts index edeee82..8479baf 100644 --- a/src/controllers/DevelopmentController.ts +++ b/src/controllers/DevelopmentController.ts @@ -1381,6 +1381,7 @@ export class DevelopmentController extends Controller { await this.developmentAddresssRepository.remove(development.developmentAddresss, { data: request, }); + const before = structuredClone(development); await Promise.all( requestBody.developmentAddresss.map(async (x) => { const data = Object.assign(new DevelopmentAddress(), x); @@ -1401,6 +1402,7 @@ export class DevelopmentController extends Controller { description: "Store DevelopmentAddresss.", }); await this.developmentAddresssRepository.save(data, { data: request }); + setLogDataDiff(request, { before, after: development }); }), ); From 29527c512e66d9ba1233ea9cd9cfd2a5ed50297d Mon Sep 17 00:00:00 2001 From: AdisakKanthawilang Date: Fri, 26 Jul 2024 16:30:38 +0700 Subject: [PATCH 116/250] add prepare data log method:POST --- src/controllers/DevelopmentController.ts | 7 ++++++- .../DevelopmentEmployeeHistoryController.ts | 5 +++-- src/controllers/DevelopmentHistoryController.ts | 5 +++-- .../DevelopmentScholarshipController.ts | 3 ++- src/controllers/PortfolioController.ts | 5 +++-- src/controllers/StrategyController.ts | 5 +++-- src/interfaces/call-api.ts | 14 ++++++++++---- src/interfaces/utils.ts | 2 ++ 8 files changed, 32 insertions(+), 14 deletions(-) diff --git a/src/controllers/DevelopmentController.ts b/src/controllers/DevelopmentController.ts index 8479baf..646237d 100644 --- a/src/controllers/DevelopmentController.ts +++ b/src/controllers/DevelopmentController.ts @@ -148,7 +148,9 @@ export class DevelopmentController extends Controller { status: "success", description: "Store Development.", }); + const before = null; await this.developmentRepository.save(development, { data: request }); + setLogDataDiff(request, { before, after: development }); return new HttpSuccess(development.id); } @@ -2151,7 +2153,7 @@ export class DevelopmentController extends Controller { const sheetName = workbook.SheetNames[0]; // Assuming we're reading the first sheet const sheet = workbook.Sheets[sheetName]; const getDevelopments = xlsx.utils.sheet_to_json(sheet); - + const before = null; await Promise.all( getDevelopments.map(async (item: any) => { if (item["รหัสประจำตัวประชาชน"] == undefined || item["รหัสประจำตัวประชาชน"].length != 13) @@ -2184,6 +2186,7 @@ export class DevelopmentController extends Controller { description: "Store DevelopmentHistory.", }); await this.developmentHistoryRepository.save(oldProfile, { data: request }); + setLogDataDiff(request, { before, after: oldProfile }); return; } if (item["ประเภท"] == undefined) return; @@ -2221,6 +2224,7 @@ export class DevelopmentController extends Controller { description: "Store DevelopmentHistory.", }); await this.developmentHistoryRepository.save(development, { data: request }); + setLogDataDiff(request, { before, after: development }); }) .catch((x) => { return; @@ -2259,6 +2263,7 @@ export class DevelopmentController extends Controller { description: "Store DevelopmentHistory.", }); await this.developmentHistoryRepository.save(development, { data: request }); + setLogDataDiff(request, { before, after: development }); }) .catch((x) => { return; diff --git a/src/controllers/DevelopmentEmployeeHistoryController.ts b/src/controllers/DevelopmentEmployeeHistoryController.ts index 731dd80..b7c34c4 100644 --- a/src/controllers/DevelopmentEmployeeHistoryController.ts +++ b/src/controllers/DevelopmentEmployeeHistoryController.ts @@ -26,7 +26,7 @@ import { import { EmployeePosType } from "../entities/EmployeePosType"; import { EmployeePosLevel } from "../entities/EmployeePosLevel"; import { RequestWithUser } from "../middlewares/user"; -import { addLogSequence } from "../interfaces/utils"; +import { addLogSequence, setLogDataDiff } from "../interfaces/utils"; @Route("api/v1/development/history/employee") @Tags("DevelopmentEmployeeHistory") @@ -110,7 +110,7 @@ export class DevelopmentEmployeeHistoryController extends Controller { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลระดับตำแหน่ง"); } } - + const before = null; const development = Object.assign(new DevelopmentHistory(), requestBody); development.type = type; development.employeePosTypeId = requestBody.posTypeId; @@ -127,6 +127,7 @@ export class DevelopmentEmployeeHistoryController extends Controller { description: "Store DevelopmentHistory.", }); await this.developmentHistoryRepository.save(development, { data: request }); + setLogDataDiff(request, { before, after: development }); return new HttpSuccess(development.id); } diff --git a/src/controllers/DevelopmentHistoryController.ts b/src/controllers/DevelopmentHistoryController.ts index ae476b5..1e5a547 100644 --- a/src/controllers/DevelopmentHistoryController.ts +++ b/src/controllers/DevelopmentHistoryController.ts @@ -26,7 +26,7 @@ import { import { PosType } from "../entities/PosType"; import { PosLevel } from "../entities/PosLevel"; import { RequestWithUser } from "../middlewares/user"; -import { addLogSequence } from "../interfaces/utils"; +import { addLogSequence, setLogDataDiff } from "../interfaces/utils"; @Route("api/v1/development/history/officer") @Tags("DevelopmentOfficerHistory") @@ -110,7 +110,7 @@ export class DevelopmentOfficerHistoryController extends Controller { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลระดับตำแหน่ง"); } } - + const before = null; const development = Object.assign(new DevelopmentHistory(), requestBody); development.type = type; development.createdUserId = request.user.sub; @@ -123,6 +123,7 @@ export class DevelopmentOfficerHistoryController extends Controller { description: "Store DevelopmentHistory.", }); await this.developmentHistoryRepository.save(development, { data: request }); + setLogDataDiff(request, { before, after: development }); return new HttpSuccess(development.id); } diff --git a/src/controllers/DevelopmentScholarshipController.ts b/src/controllers/DevelopmentScholarshipController.ts index b4bcbb4..7b30ee7 100644 --- a/src/controllers/DevelopmentScholarshipController.ts +++ b/src/controllers/DevelopmentScholarshipController.ts @@ -75,7 +75,7 @@ export class DevelopmentScholarshipController extends Controller { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลระดับตำแหน่ง"); } } - + const before = null; const development = Object.assign(new DevelopmentScholarship(), requestBody); development.createdUserId = request.user.sub; development.createdFullName = request.user.name; @@ -87,6 +87,7 @@ export class DevelopmentScholarshipController extends Controller { description: "Store Development Scholarship.", }); await this.developmentScholarshipRepository.save(development, { data: request }); + setLogDataDiff(request, { before, after: development }); return new HttpSuccess(development.id); } diff --git a/src/controllers/PortfolioController.ts b/src/controllers/PortfolioController.ts index 17b1522..04a2657 100644 --- a/src/controllers/PortfolioController.ts +++ b/src/controllers/PortfolioController.ts @@ -20,7 +20,7 @@ import HttpError from "../interfaces/http-error"; import { Not } from "typeorm"; import { CreatePortfolio, Portfolio } from "../entities/Portfolio"; import { RequestWithUser } from "../middlewares/user"; -import { addLogSequence } from "../interfaces/utils"; +import { addLogSequence, setLogDataDiff } from "../interfaces/utils"; @Route("api/v1/development/portfolio") @Tags("Portfolio") @@ -101,7 +101,7 @@ export class PortfolioController extends Controller { if (checkName) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ชื่อนี้มีอยู่ในระบบแล้ว"); } - + const before = null; _portfolio.createdUserId = request.user.sub; _portfolio.createdFullName = request.user.name; _portfolio.lastUpdateUserId = request.user.sub; @@ -112,6 +112,7 @@ export class PortfolioController extends Controller { description: "Store Portfolio.", }); await this.portfolioRepository.save(_portfolio, { data: request }); + setLogDataDiff(request, { before, after: _portfolio }); return new HttpSuccess(_portfolio.id); } diff --git a/src/controllers/StrategyController.ts b/src/controllers/StrategyController.ts index 1231641..cb44c76 100644 --- a/src/controllers/StrategyController.ts +++ b/src/controllers/StrategyController.ts @@ -42,7 +42,7 @@ import HttpError from "../interfaces/http-error"; import HttpStatus from "../interfaces/http-status"; import HttpSuccess from "../interfaces/http-success"; import { Check } from "typeorm"; -import { addLogSequence } from "../interfaces/utils"; +import { addLogSequence, setLogDataDiff } from "../interfaces/utils"; import { RequestWithUser } from "../middlewares/user"; @Route("api/v1/development/strategy") @@ -199,7 +199,7 @@ export class StrategyController extends Controller { default: throw new HttpError(HttpStatus.BAD_REQUEST, "levelnode ไม่ถูกต้อง"); } - + const before = null; strategyChild.createdUserId = request.user.sub; strategyChild.createdFullName = request.user.name; strategyChild.lastUpdateUserId = request.user.sub; @@ -210,6 +210,7 @@ export class StrategyController extends Controller { description: "Store Strategy.", }); await repoSave.save(strategyChild, { data: request }); + setLogDataDiff(request, { before, after: strategyChild }); return new HttpSuccess(strategyChild.id); } diff --git a/src/interfaces/call-api.ts b/src/interfaces/call-api.ts index 7060fd6..e95592a 100644 --- a/src/interfaces/call-api.ts +++ b/src/interfaces/call-api.ts @@ -29,10 +29,11 @@ class CallAPI { addLogSequence(request, { action: "request", status: "success", - description: JSON.stringify(response.data.result), + description: "connected", request: { method: "GET", url: url, + response: JSON.stringify(response.data.result), }, }); return response.data.result; @@ -40,10 +41,11 @@ class CallAPI { addLogSequence(request, { action: "request", status: "error", - description: JSON.stringify(error), + description: "unconnected", request: { method: "GET", url: url, + response: JSON.stringify(error), }, }); throw error; @@ -63,10 +65,12 @@ class CallAPI { addLogSequence(request, { action: "request", status: "success", - description: JSON.stringify(response.data.result), + description: "connected", request: { method: "POST", url: url, + payload: JSON.stringify(sendData), + response: JSON.stringify(response.data.result), }, }); return response.data.result; @@ -74,10 +78,12 @@ class CallAPI { addLogSequence(request, { action: "request", status: "error", - description: JSON.stringify(error), + description: "unconnected", request: { method: "POST", url: url, + payload: JSON.stringify(sendData), + response: JSON.stringify(error), }, }); throw error; diff --git a/src/interfaces/utils.ts b/src/interfaces/utils.ts index a6bf98d..12308e1 100644 --- a/src/interfaces/utils.ts +++ b/src/interfaces/utils.ts @@ -13,6 +13,8 @@ export type LogSequence = { request?: { method: "GET" | "POST" | "PUT" | "DELETE" | "PATCH"; url: string; + payload?: string; + response?: string; }; }; From 02002a32a61a14cde878ee3f003f47bc04b6cdfd Mon Sep 17 00:00:00 2001 From: AdisakKanthawilang Date: Tue, 30 Jul 2024 11:33:46 +0700 Subject: [PATCH 117/250] =?UTF-8?q?=E0=B9=80=E0=B8=9E=E0=B8=B4=E0=B9=88?= =?UTF-8?q?=E0=B8=A1=E0=B8=9F=E0=B8=B4=E0=B8=A7=20isProfile?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/DevelopmentController.ts | 1 + src/entities/DevelopmentHistory.ts | 6 ++++++ ...1722313928787-update_table_migration07302024.ts | 14 ++++++++++++++ 3 files changed, 21 insertions(+) create mode 100644 src/migration/1722313928787-update_table_migration07302024.ts diff --git a/src/controllers/DevelopmentController.ts b/src/controllers/DevelopmentController.ts index 646237d..5a7f4bc 100644 --- a/src/controllers/DevelopmentController.ts +++ b/src/controllers/DevelopmentController.ts @@ -2027,6 +2027,7 @@ export class DevelopmentController extends Controller { dateStart: item.dateStart, dateEnd: item.dateEnd, isDone: item.isDone, + isProfile: item.isProfile, })); return new HttpSuccess(_getDevelopment); } diff --git a/src/entities/DevelopmentHistory.ts b/src/entities/DevelopmentHistory.ts index 12e9ee5..79c0719 100644 --- a/src/entities/DevelopmentHistory.ts +++ b/src/entities/DevelopmentHistory.ts @@ -215,6 +215,12 @@ export class DevelopmentHistory extends EntityBase { default: false, }) isDone: boolean; + + @Column({ + comment: "มีข้อมูลอยู่ในทะเบียนประวัติ", + default: false, + }) + isProfile: boolean; } export class CreateDevelopmentHistory { @Column() diff --git a/src/migration/1722313928787-update_table_migration07302024.ts b/src/migration/1722313928787-update_table_migration07302024.ts new file mode 100644 index 0000000..2b8fef8 --- /dev/null +++ b/src/migration/1722313928787-update_table_migration07302024.ts @@ -0,0 +1,14 @@ +import { MigrationInterface, QueryRunner } from "typeorm"; + +export class UpdateTableMigration073020241722313928787 implements MigrationInterface { + name = 'UpdateTableMigration073020241722313928787' + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`developmentHistory\` ADD \`isProfile\` tinyint NOT NULL COMMENT 'มีข้อมูลอยู่ในทะเบียนประวัติ' DEFAULT 0`); + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`developmentHistory\` DROP COLUMN \`isProfile\``); + } + +} From f027422d564f1a5ee8e4439078f9bc13e868a27c Mon Sep 17 00:00:00 2001 From: AdisakKanthawilang Date: Tue, 30 Jul 2024 16:49:16 +0700 Subject: [PATCH 118/250] api uploadUser --- src/controllers/DevelopmentController.ts | 357 ++++++++++++++++++++--- src/entities/DevelopmentHistory.ts | 38 +++ 2 files changed, 353 insertions(+), 42 deletions(-) diff --git a/src/controllers/DevelopmentController.ts b/src/controllers/DevelopmentController.ts index 5a7f4bc..65ddc39 100644 --- a/src/controllers/DevelopmentController.ts +++ b/src/controllers/DevelopmentController.ts @@ -34,7 +34,11 @@ import { Province } from "../entities/Province"; import { PosType } from "../entities/PosType"; import { PosLevel } from "../entities/PosLevel"; import { PlannedGoalPosition } from "../entities/PlannedGoalPosition"; -import { DevelopmentHistory } from "../entities/DevelopmentHistory"; +import { + CreateDevelopmentHistory, + CreateDevelopmentHistoryOBO, + DevelopmentHistory, +} from "../entities/DevelopmentHistory"; import { DevelopmentProjectType } from "../entities/DevelopmentProjectType"; import { CreateDevelopmentEvaluation, @@ -908,7 +912,7 @@ export class DevelopmentController extends Controller { development.developmentProjectTechniquePlanneds, { data: request, - } + }, ); addLogSequence(request, { action: "remove", @@ -919,7 +923,7 @@ export class DevelopmentController extends Controller { development.developmentProjectTechniqueActuals, { data: request, - } + }, ); const _null: any = null; if ( @@ -1328,11 +1332,11 @@ export class DevelopmentController extends Controller { Object.assign(development, requestBody); development.lastUpdateUserId = request.user.sub; development.lastUpdateFullName = request.user.name; - addLogSequence(request, { - action: "database", - status: "success", - description: "Store DevelopmentEvaluation.", - }); + addLogSequence(request, { + action: "database", + status: "success", + description: "Store DevelopmentEvaluation.", + }); await this.developmentEvaluationRepository.save(development, { data: request }); return new HttpSuccess(development.id); } @@ -1398,11 +1402,11 @@ export class DevelopmentController extends Controller { data.createdFullName = request.user.name; data.lastUpdateUserId = request.user.sub; data.lastUpdateFullName = request.user.name; - addLogSequence(request, { - action: "database", - status: "success", - description: "Store DevelopmentAddresss.", - }); + addLogSequence(request, { + action: "database", + status: "success", + description: "Store DevelopmentAddresss.", + }); await this.developmentAddresssRepository.save(data, { data: request }); setLogDataDiff(request, { before, after: development }); }), @@ -1467,7 +1471,7 @@ export class DevelopmentController extends Controller { * @param {string} id Id รายการ */ @Delete("{id}") - async DeleteDevelopment(@Path() id: string , @Request () request: RequestWithUser) { + async DeleteDevelopment(@Path() id: string, @Request() request: RequestWithUser) { const development = await this.developmentRepository.findOne({ where: { id }, relations: { @@ -1493,26 +1497,26 @@ export class DevelopmentController extends Controller { const plannedGoalPosition = await this.plannedGoalPositionRepository.find({ where: { plannedGoalId: In(development.developmentPlannedGoals.map((x) => x.id)) }, }); - addLogSequence(request, { - action: "remove", - status: "success", - description: "Remove PlannedGoalPosition.", - }); + addLogSequence(request, { + action: "remove", + status: "success", + description: "Remove PlannedGoalPosition.", + }); await this.plannedGoalPositionRepository.remove(plannedGoalPosition, { data: request }); } - addLogSequence(request, { - action: "remove", - status: "success", - description: "Remove ActualPeople.", - }); + addLogSequence(request, { + action: "remove", + status: "success", + description: "Remove ActualPeople.", + }); await this.actualPeopleRepository.remove(development.developmentActualPeoples, { data: request, }); - addLogSequence(request, { - action: "remove", - status: "success", - description: "Remove PlannedPeople.", - }); + addLogSequence(request, { + action: "remove", + status: "success", + description: "Remove PlannedPeople.", + }); await this.plannedPeopleRepository.remove(development.developmentPlannedPeoples, { data: request, }); @@ -1663,11 +1667,11 @@ export class DevelopmentController extends Controller { getDevelopment.status = "FINISH"; getDevelopment.lastUpdateUserId = request.user.sub; getDevelopment.lastUpdateFullName = request.user.name; - addLogSequence(request, { - action: "database", - status: "success", - description: "Store Development.", - }); + addLogSequence(request, { + action: "database", + status: "success", + description: "Store Development.", + }); await this.developmentRepository.save(getDevelopment, { data: request }); return new HttpSuccess(getDevelopment); } @@ -2219,6 +2223,7 @@ export class DevelopmentController extends Controller { development.createdFullName = request.user.name; development.lastUpdateUserId = request.user.sub; development.lastUpdateFullName = request.user.name; + development.isProfile = true; addLogSequence(request, { action: "database", status: "success", @@ -2227,8 +2232,45 @@ export class DevelopmentController extends Controller { await this.developmentHistoryRepository.save(development, { data: request }); setLogDataDiff(request, { before, after: development }); }) - .catch((x) => { - return; + .catch(async (x) => { + let development = new DevelopmentHistory(); + let _null: any = null; + development.prefix = item["คำนำหน้า"] == undefined ? null : item["คำนำหน้า"]; + development.firstName = item["ชื่อ"] == undefined ? null : item["ชื่อ"]; + development.lastName = item["นามสกุล"] == undefined ? null : item["นามสกุล"]; + development.position = item["ตำแหน่ง"] == undefined ? null : item["ตำแหน่ง"]; + development.org = item["สังกัด"] == undefined ? null : item["สังกัด"]; + development.dateStart = + item["วันที่เริ่มต้น"] == undefined ? null : item["วันที่เริ่มต้น"]; + development.dateEnd = + item["วันที่สิ้นสุด"] == undefined ? null : item["วันที่สิ้นสุด"]; + development.order = + item["เลขที่คำสั่ง/เลขที่หนังสืออนุมัติ"] == undefined + ? null + : item["เลขที่คำสั่ง/เลขที่หนังสืออนุมัติ"]; + development.dateOrder = + item["คำสั่งลงวันที่/หนังสืออนุมัติลงวันที่"] == undefined + ? _null + : new Date(item["คำสั่งลงวันที่/หนังสืออนุมัติลงวันที่"]); + development.trainingDays = + item["จำนวนวันที่อบรม"] == undefined ? null : item["จำนวนวันที่อบรม"]; + development.posLevelId = x.posLevelId; + development.posTypeId = x.posTypeId; + development.employeePosLevelId = null; + development.employeePosTypeId = null; + development.developmentId = id; + development.createdUserId = request.user.sub; + development.createdFullName = request.user.name; + development.lastUpdateUserId = request.user.sub; + development.lastUpdateFullName = request.user.name; + development.isProfile = false; + addLogSequence(request, { + action: "database", + status: "success", + description: "Store DevelopmentHistory.", + }); + await this.developmentHistoryRepository.save(development, { data: request }); + setLogDataDiff(request, { before, after: development }); }); } else { await new CallAPI() @@ -2258,20 +2300,251 @@ export class DevelopmentController extends Controller { development.createdFullName = request.user.name; development.lastUpdateUserId = request.user.sub; development.lastUpdateFullName = request.user.name; + development.isProfile = true; addLogSequence(request, { - action: "database", - status: "success", - description: "Store DevelopmentHistory.", - }); + action: "database", + status: "success", + description: "Store DevelopmentHistory.", + }); await this.developmentHistoryRepository.save(development, { data: request }); setLogDataDiff(request, { before, after: development }); }) - .catch((x) => { - return; + .catch(async (x) => { + let development = new DevelopmentHistory(); + let _null: any = null; + development.prefix = item["คำนำหน้า"] == undefined ? null : item["คำนำหน้า"]; + development.firstName = item["ชื่อ"] == undefined ? null : item["ชื่อ"]; + development.lastName = item["นามสกุล"] == undefined ? null : item["นามสกุล"]; + development.position = item["ตำแหน่ง"] == undefined ? null : item["ตำแหน่ง"]; + development.org = item["สังกัด"] == undefined ? null : item["สังกัด"]; + development.dateStart = + item["วันที่เริ่มต้น"] == undefined ? null : item["วันที่เริ่มต้น"]; + development.dateEnd = + item["วันที่สิ้นสุด"] == undefined ? null : item["วันที่สิ้นสุด"]; + development.order = + item["เลขที่คำสั่ง/เลขที่หนังสืออนุมัติ"] == undefined + ? null + : item["เลขที่คำสั่ง/เลขที่หนังสืออนุมัติ"]; + development.dateOrder = + item["คำสั่งลงวันที่/หนังสืออนุมัติลงวันที่"] == undefined + ? _null + : new Date(item["คำสั่งลงวันที่/หนังสืออนุมัติลงวันที่"]); + development.trainingDays = + item["จำนวนวันที่อบรม"] == undefined ? null : item["จำนวนวันที่อบรม"]; + development.posLevelId = x.posLevelId; + development.posTypeId = x.posTypeId; + development.employeePosLevelId = null; + development.employeePosTypeId = null; + development.developmentId = id; + development.createdUserId = request.user.sub; + development.createdFullName = request.user.name; + development.lastUpdateUserId = request.user.sub; + development.lastUpdateFullName = request.user.name; + development.isProfile = false; + addLogSequence(request, { + action: "database", + status: "success", + description: "Store DevelopmentHistory.", + }); + await this.developmentHistoryRepository.save(development, { data: request }); + setLogDataDiff(request, { before, after: development }); }); } }), ); return new HttpSuccess(getDevelopments); } + /** + * API upload User One by one + * + * @summary DEV_0 - upload User One by one # + * + * @param {string} id Id โครงการ + */ + @Post("uploadUser/{id}") + async UploadUserDevelopemtOBO( + @Path() id: string, + @Body() requestBody: CreateDevelopmentHistoryOBO, + @Request() request: RequestWithUser, + ) { + const getDevelopment = await this.developmentRepository.findOne({ + where: { id: id }, + relations: { + developmentHistorys: true, + }, + }); + if (!getDevelopment) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงการ/หลักสูตรการฝึกอบรมนี้"); + } + const oldProfile: any = await this.developmentHistoryRepository.findOne({ + where: { citizenId: requestBody.citizenId }, + }); + + const before = null; + let status = null; + let _null: any = null; + if (oldProfile != null) { + if (oldProfile.isDone == true) + throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, "ข้อมูลนี้ได้ถูกบันทึกแล้ว"); + oldProfile.dateStart = requestBody.dateStart == undefined ? _null : requestBody.dateStart; + oldProfile.dateEnd = requestBody.dateEnd == undefined ? _null : requestBody.dateEnd; + oldProfile.order = requestBody.order == undefined ? _null : requestBody.order; + oldProfile.dateOrder = + requestBody.dateOrder == undefined ? _null : new Date(requestBody.dateOrder); + oldProfile.trainingDays = + requestBody.trainingDays == undefined ? _null : requestBody.trainingDays; + oldProfile.createdUserId = request.user.sub; + oldProfile.createdFullName = request.user.name; + oldProfile.lastUpdateUserId = request.user.sub; + oldProfile.lastUpdateFullName = request.user.name; + addLogSequence(request, { + action: "database", + status: "success", + description: "Store DevelopmentHistory.", + }); + await this.developmentHistoryRepository.save(oldProfile, { data: request }); + setLogDataDiff(request, { before, after: oldProfile }); + status = oldProfile.isProfile; + } + + if (requestBody.type == "OFFICER") { + await new CallAPI() + .GetData(request, `/org/unauthorize/officer/citizen/${requestBody.citizenId}`) + .then(async (x: any) => { + let development = Object.assign(new DevelopmentHistory(), x); + development.dateStart = + requestBody.dateStart == undefined ? _null : requestBody.dateStart; + development.dateEnd = requestBody.dateEnd == undefined ? _null : requestBody.dateEnd; + development.order = requestBody.order == undefined ? _null : requestBody.order; + development.dateOrder = + requestBody.dateOrder == undefined ? _null : requestBody.dateOrder; + development.trainingDays = + requestBody.trainingDays == undefined ? _null : requestBody.trainingDays; + development.posLevelId = x.posLevelId == undefined ? _null : x.posLevelId; + development.posTypeId = x.posTypeId == undefined ? _null : x.posTypeId; + development.employeePosLevelId = null; + development.employeePosTypeId = null; + development.developmentId = id; + development.isProfile = true; + development.createdUserId = request.user.sub; + development.createdFullName = request.user.name; + development.lastUpdateUserId = request.user.sub; + development.lastUpdateFullName = request.user.name; + addLogSequence(request, { + action: "database", + status: "success", + description: "Store DevelopmentHistory.", + }); + await this.developmentHistoryRepository.save(development, { data: request }); + setLogDataDiff(request, { before, after: development }); + status = development.isProfile; + }) + .catch(async (x) => { + let development = new DevelopmentHistory(); + let _null: any = null; + development.prefix = requestBody.prefix == undefined ? _null : requestBody.prefix; + development.firstName = + requestBody.firstName == undefined ? _null : requestBody.firstName; + development.lastName = requestBody.lastName == undefined ? _null : requestBody.lastName; + development.position = requestBody.position == undefined ? _null : requestBody.position; + development.org = requestBody.org == undefined ? _null : requestBody.org; + development.dateStart = + requestBody.dateStart == undefined ? _null : requestBody.dateStart; + development.dateEnd = requestBody.dateEnd == undefined ? _null : requestBody.dateEnd; + development.order = requestBody.order == undefined ? _null : requestBody.order; + development.dateOrder = + requestBody.dateOrder == undefined ? _null : requestBody.dateOrder; + development.trainingDays = + requestBody.trainingDays == undefined ? _null : requestBody.trainingDays; + development.posLevelId = x.posLevelId == undefined ? _null : x.posLevelId; + development.posTypeId = x.posTypeId == undefined ? _null : x.posTypeId; + development.employeePosLevelId = null; + development.employeePosTypeId = null; + development.developmentId = id; + development.createdUserId = request.user.sub; + development.createdFullName = request.user.name; + development.lastUpdateUserId = request.user.sub; + development.lastUpdateFullName = request.user.name; + development.isProfile = false; + addLogSequence(request, { + action: "database", + status: "success", + description: "Store DevelopmentHistory.", + }); + await this.developmentHistoryRepository.save(development, { data: request }); + setLogDataDiff(request, { before, after: development }); + console.log(development.isProfile); + status = development.isProfile; + }); + } else { + await new CallAPI() + .GetData(request, `/org/unauthorize/employee/citizen/${requestBody.citizenId}`) + .then(async (x: any) => { + let development = Object.assign(new DevelopmentHistory(), x); + development.dateStart = + requestBody.dateStart == undefined ? _null : requestBody.dateStart; + development.dateEnd = requestBody.dateEnd == undefined ? _null : requestBody.dateEnd; + development.order = requestBody.order == undefined ? _null : requestBody.order; + development.dateOrder = + requestBody.dateOrder == undefined ? _null : requestBody.dateOrder; + development.trainingDays = + requestBody.trainingDays == undefined ? _null : requestBody.trainingDays; + development.posLevelId = null; + development.posTypeId = null; + development.employeePosLevelId = x.posLevelId; + development.employeePosTypeId = x.posTypeId; + development.developmentId = id; + development.createdUserId = request.user.sub; + development.createdFullName = request.user.name; + development.lastUpdateUserId = request.user.sub; + development.lastUpdateFullName = request.user.name; + development.isProfile = true; + addLogSequence(request, { + action: "database", + status: "success", + description: "Store DevelopmentHistory.", + }); + await this.developmentHistoryRepository.save(development, { data: request }); + setLogDataDiff(request, { before, after: development }); + status = development.isProfile; + }) + .catch(async (x) => { + let development = new DevelopmentHistory(); + let _null: any = null; + development.prefix = requestBody.prefix == undefined ? _null : requestBody.prefix; + development.firstName = + requestBody.firstName == undefined ? _null : requestBody.firstName; + development.lastName = requestBody.lastName == undefined ? _null : requestBody.lastName; + development.position = requestBody.position == undefined ? _null : requestBody.position; + development.org = requestBody.org == undefined ? _null : requestBody.org; + development.dateStart = + requestBody.dateStart == undefined ? _null : requestBody.dateStart; + development.dateEnd = requestBody.dateEnd == undefined ? _null : requestBody.dateEnd; + development.order = requestBody.order == undefined ? _null : requestBody.order; + development.dateOrder = + requestBody.dateOrder == undefined ? _null : requestBody.dateOrder; + development.trainingDays = + requestBody.trainingDays == undefined ? _null : requestBody.trainingDays; + development.posLevelId = x.posLevelId; + development.posTypeId = x.posTypeId; + development.employeePosLevelId = null; + development.employeePosTypeId = null; + development.developmentId = id; + development.createdUserId = request.user.sub; + development.createdFullName = request.user.name; + development.lastUpdateUserId = request.user.sub; + development.lastUpdateFullName = request.user.name; + development.isProfile = false; + addLogSequence(request, { + action: "database", + status: "success", + description: "Store DevelopmentHistory.", + }); + await this.developmentHistoryRepository.save(development, { data: request }); + setLogDataDiff(request, { before, after: development }); + status = development.isProfile; + }); + } + return new HttpSuccess(status); + } } diff --git a/src/entities/DevelopmentHistory.ts b/src/entities/DevelopmentHistory.ts index 79c0719..f5fe93e 100644 --- a/src/entities/DevelopmentHistory.ts +++ b/src/entities/DevelopmentHistory.ts @@ -283,3 +283,41 @@ export class UpdateDevelopmentHistory { @Column() dateEnd: Date | null; } + +export class CreateDevelopmentHistoryOBO { + @Column() + rank: string | null; + @Column() + prefix: string | null; + @Column() + firstName: string | null; + @Column() + lastName: string | null; + @Column() + citizenId: string; + @Column() + position: string | null; + @Column() + posExecutive: string | null; + @Column() + posLevelId: string | null; + @Column() + posTypeId: string | null; + @Column() + developmentId: string; + @Column() + order: string | null; + @Column() + trainingDays: string | null; + @Column() + org: string | null; + @Column() + type: string | null; + @Column() + dateOrder: Date | null; + @Column() + dateStart: Date | null; + @Column() + dateEnd: Date | null; +} + From 293d41b0f2732aaa3bd76ec84045d9de7cb596e2 Mon Sep 17 00:00:00 2001 From: AdisakKanthawilang Date: Tue, 30 Jul 2024 17:23:45 +0700 Subject: [PATCH 119/250] fix --- src/controllers/DevelopmentController.ts | 22 +++++++++++----------- src/entities/DevelopmentHistory.ts | 18 +++++++++--------- 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/src/controllers/DevelopmentController.ts b/src/controllers/DevelopmentController.ts index 65ddc39..1335012 100644 --- a/src/controllers/DevelopmentController.ts +++ b/src/controllers/DevelopmentController.ts @@ -2388,9 +2388,9 @@ export class DevelopmentController extends Controller { throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, "ข้อมูลนี้ได้ถูกบันทึกแล้ว"); oldProfile.dateStart = requestBody.dateStart == undefined ? _null : requestBody.dateStart; oldProfile.dateEnd = requestBody.dateEnd == undefined ? _null : requestBody.dateEnd; - oldProfile.order = requestBody.order == undefined ? _null : requestBody.order; + oldProfile.order = requestBody.commandNumber == undefined ? _null : requestBody.commandNumber; oldProfile.dateOrder = - requestBody.dateOrder == undefined ? _null : new Date(requestBody.dateOrder); + requestBody.commandDate == undefined ? _null : new Date(requestBody.commandDate); oldProfile.trainingDays = requestBody.trainingDays == undefined ? _null : requestBody.trainingDays; oldProfile.createdUserId = request.user.sub; @@ -2415,9 +2415,9 @@ export class DevelopmentController extends Controller { development.dateStart = requestBody.dateStart == undefined ? _null : requestBody.dateStart; development.dateEnd = requestBody.dateEnd == undefined ? _null : requestBody.dateEnd; - development.order = requestBody.order == undefined ? _null : requestBody.order; + development.order = requestBody.commandNumber == undefined ? _null : requestBody.commandNumber; development.dateOrder = - requestBody.dateOrder == undefined ? _null : requestBody.dateOrder; + requestBody.commandDate == undefined ? _null : requestBody.commandDate; development.trainingDays = requestBody.trainingDays == undefined ? _null : requestBody.trainingDays; development.posLevelId = x.posLevelId == undefined ? _null : x.posLevelId; @@ -2451,9 +2451,9 @@ export class DevelopmentController extends Controller { development.dateStart = requestBody.dateStart == undefined ? _null : requestBody.dateStart; development.dateEnd = requestBody.dateEnd == undefined ? _null : requestBody.dateEnd; - development.order = requestBody.order == undefined ? _null : requestBody.order; + development.order = requestBody.commandNumber == undefined ? _null : requestBody.commandNumber; development.dateOrder = - requestBody.dateOrder == undefined ? _null : requestBody.dateOrder; + requestBody.commandDate == undefined ? _null : requestBody.commandDate; development.trainingDays = requestBody.trainingDays == undefined ? _null : requestBody.trainingDays; development.posLevelId = x.posLevelId == undefined ? _null : x.posLevelId; @@ -2484,9 +2484,9 @@ export class DevelopmentController extends Controller { development.dateStart = requestBody.dateStart == undefined ? _null : requestBody.dateStart; development.dateEnd = requestBody.dateEnd == undefined ? _null : requestBody.dateEnd; - development.order = requestBody.order == undefined ? _null : requestBody.order; + development.order = requestBody.commandNumber == undefined ? _null : requestBody.commandNumber; development.dateOrder = - requestBody.dateOrder == undefined ? _null : requestBody.dateOrder; + requestBody.commandDate == undefined ? _null : requestBody.commandDate; development.trainingDays = requestBody.trainingDays == undefined ? _null : requestBody.trainingDays; development.posLevelId = null; @@ -2520,9 +2520,9 @@ export class DevelopmentController extends Controller { development.dateStart = requestBody.dateStart == undefined ? _null : requestBody.dateStart; development.dateEnd = requestBody.dateEnd == undefined ? _null : requestBody.dateEnd; - development.order = requestBody.order == undefined ? _null : requestBody.order; - development.dateOrder = - requestBody.dateOrder == undefined ? _null : requestBody.dateOrder; + // development.order = requestBody.order == undefined ? _null : requestBody.order; + // development.dateOrder = + // requestBody.dateOrder == undefined ? _null : requestBody.dateOrder; development.trainingDays = requestBody.trainingDays == undefined ? _null : requestBody.trainingDays; development.posLevelId = x.posLevelId; diff --git a/src/entities/DevelopmentHistory.ts b/src/entities/DevelopmentHistory.ts index f5fe93e..f283e28 100644 --- a/src/entities/DevelopmentHistory.ts +++ b/src/entities/DevelopmentHistory.ts @@ -285,8 +285,8 @@ export class UpdateDevelopmentHistory { } export class CreateDevelopmentHistoryOBO { - @Column() - rank: string | null; + // @Column() + // rank: string | null; @Column() prefix: string | null; @Column() @@ -298,15 +298,17 @@ export class CreateDevelopmentHistoryOBO { @Column() position: string | null; @Column() - posExecutive: string | null; + posExecutive?: string | null; @Column() - posLevelId: string | null; + posLevelId?: string | null; @Column() - posTypeId: string | null; + posTypeId?: string | null; + // @Column() + // developmentId: string; @Column() - developmentId: string; + commandNumber: string | null; @Column() - order: string | null; + commandDate: Date | null; @Column() trainingDays: string | null; @Column() @@ -314,8 +316,6 @@ export class CreateDevelopmentHistoryOBO { @Column() type: string | null; @Column() - dateOrder: Date | null; - @Column() dateStart: Date | null; @Column() dateEnd: Date | null; From 98811c08016d70475a041a14af21794e9246b1ca Mon Sep 17 00:00:00 2001 From: AdisakKanthawilang Date: Tue, 30 Jul 2024 17:49:37 +0700 Subject: [PATCH 120/250] fix --- src/controllers/DevelopmentController.ts | 26 ++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/src/controllers/DevelopmentController.ts b/src/controllers/DevelopmentController.ts index 1335012..7f297a8 100644 --- a/src/controllers/DevelopmentController.ts +++ b/src/controllers/DevelopmentController.ts @@ -2406,7 +2406,7 @@ export class DevelopmentController extends Controller { setLogDataDiff(request, { before, after: oldProfile }); status = oldProfile.isProfile; } - + if (requestBody.type == "OFFICER") { await new CallAPI() .GetData(request, `/org/unauthorize/officer/citizen/${requestBody.citizenId}`) @@ -2415,7 +2415,8 @@ export class DevelopmentController extends Controller { development.dateStart = requestBody.dateStart == undefined ? _null : requestBody.dateStart; development.dateEnd = requestBody.dateEnd == undefined ? _null : requestBody.dateEnd; - development.order = requestBody.commandNumber == undefined ? _null : requestBody.commandNumber; + development.order = + requestBody.commandNumber == undefined ? _null : requestBody.commandNumber; development.dateOrder = requestBody.commandDate == undefined ? _null : requestBody.commandDate; development.trainingDays = @@ -2451,7 +2452,11 @@ export class DevelopmentController extends Controller { development.dateStart = requestBody.dateStart == undefined ? _null : requestBody.dateStart; development.dateEnd = requestBody.dateEnd == undefined ? _null : requestBody.dateEnd; - development.order = requestBody.commandNumber == undefined ? _null : requestBody.commandNumber; + development.citizenId = + requestBody.citizenId == undefined ? _null : requestBody.citizenId; + development.type = requestBody.type == undefined ? _null : requestBody.type; + development.order = + requestBody.commandNumber == undefined ? _null : requestBody.commandNumber; development.dateOrder = requestBody.commandDate == undefined ? _null : requestBody.commandDate; development.trainingDays = @@ -2484,7 +2489,8 @@ export class DevelopmentController extends Controller { development.dateStart = requestBody.dateStart == undefined ? _null : requestBody.dateStart; development.dateEnd = requestBody.dateEnd == undefined ? _null : requestBody.dateEnd; - development.order = requestBody.commandNumber == undefined ? _null : requestBody.commandNumber; + development.order = + requestBody.commandNumber == undefined ? _null : requestBody.commandNumber; development.dateOrder = requestBody.commandDate == undefined ? _null : requestBody.commandDate; development.trainingDays = @@ -2520,9 +2526,13 @@ export class DevelopmentController extends Controller { development.dateStart = requestBody.dateStart == undefined ? _null : requestBody.dateStart; development.dateEnd = requestBody.dateEnd == undefined ? _null : requestBody.dateEnd; - // development.order = requestBody.order == undefined ? _null : requestBody.order; - // development.dateOrder = - // requestBody.dateOrder == undefined ? _null : requestBody.dateOrder; + development.citizenId = + requestBody.citizenId == undefined ? _null : requestBody.citizenId; + development.type = requestBody.type == undefined ? _null : requestBody.type; + development.order = + requestBody.commandNumber == undefined ? _null : requestBody.commandNumber; + development.dateOrder = + requestBody.commandDate == undefined ? _null : requestBody.commandDate; development.trainingDays = requestBody.trainingDays == undefined ? _null : requestBody.trainingDays; development.posLevelId = x.posLevelId; @@ -2545,6 +2555,6 @@ export class DevelopmentController extends Controller { status = development.isProfile; }); } - return new HttpSuccess(status); + return new HttpSuccess(status); } } From 899b6acc56025c1bbe3b49a66c80c3a0ee94d66c Mon Sep 17 00:00:00 2001 From: AdisakKanthawilang Date: Wed, 31 Jul 2024 09:55:56 +0700 Subject: [PATCH 121/250] fix --- src/controllers/DevelopmentController.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/controllers/DevelopmentController.ts b/src/controllers/DevelopmentController.ts index 7f297a8..74271b9 100644 --- a/src/controllers/DevelopmentController.ts +++ b/src/controllers/DevelopmentController.ts @@ -2244,6 +2244,9 @@ export class DevelopmentController extends Controller { item["วันที่เริ่มต้น"] == undefined ? null : item["วันที่เริ่มต้น"]; development.dateEnd = item["วันที่สิ้นสุด"] == undefined ? null : item["วันที่สิ้นสุด"]; + development.citizenId = + item["รหัสประจำตัวประชาชน"] == undefined ? _null : item["รหัสประจำตัวประชาชน"]; + development.type = item["ประเภท"] == undefined ? _null : item["ประเภท"]; development.order = item["เลขที่คำสั่ง/เลขที่หนังสืออนุมัติ"] == undefined ? null @@ -2321,6 +2324,9 @@ export class DevelopmentController extends Controller { item["วันที่เริ่มต้น"] == undefined ? null : item["วันที่เริ่มต้น"]; development.dateEnd = item["วันที่สิ้นสุด"] == undefined ? null : item["วันที่สิ้นสุด"]; + development.citizenId = + item["รหัสประจำตัวประชาชน"] == undefined ? _null : item["รหัสประจำตัวประชาชน"]; + development.type = item["ประเภท"] == undefined ? _null : item["ประเภท"]; development.order = item["เลขที่คำสั่ง/เลขที่หนังสืออนุมัติ"] == undefined ? null From 9eb539b45157a0556b692f21e95eff8f9b054420 Mon Sep 17 00:00:00 2001 From: AdisakKanthawilang Date: Wed, 31 Jul 2024 10:15:24 +0700 Subject: [PATCH 122/250] fix type --- src/controllers/DevelopmentController.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/controllers/DevelopmentController.ts b/src/controllers/DevelopmentController.ts index 74271b9..d77b438 100644 --- a/src/controllers/DevelopmentController.ts +++ b/src/controllers/DevelopmentController.ts @@ -2246,7 +2246,7 @@ export class DevelopmentController extends Controller { item["วันที่สิ้นสุด"] == undefined ? null : item["วันที่สิ้นสุด"]; development.citizenId = item["รหัสประจำตัวประชาชน"] == undefined ? _null : item["รหัสประจำตัวประชาชน"]; - development.type = item["ประเภท"] == undefined ? _null : item["ประเภท"]; + development.type = "OFFICER" == undefined ? _null : "OFFICER"; development.order = item["เลขที่คำสั่ง/เลขที่หนังสืออนุมัติ"] == undefined ? null @@ -2326,7 +2326,7 @@ export class DevelopmentController extends Controller { item["วันที่สิ้นสุด"] == undefined ? null : item["วันที่สิ้นสุด"]; development.citizenId = item["รหัสประจำตัวประชาชน"] == undefined ? _null : item["รหัสประจำตัวประชาชน"]; - development.type = item["ประเภท"] == undefined ? _null : item["ประเภท"]; + development.type = "EMPLOYEE" == undefined ? _null : "EMPLOYEE"; development.order = item["เลขที่คำสั่ง/เลขที่หนังสืออนุมัติ"] == undefined ? null From 61ec81687ccb6612790d99a1a7dba1041459bedb Mon Sep 17 00:00:00 2001 From: AdisakKanthawilang Date: Thu, 1 Aug 2024 14:31:32 +0700 Subject: [PATCH 123/250] fix log --- src/controllers/DevelopmentController.ts | 550 +++++++++--------- .../DevelopmentEmployeeHistoryController.ts | 30 +- .../DevelopmentHistoryController.ts | 30 +- .../DevelopmentScholarshipController.ts | 50 +- src/controllers/PortfolioController.ts | 30 +- src/controllers/StrategyController.ts | 20 +- src/interfaces/utils.ts | 4 +- src/middlewares/auth.ts | 9 +- 8 files changed, 365 insertions(+), 358 deletions(-) diff --git a/src/controllers/DevelopmentController.ts b/src/controllers/DevelopmentController.ts index d77b438..ba4ab81 100644 --- a/src/controllers/DevelopmentController.ts +++ b/src/controllers/DevelopmentController.ts @@ -147,11 +147,11 @@ export class DevelopmentController extends Controller { development.createdFullName = request.user.name; development.lastUpdateUserId = request.user.sub; development.lastUpdateFullName = request.user.name; - addLogSequence(request, { - action: "database", - status: "success", - description: "Store Development.", - }); + // addLogSequence(request, { + // action: "database", + // status: "success", + // description: "Store Development.", + // }); const before = null; await this.developmentRepository.save(development, { data: request }); setLogDataDiff(request, { before, after: development }); @@ -273,11 +273,11 @@ export class DevelopmentController extends Controller { default: throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงการ/หลักสูตรการฝึกอบรม"); } - addLogSequence(request, { - action: "database", - status: "success", - description: "Store Development.", - }); + // addLogSequence(request, { + // action: "database", + // status: "success", + // description: "Store Development.", + // }); await this.developmentRepository.save(development, { data: request }); setLogDataDiff(request, { before, after: development }); return new HttpSuccess(development.id); @@ -313,11 +313,11 @@ export class DevelopmentController extends Controller { data.lastUpdateUserId = request.user.sub; data.lastUpdateFullName = request.user.name; data.developmentPlannedGoalId = development.id; - addLogSequence(request, { - action: "database", - status: "success", - description: "Store Development.", - }); + // addLogSequence(request, { + // action: "database", + // status: "success", + // description: "Store Development.", + // }); await this.plannedGoalRepository.save(data, { data: request }); await Promise.all( @@ -345,11 +345,11 @@ export class DevelopmentController extends Controller { _data.lastUpdateUserId = request.user.sub; _data.lastUpdateFullName = request.user.name; _data.plannedGoalId = data.id; - addLogSequence(request, { - action: "database", - status: "success", - description: "Store Development.", - }); + // addLogSequence(request, { + // action: "database", + // status: "success", + // description: "Store Development.", + // }); await this.plannedGoalPositionRepository.save(_data, { data: request }); setLogDataDiff(request, { before, after: development }); }), @@ -388,11 +388,11 @@ export class DevelopmentController extends Controller { data.lastUpdateUserId = request.user.sub; data.lastUpdateFullName = request.user.name; data.developmentPlannedPeopleId = development.id; - addLogSequence(request, { - action: "database", - status: "success", - description: "Store Development.", - }); + // addLogSequence(request, { + // action: "database", + // status: "success", + // description: "Store Development.", + // }); await this.plannedPeopleRepository.save(data, { data: request }); setLogDataDiff(request, { before, after: development }); return new HttpSuccess(data.id); @@ -455,11 +455,11 @@ export class DevelopmentController extends Controller { data.lastUpdateUserId = request.user.sub; data.lastUpdateFullName = request.user.name; data.developmentActualGoalId = development.id; - addLogSequence(request, { - action: "database", - status: "success", - description: "Store ActualGoal.", - }); + // addLogSequence(request, { + // action: "database", + // status: "success", + // description: "Store ActualGoal.", + // }); await this.actualGoalRepository.save(data, { data: request }); setLogDataDiff(request, { before, after: development }); return new HttpSuccess(data.id); @@ -496,11 +496,11 @@ export class DevelopmentController extends Controller { data.lastUpdateUserId = request.user.sub; data.lastUpdateFullName = request.user.name; data.developmentActualPeopleId = development.id; - addLogSequence(request, { - action: "database", - status: "success", - description: "Store ActualPeople.", - }); + // addLogSequence(request, { + // action: "database", + // status: "success", + // description: "Store ActualPeople.", + // }); await this.actualPeopleRepository.save(data, { data: request }); setLogDataDiff(request, { before, after: development }); return new HttpSuccess(data.id); @@ -534,22 +534,22 @@ export class DevelopmentController extends Controller { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงการ/หลักสูตรการฝึกอบรมนี้"); } const before = structuredClone(development); - addLogSequence(request, { - action: "remove", - status: "success", - description: "Remove data in the field on the PlannedGoalPosition.", - }); + // addLogSequence(request, { + // action: "remove", + // status: "success", + // description: "Remove data in the field on the PlannedGoalPosition.", + // }); await this.plannedGoalPositionRepository.remove(development.plannedGoalPositions, { data: request, }); Object.assign(development, { ...requestBody, positions: [] }); development.lastUpdateUserId = request.user.sub; development.lastUpdateFullName = request.user.name; - addLogSequence(request, { - action: "database", - status: "success", - description: "Store PlannedGoal.", - }); + // addLogSequence(request, { + // action: "database", + // status: "success", + // description: "Store PlannedGoal.", + // }); await this.plannedGoalRepository.save(development, { data: request }); setLogDataDiff(request, { before, after: development }); if (requestBody.positions != null) { @@ -577,11 +577,11 @@ export class DevelopmentController extends Controller { _data.lastUpdateUserId = request.user.sub; _data.lastUpdateFullName = request.user.name; _data.plannedGoalId = development.id; - addLogSequence(request, { - action: "database", - status: "success", - description: "Store Planned Goal Position.", - }); + // addLogSequence(request, { + // action: "database", + // status: "success", + // description: "Store Planned Goal Position.", + // }); await this.plannedGoalPositionRepository.save(_data, { data: { request: request, @@ -621,11 +621,11 @@ export class DevelopmentController extends Controller { Object.assign(development, requestBody); development.lastUpdateUserId = request.user.sub; development.lastUpdateFullName = request.user.name; - addLogSequence(request, { - action: "database", - status: "success", - description: "Store PlannedPeople.", - }); + // addLogSequence(request, { + // action: "database", + // status: "success", + // description: "Store PlannedPeople.", + // }); await this.plannedPeopleRepository.save(development, { data: request }); setLogDataDiff(request, { before, after: development }); return new HttpSuccess(development.id); @@ -685,11 +685,11 @@ export class DevelopmentController extends Controller { Object.assign(development, requestBody); development.lastUpdateUserId = request.user.sub; development.lastUpdateFullName = request.user.name; - addLogSequence(request, { - action: "database", - status: "success", - description: "Store ActualGoal.", - }); + // addLogSequence(request, { + // action: "database", + // status: "success", + // description: "Store ActualGoal.", + // }); await this.actualGoalRepository.save(development, { data: request }); setLogDataDiff(request, { before, after: development }); return new HttpSuccess(development.id); @@ -723,11 +723,11 @@ export class DevelopmentController extends Controller { Object.assign(development, requestBody); development.lastUpdateUserId = request.user.sub; development.lastUpdateFullName = request.user.name; - addLogSequence(request, { - action: "database", - status: "success", - description: "Store ActualPeople.", - }); + // addLogSequence(request, { + // action: "database", + // status: "success", + // description: "Store ActualPeople.", + // }); await this.actualPeopleRepository.save(development, { data: request }); setLogDataDiff(request, { before, after: development }); return new HttpSuccess(development.id); @@ -756,17 +756,17 @@ export class DevelopmentController extends Controller { const _development = await this.plannedGoalPositionRepository.find({ where: { plannedGoalId: id }, }); - addLogSequence(request, { - action: "remove", - status: "success", - description: "Remove data in PlannedGoalPosition.", - }); + // addLogSequence(request, { + // action: "remove", + // status: "success", + // description: "Remove data in PlannedGoalPosition.", + // }); await this.plannedGoalPositionRepository.remove(_development, { data: request }); - addLogSequence(request, { - action: "remove", - status: "success", - description: "Remove data in PlannedGoal.", - }); + // addLogSequence(request, { + // action: "remove", + // status: "success", + // description: "Remove data in PlannedGoal.", + // }); await this.plannedGoalRepository.remove(development, { data: request }); return new HttpSuccess(development.id); } @@ -791,11 +791,11 @@ export class DevelopmentController extends Controller { if (!development) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลผู้เกี่ยวข้องเป้าหมายตามแผน"); } - addLogSequence(request, { - action: "remove", - status: "success", - description: "Remove data in PlannedPeople.", - }); + // addLogSequence(request, { + // action: "remove", + // status: "success", + // description: "Remove data in PlannedPeople.", + // }); await this.plannedPeopleRepository.remove(development, { data: request }); return new HttpSuccess(development.id); } @@ -820,11 +820,11 @@ export class DevelopmentController extends Controller { if (!development) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลกลุ่มเป้าหมายตามจริง"); } - addLogSequence(request, { - action: "remove", - status: "success", - description: "Remove data in ActualGoal.", - }); + // addLogSequence(request, { + // action: "remove", + // status: "success", + // description: "Remove data in ActualGoal.", + // }); await this.actualGoalRepository.remove(development, { data: request }); return new HttpSuccess(development.id); } @@ -849,11 +849,11 @@ export class DevelopmentController extends Controller { if (!development) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลผู้เกี่ยวข้องเป้าหมายตามจริง"); } - addLogSequence(request, { - action: "remove", - status: "success", - description: "Remove data in ActualPeople.", - }); + // addLogSequence(request, { + // action: "remove", + // status: "success", + // description: "Remove data in ActualPeople.", + // }); await this.actualPeopleRepository.remove(development, { data: request }); return new HttpSuccess(development.id); } @@ -895,30 +895,30 @@ export class DevelopmentController extends Controller { }); development.lastUpdateUserId = request.user.sub; development.lastUpdateFullName = request.user.name; - addLogSequence(request, { - action: "remove", - status: "success", - description: "Remove data in DevelopmentProjectType.", - }); + // addLogSequence(request, { + // action: "remove", + // status: "success", + // description: "Remove data in DevelopmentProjectType.", + // }); await this.developmentProjectTypeRepository.remove(development.developmentProjectTypes, { data: request, }); - addLogSequence(request, { - action: "remove", - status: "success", - description: "Remove data in DevelopmentProjectTechniquePlanned.", - }); + // addLogSequence(request, { + // action: "remove", + // status: "success", + // description: "Remove data in DevelopmentProjectTechniquePlanned.", + // }); await this.developmentProjectTechniquePlannedRepository.remove( development.developmentProjectTechniquePlanneds, { data: request, }, ); - addLogSequence(request, { - action: "remove", - status: "success", - description: "Remove data in DevelopmentProjectTechniqueActual.", - }); + // addLogSequence(request, { + // action: "remove", + // status: "success", + // description: "Remove data in DevelopmentProjectTechniqueActual.", + // }); await this.developmentProjectTechniqueActualRepository.remove( development.developmentProjectTechniqueActuals, { @@ -1136,11 +1136,11 @@ export class DevelopmentController extends Controller { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลยุทธศาสตร์เป้าหมายตามจริง"); } } - addLogSequence(request, { - action: "database", - status: "success", - description: "Store Development.", - }); + // addLogSequence(request, { + // action: "database", + // status: "success", + // description: "Store Development.", + // }); await this.developmentRepository.save(development, { data: request }); if (requestBody.developmentProjectTypes != null) { await Promise.all( @@ -1152,11 +1152,11 @@ export class DevelopmentController extends Controller { data.lastUpdateUserId = request.user.sub; data.lastUpdateFullName = request.user.name; data.developmentId = development.id; - addLogSequence(request, { - action: "database", - status: "success", - description: "Store DevelopmentProjectType.", - }); + // addLogSequence(request, { + // action: "database", + // status: "success", + // description: "Store DevelopmentProjectType.", + // }); await this.developmentProjectTypeRepository.save(data, { data: request }); }), ); @@ -1171,11 +1171,11 @@ export class DevelopmentController extends Controller { data.lastUpdateUserId = request.user.sub; data.lastUpdateFullName = request.user.name; data.developmentId = development.id; - addLogSequence(request, { - action: "database", - status: "success", - description: "Store DevelopmentProjectTechniquePlanned.", - }); + // addLogSequence(request, { + // action: "database", + // status: "success", + // description: "Store DevelopmentProjectTechniquePlanned.", + // }); await this.developmentProjectTechniquePlannedRepository.save(data, { data: request }); }), ); @@ -1190,11 +1190,11 @@ export class DevelopmentController extends Controller { data.lastUpdateUserId = request.user.sub; data.lastUpdateFullName = request.user.name; data.developmentId = development.id; - addLogSequence(request, { - action: "database", - status: "success", - description: "Store DevelopmentProjectTechniqueActual.", - }); + // addLogSequence(request, { + // action: "database", + // status: "success", + // description: "Store DevelopmentProjectTechniqueActual.", + // }); await this.developmentProjectTechniqueActualRepository.save(data, { data: request }); }), ); @@ -1230,11 +1230,11 @@ export class DevelopmentController extends Controller { Object.assign(development, requestBody); development.lastUpdateUserId = request.user.sub; development.lastUpdateFullName = request.user.name; - addLogSequence(request, { - action: "database", - status: "success", - description: "Store Development.", - }); + // addLogSequence(request, { + // action: "database", + // status: "success", + // description: "Store Development.", + // }); await this.developmentRepository.save(development, { data: request }); setLogDataDiff(request, { before, after: development }); return new HttpSuccess(development.id); @@ -1271,11 +1271,11 @@ export class DevelopmentController extends Controller { data.lastUpdateUserId = request.user.sub; data.lastUpdateFullName = request.user.name; data.developmentId = development.id; - addLogSequence(request, { - action: "database", - status: "success", - description: "Store DevelopmentEvaluation.", - }); + // addLogSequence(request, { + // action: "database", + // status: "success", + // description: "Store DevelopmentEvaluation.", + // }); await this.developmentEvaluationRepository.save(data, { data: request }); setLogDataDiff(request, { before, after: development }); return new HttpSuccess(data.id); @@ -1301,11 +1301,11 @@ export class DevelopmentController extends Controller { if (!development) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลผู้เกี่ยวข้องเป้าหมายตามแผน"); } - addLogSequence(request, { - action: "remove", - status: "success", - description: "Remove Development Evaluation By ID.", - }); + // addLogSequence(request, { + // action: "remove", + // status: "success", + // description: "Remove Development Evaluation By ID.", + // }); await this.developmentEvaluationRepository.remove(development, { data: request }); return new HttpSuccess(development.id); } @@ -1332,11 +1332,11 @@ export class DevelopmentController extends Controller { Object.assign(development, requestBody); development.lastUpdateUserId = request.user.sub; development.lastUpdateFullName = request.user.name; - addLogSequence(request, { - action: "database", - status: "success", - description: "Store DevelopmentEvaluation.", - }); + // addLogSequence(request, { + // action: "database", + // status: "success", + // description: "Store DevelopmentEvaluation.", + // }); await this.developmentEvaluationRepository.save(development, { data: request }); return new HttpSuccess(development.id); } @@ -1373,17 +1373,17 @@ export class DevelopmentController extends Controller { Object.assign(development, { ...requestBody, developmentAddresss: [] }); development.lastUpdateUserId = request.user.sub; development.lastUpdateFullName = request.user.name; - addLogSequence(request, { - action: "database", - status: "success", - description: "Store Development.", - }); + // addLogSequence(request, { + // action: "database", + // status: "success", + // description: "Store Development.", + // }); await this.developmentRepository.save(development, { data: request }); - addLogSequence(request, { - action: "remove", - status: "success", - description: "Remove DevelopmentAddresss.", - }); + // addLogSequence(request, { + // action: "remove", + // status: "success", + // description: "Remove DevelopmentAddresss.", + // }); await this.developmentAddresssRepository.remove(development.developmentAddresss, { data: request, }); @@ -1402,11 +1402,11 @@ export class DevelopmentController extends Controller { data.createdFullName = request.user.name; data.lastUpdateUserId = request.user.sub; data.lastUpdateFullName = request.user.name; - addLogSequence(request, { - action: "database", - status: "success", - description: "Store DevelopmentAddresss.", - }); + // addLogSequence(request, { + // action: "database", + // status: "success", + // description: "Store DevelopmentAddresss.", + // }); await this.developmentAddresssRepository.save(data, { data: request }); setLogDataDiff(request, { before, after: development }); }), @@ -1497,92 +1497,92 @@ export class DevelopmentController extends Controller { const plannedGoalPosition = await this.plannedGoalPositionRepository.find({ where: { plannedGoalId: In(development.developmentPlannedGoals.map((x) => x.id)) }, }); - addLogSequence(request, { - action: "remove", - status: "success", - description: "Remove PlannedGoalPosition.", - }); + // addLogSequence(request, { + // action: "remove", + // status: "success", + // description: "Remove PlannedGoalPosition.", + // }); await this.plannedGoalPositionRepository.remove(plannedGoalPosition, { data: request }); } - addLogSequence(request, { - action: "remove", - status: "success", - description: "Remove ActualPeople.", - }); + // addLogSequence(request, { + // action: "remove", + // status: "success", + // description: "Remove ActualPeople.", + // }); await this.actualPeopleRepository.remove(development.developmentActualPeoples, { data: request, }); - addLogSequence(request, { - action: "remove", - status: "success", - description: "Remove PlannedPeople.", - }); + // addLogSequence(request, { + // action: "remove", + // status: "success", + // description: "Remove PlannedPeople.", + // }); await this.plannedPeopleRepository.remove(development.developmentPlannedPeoples, { data: request, }); - addLogSequence(request, { - action: "remove", - status: "success", - description: "Remove ActualGoal.", - }); + // addLogSequence(request, { + // action: "remove", + // status: "success", + // description: "Remove ActualGoal.", + // }); await this.actualGoalRepository.remove(development.developmentActualGoals, { data: request }); - addLogSequence(request, { - action: "remove", - status: "success", - description: "Remove PlannedGoal.", - }); + // addLogSequence(request, { + // action: "remove", + // status: "success", + // description: "Remove PlannedGoal.", + // }); await this.plannedGoalRepository.remove(development.developmentPlannedGoals, { data: request }); - addLogSequence(request, { - action: "remove", - status: "success", - description: "Remove DevelopmentProjectType.", - }); + // addLogSequence(request, { + // action: "remove", + // status: "success", + // description: "Remove DevelopmentProjectType.", + // }); await this.developmentProjectTypeRepository.remove(development.developmentProjectTypes, { data: request, }); - addLogSequence(request, { - action: "remove", - status: "success", - description: "Remove DevelopmentProjectTechniquePlanned.", - }); + // addLogSequence(request, { + // action: "remove", + // status: "success", + // description: "Remove DevelopmentProjectTechniquePlanned.", + // }); await this.developmentProjectTechniquePlannedRepository.remove( development.developmentProjectTechniquePlanneds, { data: request, }, ); - addLogSequence(request, { - action: "remove", - status: "success", - description: "Remove DevelopmentProjectTechniqueActuals.", - }); + // addLogSequence(request, { + // action: "remove", + // status: "success", + // description: "Remove DevelopmentProjectTechniqueActuals.", + // }); await this.developmentProjectTechniqueActualRepository.remove( development.developmentProjectTechniqueActuals, { data: request, }, ); - addLogSequence(request, { - action: "remove", - status: "success", - description: "Remove DevelopmentEvaluation.", - }); + // addLogSequence(request, { + // action: "remove", + // status: "success", + // description: "Remove DevelopmentEvaluation.", + // }); await this.developmentEvaluationRepository.remove(development.developmentEvaluations, { data: request, }); - addLogSequence(request, { - action: "remove", - status: "success", - description: "Remove DevelopmentAddresss.", - }); + // addLogSequence(request, { + // action: "remove", + // status: "success", + // description: "Remove DevelopmentAddresss.", + // }); await this.developmentAddresssRepository.remove(development.developmentAddresss, { data: request, }); - addLogSequence(request, { - action: "remove", - status: "success", - description: "Remove Development.", - }); + // addLogSequence(request, { + // action: "remove", + // status: "success", + // description: "Remove Development.", + // }); await this.developmentRepository.remove(development, { data: request }); return new HttpSuccess(); } @@ -1667,11 +1667,11 @@ export class DevelopmentController extends Controller { getDevelopment.status = "FINISH"; getDevelopment.lastUpdateUserId = request.user.sub; getDevelopment.lastUpdateFullName = request.user.name; - addLogSequence(request, { - action: "database", - status: "success", - description: "Store Development.", - }); + // addLogSequence(request, { + // action: "database", + // status: "success", + // description: "Store Development.", + // }); await this.developmentRepository.save(getDevelopment, { data: request }); return new HttpSuccess(getDevelopment); } @@ -2100,11 +2100,11 @@ export class DevelopmentController extends Controller { _data.lastUpdateUserId = request.user.sub; _data.lastUpdateFullName = request.user.name; - addLogSequence(request, { - action: "database", - status: "success", - description: "Store DevelopmentHistory.", - }); + // addLogSequence(request, { + // action: "database", + // status: "success", + // description: "Store DevelopmentHistory.", + // }); await this.developmentHistoryRepository.save(_data, { data: request }); }), ); @@ -2185,11 +2185,11 @@ export class DevelopmentController extends Controller { oldProfile.createdFullName = request.user.name; oldProfile.lastUpdateUserId = request.user.sub; oldProfile.lastUpdateFullName = request.user.name; - addLogSequence(request, { - action: "database", - status: "success", - description: "Store DevelopmentHistory.", - }); + // addLogSequence(request, { + // action: "database", + // status: "success", + // description: "Store DevelopmentHistory.", + // }); await this.developmentHistoryRepository.save(oldProfile, { data: request }); setLogDataDiff(request, { before, after: oldProfile }); return; @@ -2224,11 +2224,11 @@ export class DevelopmentController extends Controller { development.lastUpdateUserId = request.user.sub; development.lastUpdateFullName = request.user.name; development.isProfile = true; - addLogSequence(request, { - action: "database", - status: "success", - description: "Store DevelopmentHistory.", - }); + // addLogSequence(request, { + // action: "database", + // status: "success", + // description: "Store DevelopmentHistory.", + // }); await this.developmentHistoryRepository.save(development, { data: request }); setLogDataDiff(request, { before, after: development }); }) @@ -2267,11 +2267,11 @@ export class DevelopmentController extends Controller { development.lastUpdateUserId = request.user.sub; development.lastUpdateFullName = request.user.name; development.isProfile = false; - addLogSequence(request, { - action: "database", - status: "success", - description: "Store DevelopmentHistory.", - }); + // addLogSequence(request, { + // action: "database", + // status: "success", + // description: "Store DevelopmentHistory.", + // }); await this.developmentHistoryRepository.save(development, { data: request }); setLogDataDiff(request, { before, after: development }); }); @@ -2304,11 +2304,11 @@ export class DevelopmentController extends Controller { development.lastUpdateUserId = request.user.sub; development.lastUpdateFullName = request.user.name; development.isProfile = true; - addLogSequence(request, { - action: "database", - status: "success", - description: "Store DevelopmentHistory.", - }); + // addLogSequence(request, { + // action: "database", + // status: "success", + // description: "Store DevelopmentHistory.", + // }); await this.developmentHistoryRepository.save(development, { data: request }); setLogDataDiff(request, { before, after: development }); }) @@ -2347,11 +2347,11 @@ export class DevelopmentController extends Controller { development.lastUpdateUserId = request.user.sub; development.lastUpdateFullName = request.user.name; development.isProfile = false; - addLogSequence(request, { - action: "database", - status: "success", - description: "Store DevelopmentHistory.", - }); + // addLogSequence(request, { + // action: "database", + // status: "success", + // description: "Store DevelopmentHistory.", + // }); await this.developmentHistoryRepository.save(development, { data: request }); setLogDataDiff(request, { before, after: development }); }); @@ -2403,11 +2403,11 @@ export class DevelopmentController extends Controller { oldProfile.createdFullName = request.user.name; oldProfile.lastUpdateUserId = request.user.sub; oldProfile.lastUpdateFullName = request.user.name; - addLogSequence(request, { - action: "database", - status: "success", - description: "Store DevelopmentHistory.", - }); + // addLogSequence(request, { + // action: "database", + // status: "success", + // description: "Store DevelopmentHistory.", + // }); await this.developmentHistoryRepository.save(oldProfile, { data: request }); setLogDataDiff(request, { before, after: oldProfile }); status = oldProfile.isProfile; @@ -2437,11 +2437,11 @@ export class DevelopmentController extends Controller { development.createdFullName = request.user.name; development.lastUpdateUserId = request.user.sub; development.lastUpdateFullName = request.user.name; - addLogSequence(request, { - action: "database", - status: "success", - description: "Store DevelopmentHistory.", - }); + // addLogSequence(request, { + // action: "database", + // status: "success", + // description: "Store DevelopmentHistory.", + // }); await this.developmentHistoryRepository.save(development, { data: request }); setLogDataDiff(request, { before, after: development }); status = development.isProfile; @@ -2477,11 +2477,11 @@ export class DevelopmentController extends Controller { development.lastUpdateUserId = request.user.sub; development.lastUpdateFullName = request.user.name; development.isProfile = false; - addLogSequence(request, { - action: "database", - status: "success", - description: "Store DevelopmentHistory.", - }); + // addLogSequence(request, { + // action: "database", + // status: "success", + // description: "Store DevelopmentHistory.", + // }); await this.developmentHistoryRepository.save(development, { data: request }); setLogDataDiff(request, { before, after: development }); console.log(development.isProfile); @@ -2511,11 +2511,11 @@ export class DevelopmentController extends Controller { development.lastUpdateUserId = request.user.sub; development.lastUpdateFullName = request.user.name; development.isProfile = true; - addLogSequence(request, { - action: "database", - status: "success", - description: "Store DevelopmentHistory.", - }); + // addLogSequence(request, { + // action: "database", + // status: "success", + // description: "Store DevelopmentHistory.", + // }); await this.developmentHistoryRepository.save(development, { data: request }); setLogDataDiff(request, { before, after: development }); status = development.isProfile; @@ -2551,11 +2551,11 @@ export class DevelopmentController extends Controller { development.lastUpdateUserId = request.user.sub; development.lastUpdateFullName = request.user.name; development.isProfile = false; - addLogSequence(request, { - action: "database", - status: "success", - description: "Store DevelopmentHistory.", - }); + // addLogSequence(request, { + // action: "database", + // status: "success", + // description: "Store DevelopmentHistory.", + // }); await this.developmentHistoryRepository.save(development, { data: request }); setLogDataDiff(request, { before, after: development }); status = development.isProfile; diff --git a/src/controllers/DevelopmentEmployeeHistoryController.ts b/src/controllers/DevelopmentEmployeeHistoryController.ts index b7c34c4..ec40a3b 100644 --- a/src/controllers/DevelopmentEmployeeHistoryController.ts +++ b/src/controllers/DevelopmentEmployeeHistoryController.ts @@ -121,11 +121,11 @@ export class DevelopmentEmployeeHistoryController extends Controller { development.createdFullName = request.user.name; development.lastUpdateUserId = request.user.sub; development.lastUpdateFullName = request.user.name; - addLogSequence(request, { - action: "database", - status: "success", - description: "Store DevelopmentHistory.", - }); + // addLogSequence(request, { + // action: "database", + // status: "success", + // description: "Store DevelopmentHistory.", + // }); await this.developmentHistoryRepository.save(development, { data: request }); setLogDataDiff(request, { before, after: development }); return new HttpSuccess(development.id); @@ -192,11 +192,11 @@ export class DevelopmentEmployeeHistoryController extends Controller { development.posLevelId = null; development.lastUpdateUserId = request.user.sub; development.lastUpdateFullName = request.user.name; - addLogSequence(request, { - action: "database", - status: "success", - description: "Store DevelopmentHistory.", - }); + // addLogSequence(request, { + // action: "database", + // status: "success", + // description: "Store DevelopmentHistory.", + // }); await this.developmentHistoryRepository.save(development, { data: request }); return new HttpSuccess(development.id); } @@ -217,11 +217,11 @@ export class DevelopmentEmployeeHistoryController extends Controller { if (!development) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลประวัติการฝึกอบรม/ดูงานนี้"); } - addLogSequence(request, { - action: "remove", - status: "success", - description: "Remove DevelopmentHistory.", - }); + // addLogSequence(request, { + // action: "remove", + // status: "success", + // description: "Remove DevelopmentHistory.", + // }); await this.developmentHistoryRepository.remove(development, { data: request }); return new HttpSuccess(); } diff --git a/src/controllers/DevelopmentHistoryController.ts b/src/controllers/DevelopmentHistoryController.ts index 1e5a547..a2cd020 100644 --- a/src/controllers/DevelopmentHistoryController.ts +++ b/src/controllers/DevelopmentHistoryController.ts @@ -117,11 +117,11 @@ export class DevelopmentOfficerHistoryController extends Controller { development.createdFullName = request.user.name; development.lastUpdateUserId = request.user.sub; development.lastUpdateFullName = request.user.name; - addLogSequence(request, { - action: "database", - status: "success", - description: "Store DevelopmentHistory.", - }); + // addLogSequence(request, { + // action: "database", + // status: "success", + // description: "Store DevelopmentHistory.", + // }); await this.developmentHistoryRepository.save(development, { data: request }); setLogDataDiff(request, { before, after: development }); return new HttpSuccess(development.id); @@ -184,11 +184,11 @@ export class DevelopmentOfficerHistoryController extends Controller { development.type = type; development.lastUpdateUserId = request.user.sub; development.lastUpdateFullName = request.user.name; - addLogSequence(request, { - action: "database", - status: "success", - description: "Store DevelopmentHistory.", - }); + // addLogSequence(request, { + // action: "database", + // status: "success", + // description: "Store DevelopmentHistory.", + // }); await this.developmentHistoryRepository.save(development, { data: request }); return new HttpSuccess(development.id); } @@ -209,11 +209,11 @@ export class DevelopmentOfficerHistoryController extends Controller { if (!development) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลประวัติการฝึกอบรม/ดูงานนี้"); } - addLogSequence(request, { - action: "database", - status: "success", - description: "Store DevelopmentHistory.", - }); + // addLogSequence(request, { + // action: "database", + // status: "success", + // description: "Store DevelopmentHistory.", + // }); await this.developmentHistoryRepository.remove(development, { data: request }); return new HttpSuccess(); } diff --git a/src/controllers/DevelopmentScholarshipController.ts b/src/controllers/DevelopmentScholarshipController.ts index 7b30ee7..16fd798 100644 --- a/src/controllers/DevelopmentScholarshipController.ts +++ b/src/controllers/DevelopmentScholarshipController.ts @@ -81,11 +81,11 @@ export class DevelopmentScholarshipController extends Controller { development.createdFullName = request.user.name; development.lastUpdateUserId = request.user.sub; development.lastUpdateFullName = request.user.name; - addLogSequence(request, { - action: "database", - status: "success", - description: "Store Development Scholarship.", - }); + // addLogSequence(request, { + // action: "database", + // status: "success", + // description: "Store Development Scholarship.", + // }); await this.developmentScholarshipRepository.save(development, { data: request }); setLogDataDiff(request, { before, after: development }); return new HttpSuccess(development.id); @@ -145,11 +145,11 @@ export class DevelopmentScholarshipController extends Controller { Object.assign(development, requestBody); development.lastUpdateUserId = request.user.sub; development.lastUpdateFullName = request.user.name; - addLogSequence(request, { - action: "database", - status: "success", - description: "Store DevelopmentScholarship.", - }); + // addLogSequence(request, { + // action: "database", + // status: "success", + // description: "Store DevelopmentScholarship.", + // }); await this.developmentScholarshipRepository.save(development, { data: request }); setLogDataDiff(request, { before, after: development }); return new HttpSuccess(development.id); @@ -175,11 +175,11 @@ export class DevelopmentScholarshipController extends Controller { if (!development) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลทุนการศึกษา/ฝึกอบรมนี้"); } - addLogSequence(request, { - action: "remove", - status: "success", - description: "Remove Development Scholarship By ID.", - }); + // addLogSequence(request, { + // action: "remove", + // status: "success", + // description: "Remove Development Scholarship By ID.", + // }); await this.developmentScholarshipRepository.remove(development, { data: request }); return new HttpSuccess(); } @@ -489,11 +489,11 @@ export class DevelopmentScholarshipController extends Controller { Object.assign(getDevelopment, requestBody); getDevelopment.lastUpdateUserId = request.user.sub; getDevelopment.lastUpdateFullName = request.user.name; - addLogSequence(request, { - action: "database", - status: "success", - description: "Store DevelopmentScholarship.", - }); + // addLogSequence(request, { + // action: "database", + // status: "success", + // description: "Store DevelopmentScholarship.", + // }); await this.developmentScholarshipRepository.save(getDevelopment, { data: request }); setLogDataDiff(request, { before, after: getDevelopment }); return new HttpSuccess(getDevelopment.id); @@ -587,11 +587,11 @@ export class DevelopmentScholarshipController extends Controller { }); } else if (_status == "NOTGRADUATE") { getDevelopment.status = _status; - addLogSequence(request, { - action: "database", - status: "success", - description: "Change Status Development Scholarship.", - }); + // addLogSequence(request, { + // action: "database", + // status: "success", + // description: "Change Status Development Scholarship.", + // }); await this.developmentScholarshipRepository.save(getDevelopment, { data: request }); } else { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบสถานะนี้ในระบบ"); diff --git a/src/controllers/PortfolioController.ts b/src/controllers/PortfolioController.ts index 04a2657..df0aa98 100644 --- a/src/controllers/PortfolioController.ts +++ b/src/controllers/PortfolioController.ts @@ -106,11 +106,11 @@ export class PortfolioController extends Controller { _portfolio.createdFullName = request.user.name; _portfolio.lastUpdateUserId = request.user.sub; _portfolio.lastUpdateFullName = request.user.name; - addLogSequence(request, { - action: "database", - status: "success", - description: "Store Portfolio.", - }); + // addLogSequence(request, { + // action: "database", + // status: "success", + // description: "Store Portfolio.", + // }); await this.portfolioRepository.save(_portfolio, { data: request }); setLogDataDiff(request, { before, after: _portfolio }); return new HttpSuccess(_portfolio.id); @@ -144,11 +144,11 @@ export class PortfolioController extends Controller { _portfolio.lastUpdateUserId = request.user.sub; _portfolio.lastUpdateFullName = request.user.name; Object.assign(_portfolio, requestBody); - addLogSequence(request, { - action: "database", - status: "success", - description: "Store Portfolio.", - }); + // addLogSequence(request, { + // action: "database", + // status: "success", + // description: "Store Portfolio.", + // }); await this.portfolioRepository.save(_portfolio, { data: request }); return new HttpSuccess(_portfolio.id); } @@ -168,11 +168,11 @@ export class PortfolioController extends Controller { if (!_delPortfolio) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลผลงานนี้"); } - addLogSequence(request, { - action: "database", - status: "success", - description: "Store Portfolio.", - }); + // addLogSequence(request, { + // action: "database", + // status: "success", + // description: "Store Portfolio.", + // }); await this.portfolioRepository.delete(_delPortfolio.id), { data: request }; return new HttpSuccess(); } diff --git a/src/controllers/StrategyController.ts b/src/controllers/StrategyController.ts index cb44c76..bcaf7ae 100644 --- a/src/controllers/StrategyController.ts +++ b/src/controllers/StrategyController.ts @@ -204,11 +204,11 @@ export class StrategyController extends Controller { strategyChild.createdFullName = request.user.name; strategyChild.lastUpdateUserId = request.user.sub; strategyChild.lastUpdateFullName = request.user.name; - addLogSequence(request, { - action: "database", - status: "success", - description: "Store Strategy.", - }); + // addLogSequence(request, { + // action: "database", + // status: "success", + // description: "Store Strategy.", + // }); await repoSave.save(strategyChild, { data: request }); setLogDataDiff(request, { before, after: strategyChild }); @@ -285,11 +285,11 @@ export class StrategyController extends Controller { strategyChild.lastUpdateUserId = request.user.sub; strategyChild.lastUpdateFullName = request.user.name; - addLogSequence(request, { - action: "remove", - status: "success", - description: "Edit Strategy by ID.", - }); + // addLogSequence(request, { + // action: "remove", + // status: "success", + // description: "Edit Strategy by ID.", + // }); await strategyRepo.save(strategyChild, { data: request }); return new HttpSuccess(); diff --git a/src/interfaces/utils.ts b/src/interfaces/utils.ts index 12308e1..f21a398 100644 --- a/src/interfaces/utils.ts +++ b/src/interfaces/utils.ts @@ -11,8 +11,8 @@ export type LogSequence = { description: string; query?: string; request?: { - method: "GET" | "POST" | "PUT" | "DELETE" | "PATCH"; - url: string; + method?: "GET" | "POST" | "PUT" | "DELETE" | "PATCH"; + url?: string; payload?: string; response?: string; }; diff --git a/src/middlewares/auth.ts b/src/middlewares/auth.ts index 2c939d3..d43943c 100644 --- a/src/middlewares/auth.ts +++ b/src/middlewares/auth.ts @@ -3,6 +3,8 @@ 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."); @@ -22,7 +24,7 @@ const jwtVerify = createVerifier({ const jwtDecode = createDecoder(); export async function expressAuthentication( - request: express.Request, + request: RequestWithUser, securityName: string, _scopes?: string[], ) { @@ -56,6 +58,11 @@ export async function expressAuthentication( 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; From 5edd511f2ae2b1a12d2099b6f0381cdc2a868460 Mon Sep 17 00:00:00 2001 From: AdisakKanthawilang Date: Thu, 1 Aug 2024 15:38:03 +0700 Subject: [PATCH 124/250] fix --- src/controllers/DevelopmentController.ts | 1 + src/interfaces/http-success.ts | 14 +++++++++++++- src/middlewares/auth.ts | 10 +++++----- src/middlewares/logs.ts | 12 +++++++++--- 4 files changed, 28 insertions(+), 9 deletions(-) diff --git a/src/controllers/DevelopmentController.ts b/src/controllers/DevelopmentController.ts index ba4ab81..80113b1 100644 --- a/src/controllers/DevelopmentController.ts +++ b/src/controllers/DevelopmentController.ts @@ -153,6 +153,7 @@ export class DevelopmentController extends Controller { // description: "Store Development.", // }); const before = null; + await this.developmentRepository.save(development, { data: request }); setLogDataDiff(request, { before, after: development }); return new HttpSuccess(development.id); diff --git a/src/interfaces/http-success.ts b/src/interfaces/http-success.ts index 514f576..97f1bad 100644 --- a/src/interfaces/http-success.ts +++ b/src/interfaces/http-success.ts @@ -1,4 +1,6 @@ +import { RequestWithUser } from "../middlewares/user"; import HttpStatus from "./http-status"; +import { addLogSequence } from "./utils"; class HttpSuccess { /** @@ -14,5 +16,15 @@ class HttpSuccess { this.result = result; } } - +// const request = {} as RequestWithUser; +// if (request) { +// if (!request.app.locals.logData) { +// request.app.locals.logData = {}; +// } +// addLogSequence(request, { +// action: "database", +// status: "success", +// description: "Query Data.", +// }); +// } export default HttpSuccess; diff --git a/src/middlewares/auth.ts b/src/middlewares/auth.ts index d43943c..de43a0c 100644 --- a/src/middlewares/auth.ts +++ b/src/middlewares/auth.ts @@ -58,11 +58,11 @@ export async function expressAuthentication( request.app.locals.logData = {}; } - addLogSequence(request, { - action: "database", - status: "success", - description: "Query Data.", - }); + // 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; diff --git a/src/middlewares/logs.ts b/src/middlewares/logs.ts index e5acc5b..43c7f43 100644 --- a/src/middlewares/logs.ts +++ b/src/middlewares/logs.ts @@ -1,5 +1,7 @@ import { NextFunction, Request, Response } from "express"; import { Client } from "@elastic/elasticsearch"; +import { addLogSequence } from "../interfaces/utils"; +import { RequestWithUser } from "./user"; if (!process.env.ELASTICSEARCH_INDEX) { throw new Error("Require ELASTICSEARCH_INDEX to store log."); @@ -19,7 +21,7 @@ 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) { +async function logMiddleware(req: any, res: Response, next: NextFunction) { if (!req.url.startsWith("/api/")) return next(); let data: any; @@ -38,8 +40,13 @@ async function logMiddleware(req: Request, res: Response, next: NextFunction) { res.on("finish", () => { if (!req.url.startsWith("/api/")) return; - + const logData = req?.app?.locals.logData?.sequence?.at(-1); const level = LOG_LEVEL_MAP[process.env.LOG_LEVEL ?? "debug"] || 4; + addLogSequence(req, { + action: "database", + status: "success", + description: "Query Data.", + }); if (level === 1 && res.statusCode < 500) return; if (level === 2 && res.statusCode < 400) return; @@ -67,7 +74,6 @@ async function logMiddleware(req: Request, res: Response, next: NextFunction) { document: obj, }); }); - return next(); } From 4ed904316d124424fca08f0285e64837c7d46e8f Mon Sep 17 00:00:00 2001 From: AdisakKanthawilang Date: Thu, 1 Aug 2024 16:57:09 +0700 Subject: [PATCH 125/250] fix --- src/database/data-source.ts | 23 +++++++++++++++++------ src/interfaces/http-success.ts | 11 ----------- src/interfaces/utils.ts | 2 +- src/middlewares/logs.ts | 12 +++--------- 4 files changed, 21 insertions(+), 27 deletions(-) diff --git a/src/database/data-source.ts b/src/database/data-source.ts index 1eee170..8411800 100644 --- a/src/database/data-source.ts +++ b/src/database/data-source.ts @@ -4,18 +4,29 @@ 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 | undefined; - const logData = req?.app?.locals.logData?.sequence?.at(-1); + 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)) : '') - ); + // if (logData && !logData.query) logData.query = []; + // if (logData) logData.query.push( + // "Query: " + query + (parameters ? (" - Parameters:" + JSON.stringify(parameters)) : '') + // ); } logMigration(message: string, queryRunner?: QueryRunner) {} diff --git a/src/interfaces/http-success.ts b/src/interfaces/http-success.ts index 97f1bad..3d931f6 100644 --- a/src/interfaces/http-success.ts +++ b/src/interfaces/http-success.ts @@ -16,15 +16,4 @@ class HttpSuccess { this.result = result; } } -// const request = {} as RequestWithUser; -// if (request) { -// if (!request.app.locals.logData) { -// request.app.locals.logData = {}; -// } -// addLogSequence(request, { -// action: "database", -// status: "success", -// description: "Query Data.", -// }); -// } export default HttpSuccess; diff --git a/src/interfaces/utils.ts b/src/interfaces/utils.ts index f21a398..ce18535 100644 --- a/src/interfaces/utils.ts +++ b/src/interfaces/utils.ts @@ -26,7 +26,7 @@ export function setLogDataDiff(req: RequestWithUser, data: DataDiff) { } export function addLogSequence(req: RequestWithUser, data: LogSequence) { - if (!req.app.locals.logData.sequence) { + if (!req?.app?.locals?.logData?.sequence) { req.app.locals.logData.sequence = []; } req.app.locals.logData.sequence = req.app.locals.logData.sequence.concat(data); diff --git a/src/middlewares/logs.ts b/src/middlewares/logs.ts index 43c7f43..e5acc5b 100644 --- a/src/middlewares/logs.ts +++ b/src/middlewares/logs.ts @@ -1,7 +1,5 @@ import { NextFunction, Request, Response } from "express"; import { Client } from "@elastic/elasticsearch"; -import { addLogSequence } from "../interfaces/utils"; -import { RequestWithUser } from "./user"; if (!process.env.ELASTICSEARCH_INDEX) { throw new Error("Require ELASTICSEARCH_INDEX to store log."); @@ -21,7 +19,7 @@ const elasticsearch = new Client({ node: `${process.env.ELASTICSEARCH_PROTOCOL}://${process.env.ELASTICSEARCH_HOST}:${process.env.ELASTICSEARCH_PORT}`, }); -async function logMiddleware(req: any, res: Response, next: NextFunction) { +async function logMiddleware(req: Request, res: Response, next: NextFunction) { if (!req.url.startsWith("/api/")) return next(); let data: any; @@ -40,13 +38,8 @@ async function logMiddleware(req: any, res: Response, next: NextFunction) { res.on("finish", () => { if (!req.url.startsWith("/api/")) return; - const logData = req?.app?.locals.logData?.sequence?.at(-1); + const level = LOG_LEVEL_MAP[process.env.LOG_LEVEL ?? "debug"] || 4; - addLogSequence(req, { - action: "database", - status: "success", - description: "Query Data.", - }); if (level === 1 && res.statusCode < 500) return; if (level === 2 && res.statusCode < 400) return; @@ -74,6 +67,7 @@ async function logMiddleware(req: any, res: Response, next: NextFunction) { document: obj, }); }); + return next(); } From e1aa6821050e6bb38fe3ab64532e6bbf1d07c6f7 Mon Sep 17 00:00:00 2001 From: AdisakKanthawilang Date: Thu, 1 Aug 2024 17:48:28 +0700 Subject: [PATCH 126/250] fix --- src/database/data-source.ts | 14 ++++++++++---- src/interfaces/utils.ts | 2 +- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/database/data-source.ts b/src/database/data-source.ts index 8411800..d713314 100644 --- a/src/database/data-source.ts +++ b/src/database/data-source.ts @@ -16,10 +16,12 @@ export class MyCustomLogger implements Logger { action: "database", status: "success", description: "Query Data.", - query: "Query: " + query + (parameters ? " - Parameters:" + JSON.stringify(parameters) : ""), + query: [ + "Query: " + query + (parameters ? " - Parameters:" + JSON.stringify(parameters) : ""), + ], }); } - + // const req = queryRunner?.data as RequestWithUser | undefined; // const logData = req?.app?.locals.logData?.sequence?.at(-1); @@ -30,7 +32,12 @@ export class MyCustomLogger implements Logger { } logMigration(message: string, queryRunner?: QueryRunner) {} - logQueryError(error: string | Error, query: string, parameters?: any[], 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) {} } @@ -56,4 +63,3 @@ export const AppDataSource = new DataSource({ subscribers: [], logger: new MyCustomLogger(), }); - diff --git a/src/interfaces/utils.ts b/src/interfaces/utils.ts index ce18535..30035f0 100644 --- a/src/interfaces/utils.ts +++ b/src/interfaces/utils.ts @@ -9,7 +9,7 @@ export type LogSequence = { action: string; status: "success" | "error"; description: string; - query?: string; + query?: any; request?: { method?: "GET" | "POST" | "PUT" | "DELETE" | "PATCH"; url?: string; From 4c0c02cc8b5d28b2db97a6d2afcb8ca64e321ceb Mon Sep 17 00:00:00 2001 From: Kittapath Date: Tue, 6 Aug 2024 10:41:17 +0700 Subject: [PATCH 127/250] =?UTF-8?q?=E0=B8=82=E0=B9=89=E0=B8=AD=E0=B8=A1?= =?UTF-8?q?=E0=B8=B9=E0=B8=A5=E0=B9=82=E0=B8=84=E0=B8=A3=E0=B8=87=E0=B8=81?= =?UTF-8?q?=E0=B8=B2=E0=B8=A3=E0=B8=95=E0=B8=B2=E0=B8=A1=E0=B8=88=E0=B8=A3?= =?UTF-8?q?=E0=B8=B4=E0=B8=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/DevelopmentController.ts | 68 +++++++++++++++++++++++- 1 file changed, 67 insertions(+), 1 deletion(-) diff --git a/src/controllers/DevelopmentController.ts b/src/controllers/DevelopmentController.ts index 80113b1..a7d3a6c 100644 --- a/src/controllers/DevelopmentController.ts +++ b/src/controllers/DevelopmentController.ts @@ -153,7 +153,7 @@ export class DevelopmentController extends Controller { // description: "Store Development.", // }); const before = null; - + await this.developmentRepository.save(development, { data: request }); setLogDataDiff(request, { before, after: development }); return new HttpSuccess(development.id); @@ -1464,6 +1464,30 @@ export class DevelopmentController extends Controller { return new HttpSuccess({ data: data, total }); } + /** + * API รายการโครงการ/หลักสูตรการฝึกอบรมที่เสร็จสิ้น + * + * @summary DEV_004 - รายการโครงการ/หลักสูตรการฝึกอบรมที่เสร็จสิ้น + * + */ + @Get("done") + async GetDevelopmentListsDone(@Query("year") year: number) { + const [development, total] = await AppDataSource.getRepository(Development) + .createQueryBuilder("development") + .andWhere(year > 0 ? "development.year LIKE :year" : "1=1", { + year: `${year.toString()}`, + }) + .andWhere("development.status LIKE :status", { + status: `%FINISH%`, + }) + .select(["development.id", "development.projectName", "development.year"]) + .orderBy("development.year", "DESC") + .orderBy("development.createdAt", "DESC") + .getManyAndCount(); + + return new HttpSuccess({ data: development, total }); + } + /** * API ลบโครงการ/หลักสูตรการฝึกอบรม * @@ -1899,6 +1923,48 @@ export class DevelopmentController extends Controller { return new HttpSuccess(_getDevelopment); } + /** + * API รายละเอียดโครงการ/หลักสูตรการฝึกอบรม tab3 + * + * @summary DEV_00 - รายละเอียดโครงการ/หลักสูตรการฝึกอบรมtab3 # + * + * @param {string} id Id โครงการ + */ + @Get("tab3_1/{id}") + async GetDevelopemtTab3_1ById(@Path() id: string) { + const getDevelopment = await this.developmentRepository.findOne({ + where: { id: id }, + relations: [ + "developmentProjectTypes", + "developmentProjectTechniquePlanneds", + "developmentProjectTechniqueActuals", + ], + }); + if (!getDevelopment) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงการ/หลักสูตรการฝึกอบรมนี้"); + } + let _getDevelopment: any = { + projectModalActual: getDevelopment.projectModalActual, + isBackActual: getDevelopment.isBackActual, + isHoldActual: getDevelopment.isHoldActual, + projectDayBackActual: getDevelopment.projectDayBackActual, + projectDayHoldActual: getDevelopment.projectDayHoldActual, + projectNigthHoldActual: getDevelopment.projectNigthHoldActual, + reasonActual70: getDevelopment.reasonActual70, + reasonActual20: getDevelopment.reasonActual20, + reasonActual10: getDevelopment.reasonActual10, + developmentProjectTechniqueActuals: getDevelopment.developmentProjectTechniqueActuals + .map((x) => x.name) + .sort(), + strategyChild1Actual: getDevelopment.strategyChild1ActualId, + strategyChild2Actual: getDevelopment.strategyChild2ActualId, + strategyChild3Actual: getDevelopment.strategyChild3ActualId, + strategyChild4Actual: getDevelopment.strategyChild4ActualId, + strategyChild5Actual: getDevelopment.strategyChild5ActualId, + }; + return new HttpSuccess(_getDevelopment); + } + /** * API รายละเอียดโครงการ/หลักสูตรการฝึกอบรม tab4 * From 78fb5b5c0a09fe521bcb95fcf149938ec8efde0e Mon Sep 17 00:00:00 2001 From: AdisakKanthawilang Date: Wed, 7 Aug 2024 14:03:40 +0700 Subject: [PATCH 128/250] update function tab --- src/controllers/DevelopmentController.ts | 138 ++++++++++-------- src/entities/Development.ts | 96 +++++++++--- ...13963408-update_table_migration08072024.ts | 20 +++ 3 files changed, 177 insertions(+), 77 deletions(-) create mode 100644 src/migration/1723013963408-update_table_migration08072024.ts diff --git a/src/controllers/DevelopmentController.ts b/src/controllers/DevelopmentController.ts index a7d3a6c..f6f44ef 100644 --- a/src/controllers/DevelopmentController.ts +++ b/src/controllers/DevelopmentController.ts @@ -25,6 +25,8 @@ import { UpdateDevelopment3, UpdateDevelopment4, UpdateDevelopment5, + UpdateDevelopment7, + UpdateDevelopment8, } from "../entities/Development"; import { ActualPeople, CreateActualPeople } from "../entities/ActualPeople"; import { CreatePlannedPeople, PlannedPeople } from "../entities/PlannedPeople"; @@ -1200,6 +1202,31 @@ export class DevelopmentController extends Controller { }), ); } + //move from tab5 + await this.developmentAddresssRepository.remove(development.developmentAddresss, { + data: request, + }); + const before = structuredClone(development); + await Promise.all( + requestBody.developmentAddresss.map(async (x) => { + const data = Object.assign(new DevelopmentAddress(), x); + const chkProvince = await this.provinceRepository.findOne({ + where: { + id: x.provinceId, + }, + }); + if (chkProvince == null) return; + data.developmentId = development.id; + data.createdUserId = request.user.sub; + data.createdFullName = request.user.name; + data.lastUpdateUserId = request.user.sub; + data.lastUpdateFullName = request.user.name; + await this.developmentAddresssRepository.save(data, { data: request }); + setLogDataDiff(request, { before, after: development }); + }), + ); + Object.assign(development, { ...requestBody, developmentAddresss: [] }); + //End return new HttpSuccess(development.id); } @@ -1216,11 +1243,6 @@ export class DevelopmentController extends Controller { @Body() requestBody: UpdateDevelopment4, @Request() request: RequestWithUser, ) { - // addLogSequence(request, { - // action: "database", - // status: "success", - // description: "Get Development.", - // }); const development = await this.developmentRepository.findOne({ where: { id }, }); @@ -1231,11 +1253,6 @@ export class DevelopmentController extends Controller { Object.assign(development, requestBody); development.lastUpdateUserId = request.user.sub; development.lastUpdateFullName = request.user.name; - // addLogSequence(request, { - // action: "database", - // status: "success", - // description: "Store Development.", - // }); await this.developmentRepository.save(development, { data: request }); setLogDataDiff(request, { before, after: development }); return new HttpSuccess(development.id); @@ -1254,11 +1271,6 @@ export class DevelopmentController extends Controller { @Body() requestBody: CreateDevelopmentEvaluation, @Request() request: RequestWithUser, ) { - // addLogSequence(request, { - // action: "database", - // status: "success", - // description: "Get Development.", - // }); const development = await this.developmentRepository.findOne({ where: { id }, }); @@ -1272,11 +1284,6 @@ export class DevelopmentController extends Controller { data.lastUpdateUserId = request.user.sub; data.lastUpdateFullName = request.user.name; data.developmentId = development.id; - // addLogSequence(request, { - // action: "database", - // status: "success", - // description: "Store DevelopmentEvaluation.", - // }); await this.developmentEvaluationRepository.save(data, { data: request }); setLogDataDiff(request, { before, after: development }); return new HttpSuccess(data.id); @@ -1370,49 +1377,64 @@ export class DevelopmentController extends Controller { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลจังหวัดข้อมูลด้านวิชาการ"); } } - Object.assign(development, { ...requestBody, developmentAddresss: [] }); development.lastUpdateUserId = request.user.sub; development.lastUpdateFullName = request.user.name; - // addLogSequence(request, { - // action: "database", - // status: "success", - // description: "Store Development.", - // }); await this.developmentRepository.save(development, { data: request }); - // addLogSequence(request, { - // action: "remove", - // status: "success", - // description: "Remove DevelopmentAddresss.", - // }); - await this.developmentAddresssRepository.remove(development.developmentAddresss, { - data: request, - }); - const before = structuredClone(development); - await Promise.all( - requestBody.developmentAddresss.map(async (x) => { - const data = Object.assign(new DevelopmentAddress(), x); - const chkProvince = await this.provinceRepository.findOne({ - where: { - id: x.provinceId, - }, - }); - if (chkProvince == null) return; - data.developmentId = development.id; - data.createdUserId = request.user.sub; - data.createdFullName = request.user.name; - data.lastUpdateUserId = request.user.sub; - data.lastUpdateFullName = request.user.name; - // addLogSequence(request, { - // action: "database", - // status: "success", - // description: "Store DevelopmentAddresss.", - // }); - await this.developmentAddresssRepository.save(data, { data: request }); - setLogDataDiff(request, { before, after: development }); - }), - ); + return new HttpSuccess(development.id); + } + /** + * API แก้ไขโครงการ/หลักสูตรการฝึกอบรม tab7 + * + * @summary DEV_00 - แก้ไขโครงการ/หลักสูตรการฝึกอบรม tab7 # + * + * @param {string} id Id โครงการ + */ + @Put("tab7/{id}") + async UpdateDevelopmentTab7( + @Path() id: string, + @Body() requestBody: UpdateDevelopment7, + @Request() request: RequestWithUser, + ) { + const development = await this.developmentRepository.findOne({ + where: { id }, + relations: { developmentAddresss: true }, + }); + if (!development) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงการ/หลักสูตรการฝึกอบรมนี้"); + } + Object.assign(development, { ...requestBody }); + development.lastUpdateUserId = request.user.sub; + development.lastUpdateFullName = request.user.name; + await this.developmentRepository.save(development, { data: request }); + return new HttpSuccess(development.id); + } + + /** + * API แก้ไขโครงการ/หลักสูตรการฝึกอบรม tab8 + * + * @summary DEV_00 - แก้ไขโครงการ/หลักสูตรการฝึกอบรม tab8 # + * + * @param {string} id Id โครงการ + */ + @Put("tab8/{id}") + async UpdateDevelopmentTab8( + @Path() id: string, + @Body() requestBody: UpdateDevelopment8, + @Request() request: RequestWithUser, + ) { + const development = await this.developmentRepository.findOne({ + where: { id }, + relations: { developmentAddresss: true }, + }); + if (!development) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงการ/หลักสูตรการฝึกอบรมนี้"); + } + Object.assign(development, { ...requestBody }); + development.lastUpdateUserId = request.user.sub; + development.lastUpdateFullName = request.user.name; + await this.developmentRepository.save(development, { data: request }); return new HttpSuccess(development.id); } diff --git a/src/entities/Development.ts b/src/entities/Development.ts index f65b06e..e5bce76 100644 --- a/src/entities/Development.ts +++ b/src/entities/Development.ts @@ -652,6 +652,38 @@ export class Development extends EntityBase { @ManyToOne(() => StrategyChild5, (strategyChild5) => strategyChild5.developmentActuals) @JoinColumn({ name: "strategyChild5ActualId" }) strategyChild5Actual: StrategyChild5; + + @Column({ + type: "longtext", + nullable: true, + comment: "การติดตามความก้าวหน้า", + default: null, + }) + progressTracking: string; + + @Column({ + type: "longtext", + nullable: true, + comment: "การประเมินผลโครงการ", + default: null, + }) + projectEvaluation: string; + + @Column({ + type: "longtext", + nullable: true, + comment: "ปัญหาอุปสรรค", + default: null, + }) + obstacle: string; + + @Column({ + type: "longtext", + nullable: true, + comment: "ข้อเสนอแนะ", + default: null, + }) + suggestion: string; } export class CreateDevelopment { @Column() @@ -695,6 +727,16 @@ export class UpdateDevelopment2_2 { plannedPeoples: CreatePlannedPeople[]; } export class UpdateDevelopment3 { + //move from tab5 + @Column() + dateStart: Date | null; + @Column() + dateEnd: Date | null; + @Column() + totalDate: number | null; + //end + @Column() + developmentAddresss: CreateDevelopmentAddress[]; @Column() developmentProjectTypes?: string[]; @Column() @@ -749,6 +791,22 @@ export class UpdateDevelopment3 { export class UpdateDevelopment4 { // @Column() // developmentEvaluations: CreateDevelopmentEvaluation[]; + //new + @Column() + progressTracking: string | null; + @Column() + projectEvaluation: string | null; + //end + +} +export class UpdateDevelopment5 { + //new + @Column() + obstacle: string | null; + @Column() + suggestion: string | null; + //end + //move from tab4 @Column() project: string | null; @Column() @@ -761,16 +819,21 @@ export class UpdateDevelopment4 { isBudget: boolean; @Column() isOutBudget: boolean; + //end + @Column() + budgetPay: Double | null; + @Column() + expect: string | null; + @Column() + topicAcademic: string | null; + @Column() + addressAcademic: string | null; + @Column() + provinceActualId: string | null; } -export class UpdateDevelopment5 { - @Column() - dateStart: Date | null; - @Column() - dateEnd: Date | null; - @Column() - totalDate: number | null; - @Column() - developmentAddresss: CreateDevelopmentAddress[]; + +export class UpdateDevelopment7 { +//move from tab5 @Column() budget: string | null; @Column() @@ -781,8 +844,10 @@ export class UpdateDevelopment5 { receive: Double | null; @Column() approved: Double | null; - @Column() - budgetPay: Double | null; +//end +} +export class UpdateDevelopment8 { + //move from tab5 @Column() issues: string | null; @Column() @@ -793,12 +858,5 @@ export class UpdateDevelopment5 { riskLevel: string | null; @Column() riskManagement: string | null; - @Column() - expect: string | null; - @Column() - topicAcademic: string | null; - @Column() - addressAcademic: string | null; - @Column() - provinceActualId: string | null; + //end } diff --git a/src/migration/1723013963408-update_table_migration08072024.ts b/src/migration/1723013963408-update_table_migration08072024.ts new file mode 100644 index 0000000..18d23e8 --- /dev/null +++ b/src/migration/1723013963408-update_table_migration08072024.ts @@ -0,0 +1,20 @@ +import { MigrationInterface, QueryRunner } from "typeorm"; + +export class UpdateTableMigration080720241723013963408 implements MigrationInterface { + name = 'UpdateTableMigration080720241723013963408' + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`development\` ADD \`progressTracking\` longtext NULL COMMENT 'การติดตามความก้าวหน้า'`); + await queryRunner.query(`ALTER TABLE \`development\` ADD \`projectEvaluation\` longtext NULL COMMENT 'การประเมินผลโครงการ'`); + await queryRunner.query(`ALTER TABLE \`development\` ADD \`obstacle\` longtext NULL COMMENT 'ปัญหาอุปสรรค'`); + await queryRunner.query(`ALTER TABLE \`development\` ADD \`suggestion\` longtext NULL COMMENT 'ข้อเสนอแนะ'`); + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`suggestion\``); + await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`obstacle\``); + await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`projectEvaluation\``); + await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`progressTracking\``); + } + +} From 8a36a6c977170eb599c8490737c8bec1e9cd5506 Mon Sep 17 00:00:00 2001 From: AdisakKanthawilang Date: Wed, 7 Aug 2024 15:08:40 +0700 Subject: [PATCH 129/250] get tab7 --- src/controllers/DevelopmentController.ts | 23 +++++++++++++++++++++++ src/entities/Development.ts | 8 ++++---- 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/src/controllers/DevelopmentController.ts b/src/controllers/DevelopmentController.ts index f6f44ef..2e776e3 100644 --- a/src/controllers/DevelopmentController.ts +++ b/src/controllers/DevelopmentController.ts @@ -1410,6 +1410,29 @@ export class DevelopmentController extends Controller { await this.developmentRepository.save(development, { data: request }); return new HttpSuccess(development.id); } + /** + * API รายละเอียดโครงการ/หลักสูตรการฝึกอบรม tab6 + * + * @summary DEV_00 - รายละเอียดโครงการ/หลักสูตรการฝึกอบรมtab6 # + * + * @param {string} id Id โครงการ + */ + @Get("tab7/{id}") + async GetDevelopemtTab7ById(@Path() id: string) { + const getDevelopment = await this.developmentRepository.findOne({ + where: { id }, + }); + const _getDevelopment = { + id: getDevelopment ? getDevelopment.id : null, + accept: getDevelopment ? getDevelopment.accept : null, + receive: getDevelopment ? getDevelopment.receive : null, + approved: getDevelopment ? getDevelopment.approved : null, + budget: getDevelopment ? getDevelopment.budget : null, + budgetSub: getDevelopment ? getDevelopment.budgetSub : null, + budgetPay: getDevelopment ? getDevelopment.budgetPay : null, + }; + return new HttpSuccess(_getDevelopment); + } /** * API แก้ไขโครงการ/หลักสูตรการฝึกอบรม tab8 diff --git a/src/entities/Development.ts b/src/entities/Development.ts index e5bce76..9dab344 100644 --- a/src/entities/Development.ts +++ b/src/entities/Development.ts @@ -821,8 +821,6 @@ export class UpdateDevelopment5 { isOutBudget: boolean; //end @Column() - budgetPay: Double | null; - @Column() expect: string | null; @Column() topicAcademic: string | null; @@ -833,18 +831,20 @@ export class UpdateDevelopment5 { } export class UpdateDevelopment7 { -//move from tab5 + //move from tab5 @Column() budget: string | null; @Column() budgetSub: string | null; @Column() + budgetPay: Double | null; + @Column() accept: Double | null; @Column() receive: Double | null; @Column() approved: Double | null; -//end + //end } export class UpdateDevelopment8 { //move from tab5 From 6fc0c04a9b85405fba46266fbe19a874df6c8995 Mon Sep 17 00:00:00 2001 From: AdisakKanthawilang Date: Wed, 7 Aug 2024 17:34:44 +0700 Subject: [PATCH 130/250] migrate --- src/controllers/DevelopmentController.ts | 116 +++++++++++++++++- src/entities/Development.ts | 17 ++- src/entities/DevelopmentRisk.ts | 59 +++++++++ ...794685-update_table_migration2_08072024.ts | 16 +++ 4 files changed, 202 insertions(+), 6 deletions(-) create mode 100644 src/entities/DevelopmentRisk.ts create mode 100644 src/migration/1723026794685-update_table_migration2_08072024.ts diff --git a/src/controllers/DevelopmentController.ts b/src/controllers/DevelopmentController.ts index 2e776e3..5f02eca 100644 --- a/src/controllers/DevelopmentController.ts +++ b/src/controllers/DevelopmentController.ts @@ -27,6 +27,7 @@ import { UpdateDevelopment5, UpdateDevelopment7, UpdateDevelopment8, + UpdateDevelopment8_1, } from "../entities/Development"; import { ActualPeople, CreateActualPeople } from "../entities/ActualPeople"; import { CreatePlannedPeople, PlannedPeople } from "../entities/PlannedPeople"; @@ -60,12 +61,14 @@ import { FileInterceptor } from "@nestjs/platform-express"; import * as xlsx from "xlsx"; import { addLogSequence, setLogDataDiff } from "../interfaces/utils"; import { RequestWithUser } from "../middlewares/user"; +import { DevelopmentRisk } from "../entities/DevelopmentRisk"; @Route("api/v1/development/main") @Tags("Development") @Security("bearerAuth") export class DevelopmentController extends Controller { private developmentRepository = AppDataSource.getRepository(Development); + private developmentRiskRepository = AppDataSource.getRepository(DevelopmentRisk); private developmentAddresssRepository = AppDataSource.getRepository(DevelopmentAddress); private developmentEvaluationRepository = AppDataSource.getRepository(DevelopmentEvaluation); private developmentProjectTypeRepository = AppDataSource.getRepository(DevelopmentProjectType); @@ -1410,10 +1413,11 @@ export class DevelopmentController extends Controller { await this.developmentRepository.save(development, { data: request }); return new HttpSuccess(development.id); } + /** - * API รายละเอียดโครงการ/หลักสูตรการฝึกอบรม tab6 + * API รายละเอียดโครงการ/หลักสูตรการฝึกอบรม tab7 * - * @summary DEV_00 - รายละเอียดโครงการ/หลักสูตรการฝึกอบรมtab6 # + * @summary DEV_00 - รายละเอียดโครงการ/หลักสูตรการฝึกอบรมtab7 # * * @param {string} id Id โครงการ */ @@ -1434,6 +1438,38 @@ export class DevelopmentController extends Controller { return new HttpSuccess(_getDevelopment); } + + /** + * API รายละเอียดโครงการ/หลักสูตรการฝึกอบรม tab8 + * + * @summary DEV_00 - รายละเอียดโครงการ/หลักสูตรการฝึกอบรมtab8 # + * + * @param {string} id Id โครงการ + */ + @Get("tab8/{id}") + async GetDevelopemtTab8ById(@Path() id: string) { + const getDevelopment = await this.developmentRepository.findOne({ + relations: ["developmentRisks"], + where: { id: id }, + }); + if (!getDevelopment) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงการ/หลักสูตรการฝึกอบรมนี้"); + } + let _getDevelopment = { + developmentRisks: + getDevelopment.developmentRisks == null + ? null + : getDevelopment.developmentRisks.sort((a, b) => + (a.id == null ? "" : a.id).localeCompare( + b.id == null ? "" : b.id, + ), + ), + expect: getDevelopment.expect, + }; + + return new HttpSuccess(_getDevelopment); + } + /** * API แก้ไขโครงการ/หลักสูตรการฝึกอบรม tab8 * @@ -1460,6 +1496,82 @@ export class DevelopmentController extends Controller { await this.developmentRepository.save(development, { data: request }); return new HttpSuccess(development.id); } + /** + * API เพิ่มโครงการ/หลักสูตรการฝึกอบรมtab8-1 + * + * @summary DEV_00 - เพิ่มโครงการ/หลักสูตรการฝึกอบรมtab8-1 # + * + * @param {string} id Id โครงการ + */ + @Put("tab8_1_add/{id}") + async CreateDevelopmenttab8_1( + @Path() id: string, + @Body() requestBody: UpdateDevelopment8_1, + @Request() request: RequestWithUser, + ) { + const development = await this.developmentRepository.findOne({ + where: { id }, + }); + if (!development) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงการ/หลักสูตรการฝึกอบรมนี้"); + } + const before = structuredClone(development); + const data = Object.assign(new DevelopmentEvaluation(), requestBody); + data.createdUserId = request.user.sub; + data.createdFullName = request.user.name; + data.lastUpdateUserId = request.user.sub; + data.lastUpdateFullName = request.user.name; + data.developmentId = development.id; + await this.developmentEvaluationRepository.save(data, { data: request }); + setLogDataDiff(request, { before, after: development }); + return new HttpSuccess(data.id); + } + + /** + * API ลบโครงการ/หลักสูตรการฝึกอบรมtab8-1 + * + * @summary DEV_00 - ลบโครงการ/หลักสูตรการฝึกอบรมtab8-1 # + * + * @param {string} id Id รายการ + */ + @Delete("tab8_1/{id}") + async DeleteDevelopmenttab8_1(@Path() id: string, @Request() request: RequestWithUser) { + const development = await this.developmentEvaluationRepository.findOne({ + where: { id }, + }); + if (!development) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลผู้เกี่ยวข้องเป้าหมายตามแผน"); + } + await this.developmentEvaluationRepository.remove(development, { data: request }); + return new HttpSuccess(development.id); + } + + /** + * API แก้ไขโครงการ/หลักสูตรการฝึกอบรมtab8-1 + * + * @summary DEV_00 - แก้ไขโครงการ/หลักสูตรการฝึกอบรมtab8-1 # + * + * @param {string} id Id รายการ + */ + @Put("tab8_1_edit/{id}") + async UpdateDevelopmenttab8_1( + @Path() id: string, + @Body() requestBody: UpdateDevelopment8_1, + @Request() request: RequestWithUser, + ) { + const development = await this.developmentEvaluationRepository.findOne({ + where: { id }, + }); + if (!development) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงการ/หลักสูตรการฝึกอบรมนี้"); + } + Object.assign(development, requestBody); + development.lastUpdateUserId = request.user.sub; + development.lastUpdateFullName = request.user.name; + + await this.developmentEvaluationRepository.save(development, { data: request }); + return new HttpSuccess(development.id); + } /** * API ค้นหาโครงการ diff --git a/src/entities/Development.ts b/src/entities/Development.ts index 9dab344..25532a7 100644 --- a/src/entities/Development.ts +++ b/src/entities/Development.ts @@ -16,6 +16,7 @@ import { StrategyChild4 } from "./StrategyChild4"; import { StrategyChild3 } from "./StrategyChild3"; import { StrategyChild2 } from "./StrategyChild2"; import { StrategyChild1 } from "./StrategyChild1"; +import { DevelopmentRisk } from "./DevelopmentRisk"; @Entity("development") export class Development extends EntityBase { @@ -187,7 +188,12 @@ export class Development extends EntityBase { @OneToMany(() => PlannedGoal, (plannedGoal: PlannedGoal) => plannedGoal.developmentPlannedGoal) developmentPlannedGoals: PlannedGoal[]; - ////////////////////////////////////////tab ลักษณะโครงการ + @OneToMany( + () => DevelopmentRisk, + (developmentRisk: DevelopmentRisk) => developmentRisk.development, + ) + developmentRisks: DevelopmentRisk[]; + @OneToMany( () => DevelopmentProjectType, (developmentProjectType: DevelopmentProjectType) => developmentProjectType.development, @@ -821,8 +827,6 @@ export class UpdateDevelopment5 { isOutBudget: boolean; //end @Column() - expect: string | null; - @Column() topicAcademic: string | null; @Column() addressAcademic: string | null; @@ -846,7 +850,7 @@ export class UpdateDevelopment7 { approved: Double | null; //end } -export class UpdateDevelopment8 { +export class UpdateDevelopment8_1 { //move from tab5 @Column() issues: string | null; @@ -860,3 +864,8 @@ export class UpdateDevelopment8 { riskManagement: string | null; //end } + +export class UpdateDevelopment8{ + @Column() + expect: string | null; +} \ No newline at end of file diff --git a/src/entities/DevelopmentRisk.ts b/src/entities/DevelopmentRisk.ts new file mode 100644 index 0000000..5df5af0 --- /dev/null +++ b/src/entities/DevelopmentRisk.ts @@ -0,0 +1,59 @@ +import { Entity, Column, ManyToOne, JoinColumn } from "typeorm"; +import { EntityBase } from "./base/Base"; +import { Development } from "./Development"; +import { Province } from "./Province"; + +@Entity("developmentRisk") +export class DevelopmentRisk extends EntityBase { + @Column({ + nullable: true, + comment: "ประเด็นความเสี่ยง", + default: null, + }) + issues: string; + + @Column({ + nullable: true, + comment: "โอกาสที่จะเกิด", + default: null, + }) + chance: number; + + @Column({ + nullable: true, + comment: "ผลกระทบจากการเกิด", + default: null, + }) + effects: number; + + @Column({ + nullable: true, + comment: "ระดับความเสี่ยง", + default: null, + }) + riskLevel: string; + + @Column({ + nullable: true, + comment: "เเนวทางการบริหารความเสี่ยง", + default: null, + }) + riskManagement: string; + + @Column({ + nullable: true, + comment: "คีย์นอก(FK)ของตาราง development", + default: null, + }) + developmentId: string; + + @ManyToOne(() => Development, (development: Development) => development.developmentRisks) + @JoinColumn({ name: "developmentId" }) + development: Development; +} +export class CreateDevelopmentRisk { + @Column() + address: string | null; + @Column() + provinceId: string; +} diff --git a/src/migration/1723026794685-update_table_migration2_08072024.ts b/src/migration/1723026794685-update_table_migration2_08072024.ts new file mode 100644 index 0000000..97fc16d --- /dev/null +++ b/src/migration/1723026794685-update_table_migration2_08072024.ts @@ -0,0 +1,16 @@ +import { MigrationInterface, QueryRunner } from "typeorm"; + +export class UpdateTableMigration2080720241723026794685 implements MigrationInterface { + name = 'UpdateTableMigration2080720241723026794685' + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(`CREATE TABLE \`developmentRisk\` (\`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', \`issues\` varchar(255) NULL COMMENT 'ประเด็นความเสี่ยง', \`chance\` int NULL COMMENT 'โอกาสที่จะเกิด', \`effects\` int NULL COMMENT 'ผลกระทบจากการเกิด', \`riskLevel\` varchar(255) NULL COMMENT 'ระดับความเสี่ยง', \`riskManagement\` varchar(255) NULL COMMENT 'เเนวทางการบริหารความเสี่ยง', \`developmentId\` varchar(255) NULL COMMENT 'คีย์นอก(FK)ของตาราง development', PRIMARY KEY (\`id\`)) ENGINE=InnoDB`); + await queryRunner.query(`ALTER TABLE \`developmentRisk\` ADD CONSTRAINT \`FK_b1990ff92f534f65a4653ef1671\` FOREIGN KEY (\`developmentId\`) REFERENCES \`development\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`); + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`developmentRisk\` DROP FOREIGN KEY \`FK_b1990ff92f534f65a4653ef1671\``); + await queryRunner.query(`DROP TABLE \`developmentRisk\``); + } + +} From b9cc922edcfb96e86a4f973ade5f595f4fd295f6 Mon Sep 17 00:00:00 2001 From: AdisakKanthawilang Date: Wed, 7 Aug 2024 18:15:55 +0700 Subject: [PATCH 131/250] Tab8 API --- src/controllers/DevelopmentController.ts | 77 ++++++++++++------------ src/entities/DevelopmentRisk.ts | 13 +++- 2 files changed, 47 insertions(+), 43 deletions(-) diff --git a/src/controllers/DevelopmentController.ts b/src/controllers/DevelopmentController.ts index 5f02eca..8fbf159 100644 --- a/src/controllers/DevelopmentController.ts +++ b/src/controllers/DevelopmentController.ts @@ -61,7 +61,7 @@ import { FileInterceptor } from "@nestjs/platform-express"; import * as xlsx from "xlsx"; import { addLogSequence, setLogDataDiff } from "../interfaces/utils"; import { RequestWithUser } from "../middlewares/user"; -import { DevelopmentRisk } from "../entities/DevelopmentRisk"; +import { DevelopmentRisk, UpdateDevelopmentRisk } from "../entities/DevelopmentRisk"; @Route("api/v1/development/main") @Tags("Development") @@ -1206,27 +1206,27 @@ export class DevelopmentController extends Controller { ); } //move from tab5 - await this.developmentAddresssRepository.remove(development.developmentAddresss, { - data: request, - }); - const before = structuredClone(development); - await Promise.all( - requestBody.developmentAddresss.map(async (x) => { - const data = Object.assign(new DevelopmentAddress(), x); - const chkProvince = await this.provinceRepository.findOne({ - where: { - id: x.provinceId, - }, - }); - if (chkProvince == null) return; - data.developmentId = development.id; - data.createdUserId = request.user.sub; - data.createdFullName = request.user.name; - data.lastUpdateUserId = request.user.sub; - data.lastUpdateFullName = request.user.name; - await this.developmentAddresssRepository.save(data, { data: request }); - setLogDataDiff(request, { before, after: development }); - }), + await this.developmentAddresssRepository.remove(development.developmentAddresss, { + data: request, + }); + const before = structuredClone(development); + await Promise.all( + requestBody.developmentAddresss.map(async (x) => { + const data = Object.assign(new DevelopmentAddress(), x); + const chkProvince = await this.provinceRepository.findOne({ + where: { + id: x.provinceId, + }, + }); + if (chkProvince == null) return; + data.developmentId = development.id; + data.createdUserId = request.user.sub; + data.createdFullName = request.user.name; + data.lastUpdateUserId = request.user.sub; + data.lastUpdateFullName = request.user.name; + await this.developmentAddresssRepository.save(data, { data: request }); + setLogDataDiff(request, { before, after: development }); + }), ); Object.assign(development, { ...requestBody, developmentAddresss: [] }); //End @@ -1387,7 +1387,7 @@ export class DevelopmentController extends Controller { return new HttpSuccess(development.id); } - /** + /** * API แก้ไขโครงการ/หลักสูตรการฝึกอบรม tab7 * * @summary DEV_00 - แก้ไขโครงการ/หลักสูตรการฝึกอบรม tab7 # @@ -1438,8 +1438,7 @@ export class DevelopmentController extends Controller { return new HttpSuccess(_getDevelopment); } - - /** + /** * API รายละเอียดโครงการ/หลักสูตรการฝึกอบรม tab8 * * @summary DEV_00 - รายละเอียดโครงการ/หลักสูตรการฝึกอบรมtab8 # @@ -1460,9 +1459,7 @@ export class DevelopmentController extends Controller { getDevelopment.developmentRisks == null ? null : getDevelopment.developmentRisks.sort((a, b) => - (a.id == null ? "" : a.id).localeCompare( - b.id == null ? "" : b.id, - ), + (a.id == null ? "" : a.id).localeCompare(b.id == null ? "" : b.id), ), expect: getDevelopment.expect, }; @@ -1470,7 +1467,7 @@ export class DevelopmentController extends Controller { return new HttpSuccess(_getDevelopment); } - /** + /** * API แก้ไขโครงการ/หลักสูตรการฝึกอบรม tab8 * * @summary DEV_00 - แก้ไขโครงการ/หลักสูตรการฝึกอบรม tab8 # @@ -1506,7 +1503,7 @@ export class DevelopmentController extends Controller { @Put("tab8_1_add/{id}") async CreateDevelopmenttab8_1( @Path() id: string, - @Body() requestBody: UpdateDevelopment8_1, + @Body() requestBody: UpdateDevelopmentRisk, @Request() request: RequestWithUser, ) { const development = await this.developmentRepository.findOne({ @@ -1516,13 +1513,13 @@ export class DevelopmentController extends Controller { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงการ/หลักสูตรการฝึกอบรมนี้"); } const before = structuredClone(development); - const data = Object.assign(new DevelopmentEvaluation(), requestBody); + const data = Object.assign(new DevelopmentRisk(), requestBody); data.createdUserId = request.user.sub; data.createdFullName = request.user.name; data.lastUpdateUserId = request.user.sub; data.lastUpdateFullName = request.user.name; data.developmentId = development.id; - await this.developmentEvaluationRepository.save(data, { data: request }); + await this.developmentRiskRepository.save(data, { data: request }); setLogDataDiff(request, { before, after: development }); return new HttpSuccess(data.id); } @@ -1536,13 +1533,13 @@ export class DevelopmentController extends Controller { */ @Delete("tab8_1/{id}") async DeleteDevelopmenttab8_1(@Path() id: string, @Request() request: RequestWithUser) { - const development = await this.developmentEvaluationRepository.findOne({ + const development = await this.developmentRiskRepository.findOne({ where: { id }, }); if (!development) { - throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลผู้เกี่ยวข้องเป้าหมายตามแผน"); + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลความเสี่ยงของโครงการ"); } - await this.developmentEvaluationRepository.remove(development, { data: request }); + await this.developmentRiskRepository.remove(development, { data: request }); return new HttpSuccess(development.id); } @@ -1556,20 +1553,20 @@ export class DevelopmentController extends Controller { @Put("tab8_1_edit/{id}") async UpdateDevelopmenttab8_1( @Path() id: string, - @Body() requestBody: UpdateDevelopment8_1, + @Body() requestBody: UpdateDevelopmentRisk, @Request() request: RequestWithUser, ) { - const development = await this.developmentEvaluationRepository.findOne({ + const development = await this.developmentRiskRepository.findOne({ where: { id }, }); if (!development) { - throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงการ/หลักสูตรการฝึกอบรมนี้"); + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลความเสี่ยงของโครงการ"); } Object.assign(development, requestBody); development.lastUpdateUserId = request.user.sub; development.lastUpdateFullName = request.user.name; - - await this.developmentEvaluationRepository.save(development, { data: request }); + + await this.developmentRiskRepository.save(development, { data: request }); return new HttpSuccess(development.id); } diff --git a/src/entities/DevelopmentRisk.ts b/src/entities/DevelopmentRisk.ts index 5df5af0..e12c614 100644 --- a/src/entities/DevelopmentRisk.ts +++ b/src/entities/DevelopmentRisk.ts @@ -51,9 +51,16 @@ export class DevelopmentRisk extends EntityBase { @JoinColumn({ name: "developmentId" }) development: Development; } -export class CreateDevelopmentRisk { + +export class UpdateDevelopmentRisk { @Column() - address: string | null; + issues: string | null; @Column() - provinceId: string; + chance: number | null; + @Column() + effects: number | null; + @Column() + riskLevel: string | null; + @Column() + riskManagement: string | null; } From 3056dfeb2af26f32682b303fd9d58affbdd8f5df Mon Sep 17 00:00:00 2001 From: AdisakKanthawilang Date: Thu, 8 Aug 2024 10:39:44 +0700 Subject: [PATCH 132/250] migatation and get tab4 --- src/controllers/DevelopmentController.ts | 48 +----------------------- src/entities/Development.ts | 7 ++++ src/entities/DevelopmentOther.ts | 48 ++++++++++++++++++++++++ 3 files changed, 57 insertions(+), 46 deletions(-) create mode 100644 src/entities/DevelopmentOther.ts diff --git a/src/controllers/DevelopmentController.ts b/src/controllers/DevelopmentController.ts index 8fbf159..53af128 100644 --- a/src/controllers/DevelopmentController.ts +++ b/src/controllers/DevelopmentController.ts @@ -877,11 +877,6 @@ export class DevelopmentController extends Controller { @Body() requestBody: UpdateDevelopment3, @Request() request: RequestWithUser, ) { - // addLogSequence(request, { - // action: "database", - // status: "success", - // description: "Get Development.", - // }); const development = await this.developmentRepository.findOne({ where: { id }, relations: { @@ -901,30 +896,15 @@ export class DevelopmentController extends Controller { }); development.lastUpdateUserId = request.user.sub; development.lastUpdateFullName = request.user.name; - // addLogSequence(request, { - // action: "remove", - // status: "success", - // description: "Remove data in DevelopmentProjectType.", - // }); await this.developmentProjectTypeRepository.remove(development.developmentProjectTypes, { data: request, }); - // addLogSequence(request, { - // action: "remove", - // status: "success", - // description: "Remove data in DevelopmentProjectTechniquePlanned.", - // }); await this.developmentProjectTechniquePlannedRepository.remove( development.developmentProjectTechniquePlanneds, { data: request, }, ); - // addLogSequence(request, { - // action: "remove", - // status: "success", - // description: "Remove data in DevelopmentProjectTechniqueActual.", - // }); await this.developmentProjectTechniqueActualRepository.remove( development.developmentProjectTechniqueActuals, { @@ -1142,11 +1122,6 @@ export class DevelopmentController extends Controller { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลยุทธศาสตร์เป้าหมายตามจริง"); } } - // addLogSequence(request, { - // action: "database", - // status: "success", - // description: "Store Development.", - // }); await this.developmentRepository.save(development, { data: request }); if (requestBody.developmentProjectTypes != null) { await Promise.all( @@ -1158,11 +1133,6 @@ export class DevelopmentController extends Controller { data.lastUpdateUserId = request.user.sub; data.lastUpdateFullName = request.user.name; data.developmentId = development.id; - // addLogSequence(request, { - // action: "database", - // status: "success", - // description: "Store DevelopmentProjectType.", - // }); await this.developmentProjectTypeRepository.save(data, { data: request }); }), ); @@ -1177,11 +1147,6 @@ export class DevelopmentController extends Controller { data.lastUpdateUserId = request.user.sub; data.lastUpdateFullName = request.user.name; data.developmentId = development.id; - // addLogSequence(request, { - // action: "database", - // status: "success", - // description: "Store DevelopmentProjectTechniquePlanned.", - // }); await this.developmentProjectTechniquePlannedRepository.save(data, { data: request }); }), ); @@ -1196,11 +1161,6 @@ export class DevelopmentController extends Controller { data.lastUpdateUserId = request.user.sub; data.lastUpdateFullName = request.user.name; data.developmentId = development.id; - // addLogSequence(request, { - // action: "database", - // status: "success", - // description: "Store DevelopmentProjectTechniqueActual.", - // }); await this.developmentProjectTechniqueActualRepository.save(data, { data: request }); }), ); @@ -2144,12 +2104,8 @@ export class DevelopmentController extends Controller { b.indicators == null ? "" : b.indicators, ), ), - project: getDevelopment.project, - isPassAllocate: getDevelopment.isPassAllocate, - isPassNoAllocate: getDevelopment.isPassNoAllocate, - isNoPass: getDevelopment.isNoPass, - isBudget: getDevelopment.isBudget, - isOutBudget: getDevelopment.isOutBudget, + progressTracking: getDevelopment.progressTracking, + projectEvaluation: getDevelopment.projectEvaluation, }; return new HttpSuccess(_getDevelopment); diff --git a/src/entities/Development.ts b/src/entities/Development.ts index 25532a7..94b088a 100644 --- a/src/entities/Development.ts +++ b/src/entities/Development.ts @@ -17,6 +17,7 @@ import { StrategyChild3 } from "./StrategyChild3"; import { StrategyChild2 } from "./StrategyChild2"; import { StrategyChild1 } from "./StrategyChild1"; import { DevelopmentRisk } from "./DevelopmentRisk"; +import { DevelopmentOther } from "./DevelopmentOther"; @Entity("development") export class Development extends EntityBase { @@ -194,6 +195,12 @@ export class Development extends EntityBase { ) developmentRisks: DevelopmentRisk[]; + @OneToMany( + () => DevelopmentOther, + (developmentOther: DevelopmentOther) => developmentOther.development, + ) + developmentOthers: DevelopmentOther[]; + @OneToMany( () => DevelopmentProjectType, (developmentProjectType: DevelopmentProjectType) => developmentProjectType.development, diff --git a/src/entities/DevelopmentOther.ts b/src/entities/DevelopmentOther.ts new file mode 100644 index 0000000..1747c26 --- /dev/null +++ b/src/entities/DevelopmentOther.ts @@ -0,0 +1,48 @@ +import { Entity, Column, ManyToOne, JoinColumn } from "typeorm"; +import { EntityBase } from "./base/Base"; +import { Development } from "./Development"; +import { Province } from "./Province"; + +@Entity("developmentOther") +export class DevelopmentOther extends EntityBase { + @Column({ + nullable: true, + comment: "หัวข้อ/ประเด็นการฝึกอบรม ศึกษาดูงาน", + default: null, + }) + topicAcademic: string; + + @Column({ + nullable: true, + comment: "สถานที่ฝึกอบรม ศึกษาดูงาน", + default: null, + }) + addressAcademic: string; + + @Column({ + nullable: true, + comment: "จังหวัด(ข้อมูลวิชาการ)", + default: null, + }) + provinceActualId: string; + + @Column({ + nullable: true, + comment: "คีย์นอก(FK)ของตาราง development", + default: null, + }) + developmentId: string; + + @ManyToOne(() => Development, (development: Development) => development.developmentOthers) + @JoinColumn({ name: "developmentId" }) + development: Development; +} + +export class UpdateDevelopmentOther { + @Column() + topicAcademic: string | null; + @Column() + addressAcademic: number | null; + @Column() + provinceActualId: number | null; +} From 15a730d4a9a7ecd896a2dc780975636c7cbd60c8 Mon Sep 17 00:00:00 2001 From: Bright Date: Thu, 8 Aug 2024 10:52:30 +0700 Subject: [PATCH 133/250] migrate --- src/migration/1723089052077-add_Table.ts | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 src/migration/1723089052077-add_Table.ts diff --git a/src/migration/1723089052077-add_Table.ts b/src/migration/1723089052077-add_Table.ts new file mode 100644 index 0000000..c1820ad --- /dev/null +++ b/src/migration/1723089052077-add_Table.ts @@ -0,0 +1,16 @@ +import { MigrationInterface, QueryRunner } from "typeorm"; + +export class AddTable1723089052077 implements MigrationInterface { + name = 'AddTable1723089052077' + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(`CREATE TABLE \`developmentOther\` (\`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', \`topicAcademic\` varchar(255) NULL COMMENT 'หัวข้อ/ประเด็นการฝึกอบรม ศึกษาดูงาน', \`addressAcademic\` varchar(255) NULL COMMENT 'สถานที่ฝึกอบรม ศึกษาดูงาน', \`provinceActualId\` varchar(255) NULL COMMENT 'จังหวัด(ข้อมูลวิชาการ)', \`developmentId\` varchar(255) NULL COMMENT 'คีย์นอก(FK)ของตาราง development', PRIMARY KEY (\`id\`)) ENGINE=InnoDB`); + await queryRunner.query(`ALTER TABLE \`developmentOther\` ADD CONSTRAINT \`FK_d5dfdb7ca0d11c0cdf3b3a55e6f\` FOREIGN KEY (\`developmentId\`) REFERENCES \`development\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`); + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`developmentOther\` DROP FOREIGN KEY \`FK_d5dfdb7ca0d11c0cdf3b3a55e6f\``); + await queryRunner.query(`DROP TABLE \`developmentOther\``); + } + +} From b8575cd3a042ffdf0d6cef857eeb8f144f0a3c4e Mon Sep 17 00:00:00 2001 From: AdisakKanthawilang Date: Thu, 8 Aug 2024 11:27:28 +0700 Subject: [PATCH 134/250] api tab5 --- src/controllers/DevelopmentController.ts | 125 +++++++++++++++++------ src/entities/Development.ts | 6 -- src/entities/DevelopmentOther.ts | 2 +- 3 files changed, 96 insertions(+), 37 deletions(-) diff --git a/src/controllers/DevelopmentController.ts b/src/controllers/DevelopmentController.ts index 53af128..eb2f0bf 100644 --- a/src/controllers/DevelopmentController.ts +++ b/src/controllers/DevelopmentController.ts @@ -62,6 +62,7 @@ import * as xlsx from "xlsx"; import { addLogSequence, setLogDataDiff } from "../interfaces/utils"; import { RequestWithUser } from "../middlewares/user"; import { DevelopmentRisk, UpdateDevelopmentRisk } from "../entities/DevelopmentRisk"; +import { DevelopmentOther, UpdateDevelopmentOther } from "../entities/DevelopmentOther"; @Route("api/v1/development/main") @Tags("Development") @@ -69,6 +70,7 @@ import { DevelopmentRisk, UpdateDevelopmentRisk } from "../entities/DevelopmentR export class DevelopmentController extends Controller { private developmentRepository = AppDataSource.getRepository(Development); private developmentRiskRepository = AppDataSource.getRepository(DevelopmentRisk); + private developmentOtherRepository = AppDataSource.getRepository(DevelopmentOther); private developmentAddresssRepository = AppDataSource.getRepository(DevelopmentAddress); private developmentEvaluationRepository = AppDataSource.getRepository(DevelopmentEvaluation); private developmentProjectTypeRepository = AppDataSource.getRepository(DevelopmentProjectType); @@ -1332,7 +1334,32 @@ export class DevelopmentController extends Controller { if (!development) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงการ/หลักสูตรการฝึกอบรมนี้"); } - if (requestBody.provinceActualId != null) { + Object.assign(development, { ...requestBody, developmentAddresss: [] }); + development.lastUpdateUserId = request.user.sub; + development.lastUpdateFullName = request.user.name; + await this.developmentRepository.save(development, { data: request }); + return new HttpSuccess(development.id); + } + /** + * API เพิ่มโครงการ/หลักสูตรการฝึกอบรมtab5-1 + * + * @summary DEV_00 - เพิ่มโครงการ/หลักสูตรการฝึกอบรมtab5-1 # + * + * @param {string} id Id โครงการ + */ + @Put("tab5_1_add/{id}") + async CreateDevelopmenttab5_1( + @Path() id: string, + @Body() requestBody: UpdateDevelopmentOther, + @Request() request: RequestWithUser, + ) { + const development = await this.developmentRepository.findOne({ + where: { id }, + }); + if (!development) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงการ/หลักสูตรการฝึกอบรมนี้"); + } + if (requestBody.provinceActualId != null) { const checkId = await this.provinceRepository.findOne({ where: { id: requestBody.provinceActualId }, }); @@ -1340,10 +1367,61 @@ export class DevelopmentController extends Controller { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลจังหวัดข้อมูลด้านวิชาการ"); } } - Object.assign(development, { ...requestBody, developmentAddresss: [] }); + const before = structuredClone(development); + const data = Object.assign(new DevelopmentOther(), requestBody); + data.createdUserId = request.user.sub; + data.createdFullName = request.user.name; + data.lastUpdateUserId = request.user.sub; + data.lastUpdateFullName = request.user.name; + data.developmentId = development.id; + await this.developmentOtherRepository.save(data, { data: request }); + setLogDataDiff(request, { before, after: development }); + return new HttpSuccess(data.id); + } + + /** + * API ลบโครงการ/หลักสูตรการฝึกอบรมtab5-1 + * + * @summary DEV_00 - ลบโครงการ/หลักสูตรการฝึกอบรมtab5-1 # + * + * @param {string} id Id รายการ + */ + @Delete("tab5_1/{id}") + async DeleteDevelopmenttab5_1(@Path() id: string, @Request() request: RequestWithUser) { + const development = await this.developmentOtherRepository.findOne({ + where: { id }, + }); + if (!development) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลความเสี่ยงของโครงการ"); + } + await this.developmentOtherRepository.remove(development, { data: request }); + return new HttpSuccess(development.id); + } + + /** + * API แก้ไขโครงการ/หลักสูตรการฝึกอบรมtab5-1 + * + * @summary DEV_00 - แก้ไขโครงการ/หลักสูตรการฝึกอบรมtab5-1 # + * + * @param {string} id Id รายการ + */ + @Put("tab5_1_edit/{id}") + async UpdateDevelopmenttab5_1( + @Path() id: string, + @Body() requestBody: UpdateDevelopmentOther, + @Request() request: RequestWithUser, + ) { + const development = await this.developmentOtherRepository.findOne({ + where: { id }, + }); + if (!development) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลความเสี่ยงของโครงการ"); + } + Object.assign(development, requestBody); development.lastUpdateUserId = request.user.sub; development.lastUpdateFullName = request.user.name; - await this.developmentRepository.save(development, { data: request }); + + await this.developmentOtherRepository.save(development, { data: request }); return new HttpSuccess(development.id); } @@ -2121,40 +2199,27 @@ export class DevelopmentController extends Controller { @Get("tab5/{id}") async GetDevelopemtTab5ById(@Path() id: string) { const getDevelopment = await this.developmentRepository.findOne({ + relations: ["developmentOthers"], where: { id: id }, - relations: ["developmentAddresss"], }); - if (!getDevelopment) { + if (!getDevelopment) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงการ/หลักสูตรการฝึกอบรมนี้"); } - let _getDevelopment = { - dateStart: getDevelopment.dateStart, - dateEnd: getDevelopment.dateEnd, - totalDate: getDevelopment.totalDate, - developmentAddresss: - getDevelopment.developmentAddresss == null + let _getDevelopment = { + developmentOthers: + getDevelopment.developmentOthers == null ? null - : getDevelopment.developmentAddresss.sort((a, b) => - (a.address == null ? "" : a.address).localeCompare( - b.address == null ? "" : b.address, - ), + : getDevelopment.developmentOthers.sort((a, b) => + (a.id == null ? "" : a.id).localeCompare(b.id == null ? "" : b.id), ), - budget: getDevelopment.budget, - budgetSub: getDevelopment.budgetSub, - accept: getDevelopment.accept, - receive: getDevelopment.receive, - approved: getDevelopment.approved, - budgetPay: getDevelopment.budgetPay, - issues: getDevelopment.issues, - chance: getDevelopment.chance, - effects: getDevelopment.effects, - riskLevel: getDevelopment.riskLevel, - riskManagement: getDevelopment.riskManagement, - expect: getDevelopment.expect, - topicAcademic: getDevelopment.topicAcademic, - addressAcademic: getDevelopment.addressAcademic, - provinceActualId: getDevelopment.provinceActualId, + obstacle: getDevelopment.obstacle, + suggestion: getDevelopment.suggestion, + isPassAllocate: getDevelopment.isPassAllocate, + isNoPass: getDevelopment.isNoPass, + isBudget: getDevelopment.isBudget, + isOutBudget: getDevelopment.isOutBudget, }; + return new HttpSuccess(_getDevelopment); } diff --git a/src/entities/Development.ts b/src/entities/Development.ts index 94b088a..58ebd11 100644 --- a/src/entities/Development.ts +++ b/src/entities/Development.ts @@ -833,12 +833,6 @@ export class UpdateDevelopment5 { @Column() isOutBudget: boolean; //end - @Column() - topicAcademic: string | null; - @Column() - addressAcademic: string | null; - @Column() - provinceActualId: string | null; } export class UpdateDevelopment7 { diff --git a/src/entities/DevelopmentOther.ts b/src/entities/DevelopmentOther.ts index 1747c26..87d53e3 100644 --- a/src/entities/DevelopmentOther.ts +++ b/src/entities/DevelopmentOther.ts @@ -44,5 +44,5 @@ export class UpdateDevelopmentOther { @Column() addressAcademic: number | null; @Column() - provinceActualId: number | null; + provinceActualId: string | null; } From 57240eded1c72a738a6c59557678caeaee295908 Mon Sep 17 00:00:00 2001 From: AdisakKanthawilang Date: Thu, 8 Aug 2024 11:52:15 +0700 Subject: [PATCH 135/250] fix --- src/controllers/DevelopmentController.ts | 2 ++ src/entities/DevelopmentOther.ts | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/controllers/DevelopmentController.ts b/src/controllers/DevelopmentController.ts index eb2f0bf..bc92d58 100644 --- a/src/controllers/DevelopmentController.ts +++ b/src/controllers/DevelopmentController.ts @@ -2214,7 +2214,9 @@ export class DevelopmentController extends Controller { ), obstacle: getDevelopment.obstacle, suggestion: getDevelopment.suggestion, + project: getDevelopment.project, isPassAllocate: getDevelopment.isPassAllocate, + isPassNoAllocate: getDevelopment.isPassNoAllocate, isNoPass: getDevelopment.isNoPass, isBudget: getDevelopment.isBudget, isOutBudget: getDevelopment.isOutBudget, diff --git a/src/entities/DevelopmentOther.ts b/src/entities/DevelopmentOther.ts index 87d53e3..4315669 100644 --- a/src/entities/DevelopmentOther.ts +++ b/src/entities/DevelopmentOther.ts @@ -42,7 +42,7 @@ export class UpdateDevelopmentOther { @Column() topicAcademic: string | null; @Column() - addressAcademic: number | null; + addressAcademic: string | null; @Column() provinceActualId: string | null; } From 33206465218e4e11a598ff8b1c80ae05eec1f7da Mon Sep 17 00:00:00 2001 From: AdisakKanthawilang Date: Thu, 8 Aug 2024 13:27:23 +0700 Subject: [PATCH 136/250] tab 3 --- src/controllers/DevelopmentController.ts | 18 +++++++++++++++--- src/entities/Development.ts | 2 +- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/controllers/DevelopmentController.ts b/src/controllers/DevelopmentController.ts index bc92d58..04954e8 100644 --- a/src/controllers/DevelopmentController.ts +++ b/src/controllers/DevelopmentController.ts @@ -885,6 +885,7 @@ export class DevelopmentController extends Controller { developmentProjectTypes: true, developmentProjectTechniquePlanneds: true, developmentProjectTechniqueActuals: true, + developmentAddresss: true }, }); if (!development) { @@ -895,6 +896,7 @@ export class DevelopmentController extends Controller { developmentProjectTypes: [], developmentProjectTechniquePlanneds: [], developmentProjectTechniqueActuals: [], + developmentAddresss: [] }); development.lastUpdateUserId = request.user.sub; development.lastUpdateFullName = request.user.name; @@ -1171,7 +1173,7 @@ export class DevelopmentController extends Controller { await this.developmentAddresssRepository.remove(development.developmentAddresss, { data: request, }); - const before = structuredClone(development); + // const before = structuredClone(development); await Promise.all( requestBody.developmentAddresss.map(async (x) => { const data = Object.assign(new DevelopmentAddress(), x); @@ -1187,10 +1189,10 @@ export class DevelopmentController extends Controller { data.lastUpdateUserId = request.user.sub; data.lastUpdateFullName = request.user.name; await this.developmentAddresssRepository.save(data, { data: request }); - setLogDataDiff(request, { before, after: development }); + // setLogDataDiff(request, { before, after: development }); }), ); - Object.assign(development, { ...requestBody, developmentAddresss: [] }); + //End return new HttpSuccess(development.id); } @@ -2070,6 +2072,7 @@ export class DevelopmentController extends Controller { "developmentProjectTypes", "developmentProjectTechniquePlanneds", "developmentProjectTechniqueActuals", + "developmentAddresss", ], }); if (!getDevelopment) { @@ -2111,6 +2114,15 @@ export class DevelopmentController extends Controller { strategyChild3Actual: getDevelopment.strategyChild3ActualId, strategyChild4Actual: getDevelopment.strategyChild4ActualId, strategyChild5Actual: getDevelopment.strategyChild5ActualId, + developmentAddresss: + getDevelopment.developmentAddresss == null + ? null + : getDevelopment.developmentAddresss + .sort((a, b) => + (a.id == null ? "" : a.id).localeCompare( + b.id == null ? "" : b.id, + ), + ) }; return new HttpSuccess(_getDevelopment); } diff --git a/src/entities/Development.ts b/src/entities/Development.ts index 58ebd11..0a6fecd 100644 --- a/src/entities/Development.ts +++ b/src/entities/Development.ts @@ -747,9 +747,9 @@ export class UpdateDevelopment3 { dateEnd: Date | null; @Column() totalDate: number | null; - //end @Column() developmentAddresss: CreateDevelopmentAddress[]; + //end @Column() developmentProjectTypes?: string[]; @Column() From 04344cd4c5320470312a2f178d96b5a838e70e00 Mon Sep 17 00:00:00 2001 From: AdisakKanthawilang Date: Thu, 8 Aug 2024 14:04:14 +0700 Subject: [PATCH 137/250] fix --- src/controllers/DevelopmentController.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/controllers/DevelopmentController.ts b/src/controllers/DevelopmentController.ts index 04954e8..c08f37a 100644 --- a/src/controllers/DevelopmentController.ts +++ b/src/controllers/DevelopmentController.ts @@ -1173,9 +1173,12 @@ export class DevelopmentController extends Controller { await this.developmentAddresssRepository.remove(development.developmentAddresss, { data: request, }); + // const before = structuredClone(development); await Promise.all( requestBody.developmentAddresss.map(async (x) => { + if (x.provinceId == "") + throw new HttpError(HttpStatusCode.BAD_REQUEST, "กรุณาเลือกจังหวัด"); const data = Object.assign(new DevelopmentAddress(), x); const chkProvince = await this.provinceRepository.findOne({ where: { @@ -2114,6 +2117,9 @@ export class DevelopmentController extends Controller { strategyChild3Actual: getDevelopment.strategyChild3ActualId, strategyChild4Actual: getDevelopment.strategyChild4ActualId, strategyChild5Actual: getDevelopment.strategyChild5ActualId, + dateStart: getDevelopment.dateStart, + dateEnd: getDevelopment.dateEnd, + totalDate: getDevelopment.totalDate, developmentAddresss: getDevelopment.developmentAddresss == null ? null From ae15f71a899581a116a720396e77a628303455e3 Mon Sep 17 00:00:00 2001 From: Bright Date: Thu, 8 Aug 2024 14:16:14 +0700 Subject: [PATCH 138/250] permission --- src/controllers/StrategyController.ts | 5 ++- src/interfaces/permission.ts | 58 +++++++++++++++++++++++++++ 2 files changed, 62 insertions(+), 1 deletion(-) create mode 100644 src/interfaces/permission.ts diff --git a/src/controllers/StrategyController.ts b/src/controllers/StrategyController.ts index bcaf7ae..c091073 100644 --- a/src/controllers/StrategyController.ts +++ b/src/controllers/StrategyController.ts @@ -44,7 +44,7 @@ import HttpSuccess from "../interfaces/http-success"; import { Check } from "typeorm"; import { addLogSequence, setLogDataDiff } from "../interfaces/utils"; import { RequestWithUser } from "../middlewares/user"; - +import permission from "../interfaces/permission"; @Route("api/v1/development/strategy") @Tags("Strategy") @Security("bearerAuth") @@ -115,6 +115,7 @@ export class StrategyController extends Controller { idnode?: string | null; }, ) { + await new permission().PermissionCreate(request,"SYS_EVA_STRATIGIC"); let strategyRepo: any; let strategyChild: any; let repoSave: any; @@ -225,6 +226,7 @@ export class StrategyController extends Controller { idnode: string; }, ) { + await new permission().PermissionUpdate(request,"SYS_EVA_STRATIGIC"); let strategyRepo: any; let strategyChild: any; @@ -304,6 +306,7 @@ export class StrategyController extends Controller { idnode: string; }, ) { + await new permission().PermissionDelete(request,"SYS_EVA_STRATIGIC"); let strategyRepo: any; let data: any; diff --git a/src/interfaces/permission.ts b/src/interfaces/permission.ts new file mode 100644 index 0000000..74bb1de --- /dev/null +++ b/src/interfaces/permission.ts @@ -0,0 +1,58 @@ +import { + Controller, + Request, + Get, + Post, + Put, + Delete, + Patch, + Route, + Security, + Tags, + Path, +} from "tsoa"; +import axios from "axios"; +import { RequestWithUser } from "../middlewares/user"; +import CallAPI from "./call-api"; +import HttpError from "./http-error"; +import HttpStatus from "./http-status"; + +class CheckAuth { + public async Permission(req: RequestWithUser, system: string, action: string) { + 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 (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 (role.attrOwnership == "OWNER") permission = true; + if (permission == false) throw "ไม่มีสิทธิ์ใช้งานระบบนี้"; + return role.attrPrivilege; + }) + .catch((x) => { + throw new HttpError(HttpStatus.FORBIDDEN, x); + }); + } + public async PermissionCreate(req: RequestWithUser, system: string) { + this.Permission(req, system, "CREATE"); + } + public async PermissionDelete(req: RequestWithUser, system: string) { + this.Permission(req, system, "DELETE"); + } + public async PermissionGet(req: RequestWithUser, system: string) { + this.Permission(req, system, "GET"); + } + public async PermissionList(req: RequestWithUser, system: string) { + this.Permission(req, system, "LIST"); + } + public async PermissionUpdate(req: RequestWithUser, system: string) { + this.Permission(req, system, "UPDATE"); + } +} + +export default CheckAuth; From 567af430c142835d34c7adcf90dd08e6a1479804 Mon Sep 17 00:00:00 2001 From: AdisakKanthawilang Date: Thu, 8 Aug 2024 14:56:11 +0700 Subject: [PATCH 139/250] fix --- src/controllers/DevelopmentController.ts | 23 +++++++++++++++-------- src/entities/DevelopmentEvaluation.ts | 2 +- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/src/controllers/DevelopmentController.ts b/src/controllers/DevelopmentController.ts index c08f37a..cf5d3b1 100644 --- a/src/controllers/DevelopmentController.ts +++ b/src/controllers/DevelopmentController.ts @@ -1177,15 +1177,18 @@ export class DevelopmentController extends Controller { // const before = structuredClone(development); await Promise.all( requestBody.developmentAddresss.map(async (x) => { - if (x.provinceId == "") - throw new HttpError(HttpStatusCode.BAD_REQUEST, "กรุณาเลือกจังหวัด"); + let _null: any = null; const data = Object.assign(new DevelopmentAddress(), x); - const chkProvince = await this.provinceRepository.findOne({ - where: { - id: x.provinceId, - }, - }); - if (chkProvince == null) return; + if (x.provinceId != null) { + const chkProvince = await this.provinceRepository.findOne({ + where: { + id: x.provinceId, + }, + }); + if (chkProvince == null) { + data.provinceId = _null; + } + } data.developmentId = development.id; data.createdUserId = request.user.sub; data.createdFullName = request.user.name; @@ -1247,8 +1250,12 @@ export class DevelopmentController extends Controller { if (!development) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงการ/หลักสูตรการฝึกอบรมนี้"); } + console.log(">>>>>>>>>>", requestBody.results); + let results:any = requestBody.results && requestBody.results != ""?requestBody.results:null; const before = structuredClone(development); const data = Object.assign(new DevelopmentEvaluation(), requestBody); + data.results = results; + data.createdUserId = request.user.sub; data.createdUserId = request.user.sub; data.createdFullName = request.user.name; data.lastUpdateUserId = request.user.sub; diff --git a/src/entities/DevelopmentEvaluation.ts b/src/entities/DevelopmentEvaluation.ts index 0e4a4c4..6dff8d6 100644 --- a/src/entities/DevelopmentEvaluation.ts +++ b/src/entities/DevelopmentEvaluation.ts @@ -82,7 +82,7 @@ export class CreateDevelopmentEvaluation { @Column() measuRement: string | null; @Column() - results: string | null; + results?: string | null; @Column() obstacles: string | null; @Column() From 3badc39ac2c02bdb3d31d0fca31ae050b9a42f43 Mon Sep 17 00:00:00 2001 From: AdisakKanthawilang Date: Thu, 8 Aug 2024 15:28:29 +0700 Subject: [PATCH 140/250] fix --- src/controllers/DevelopmentController.ts | 23 ++++++++++------------- src/entities/DevelopmentAddress.ts | 2 +- 2 files changed, 11 insertions(+), 14 deletions(-) diff --git a/src/controllers/DevelopmentController.ts b/src/controllers/DevelopmentController.ts index cf5d3b1..843b5a2 100644 --- a/src/controllers/DevelopmentController.ts +++ b/src/controllers/DevelopmentController.ts @@ -1189,12 +1189,14 @@ export class DevelopmentController extends Controller { data.provinceId = _null; } } - data.developmentId = development.id; - data.createdUserId = request.user.sub; - data.createdFullName = request.user.name; - data.lastUpdateUserId = request.user.sub; - data.lastUpdateFullName = request.user.name; - await this.developmentAddresssRepository.save(data, { data: request }); + if (x.address) { + data.developmentId = development.id; + data.createdUserId = request.user.sub; + data.createdFullName = request.user.name; + data.lastUpdateUserId = request.user.sub; + data.lastUpdateFullName = request.user.name; + await this.developmentAddresssRepository.save(data, { data: request }); + } // setLogDataDiff(request, { before, after: development }); }), ); @@ -1509,7 +1511,7 @@ export class DevelopmentController extends Controller { getDevelopment.developmentRisks == null ? null : getDevelopment.developmentRisks.sort((a, b) => - (a.id == null ? "" : a.id).localeCompare(b.id == null ? "" : b.id), + (a.createdAt.toString() == null ? "" : a.createdAt.toString()).localeCompare(b.createdAt.toString() == null ? "" : b.createdAt.toString()), ), expect: getDevelopment.expect, }; @@ -2131,11 +2133,6 @@ export class DevelopmentController extends Controller { getDevelopment.developmentAddresss == null ? null : getDevelopment.developmentAddresss - .sort((a, b) => - (a.id == null ? "" : a.id).localeCompare( - b.id == null ? "" : b.id, - ), - ) }; return new HttpSuccess(_getDevelopment); } @@ -2235,7 +2232,7 @@ export class DevelopmentController extends Controller { getDevelopment.developmentOthers == null ? null : getDevelopment.developmentOthers.sort((a, b) => - (a.id == null ? "" : a.id).localeCompare(b.id == null ? "" : b.id), + (a.createdAt.toString() == null ? "" : a.createdAt.toString()).localeCompare(b.createdAt.toString() == null ? "" : b.createdAt.toString()), ), obstacle: getDevelopment.obstacle, suggestion: getDevelopment.suggestion, diff --git a/src/entities/DevelopmentAddress.ts b/src/entities/DevelopmentAddress.ts index e1490c8..37be847 100644 --- a/src/entities/DevelopmentAddress.ts +++ b/src/entities/DevelopmentAddress.ts @@ -38,5 +38,5 @@ export class CreateDevelopmentAddress { @Column() address: string | null; @Column() - provinceId: string; + provinceId: string | null; } From 2ff993b8408d96bc5ec793ececd9a25bfc155e68 Mon Sep 17 00:00:00 2001 From: AdisakKanthawilang Date: Fri, 9 Aug 2024 17:08:28 +0700 Subject: [PATCH 141/250] role --- src/controllers/DevelopmentController.ts | 37 ++++++++++++++++--- .../DevelopmentScholarshipController.ts | 5 +++ 2 files changed, 37 insertions(+), 5 deletions(-) diff --git a/src/controllers/DevelopmentController.ts b/src/controllers/DevelopmentController.ts index 843b5a2..bdea190 100644 --- a/src/controllers/DevelopmentController.ts +++ b/src/controllers/DevelopmentController.ts @@ -63,6 +63,7 @@ import { addLogSequence, setLogDataDiff } from "../interfaces/utils"; import { RequestWithUser } from "../middlewares/user"; import { DevelopmentRisk, UpdateDevelopmentRisk } from "../entities/DevelopmentRisk"; import { DevelopmentOther, UpdateDevelopmentOther } from "../entities/DevelopmentOther"; +import permission from "../interfaces/permission"; @Route("api/v1/development/main") @Tags("Development") @@ -106,6 +107,7 @@ export class DevelopmentController extends Controller { @Body() requestBody: CreateDevelopment, @Request() request: RequestWithUser, ) { + await new permission().PermissionCreate(request, "SYS_DEV_PROJECT"); const chk_name = await this.developmentRepository.find({ where: { projectName: requestBody.projectName, @@ -184,6 +186,7 @@ export class DevelopmentController extends Controller { // status: "success", // description: "Get Development.", // }); + await new permission().PermissionUpdate(request, "SYS_DEV_PROJECT"); const development = await this.developmentRepository.findOne({ where: { id }, }); @@ -309,6 +312,7 @@ export class DevelopmentController extends Controller { // status: "success", // description: "Get Development.", // }); + await new permission().PermissionCreate(request, "SYS_DEV_PROJECT"); const development = await this.developmentRepository.findOne({ where: { id }, }); @@ -383,6 +387,7 @@ export class DevelopmentController extends Controller { // status: "success", // description: "Get Development.", // }); + await new permission().PermissionCreate(request, "SYS_DEV_PROJECT"); const development = await this.developmentRepository.findOne({ where: { id }, }); @@ -419,11 +424,7 @@ export class DevelopmentController extends Controller { @Body() requestBody: CreateActualGoal, @Request() request: RequestWithUser, ) { - // addLogSequence(request, { - // action: "database", - // status: "success", - // description: "Get Development.", - // }); + await new permission().PermissionCreate(request, "SYS_DEV_PROJECT"); const development = await this.developmentRepository.findOne({ where: { id }, }); @@ -491,6 +492,7 @@ export class DevelopmentController extends Controller { // status: "success", // description: "Get Development.", // }); + await new permission().PermissionUpdate(request, "SYS_DEV_PROJECT"); const development = await this.developmentRepository.findOne({ where: { id }, }); @@ -532,6 +534,7 @@ export class DevelopmentController extends Controller { // status: "success", // description: "Get Development.", // }); + await new permission().PermissionUpdate(request, "SYS_DEV_PROJECT"); const development = await this.plannedGoalRepository.findOne({ where: { id }, relations: { @@ -619,6 +622,7 @@ export class DevelopmentController extends Controller { // status: "success", // description: "Get Development.", // }); + await new permission().PermissionUpdate(request, "SYS_DEV_PROJECT"); const development = await this.plannedPeopleRepository.findOne({ where: { id }, }); @@ -657,6 +661,7 @@ export class DevelopmentController extends Controller { // status: "success", // description: "Get Development.", // }); + await new permission().PermissionUpdate(request, "SYS_DEV_PROJECT"); const development = await this.actualGoalRepository.findOne({ where: { id }, }); @@ -721,6 +726,7 @@ export class DevelopmentController extends Controller { // status: "success", // description: "Get Development.", // }); + await new permission().PermissionUpdate(request, "SYS_DEV_PROJECT"); const development = await this.actualPeopleRepository.findOne({ where: { id }, }); @@ -755,6 +761,7 @@ export class DevelopmentController extends Controller { // status: "success", // description: "Get Development.", // }); + await new permission().PermissionDelete(request, "SYS_DEV_PROJECT"); const development = await this.plannedGoalRepository.findOne({ where: { id }, }); @@ -793,6 +800,7 @@ export class DevelopmentController extends Controller { // status: "success", // description: "Get Development.", // }); + await new permission().PermissionDelete(request, "SYS_DEV_PROJECT"); const development = await this.plannedPeopleRepository.findOne({ where: { id }, }); @@ -822,6 +830,7 @@ export class DevelopmentController extends Controller { // status: "success", // description: "Get Development.", // }); + await new permission().PermissionDelete(request, "SYS_DEV_PROJECT"); const development = await this.actualGoalRepository.findOne({ where: { id }, }); @@ -851,6 +860,7 @@ export class DevelopmentController extends Controller { // status: "success", // description: "Get Development.", // }); + await new permission().PermissionDelete(request, "SYS_DEV_PROJECT"); const development = await this.actualPeopleRepository.findOne({ where: { id }, }); @@ -879,6 +889,7 @@ export class DevelopmentController extends Controller { @Body() requestBody: UpdateDevelopment3, @Request() request: RequestWithUser, ) { + await new permission().PermissionUpdate(request, "SYS_DEV_PROJECT"); const development = await this.developmentRepository.findOne({ where: { id }, relations: { @@ -1218,6 +1229,7 @@ export class DevelopmentController extends Controller { @Body() requestBody: UpdateDevelopment4, @Request() request: RequestWithUser, ) { + await new permission().PermissionUpdate(request, "SYS_DEV_PROJECT"); const development = await this.developmentRepository.findOne({ where: { id }, }); @@ -1246,6 +1258,7 @@ export class DevelopmentController extends Controller { @Body() requestBody: CreateDevelopmentEvaluation, @Request() request: RequestWithUser, ) { + await new permission().PermissionCreate(request, "SYS_DEV_PROJECT"); const development = await this.developmentRepository.findOne({ where: { id }, }); @@ -1282,6 +1295,7 @@ export class DevelopmentController extends Controller { // status: "success", // description: "Get Development Evaluation By ID.", // }); + await new permission().PermissionDelete(request, "SYS_DEV_PROJECT"); const development = await this.developmentEvaluationRepository.findOne({ where: { id }, }); @@ -1310,6 +1324,7 @@ export class DevelopmentController extends Controller { @Body() requestBody: CreateDevelopmentEvaluation, @Request() request: RequestWithUser, ) { + await new permission().PermissionUpdate(request, "SYS_DEV_PROJECT"); const development = await this.developmentEvaluationRepository.findOne({ where: { id }, }); @@ -1341,6 +1356,7 @@ export class DevelopmentController extends Controller { @Body() requestBody: UpdateDevelopment5, @Request() request: RequestWithUser, ) { + await new permission().PermissionUpdate(request, "SYS_DEV_PROJECT"); const development = await this.developmentRepository.findOne({ where: { id }, relations: { developmentAddresss: true }, @@ -1367,6 +1383,7 @@ export class DevelopmentController extends Controller { @Body() requestBody: UpdateDevelopmentOther, @Request() request: RequestWithUser, ) { + await new permission().PermissionCreate(request, "SYS_DEV_PROJECT"); const development = await this.developmentRepository.findOne({ where: { id }, }); @@ -1402,6 +1419,7 @@ export class DevelopmentController extends Controller { */ @Delete("tab5_1/{id}") async DeleteDevelopmenttab5_1(@Path() id: string, @Request() request: RequestWithUser) { + await new permission().PermissionDelete(request, "SYS_DEV_PROJECT"); const development = await this.developmentOtherRepository.findOne({ where: { id }, }); @@ -1425,6 +1443,7 @@ export class DevelopmentController extends Controller { @Body() requestBody: UpdateDevelopmentOther, @Request() request: RequestWithUser, ) { + await new permission().PermissionUpdate(request, "SYS_DEV_PROJECT"); const development = await this.developmentOtherRepository.findOne({ where: { id }, }); @@ -1452,6 +1471,7 @@ export class DevelopmentController extends Controller { @Body() requestBody: UpdateDevelopment7, @Request() request: RequestWithUser, ) { + await new permission().PermissionUpdate(request, "SYS_DEV_PROJECT"); const development = await this.developmentRepository.findOne({ where: { id }, relations: { developmentAddresss: true }, @@ -1532,6 +1552,7 @@ export class DevelopmentController extends Controller { @Body() requestBody: UpdateDevelopment8, @Request() request: RequestWithUser, ) { + await new permission().PermissionUpdate(request, "SYS_DEV_PROJECT"); const development = await this.developmentRepository.findOne({ where: { id }, relations: { developmentAddresss: true }, @@ -1558,6 +1579,7 @@ export class DevelopmentController extends Controller { @Body() requestBody: UpdateDevelopmentRisk, @Request() request: RequestWithUser, ) { + await new permission().PermissionCreate(request, "SYS_DEV_PROJECT"); const development = await this.developmentRepository.findOne({ where: { id }, }); @@ -1585,6 +1607,7 @@ export class DevelopmentController extends Controller { */ @Delete("tab8_1/{id}") async DeleteDevelopmenttab8_1(@Path() id: string, @Request() request: RequestWithUser) { + await new permission().PermissionDelete(request, "SYS_DEV_PROJECT"); const development = await this.developmentRiskRepository.findOne({ where: { id }, }); @@ -1608,6 +1631,7 @@ export class DevelopmentController extends Controller { @Body() requestBody: UpdateDevelopmentRisk, @Request() request: RequestWithUser, ) { + await new permission().PermissionUpdate(request, "SYS_DEV_PROJECT"); const development = await this.developmentRiskRepository.findOne({ where: { id }, }); @@ -1703,6 +1727,7 @@ export class DevelopmentController extends Controller { */ @Delete("{id}") async DeleteDevelopment(@Path() id: string, @Request() request: RequestWithUser) { + await new permission().PermissionDelete(request, "SYS_DEV_PROJECT"); const development = await this.developmentRepository.findOne({ where: { id }, relations: { @@ -2411,6 +2436,7 @@ export class DevelopmentController extends Controller { @UploadedFile() file: Express.Multer.File, @Request() request: RequestWithUser, ) { + await new permission().PermissionCreate(request, "SYS_DEV_PROJECT"); const getDevelopment = await this.developmentRepository.findOne({ where: { id: id }, relations: { @@ -2639,6 +2665,7 @@ export class DevelopmentController extends Controller { @Body() requestBody: CreateDevelopmentHistoryOBO, @Request() request: RequestWithUser, ) { + await new permission().PermissionCreate(request, "SYS_DEV_PROJECT"); const getDevelopment = await this.developmentRepository.findOne({ where: { id: id }, relations: { diff --git a/src/controllers/DevelopmentScholarshipController.ts b/src/controllers/DevelopmentScholarshipController.ts index 16fd798..8659f75 100644 --- a/src/controllers/DevelopmentScholarshipController.ts +++ b/src/controllers/DevelopmentScholarshipController.ts @@ -29,6 +29,7 @@ import CallAPI from "../interfaces/call-api"; import { RequestWithUser } from "../middlewares/user"; import { addLogSequence, setLogDataDiff } from "../interfaces/utils"; import { request } from "axios"; +import permission from "../interfaces/permission"; @Route("api/v1/development/scholarship") @Tags("DevelopmentScholarship") @@ -49,6 +50,7 @@ export class DevelopmentScholarshipController extends Controller { @Body() requestBody: CreateDevelopmentScholarship, @Request() request: RequestWithUser, ) { + await new permission().PermissionCreate(request, "SYS_DEV_SCHOLARSHIP"); if (requestBody.posTypeId != null) { // addLogSequence(request, { // action: "database", @@ -109,6 +111,7 @@ export class DevelopmentScholarshipController extends Controller { // status: "success", // description: "Get Development Scholarship.", // }); + await new permission().PermissionUpdate(request, "SYS_DEV_SCHOLARSHIP"); const development = await this.developmentScholarshipRepository.findOne({ where: { id: id }, }); @@ -169,6 +172,7 @@ export class DevelopmentScholarshipController extends Controller { // status: "success", // description: "Get Development Scholarship", // }); + await new permission().PermissionDelete(request, "SYS_DEV_SCHOLARSHIP"); const development = await this.developmentScholarshipRepository.findOne({ where: { id: id }, }); @@ -479,6 +483,7 @@ export class DevelopmentScholarshipController extends Controller { // status: "success", // description: "Get Development Scholarship.", // }); + await new permission().PermissionUpdate(request, "SYS_DEV_SCHOLARSHIP"); const getDevelopment = await this.developmentScholarshipRepository.findOne({ where: { id: id }, }); From 5a92e60e0e435e50815bfcbc1d43ebfe4c5407bf Mon Sep 17 00:00:00 2001 From: kittapath Date: Tue, 13 Aug 2024 11:08:49 +0700 Subject: [PATCH 142/250] no message --- ...026794685-update_table_migration2_08072024.ts | 16 ---------------- src/migration/1723089052077-add_Table.ts | 16 ---------------- 2 files changed, 32 deletions(-) delete mode 100644 src/migration/1723026794685-update_table_migration2_08072024.ts delete mode 100644 src/migration/1723089052077-add_Table.ts diff --git a/src/migration/1723026794685-update_table_migration2_08072024.ts b/src/migration/1723026794685-update_table_migration2_08072024.ts deleted file mode 100644 index 97fc16d..0000000 --- a/src/migration/1723026794685-update_table_migration2_08072024.ts +++ /dev/null @@ -1,16 +0,0 @@ -import { MigrationInterface, QueryRunner } from "typeorm"; - -export class UpdateTableMigration2080720241723026794685 implements MigrationInterface { - name = 'UpdateTableMigration2080720241723026794685' - - public async up(queryRunner: QueryRunner): Promise { - await queryRunner.query(`CREATE TABLE \`developmentRisk\` (\`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', \`issues\` varchar(255) NULL COMMENT 'ประเด็นความเสี่ยง', \`chance\` int NULL COMMENT 'โอกาสที่จะเกิด', \`effects\` int NULL COMMENT 'ผลกระทบจากการเกิด', \`riskLevel\` varchar(255) NULL COMMENT 'ระดับความเสี่ยง', \`riskManagement\` varchar(255) NULL COMMENT 'เเนวทางการบริหารความเสี่ยง', \`developmentId\` varchar(255) NULL COMMENT 'คีย์นอก(FK)ของตาราง development', PRIMARY KEY (\`id\`)) ENGINE=InnoDB`); - await queryRunner.query(`ALTER TABLE \`developmentRisk\` ADD CONSTRAINT \`FK_b1990ff92f534f65a4653ef1671\` FOREIGN KEY (\`developmentId\`) REFERENCES \`development\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`); - } - - public async down(queryRunner: QueryRunner): Promise { - await queryRunner.query(`ALTER TABLE \`developmentRisk\` DROP FOREIGN KEY \`FK_b1990ff92f534f65a4653ef1671\``); - await queryRunner.query(`DROP TABLE \`developmentRisk\``); - } - -} diff --git a/src/migration/1723089052077-add_Table.ts b/src/migration/1723089052077-add_Table.ts deleted file mode 100644 index c1820ad..0000000 --- a/src/migration/1723089052077-add_Table.ts +++ /dev/null @@ -1,16 +0,0 @@ -import { MigrationInterface, QueryRunner } from "typeorm"; - -export class AddTable1723089052077 implements MigrationInterface { - name = 'AddTable1723089052077' - - public async up(queryRunner: QueryRunner): Promise { - await queryRunner.query(`CREATE TABLE \`developmentOther\` (\`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', \`topicAcademic\` varchar(255) NULL COMMENT 'หัวข้อ/ประเด็นการฝึกอบรม ศึกษาดูงาน', \`addressAcademic\` varchar(255) NULL COMMENT 'สถานที่ฝึกอบรม ศึกษาดูงาน', \`provinceActualId\` varchar(255) NULL COMMENT 'จังหวัด(ข้อมูลวิชาการ)', \`developmentId\` varchar(255) NULL COMMENT 'คีย์นอก(FK)ของตาราง development', PRIMARY KEY (\`id\`)) ENGINE=InnoDB`); - await queryRunner.query(`ALTER TABLE \`developmentOther\` ADD CONSTRAINT \`FK_d5dfdb7ca0d11c0cdf3b3a55e6f\` FOREIGN KEY (\`developmentId\`) REFERENCES \`development\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`); - } - - public async down(queryRunner: QueryRunner): Promise { - await queryRunner.query(`ALTER TABLE \`developmentOther\` DROP FOREIGN KEY \`FK_d5dfdb7ca0d11c0cdf3b3a55e6f\``); - await queryRunner.query(`DROP TABLE \`developmentOther\``); - } - -} From 666a7f802141c3adfb7ea3e81eafa4331d4d1927 Mon Sep 17 00:00:00 2001 From: kittapath Date: Thu, 15 Aug 2024 13:28:20 +0700 Subject: [PATCH 143/250] service call service --- src/interfaces/call-api.ts | 44 ++++++++++--------- src/interfaces/permission.ts | 17 ++++--- ...13928787-update_table_migration07302024.ts | 14 ------ ...13963408-update_table_migration08072024.ts | 20 --------- .../1723605750693-import0508241320.ts | 28 ++++++++++++ 5 files changed, 63 insertions(+), 60 deletions(-) delete mode 100644 src/migration/1722313928787-update_table_migration07302024.ts delete mode 100644 src/migration/1723013963408-update_table_migration08072024.ts create mode 100644 src/migration/1723605750693-import0508241320.ts diff --git a/src/interfaces/call-api.ts b/src/interfaces/call-api.ts index e95592a..78f0f14 100644 --- a/src/interfaces/call-api.ts +++ b/src/interfaces/call-api.ts @@ -24,6 +24,7 @@ class CallAPI { headers: { Authorization: `${token}`, "Content-Type": "application/json", + api_key: process.env.API_KEY, }, }); addLogSequence(request, { @@ -38,16 +39,16 @@ class CallAPI { }); return response.data.result; } catch (error) { - addLogSequence(request, { - action: "request", - status: "error", - description: "unconnected", - request: { - method: "GET", - url: url, - response: JSON.stringify(error), - }, - }); + addLogSequence(request, { + action: "request", + status: "error", + description: "unconnected", + request: { + method: "GET", + url: url, + response: JSON.stringify(error), + }, + }); throw error; } } @@ -60,6 +61,7 @@ class CallAPI { headers: { Authorization: `${token}`, "Content-Type": "application/json", + api_key: process.env.API_KEY, }, }); addLogSequence(request, { @@ -75,17 +77,17 @@ class CallAPI { }); 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), - }, - }); + addLogSequence(request, { + action: "request", + status: "error", + description: "unconnected", + request: { + method: "POST", + url: url, + payload: JSON.stringify(sendData), + response: JSON.stringify(error), + }, + }); throw error; } } diff --git a/src/interfaces/permission.ts b/src/interfaces/permission.ts index 74bb1de..539def0 100644 --- a/src/interfaces/permission.ts +++ b/src/interfaces/permission.ts @@ -19,6 +19,13 @@ import HttpStatus from "./http-status"; class CheckAuth { 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; + } await new CallAPI() .GetData(req, "/org/permission") .then((x) => { @@ -39,19 +46,19 @@ class CheckAuth { }); } public async PermissionCreate(req: RequestWithUser, system: string) { - this.Permission(req, system, "CREATE"); + return await this.Permission(req, system, "CREATE"); } public async PermissionDelete(req: RequestWithUser, system: string) { - this.Permission(req, system, "DELETE"); + return await this.Permission(req, system, "DELETE"); } public async PermissionGet(req: RequestWithUser, system: string) { - this.Permission(req, system, "GET"); + return await this.Permission(req, system, "GET"); } public async PermissionList(req: RequestWithUser, system: string) { - this.Permission(req, system, "LIST"); + return await this.Permission(req, system, "LIST"); } public async PermissionUpdate(req: RequestWithUser, system: string) { - this.Permission(req, system, "UPDATE"); + return await this.Permission(req, system, "UPDATE"); } } diff --git a/src/migration/1722313928787-update_table_migration07302024.ts b/src/migration/1722313928787-update_table_migration07302024.ts deleted file mode 100644 index 2b8fef8..0000000 --- a/src/migration/1722313928787-update_table_migration07302024.ts +++ /dev/null @@ -1,14 +0,0 @@ -import { MigrationInterface, QueryRunner } from "typeorm"; - -export class UpdateTableMigration073020241722313928787 implements MigrationInterface { - name = 'UpdateTableMigration073020241722313928787' - - public async up(queryRunner: QueryRunner): Promise { - await queryRunner.query(`ALTER TABLE \`developmentHistory\` ADD \`isProfile\` tinyint NOT NULL COMMENT 'มีข้อมูลอยู่ในทะเบียนประวัติ' DEFAULT 0`); - } - - public async down(queryRunner: QueryRunner): Promise { - await queryRunner.query(`ALTER TABLE \`developmentHistory\` DROP COLUMN \`isProfile\``); - } - -} diff --git a/src/migration/1723013963408-update_table_migration08072024.ts b/src/migration/1723013963408-update_table_migration08072024.ts deleted file mode 100644 index 18d23e8..0000000 --- a/src/migration/1723013963408-update_table_migration08072024.ts +++ /dev/null @@ -1,20 +0,0 @@ -import { MigrationInterface, QueryRunner } from "typeorm"; - -export class UpdateTableMigration080720241723013963408 implements MigrationInterface { - name = 'UpdateTableMigration080720241723013963408' - - public async up(queryRunner: QueryRunner): Promise { - await queryRunner.query(`ALTER TABLE \`development\` ADD \`progressTracking\` longtext NULL COMMENT 'การติดตามความก้าวหน้า'`); - await queryRunner.query(`ALTER TABLE \`development\` ADD \`projectEvaluation\` longtext NULL COMMENT 'การประเมินผลโครงการ'`); - await queryRunner.query(`ALTER TABLE \`development\` ADD \`obstacle\` longtext NULL COMMENT 'ปัญหาอุปสรรค'`); - await queryRunner.query(`ALTER TABLE \`development\` ADD \`suggestion\` longtext NULL COMMENT 'ข้อเสนอแนะ'`); - } - - public async down(queryRunner: QueryRunner): Promise { - await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`suggestion\``); - await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`obstacle\``); - await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`projectEvaluation\``); - await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`progressTracking\``); - } - -} diff --git a/src/migration/1723605750693-import0508241320.ts b/src/migration/1723605750693-import0508241320.ts new file mode 100644 index 0000000..97a5c4b --- /dev/null +++ b/src/migration/1723605750693-import0508241320.ts @@ -0,0 +1,28 @@ +import { MigrationInterface, QueryRunner } from "typeorm"; + +export class Import05082413201723605750693 implements MigrationInterface { + name = 'Import05082413201723605750693' + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(`CREATE TABLE \`developmentRisk\` (\`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', \`issues\` varchar(255) NULL COMMENT 'ประเด็นความเสี่ยง', \`chance\` int NULL COMMENT 'โอกาสที่จะเกิด', \`effects\` int NULL COMMENT 'ผลกระทบจากการเกิด', \`riskLevel\` varchar(255) NULL COMMENT 'ระดับความเสี่ยง', \`riskManagement\` varchar(255) NULL COMMENT 'เเนวทางการบริหารความเสี่ยง', \`developmentId\` varchar(255) NULL COMMENT 'คีย์นอก(FK)ของตาราง development', PRIMARY KEY (\`id\`)) ENGINE=InnoDB`); + await queryRunner.query(`CREATE TABLE \`developmentOther\` (\`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', \`topicAcademic\` varchar(255) NULL COMMENT 'หัวข้อ/ประเด็นการฝึกอบรม ศึกษาดูงาน', \`addressAcademic\` varchar(255) NULL COMMENT 'สถานที่ฝึกอบรม ศึกษาดูงาน', \`provinceActualId\` varchar(255) NULL COMMENT 'จังหวัด(ข้อมูลวิชาการ)', \`developmentId\` varchar(255) NULL COMMENT 'คีย์นอก(FK)ของตาราง development', PRIMARY KEY (\`id\`)) ENGINE=InnoDB`); + await queryRunner.query(`ALTER TABLE \`development\` ADD \`progressTracking\` longtext NULL COMMENT 'การติดตามความก้าวหน้า'`); + await queryRunner.query(`ALTER TABLE \`development\` ADD \`projectEvaluation\` longtext NULL COMMENT 'การประเมินผลโครงการ'`); + await queryRunner.query(`ALTER TABLE \`development\` ADD \`obstacle\` longtext NULL COMMENT 'ปัญหาอุปสรรค'`); + await queryRunner.query(`ALTER TABLE \`development\` ADD \`suggestion\` longtext NULL COMMENT 'ข้อเสนอแนะ'`); + await queryRunner.query(`ALTER TABLE \`developmentRisk\` ADD CONSTRAINT \`FK_b1990ff92f534f65a4653ef1671\` FOREIGN KEY (\`developmentId\`) REFERENCES \`development\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`); + await queryRunner.query(`ALTER TABLE \`developmentOther\` ADD CONSTRAINT \`FK_d5dfdb7ca0d11c0cdf3b3a55e6f\` FOREIGN KEY (\`developmentId\`) REFERENCES \`development\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`); + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`developmentOther\` DROP FOREIGN KEY \`FK_d5dfdb7ca0d11c0cdf3b3a55e6f\``); + await queryRunner.query(`ALTER TABLE \`developmentRisk\` DROP FOREIGN KEY \`FK_b1990ff92f534f65a4653ef1671\``); + await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`suggestion\``); + await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`obstacle\``); + await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`projectEvaluation\``); + await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`progressTracking\``); + await queryRunner.query(`DROP TABLE \`developmentOther\``); + await queryRunner.query(`DROP TABLE \`developmentRisk\``); + } + +} From 2a536dcc32f59e8f1bfc2296d27031551cb7f1bd Mon Sep 17 00:00:00 2001 From: kittapath Date: Wed, 21 Aug 2024 22:09:56 +0700 Subject: [PATCH 144/250] =?UTF-8?q?=E0=B8=9C=E0=B8=B9=E0=B8=81=E0=B8=AA?= =?UTF-8?q?=E0=B8=B4=E0=B8=94=E0=B8=82=E0=B9=89=E0=B8=AD=E0=B8=A1=E0=B8=B9?= =?UTF-8?q?=E0=B8=A5=E0=B8=AB=E0=B8=A5=E0=B8=B1=E0=B8=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/StrategyController.ts | 57 ++------ src/interfaces/permission.ts | 194 +++++++++++++++++++++++--- 2 files changed, 190 insertions(+), 61 deletions(-) diff --git a/src/controllers/StrategyController.ts b/src/controllers/StrategyController.ts index c091073..282dea7 100644 --- a/src/controllers/StrategyController.ts +++ b/src/controllers/StrategyController.ts @@ -1,48 +1,14 @@ -import { - Body, - Controller, - Delete, - Example, - Get, - Patch, - Path, - Post, - Request, - Route, - Security, - Tags, -} from "tsoa"; +import { Body, Controller, Delete, Get, Patch, Post, Request, Route, Security, Tags } from "tsoa"; import { AppDataSource } from "../database/data-source"; -import { - CreateStrategyChild1, - StrategyChild1, - UpdateStrategyChild1, -} from "../entities/StrategyChild1"; -import { - CreateStrategyChild2, - StrategyChild2, - UpdateStrategyChild2, -} from "../entities/StrategyChild2"; -import { - CreateStrategyChild3, - StrategyChild3, - UpdateStrategyChild3, -} from "../entities/StrategyChild3"; -import { - CreateStrategyChild4, - StrategyChild4, - UpdateStrategyChild4, -} from "../entities/StrategyChild4"; -import { - CreateStrategyChild5, - StrategyChild5, - UpdateStrategyChild5, -} from "../entities/StrategyChild5"; +import { StrategyChild1 } from "../entities/StrategyChild1"; +import { StrategyChild2 } from "../entities/StrategyChild2"; +import { StrategyChild3 } from "../entities/StrategyChild3"; +import { StrategyChild4 } from "../entities/StrategyChild4"; +import { StrategyChild5 } from "../entities/StrategyChild5"; import HttpError from "../interfaces/http-error"; import HttpStatus from "../interfaces/http-status"; import HttpSuccess from "../interfaces/http-success"; -import { Check } from "typeorm"; -import { addLogSequence, setLogDataDiff } from "../interfaces/utils"; +import { setLogDataDiff } from "../interfaces/utils"; import { RequestWithUser } from "../middlewares/user"; import permission from "../interfaces/permission"; @Route("api/v1/development/strategy") @@ -55,7 +21,8 @@ export class StrategyController extends Controller { private strategy4Repo = AppDataSource.getRepository(StrategyChild4); private strategy5Repo = AppDataSource.getRepository(StrategyChild5); @Get() - public async listStrategyChild1() { + public async listStrategyChild1(@Request() request: RequestWithUser) { + let _data = await new permission().PermissionList(request, "SYS_EVA_STRATIGIC"); const listStrategyChild1 = await this.strategy1Repo.find({ relations: [ "strategyChild2s", @@ -115,7 +82,7 @@ export class StrategyController extends Controller { idnode?: string | null; }, ) { - await new permission().PermissionCreate(request,"SYS_EVA_STRATIGIC"); + await new permission().PermissionCreate(request, "SYS_EVA_STRATIGIC"); let strategyRepo: any; let strategyChild: any; let repoSave: any; @@ -226,7 +193,7 @@ export class StrategyController extends Controller { idnode: string; }, ) { - await new permission().PermissionUpdate(request,"SYS_EVA_STRATIGIC"); + await new permission().PermissionUpdate(request, "SYS_EVA_STRATIGIC"); let strategyRepo: any; let strategyChild: any; @@ -306,7 +273,7 @@ export class StrategyController extends Controller { idnode: string; }, ) { - await new permission().PermissionDelete(request,"SYS_EVA_STRATIGIC"); + await new permission().PermissionDelete(request, "SYS_EVA_STRATIGIC"); let strategyRepo: any; let data: any; diff --git a/src/interfaces/permission.ts b/src/interfaces/permission.ts index 539def0..1669018 100644 --- a/src/interfaces/permission.ts +++ b/src/interfaces/permission.ts @@ -1,16 +1,3 @@ -import { - Controller, - Request, - Get, - Post, - Put, - Delete, - Patch, - Route, - Security, - Tags, - Path, -} from "tsoa"; import axios from "axios"; import { RequestWithUser } from "../middlewares/user"; import CallAPI from "./call-api"; @@ -26,23 +13,166 @@ class CheckAuth { ) { return null; } - await new CallAPI() + 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 (role.attrOwnership == "OWNER") permission = true; if (permission == false) throw "ไม่มีสิทธิ์ใช้งานระบบนี้"; return role.attrPrivilege; }) .catch((x) => { - throw new HttpError(HttpStatus.FORBIDDEN, 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 null; + } + return await new CallAPI() + .GetData(req, "/org/permission/org") + .then(async (x) => { + let privilege = null; + if (action.trim().toLocaleUpperCase() == "CREATE") + privilege = await this.PermissionCreate(req, system); + if (action.trim().toLocaleUpperCase() == "DELETE") + privilege = await this.PermissionDelete(req, system); + if (action.trim().toLocaleUpperCase() == "GET") + privilege = await this.PermissionGet(req, system); + if (action.trim().toLocaleUpperCase() == "LIST") + privilege = await this.PermissionList(req, system); + if (action.trim().toLocaleUpperCase() == "UPDATE") + privilege = await this.PermissionUpdate(req, system); + + let data: any = { + root: [null], + child1: [null], + child2: [null], + child3: [null], + child4: [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 == "ROOT") { + data = { + root: [x.orgRootId], + child1: null, + child2: null, + child3: null, + child4: null, + }; + } 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, + }; + } else if (privilege == "NORMAL") { + data = { + root: [x.orgRootId], + child1: [x.orgChild1Id], + child2: [x.orgChild2Id], + child3: [x.orgChild3Id], + child4: [x.orgChild4Id], + }; + } else if (privilege == "SPECIFIC") { + } else if (privilege == "OWNER") { + data = { + root: null, + child1: null, + child2: null, + child3: null, + child4: null, + }; + } + + 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/${profileId}`) + .then(async (x) => { + let org = { + root: [null], + child1: [null], + child2: [null], + child3: [null], + child4: [null], + }; + if (action.trim().toLocaleUpperCase() == "CREATE") + org = await this.PermissionOrgCreate(req, system); + if (action.trim().toLocaleUpperCase() == "DELETE") + org = await this.PermissionOrgDelete(req, system); + if (action.trim().toLocaleUpperCase() == "GET") + org = await this.PermissionOrgGet(req, system); + if (action.trim().toLocaleUpperCase() == "LIST") + org = await this.PermissionOrgList(req, system); + if (action.trim().toLocaleUpperCase() == "UPDATE") + org = await this.PermissionOrgUpdate(req, system); + + 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 PermissionCreate(req: RequestWithUser, system: string) { @@ -60,6 +190,38 @@ class CheckAuth { 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; From 204984f63e49504b75615e1f1818015878ea1331 Mon Sep 17 00:00:00 2001 From: kittapath Date: Thu, 22 Aug 2024 14:14:35 +0700 Subject: [PATCH 145/250] =?UTF-8?q?=E0=B8=9C=E0=B8=B9=E0=B8=81=E0=B8=AA?= =?UTF-8?q?=E0=B8=B4=E0=B8=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/DevelopmentController.ts | 52 ++++++++++++------- .../DevelopmentEmployeeHistoryController.ts | 14 +++-- .../DevelopmentHistoryController.ts | 14 +++-- .../DevelopmentScholarshipController.ts | 5 +- 4 files changed, 58 insertions(+), 27 deletions(-) diff --git a/src/controllers/DevelopmentController.ts b/src/controllers/DevelopmentController.ts index bdea190..8a75f9e 100644 --- a/src/controllers/DevelopmentController.ts +++ b/src/controllers/DevelopmentController.ts @@ -896,7 +896,7 @@ export class DevelopmentController extends Controller { developmentProjectTypes: true, developmentProjectTechniquePlanneds: true, developmentProjectTechniqueActuals: true, - developmentAddresss: true + developmentAddresss: true, }, }); if (!development) { @@ -907,7 +907,7 @@ export class DevelopmentController extends Controller { developmentProjectTypes: [], developmentProjectTechniquePlanneds: [], developmentProjectTechniqueActuals: [], - developmentAddresss: [] + developmentAddresss: [], }); development.lastUpdateUserId = request.user.sub; development.lastUpdateFullName = request.user.name; @@ -1184,7 +1184,7 @@ export class DevelopmentController extends Controller { await this.developmentAddresssRepository.remove(development.developmentAddresss, { data: request, }); - + // const before = structuredClone(development); await Promise.all( requestBody.developmentAddresss.map(async (x) => { @@ -1211,7 +1211,7 @@ export class DevelopmentController extends Controller { // setLogDataDiff(request, { before, after: development }); }), ); - + //End return new HttpSuccess(development.id); } @@ -1266,7 +1266,8 @@ export class DevelopmentController extends Controller { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงการ/หลักสูตรการฝึกอบรมนี้"); } console.log(">>>>>>>>>>", requestBody.results); - let results:any = requestBody.results && requestBody.results != ""?requestBody.results:null; + let results: any = + requestBody.results && requestBody.results != "" ? requestBody.results : null; const before = structuredClone(development); const data = Object.assign(new DevelopmentEvaluation(), requestBody); data.results = results; @@ -1390,7 +1391,7 @@ export class DevelopmentController extends Controller { if (!development) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงการ/หลักสูตรการฝึกอบรมนี้"); } - if (requestBody.provinceActualId != null) { + if (requestBody.provinceActualId != null) { const checkId = await this.provinceRepository.findOne({ where: { id: requestBody.provinceActualId }, }); @@ -1494,7 +1495,8 @@ export class DevelopmentController extends Controller { * @param {string} id Id โครงการ */ @Get("tab7/{id}") - async GetDevelopemtTab7ById(@Path() id: string) { + async GetDevelopemtTab7ById(@Request() request: RequestWithUser, @Path() id: string) { + await new permission().PermissionGet(request, "SYS_DEV_SCHOLARSHIP"); const getDevelopment = await this.developmentRepository.findOne({ where: { id }, }); @@ -1518,7 +1520,8 @@ export class DevelopmentController extends Controller { * @param {string} id Id โครงการ */ @Get("tab8/{id}") - async GetDevelopemtTab8ById(@Path() id: string) { + async GetDevelopemtTab8ById(@Request() request: RequestWithUser, @Path() id: string) { + await new permission().PermissionGet(request, "SYS_DEV_SCHOLARSHIP"); const getDevelopment = await this.developmentRepository.findOne({ relations: ["developmentRisks"], where: { id: id }, @@ -1531,7 +1534,9 @@ export class DevelopmentController extends Controller { getDevelopment.developmentRisks == null ? null : getDevelopment.developmentRisks.sort((a, b) => - (a.createdAt.toString() == null ? "" : a.createdAt.toString()).localeCompare(b.createdAt.toString() == null ? "" : b.createdAt.toString()), + (a.createdAt.toString() == null ? "" : a.createdAt.toString()).localeCompare( + b.createdAt.toString() == null ? "" : b.createdAt.toString(), + ), ), expect: getDevelopment.expect, }; @@ -1851,6 +1856,7 @@ export class DevelopmentController extends Controller { */ @Get() async GetDevelopmentLists( + @Request() request: RequestWithUser, @Query("page") page: number = 1, @Query("pageSize") pageSize: number = 10, @Query("year") year: number, @@ -1859,6 +1865,7 @@ export class DevelopmentController extends Controller { @Query("node") node?: number | null, @Query("keyword") keyword?: string, ) { + await new permission().PermissionList(request, "SYS_DEV_SCHOLARSHIP"); const [development, total] = await AppDataSource.getRepository(Development) .createQueryBuilder("development") .andWhere(year > 0 ? "development.year LIKE :year" : "1=1", { @@ -1956,7 +1963,8 @@ export class DevelopmentController extends Controller { * @param {string} id Id โครงการ */ @Get("tab1/{id}") - async GetDevelopemtTab1ById(@Path() id: string) { + async GetDevelopemtTab1ById(@Request() request: RequestWithUser, @Path() id: string) { + await new permission().PermissionGet(request, "SYS_DEV_SCHOLARSHIP"); const getDevelopment = await this.developmentRepository.findOne({ where: { id: id }, }); @@ -2008,7 +2016,8 @@ export class DevelopmentController extends Controller { * @param {string} id Id โครงการ */ @Get("tab2/{id}") - async GetDevelopemtTab2ById(@Path() id: string) { + async GetDevelopemtTab2ById(@Request() request: RequestWithUser, @Path() id: string) { + await new permission().PermissionGet(request, "SYS_DEV_SCHOLARSHIP"); const getDevelopment = await this.developmentRepository.findOne({ where: { id: id }, relations: [ @@ -2102,7 +2111,8 @@ export class DevelopmentController extends Controller { * @param {string} id Id โครงการ */ @Get("tab3/{id}") - async GetDevelopemtTab3ById(@Path() id: string) { + async GetDevelopemtTab3ById(@Request() request: RequestWithUser, @Path() id: string) { + await new permission().PermissionGet(request, "SYS_DEV_SCHOLARSHIP"); const getDevelopment = await this.developmentRepository.findOne({ where: { id: id }, relations: [ @@ -2155,9 +2165,7 @@ export class DevelopmentController extends Controller { dateEnd: getDevelopment.dateEnd, totalDate: getDevelopment.totalDate, developmentAddresss: - getDevelopment.developmentAddresss == null - ? null - : getDevelopment.developmentAddresss + getDevelopment.developmentAddresss == null ? null : getDevelopment.developmentAddresss, }; return new HttpSuccess(_getDevelopment); } @@ -2212,7 +2220,8 @@ export class DevelopmentController extends Controller { * @param {string} id Id โครงการ */ @Get("tab4/{id}") - async GetDevelopemtTab4ById(@Path() id: string) { + async GetDevelopemtTab4ById(@Request() request: RequestWithUser, @Path() id: string) { + await new permission().PermissionGet(request, "SYS_DEV_SCHOLARSHIP"); const getDevelopment = await this.developmentRepository.findOne({ where: { id: id }, relations: ["developmentEvaluations"], @@ -2244,20 +2253,23 @@ export class DevelopmentController extends Controller { * @param {string} id Id โครงการ */ @Get("tab5/{id}") - async GetDevelopemtTab5ById(@Path() id: string) { + async GetDevelopemtTab5ById(@Request() request: RequestWithUser, @Path() id: string) { + await new permission().PermissionGet(request, "SYS_DEV_SCHOLARSHIP"); const getDevelopment = await this.developmentRepository.findOne({ relations: ["developmentOthers"], where: { id: id }, }); - if (!getDevelopment) { + if (!getDevelopment) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงการ/หลักสูตรการฝึกอบรมนี้"); } - let _getDevelopment = { + let _getDevelopment = { developmentOthers: getDevelopment.developmentOthers == null ? null : getDevelopment.developmentOthers.sort((a, b) => - (a.createdAt.toString() == null ? "" : a.createdAt.toString()).localeCompare(b.createdAt.toString() == null ? "" : b.createdAt.toString()), + (a.createdAt.toString() == null ? "" : a.createdAt.toString()).localeCompare( + b.createdAt.toString() == null ? "" : b.createdAt.toString(), + ), ), obstacle: getDevelopment.obstacle, suggestion: getDevelopment.suggestion, diff --git a/src/controllers/DevelopmentEmployeeHistoryController.ts b/src/controllers/DevelopmentEmployeeHistoryController.ts index ec40a3b..1ee5004 100644 --- a/src/controllers/DevelopmentEmployeeHistoryController.ts +++ b/src/controllers/DevelopmentEmployeeHistoryController.ts @@ -27,6 +27,7 @@ import { EmployeePosType } from "../entities/EmployeePosType"; import { EmployeePosLevel } from "../entities/EmployeePosLevel"; import { RequestWithUser } from "../middlewares/user"; import { addLogSequence, setLogDataDiff } from "../interfaces/utils"; +import permission from "../interfaces/permission"; @Route("api/v1/development/history/employee") @Tags("DevelopmentEmployeeHistory") @@ -44,7 +45,8 @@ export class DevelopmentEmployeeHistoryController extends Controller { * */ @Get("org/{year}") - async GetOrgDevelopemt(@Path() year: number) { + async GetOrgDevelopemt(@Request() request: RequestWithUser, @Path() year: number) { + await new permission().PermissionList(request, "SYS_DEV_HISTORY_EMP"); const type = "EMPLOYEE"; const getOrg = await this.developmentHistoryRepository .createQueryBuilder("developmentHistory") @@ -76,6 +78,7 @@ export class DevelopmentEmployeeHistoryController extends Controller { @Body() requestBody: CreateDevelopmentHistory, @Request() request: RequestWithUser, ) { + await new permission().PermissionCreate(request, "SYS_DEV_HISTORY_EMP"); const type = "EMPLOYEE"; const chk_name = await this.developmentHistoryRepository.find({ where: { @@ -144,6 +147,7 @@ export class DevelopmentEmployeeHistoryController extends Controller { @Body() requestBody: UpdateDevelopmentHistory, @Request() request: RequestWithUser, ) { + await new permission().PermissionUpdate(request, "SYS_DEV_HISTORY_EMP"); const type = "EMPLOYEE"; const development = await this.developmentHistoryRepository.findOne({ where: { id: id, type: type }, @@ -209,7 +213,8 @@ export class DevelopmentEmployeeHistoryController extends Controller { * @param {string} id Id โครงการ */ @Delete("{id}") - async DeleteDevelopmentHistory(@Path() id: string,@Request () request: RequestWithUser) { + async DeleteDevelopmentHistory(@Path() id: string, @Request() request: RequestWithUser) { + await new permission().PermissionDelete(request, "SYS_DEV_HISTORY_EMP"); const type = "EMPLOYEE"; const development = await this.developmentHistoryRepository.findOne({ where: { id: id, type: type }, @@ -234,6 +239,7 @@ export class DevelopmentEmployeeHistoryController extends Controller { */ @Post("filter") async GetDevelopmentHistoryLists( + @Request() request: RequestWithUser, @Body() body: { page: number; @@ -243,6 +249,7 @@ export class DevelopmentEmployeeHistoryController extends Controller { root: string | null; }, ) { + await new permission().PermissionList(request, "SYS_DEV_HISTORY_EMP"); const type = "EMPLOYEE"; const [development, total] = await AppDataSource.getRepository(DevelopmentHistory) .createQueryBuilder("developmentHistory") @@ -352,7 +359,8 @@ export class DevelopmentEmployeeHistoryController extends Controller { * @param {string} id Id โครงการ */ @Get("{id}") - async GetDevelopemtHistoryById(@Path() id: string) { + async GetDevelopemtHistoryById(@Request() request: RequestWithUser, @Path() id: string) { + await new permission().PermissionGet(request, "SYS_DEV_HISTORY_EMP"); const type = "EMPLOYEE"; const getDevelopment = await this.developmentHistoryRepository.findOne({ relations: ["development", "employeePosLevel", "employeePosType"], diff --git a/src/controllers/DevelopmentHistoryController.ts b/src/controllers/DevelopmentHistoryController.ts index a2cd020..547312b 100644 --- a/src/controllers/DevelopmentHistoryController.ts +++ b/src/controllers/DevelopmentHistoryController.ts @@ -27,6 +27,7 @@ import { PosType } from "../entities/PosType"; import { PosLevel } from "../entities/PosLevel"; import { RequestWithUser } from "../middlewares/user"; import { addLogSequence, setLogDataDiff } from "../interfaces/utils"; +import permission from "../interfaces/permission"; @Route("api/v1/development/history/officer") @Tags("DevelopmentOfficerHistory") @@ -44,7 +45,8 @@ export class DevelopmentOfficerHistoryController extends Controller { * */ @Get("org/{year}") - async GetOrgDevelopemt(@Path() year: number) { + async GetOrgDevelopemt(@Request() request: RequestWithUser, @Path() year: number) { + await new permission().PermissionList(request, "SYS_DEV_HISTORY_OFFICER"); const type = "OFFICER"; const getOrg = await this.developmentHistoryRepository .createQueryBuilder("developmentHistory") @@ -76,6 +78,7 @@ export class DevelopmentOfficerHistoryController extends Controller { @Body() requestBody: CreateDevelopmentHistory, @Request() request: RequestWithUser, ) { + await new permission().PermissionCreate(request, "SYS_DEV_HISTORY_OFFICER"); const type = "OFFICER"; const chk_name = await this.developmentHistoryRepository.find({ where: { @@ -140,6 +143,7 @@ export class DevelopmentOfficerHistoryController extends Controller { @Body() requestBody: UpdateDevelopmentHistory, @Request() request: RequestWithUser, ) { + await new permission().PermissionUpdate(request, "SYS_DEV_HISTORY_OFFICER"); const type = "OFFICER"; const development = await this.developmentHistoryRepository.findOne({ where: { id: id, type: type }, @@ -202,6 +206,7 @@ export class DevelopmentOfficerHistoryController extends Controller { */ @Delete("{id}") async DeleteDevelopmentHistory(@Path() id: string, @Request() request: RequestWithUser) { + await new permission().PermissionDelete(request, "SYS_DEV_HISTORY_OFFICER"); const type = "OFFICER"; const development = await this.developmentHistoryRepository.findOne({ where: { id: id, type: type }, @@ -226,6 +231,7 @@ export class DevelopmentOfficerHistoryController extends Controller { */ @Post("filter") async GetDevelopmentHistoryLists( + @Request() request: RequestWithUser, @Body() body: { page: number; @@ -235,6 +241,7 @@ export class DevelopmentOfficerHistoryController extends Controller { root: string | null; }, ) { + await new permission().PermissionList(request, "SYS_DEV_HISTORY_OFFICER"); const type = "OFFICER"; const [development, total] = await AppDataSource.getRepository(DevelopmentHistory) .createQueryBuilder("developmentHistory") @@ -330,7 +337,7 @@ export class DevelopmentOfficerHistoryController extends Controller { fullName: item.prefix + item.firstName + " " + item.lastName, position: item.position, year: item.development.year, - root: item.development.root,//test + root: item.development.root, //test posType: item.posType ? item.posType.posTypeName : null, posLevel: item.posLevel ? item.posLevel.posLevelName : null, posExecutive: item.posExecutive, @@ -348,7 +355,8 @@ export class DevelopmentOfficerHistoryController extends Controller { * @param {string} id Id โครงการ */ @Get("{id}") - async GetDevelopemtHistoryById(@Path() id: string) { + async GetDevelopemtHistoryById(@Request() request: RequestWithUser, @Path() id: string) { + await new permission().PermissionGet(request, "SYS_DEV_HISTORY_OFFICER"); const type = "OFFICER"; const getDevelopment = await this.developmentHistoryRepository.findOne({ relations: ["development", "posLevel", "posType"], diff --git a/src/controllers/DevelopmentScholarshipController.ts b/src/controllers/DevelopmentScholarshipController.ts index 8659f75..c825e12 100644 --- a/src/controllers/DevelopmentScholarshipController.ts +++ b/src/controllers/DevelopmentScholarshipController.ts @@ -196,12 +196,14 @@ export class DevelopmentScholarshipController extends Controller { */ @Get() async GetDevelopmentScholarshipLists( + @Request() request: RequestWithUser, @Query("page") page: number = 1, @Query("pageSize") pageSize: number = 10, @Query("keyword") keyword?: string, @Query("year") year?: number, @Query("scholarshipType") scholarshipType?: string, ) { + await new permission().PermissionList(request, "SYS_DEV_SCHOLARSHIP"); const [development, total] = await AppDataSource.getRepository(DevelopmentScholarship) .createQueryBuilder("developmentScholarship") .leftJoinAndSelect("developmentScholarship.posLevel", "posLevel") @@ -292,7 +294,8 @@ export class DevelopmentScholarshipController extends Controller { * @param {string} id Id ข้าราชการฯที่ได้รับทุนการศึกษา */ @Get("{id}") - async GetDevelopemtScholarshipById(@Path() id: string) { + async GetDevelopemtScholarshipById(@Request() request: RequestWithUser, @Path() id: string) { + await new permission().PermissionGet(request, "SYS_DEV_SCHOLARSHIP"); const getDevelopment = await this.developmentScholarshipRepository.findOne({ relations: ["posLevel", "posType", "posLevelguarantor", "posTypeguarantor"], where: { id: id }, From 3abd92e15ff4b06e384418736e7bde578436cd55 Mon Sep 17 00:00:00 2001 From: kittapath Date: Thu, 22 Aug 2024 17:23:57 +0700 Subject: [PATCH 146/250] no message --- src/controllers/StrategyController.ts | 52 ++++++++++++++++++++++++++- 1 file changed, 51 insertions(+), 1 deletion(-) diff --git a/src/controllers/StrategyController.ts b/src/controllers/StrategyController.ts index 282dea7..f0d781f 100644 --- a/src/controllers/StrategyController.ts +++ b/src/controllers/StrategyController.ts @@ -20,9 +20,59 @@ export class StrategyController extends Controller { private strategy3Repo = AppDataSource.getRepository(StrategyChild3); private strategy4Repo = AppDataSource.getRepository(StrategyChild4); private strategy5Repo = AppDataSource.getRepository(StrategyChild5); + @Get("edit") + public async listStrategyChild1Edit(@Request() request: RequestWithUser) { + let _data = await new permission().PermissionList(request, "SYS_EVA_STRATIGIC"); + const listStrategyChild1 = await this.strategy1Repo.find({ + relations: [ + "strategyChild2s", + "strategyChild2s.strategyChild3s", + "strategyChild2s.strategyChild3s.strategyChild4s", + "strategyChild2s.strategyChild3s.strategyChild4s.strategyChild5s", + ], + order: { createdAt: "ASC" }, + }); + + // if (!listStrategyChild1 || listStrategyChild1.length === 0) { + // throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลยุทธศาสตร์"); + // } + + const formattedData = listStrategyChild1.map((item) => ({ + id: item.id, + level: 1, + name: item.strategyChild1Name, + children: item.strategyChild2s.map((child2) => ({ + id: child2.id, + level: 2, + name: child2.strategyChild2Name, + children: child2.strategyChild3s + ? child2.strategyChild3s.map((child3) => ({ + id: child3.id, + level: 3, + name: child3.strategyChild3Name, + children: child3.strategyChild4s + ? child3.strategyChild4s.map((child4) => ({ + id: child4.id, + level: 4, + name: child4.strategyChild4Name, + children: child4.strategyChild5s + ? child4.strategyChild5s.map((child5) => ({ + id: child5.id, + level: 5, + name: child5.strategyChild5Name, + })) + : [], + })) + : [], + })) + : [], + })), + })); + + return new HttpSuccess(formattedData); + } @Get() public async listStrategyChild1(@Request() request: RequestWithUser) { - let _data = await new permission().PermissionList(request, "SYS_EVA_STRATIGIC"); const listStrategyChild1 = await this.strategy1Repo.find({ relations: [ "strategyChild2s", From d13da7269c5824382d0fa69b291302a455c0ce7e Mon Sep 17 00:00:00 2001 From: AdisakKanthawilang Date: Fri, 30 Aug 2024 14:17:29 +0700 Subject: [PATCH 147/250] add path admin(detail scholarship) --- .../DevelopmentScholarshipController.ts | 188 +++++++++++------- 1 file changed, 117 insertions(+), 71 deletions(-) diff --git a/src/controllers/DevelopmentScholarshipController.ts b/src/controllers/DevelopmentScholarshipController.ts index c825e12..779f291 100644 --- a/src/controllers/DevelopmentScholarshipController.ts +++ b/src/controllers/DevelopmentScholarshipController.ts @@ -52,11 +52,6 @@ export class DevelopmentScholarshipController extends Controller { ) { await new permission().PermissionCreate(request, "SYS_DEV_SCHOLARSHIP"); if (requestBody.posTypeId != null) { - // addLogSequence(request, { - // action: "database", - // status: "success", - // description: "Get Position Type.", - // }); const checkId = await this.posTypeRepository.findOne({ where: { id: requestBody.posTypeId }, }); @@ -65,11 +60,6 @@ export class DevelopmentScholarshipController extends Controller { } } if (requestBody.posLevelId != null) { - // addLogSequence(request, { - // action: "database", - // status: "success", - // description: "Get Position Level.", - // }); const checkId = await this.posLevelRepository.findOne({ where: { id: requestBody.posLevelId }, }); @@ -83,11 +73,6 @@ export class DevelopmentScholarshipController extends Controller { development.createdFullName = request.user.name; development.lastUpdateUserId = request.user.sub; development.lastUpdateFullName = request.user.name; - // addLogSequence(request, { - // action: "database", - // status: "success", - // description: "Store Development Scholarship.", - // }); await this.developmentScholarshipRepository.save(development, { data: request }); setLogDataDiff(request, { before, after: development }); return new HttpSuccess(development.id); @@ -106,11 +91,6 @@ export class DevelopmentScholarshipController extends Controller { @Body() requestBody: UpdateDevelopmentScholarship, @Request() request: RequestWithUser, ) { - // addLogSequence(request, { - // action: "database", - // status: "success", - // description: "Get Development Scholarship.", - // }); await new permission().PermissionUpdate(request, "SYS_DEV_SCHOLARSHIP"); const development = await this.developmentScholarshipRepository.findOne({ where: { id: id }, @@ -119,11 +99,6 @@ export class DevelopmentScholarshipController extends Controller { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลทุนการศึกษา/ฝึกอบรมนี้"); } if (requestBody.posTypeId != null) { - // addLogSequence(request, { - // action: "database", - // status: "success", - // description: "Get Position Type.", - // }); const checkId = await this.posTypeRepository.findOne({ where: { id: requestBody.posTypeId }, }); @@ -132,11 +107,6 @@ export class DevelopmentScholarshipController extends Controller { } } if (requestBody.posLevelId != null) { - // addLogSequence(request, { - // action: "database", - // status: "success", - // description: "Get Position Level.", - // }); const checkId = await this.posLevelRepository.findOne({ where: { id: requestBody.posLevelId }, }); @@ -148,11 +118,6 @@ export class DevelopmentScholarshipController extends Controller { Object.assign(development, requestBody); development.lastUpdateUserId = request.user.sub; development.lastUpdateFullName = request.user.name; - // addLogSequence(request, { - // action: "database", - // status: "success", - // description: "Store DevelopmentScholarship.", - // }); await this.developmentScholarshipRepository.save(development, { data: request }); setLogDataDiff(request, { before, after: development }); return new HttpSuccess(development.id); @@ -167,11 +132,6 @@ export class DevelopmentScholarshipController extends Controller { */ @Delete("{id}") async DeleteDevelopmentScholarship(@Path() id: string, @Request() request: RequestWithUser) { - // addLogSequence(request, { - // action: "database", - // status: "success", - // description: "Get Development Scholarship", - // }); await new permission().PermissionDelete(request, "SYS_DEV_SCHOLARSHIP"); const development = await this.developmentScholarshipRepository.findOne({ where: { id: id }, @@ -179,11 +139,7 @@ export class DevelopmentScholarshipController extends Controller { if (!development) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลทุนการศึกษา/ฝึกอบรมนี้"); } - // addLogSequence(request, { - // action: "remove", - // status: "success", - // description: "Remove Development Scholarship By ID.", - // }); + await this.developmentScholarshipRepository.remove(development, { data: request }); return new HttpSuccess(); } @@ -295,6 +251,121 @@ export class DevelopmentScholarshipController extends Controller { */ @Get("{id}") async GetDevelopemtScholarshipById(@Request() request: RequestWithUser, @Path() id: string) { + // await new permission().PermissionGet(request, "SYS_DEV_SCHOLARSHIP");//USER + const getDevelopment = await this.developmentScholarshipRepository.findOne({ + relations: ["posLevel", "posType", "posLevelguarantor", "posTypeguarantor"], + where: { id: id }, + }); + if (!getDevelopment) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลทุนการศึกษา/ฝึกอบรมนี้"); + } + const formattedData = { + rootId: getDevelopment.rootId ? getDevelopment.rootId : null, + root: getDevelopment.root ? getDevelopment.root : null, + org: getDevelopment.org ? getDevelopment.org : null, + orgRootShortName: getDevelopment.orgRootShortName ? getDevelopment.orgRootShortName : null, + orgRevisionId: getDevelopment.orgRevisionId ? getDevelopment.orgRevisionId : null, + rank: getDevelopment.rank ? getDevelopment.rank : null, + prefix: getDevelopment.prefix ? getDevelopment.prefix : null, + firstName: getDevelopment.firstName ? getDevelopment.firstName : null, + lastName: getDevelopment.lastName ? getDevelopment.lastName : null, + citizenId: getDevelopment.citizenId ? getDevelopment.citizenId : null, + position: getDevelopment.position ? getDevelopment.position : null, + posExecutive: getDevelopment.posExecutive ? getDevelopment.posExecutive : null, + posLevelId: getDevelopment.posLevelId ? getDevelopment.posLevelId : null, + posLevelName: getDevelopment.posLevel?.posLevelName + ? getDevelopment.posLevel?.posLevelName + : null, + posTypeId: getDevelopment.posTypeId ? getDevelopment.posTypeId : null, + posTypeName: getDevelopment.posType?.posTypeName ? getDevelopment.posType?.posTypeName : null, + guarantorRootId: getDevelopment.guarantorRootId ? getDevelopment.guarantorRootId : null, + guarantorRoot: getDevelopment.guarantorRoot ? getDevelopment.guarantorRoot : null, + guarantorOrg: getDevelopment.guarantorOrg ? getDevelopment.guarantorOrg : null, + guarantorOrgRootShortName: getDevelopment.guarantorOrgRootShortName + ? getDevelopment.guarantorOrgRootShortName + : null, + guarantorOrgRevisionId: getDevelopment.guarantorOrgRevisionId + ? getDevelopment.guarantorOrgRevisionId + : null, + guarantorRank: getDevelopment.guarantorRank ? getDevelopment.guarantorRank : null, + guarantorPrefix: getDevelopment.guarantorPrefix ? getDevelopment.guarantorPrefix : null, + guarantorFirstName: getDevelopment.guarantorFirstName + ? getDevelopment.guarantorFirstName + : null, + guarantorLastName: getDevelopment.guarantorLastName ? getDevelopment.guarantorLastName : null, + guarantorCitizenId: getDevelopment.guarantorCitizenId + ? getDevelopment.guarantorCitizenId + : null, + guarantorPosition: getDevelopment.guarantorPosition ? getDevelopment.guarantorPosition : null, + guarantorPosExecutive: getDevelopment.guarantorPosExecutive + ? getDevelopment.guarantorPosExecutive + : null, + posLevelguarantorId: getDevelopment.posLevelguarantorId + ? getDevelopment.posLevelguarantorId + : null, + posLevelguarantorName: getDevelopment.posLevelguarantor?.posLevelName + ? getDevelopment.posLevelguarantor?.posLevelName + : null, + posTypeguarantorId: getDevelopment.posTypeguarantorId + ? getDevelopment.posTypeguarantorId + : null, + posTypeguarantorName: getDevelopment.posTypeguarantor?.posTypeName + ? getDevelopment.posTypeguarantor?.posTypeName + : null, + scholarshipYear: getDevelopment.scholarshipYear ? getDevelopment.scholarshipYear : null, + budgetSource: getDevelopment.budgetSource ? getDevelopment.budgetSource : null, + budgetApprove: getDevelopment.budgetApprove ? getDevelopment.budgetApprove : null, + bookNo: getDevelopment.bookNo ? getDevelopment.bookNo : null, + bookNoDate: getDevelopment.bookNoDate ? getDevelopment.bookNoDate : null, + bookApproveDate: getDevelopment.bookApproveDate ? getDevelopment.bookApproveDate : null, + useOfficialTime: getDevelopment.useOfficialTime ? getDevelopment.useOfficialTime : false, + changeDetail: getDevelopment.changeDetail ? getDevelopment.changeDetail : null, + scholarshipType: getDevelopment.scholarshipType ? getDevelopment.scholarshipType : null, + fundType: getDevelopment.fundType ? getDevelopment.fundType : null, + contractNo: getDevelopment.contractNo ? getDevelopment.contractNo : null, + contractDate: getDevelopment.contractDate ? getDevelopment.contractDate : null, + reportBackNo: getDevelopment.reportBackNo ? getDevelopment.reportBackNo : null, + reportBackNoDate: getDevelopment.reportBackNoDate ? getDevelopment.reportBackNoDate : null, + reportBackDate: getDevelopment.reportBackDate ? getDevelopment.reportBackDate : null, + degreeLevel: getDevelopment.degreeLevel ? getDevelopment.degreeLevel : null, + course: getDevelopment.course ? getDevelopment.course : null, + field: getDevelopment.field ? getDevelopment.field : null, + faculty: getDevelopment.faculty ? getDevelopment.faculty : null, + educationalInstitution: getDevelopment.educationalInstitution + ? getDevelopment.educationalInstitution + : null, + startDate: getDevelopment.startDate ? getDevelopment.startDate : null, + endDate: getDevelopment.endDate ? getDevelopment.endDate : null, + studyPlace: getDevelopment.studyPlace ? getDevelopment.studyPlace : null, + studyTopic: getDevelopment.studyTopic ? getDevelopment.studyTopic : null, + studyStartDate: getDevelopment.studyStartDate ? getDevelopment.studyStartDate : null, + studyEndDate: getDevelopment.studyEndDate ? getDevelopment.studyEndDate : null, + studyCountry: getDevelopment.studyCountry ? getDevelopment.studyCountry : null, + studyAbroadTopic: getDevelopment.studyAbroadTopic ? getDevelopment.studyAbroadTopic : null, + studyAbroadStartDate: getDevelopment.studyAbroadStartDate + ? getDevelopment.studyAbroadStartDate + : null, + studyAbroadEndDate: getDevelopment.studyAbroadEndDate + ? getDevelopment.studyAbroadEndDate + : null, + totalPeriod: getDevelopment.totalPeriod ? getDevelopment.totalPeriod : null, + status: getDevelopment.status ? getDevelopment.status : null, + profileId: getDevelopment.profileId ? getDevelopment.profileId : null, + planType: getDevelopment.planType ? getDevelopment.planType : null, + isNoUseBudget: getDevelopment.isNoUseBudget ? getDevelopment.isNoUseBudget : null, + }; + return new HttpSuccess(formattedData); + } + + /** + * API รายละเอียดทุนการศึกษา/ฝึกอบรม ADMIN + * + * @summary DEV_015 - รายละเอียดทุนการศึกษา/ฝึกอบรม #15 ADMIN + * + * @param {string} id Id ข้าราชการฯที่ได้รับทุนการศึกษา ADMIN + */ + @Get("admin/{id}") + async GetDevelopemtScholarshipAdminById(@Request() request: RequestWithUser, @Path() id: string) { await new permission().PermissionGet(request, "SYS_DEV_SCHOLARSHIP"); const getDevelopment = await this.developmentScholarshipRepository.findOne({ relations: ["posLevel", "posType", "posLevelguarantor", "posTypeguarantor"], @@ -481,12 +552,7 @@ export class DevelopmentScholarshipController extends Controller { @Body() requestBody: UpdateDevelopmentScholarshipUser, @Request() request: RequestWithUser, ) { - // addLogSequence(request, { - // action: "database", - // status: "success", - // description: "Get Development Scholarship.", - // }); - await new permission().PermissionUpdate(request, "SYS_DEV_SCHOLARSHIP"); + // await new permission().PermissionUpdate(request, "SYS_DEV_SCHOLARSHIP"); const getDevelopment = await this.developmentScholarshipRepository.findOne({ where: { id: id }, }); @@ -497,11 +563,6 @@ export class DevelopmentScholarshipController extends Controller { Object.assign(getDevelopment, requestBody); getDevelopment.lastUpdateUserId = request.user.sub; getDevelopment.lastUpdateFullName = request.user.name; - // addLogSequence(request, { - // action: "database", - // status: "success", - // description: "Store DevelopmentScholarship.", - // }); await this.developmentScholarshipRepository.save(getDevelopment, { data: request }); setLogDataDiff(request, { before, after: getDevelopment }); return new HttpSuccess(getDevelopment.id); @@ -521,11 +582,6 @@ export class DevelopmentScholarshipController extends Controller { @Path() status: string, @Request() request: RequestWithUser, ) { - // addLogSequence(request, { - // action: "database", - // status: "success", - // description: "Get Development Scholarship.", - // }); const getDevelopment = await this.developmentScholarshipRepository.findOne({ where: { id: id }, }); @@ -539,11 +595,6 @@ export class DevelopmentScholarshipController extends Controller { let scholarshipType = ""; if (_status == "GRADUATE") { if (getDevelopment.scholarshipType != null) { - // addLogSequence(request, { - // action: "database", - // status: "success", - // description: "Change Status Development Scholarship.", - // }); switch (getDevelopment.scholarshipType.trim().toUpperCase()) { case "DOMESTICE": scholarshipType = "การศึกษาในประเทศ"; @@ -595,11 +646,6 @@ export class DevelopmentScholarshipController extends Controller { }); } else if (_status == "NOTGRADUATE") { getDevelopment.status = _status; - // addLogSequence(request, { - // action: "database", - // status: "success", - // description: "Change Status Development Scholarship.", - // }); await this.developmentScholarshipRepository.save(getDevelopment, { data: request }); } else { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบสถานะนี้ในระบบ"); From bc69873705bb9e34695978aa1f423d9cba79d983 Mon Sep 17 00:00:00 2001 From: AdisakKanthawilang Date: Tue, 3 Sep 2024 11:44:57 +0700 Subject: [PATCH 148/250] fix --- src/controllers/DevelopmentController.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/controllers/DevelopmentController.ts b/src/controllers/DevelopmentController.ts index 8a75f9e..3784d02 100644 --- a/src/controllers/DevelopmentController.ts +++ b/src/controllers/DevelopmentController.ts @@ -1865,7 +1865,7 @@ export class DevelopmentController extends Controller { @Query("node") node?: number | null, @Query("keyword") keyword?: string, ) { - await new permission().PermissionList(request, "SYS_DEV_SCHOLARSHIP"); + // await new permission().PermissionOrgList(request, "SYS_DEV_SCHOLARSHIP"); const [development, total] = await AppDataSource.getRepository(Development) .createQueryBuilder("development") .andWhere(year > 0 ? "development.year LIKE :year" : "1=1", { From dd6e770ec744a0e0ff5627a91cd602c80de983a5 Mon Sep 17 00:00:00 2001 From: kittapath Date: Tue, 3 Sep 2024 14:59:53 +0700 Subject: [PATCH 149/250] =?UTF-8?q?=E0=B9=80=E0=B8=9E=E0=B8=B4=E0=B9=88?= =?UTF-8?q?=E0=B8=A1=E0=B8=A7=E0=B8=B1=E0=B8=99=E0=B9=80=E0=B8=A7=E0=B8=A5?= =?UTF-8?q?=E0=B8=B2=20=E0=B9=81=E0=B8=81=E0=B9=89=E0=B9=84=E0=B8=82/?= =?UTF-8?q?=E0=B8=AA=E0=B8=A3=E0=B9=89=E0=B8=B2=E0=B8=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/DevelopmentController.ts | 72 +++++++++++++++++-- .../DevelopmentEmployeeHistoryController.ts | 3 + .../DevelopmentHistoryController.ts | 3 + .../DevelopmentScholarshipController.ts | 7 ++ src/controllers/PortfolioController.ts | 3 + src/controllers/StrategyController.ts | 3 + 6 files changed, 87 insertions(+), 4 deletions(-) diff --git a/src/controllers/DevelopmentController.ts b/src/controllers/DevelopmentController.ts index 3784d02..ac8db88 100644 --- a/src/controllers/DevelopmentController.ts +++ b/src/controllers/DevelopmentController.ts @@ -156,6 +156,9 @@ export class DevelopmentController extends Controller { development.createdFullName = request.user.name; development.lastUpdateUserId = request.user.sub; development.lastUpdateFullName = request.user.name; + development.createdAt = new Date(); + development.lastUpdatedAt = new Date(); + // addLogSequence(request, { // action: "database", // status: "success", @@ -235,8 +238,6 @@ export class DevelopmentController extends Controller { development.child4ShortName = x.child4ShortName; }) .catch((x) => {}); - development.lastUpdateUserId = request.user.sub; - development.lastUpdateFullName = request.user.name; const _null: any = null; switch (requestBody.node) { case 0: { @@ -284,6 +285,9 @@ export class DevelopmentController extends Controller { default: throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงการ/หลักสูตรการฝึกอบรม"); } + development.lastUpdateUserId = request.user.sub; + development.lastUpdateFullName = request.user.name; + development.lastUpdatedAt = new Date(); // addLogSequence(request, { // action: "database", // status: "success", @@ -324,6 +328,8 @@ export class DevelopmentController extends Controller { data.createdFullName = request.user.name; data.lastUpdateUserId = request.user.sub; data.lastUpdateFullName = request.user.name; + data.createdAt = new Date(); + data.lastUpdatedAt = new Date(); data.developmentPlannedGoalId = development.id; // addLogSequence(request, { // action: "database", @@ -356,6 +362,8 @@ export class DevelopmentController extends Controller { _data.createdFullName = request.user.name; _data.lastUpdateUserId = request.user.sub; _data.lastUpdateFullName = request.user.name; + _data.createdAt = new Date(); + _data.lastUpdatedAt = new Date(); _data.plannedGoalId = data.id; // addLogSequence(request, { // action: "database", @@ -400,6 +408,8 @@ export class DevelopmentController extends Controller { data.createdFullName = request.user.name; data.lastUpdateUserId = request.user.sub; data.lastUpdateFullName = request.user.name; + data.createdAt = new Date(); + data.lastUpdatedAt = new Date(); data.developmentPlannedPeopleId = development.id; // addLogSequence(request, { // action: "database", @@ -463,6 +473,8 @@ export class DevelopmentController extends Controller { data.createdFullName = request.user.name; data.lastUpdateUserId = request.user.sub; data.lastUpdateFullName = request.user.name; + data.createdAt = new Date(); + data.lastUpdatedAt = new Date(); data.developmentActualGoalId = development.id; // addLogSequence(request, { // action: "database", @@ -505,6 +517,8 @@ export class DevelopmentController extends Controller { data.createdFullName = request.user.name; data.lastUpdateUserId = request.user.sub; data.lastUpdateFullName = request.user.name; + data.createdAt = new Date(); + data.lastUpdatedAt = new Date(); data.developmentActualPeopleId = development.id; // addLogSequence(request, { // action: "database", @@ -556,6 +570,7 @@ export class DevelopmentController extends Controller { Object.assign(development, { ...requestBody, positions: [] }); development.lastUpdateUserId = request.user.sub; development.lastUpdateFullName = request.user.name; + development.lastUpdatedAt = new Date(); // addLogSequence(request, { // action: "database", // status: "success", @@ -587,6 +602,8 @@ export class DevelopmentController extends Controller { _data.createdFullName = request.user.name; _data.lastUpdateUserId = request.user.sub; _data.lastUpdateFullName = request.user.name; + _data.createdAt = new Date(); + _data.lastUpdatedAt = new Date(); _data.plannedGoalId = development.id; // addLogSequence(request, { // action: "database", @@ -633,6 +650,7 @@ export class DevelopmentController extends Controller { Object.assign(development, requestBody); development.lastUpdateUserId = request.user.sub; development.lastUpdateFullName = request.user.name; + development.lastUpdatedAt = new Date(); // addLogSequence(request, { // action: "database", // status: "success", @@ -698,6 +716,7 @@ export class DevelopmentController extends Controller { Object.assign(development, requestBody); development.lastUpdateUserId = request.user.sub; development.lastUpdateFullName = request.user.name; + development.lastUpdatedAt = new Date(); // addLogSequence(request, { // action: "database", // status: "success", @@ -737,6 +756,7 @@ export class DevelopmentController extends Controller { Object.assign(development, requestBody); development.lastUpdateUserId = request.user.sub; development.lastUpdateFullName = request.user.name; + development.lastUpdatedAt = new Date(); // addLogSequence(request, { // action: "database", // status: "success", @@ -1137,6 +1157,9 @@ export class DevelopmentController extends Controller { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลยุทธศาสตร์เป้าหมายตามจริง"); } } + development.lastUpdateUserId = request.user.sub; + development.lastUpdateFullName = request.user.name; + development.lastUpdatedAt = new Date(); await this.developmentRepository.save(development, { data: request }); if (requestBody.developmentProjectTypes != null) { await Promise.all( @@ -1147,6 +1170,8 @@ export class DevelopmentController extends Controller { data.createdFullName = request.user.name; data.lastUpdateUserId = request.user.sub; data.lastUpdateFullName = request.user.name; + data.createdAt = new Date(); + data.lastUpdatedAt = new Date(); data.developmentId = development.id; await this.developmentProjectTypeRepository.save(data, { data: request }); }), @@ -1161,6 +1186,8 @@ export class DevelopmentController extends Controller { data.createdFullName = request.user.name; data.lastUpdateUserId = request.user.sub; data.lastUpdateFullName = request.user.name; + data.createdAt = new Date(); + data.lastUpdatedAt = new Date(); data.developmentId = development.id; await this.developmentProjectTechniquePlannedRepository.save(data, { data: request }); }), @@ -1175,6 +1202,8 @@ export class DevelopmentController extends Controller { data.createdFullName = request.user.name; data.lastUpdateUserId = request.user.sub; data.lastUpdateFullName = request.user.name; + data.createdAt = new Date(); + data.lastUpdatedAt = new Date(); data.developmentId = development.id; await this.developmentProjectTechniqueActualRepository.save(data, { data: request }); }), @@ -1206,6 +1235,8 @@ export class DevelopmentController extends Controller { data.createdFullName = request.user.name; data.lastUpdateUserId = request.user.sub; data.lastUpdateFullName = request.user.name; + data.createdAt = new Date(); + data.lastUpdatedAt = new Date(); await this.developmentAddresssRepository.save(data, { data: request }); } // setLogDataDiff(request, { before, after: development }); @@ -1240,6 +1271,7 @@ export class DevelopmentController extends Controller { Object.assign(development, requestBody); development.lastUpdateUserId = request.user.sub; development.lastUpdateFullName = request.user.name; + development.lastUpdatedAt = new Date(); await this.developmentRepository.save(development, { data: request }); setLogDataDiff(request, { before, after: development }); return new HttpSuccess(development.id); @@ -1265,7 +1297,6 @@ export class DevelopmentController extends Controller { if (!development) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงการ/หลักสูตรการฝึกอบรมนี้"); } - console.log(">>>>>>>>>>", requestBody.results); let results: any = requestBody.results && requestBody.results != "" ? requestBody.results : null; const before = structuredClone(development); @@ -1276,6 +1307,8 @@ export class DevelopmentController extends Controller { data.createdFullName = request.user.name; data.lastUpdateUserId = request.user.sub; data.lastUpdateFullName = request.user.name; + data.createdAt = new Date(); + data.lastUpdatedAt = new Date(); data.developmentId = development.id; await this.developmentEvaluationRepository.save(data, { data: request }); setLogDataDiff(request, { before, after: development }); @@ -1335,6 +1368,7 @@ export class DevelopmentController extends Controller { Object.assign(development, requestBody); development.lastUpdateUserId = request.user.sub; development.lastUpdateFullName = request.user.name; + development.lastUpdatedAt = new Date(); // addLogSequence(request, { // action: "database", // status: "success", @@ -1368,6 +1402,7 @@ export class DevelopmentController extends Controller { Object.assign(development, { ...requestBody, developmentAddresss: [] }); development.lastUpdateUserId = request.user.sub; development.lastUpdateFullName = request.user.name; + development.lastUpdatedAt = new Date(); await this.developmentRepository.save(development, { data: request }); return new HttpSuccess(development.id); } @@ -1405,6 +1440,8 @@ export class DevelopmentController extends Controller { data.createdFullName = request.user.name; data.lastUpdateUserId = request.user.sub; data.lastUpdateFullName = request.user.name; + data.createdAt = new Date(); + data.lastUpdatedAt = new Date(); data.developmentId = development.id; await this.developmentOtherRepository.save(data, { data: request }); setLogDataDiff(request, { before, after: development }); @@ -1454,6 +1491,7 @@ export class DevelopmentController extends Controller { Object.assign(development, requestBody); development.lastUpdateUserId = request.user.sub; development.lastUpdateFullName = request.user.name; + development.lastUpdatedAt = new Date(); await this.developmentOtherRepository.save(development, { data: request }); return new HttpSuccess(development.id); @@ -1483,6 +1521,7 @@ export class DevelopmentController extends Controller { Object.assign(development, { ...requestBody }); development.lastUpdateUserId = request.user.sub; development.lastUpdateFullName = request.user.name; + development.lastUpdatedAt = new Date(); await this.developmentRepository.save(development, { data: request }); return new HttpSuccess(development.id); } @@ -1568,6 +1607,7 @@ export class DevelopmentController extends Controller { Object.assign(development, { ...requestBody }); development.lastUpdateUserId = request.user.sub; development.lastUpdateFullName = request.user.name; + development.lastUpdatedAt = new Date(); await this.developmentRepository.save(development, { data: request }); return new HttpSuccess(development.id); } @@ -1597,6 +1637,8 @@ export class DevelopmentController extends Controller { data.createdFullName = request.user.name; data.lastUpdateUserId = request.user.sub; data.lastUpdateFullName = request.user.name; + data.createdAt = new Date(); + data.lastUpdatedAt = new Date(); data.developmentId = development.id; await this.developmentRiskRepository.save(data, { data: request }); setLogDataDiff(request, { before, after: development }); @@ -1646,6 +1688,7 @@ export class DevelopmentController extends Controller { Object.assign(development, requestBody); development.lastUpdateUserId = request.user.sub; development.lastUpdateFullName = request.user.name; + development.lastUpdatedAt = new Date(); await this.developmentRiskRepository.save(development, { data: request }); return new HttpSuccess(development.id); @@ -1930,6 +1973,7 @@ export class DevelopmentController extends Controller { getDevelopment.status = "FINISH"; getDevelopment.lastUpdateUserId = request.user.sub; getDevelopment.lastUpdateFullName = request.user.name; + getDevelopment.lastUpdatedAt = new Date(); // addLogSequence(request, { // action: "database", // status: "success", @@ -2403,6 +2447,7 @@ export class DevelopmentController extends Controller { _data.lastUpdateUserId = request.user.sub; _data.lastUpdateFullName = request.user.name; + _data.lastUpdatedAt = new Date(); // addLogSequence(request, { // action: "database", // status: "success", @@ -2489,6 +2534,8 @@ export class DevelopmentController extends Controller { oldProfile.createdFullName = request.user.name; oldProfile.lastUpdateUserId = request.user.sub; oldProfile.lastUpdateFullName = request.user.name; + oldProfile.createdAt = new Date(); + oldProfile.lastUpdatedAt = new Date(); // addLogSequence(request, { // action: "database", // status: "success", @@ -2527,6 +2574,8 @@ export class DevelopmentController extends Controller { development.createdFullName = request.user.name; development.lastUpdateUserId = request.user.sub; development.lastUpdateFullName = request.user.name; + development.createdAt = new Date(); + development.lastUpdatedAt = new Date(); development.isProfile = true; // addLogSequence(request, { // action: "database", @@ -2570,6 +2619,8 @@ export class DevelopmentController extends Controller { development.createdFullName = request.user.name; development.lastUpdateUserId = request.user.sub; development.lastUpdateFullName = request.user.name; + development.createdAt = new Date(); + development.lastUpdatedAt = new Date(); development.isProfile = false; // addLogSequence(request, { // action: "database", @@ -2607,6 +2658,8 @@ export class DevelopmentController extends Controller { development.createdFullName = request.user.name; development.lastUpdateUserId = request.user.sub; development.lastUpdateFullName = request.user.name; + development.createdAt = new Date(); + development.lastUpdatedAt = new Date(); development.isProfile = true; // addLogSequence(request, { // action: "database", @@ -2650,6 +2703,8 @@ export class DevelopmentController extends Controller { development.createdFullName = request.user.name; development.lastUpdateUserId = request.user.sub; development.lastUpdateFullName = request.user.name; + development.createdAt = new Date(); + development.lastUpdatedAt = new Date(); development.isProfile = false; // addLogSequence(request, { // action: "database", @@ -2708,6 +2763,8 @@ export class DevelopmentController extends Controller { oldProfile.createdFullName = request.user.name; oldProfile.lastUpdateUserId = request.user.sub; oldProfile.lastUpdateFullName = request.user.name; + oldProfile.createdAt = new Date(); + oldProfile.lastUpdatedAt = new Date(); // addLogSequence(request, { // action: "database", // status: "success", @@ -2742,6 +2799,8 @@ export class DevelopmentController extends Controller { development.createdFullName = request.user.name; development.lastUpdateUserId = request.user.sub; development.lastUpdateFullName = request.user.name; + development.createdAt = new Date(); + development.lastUpdatedAt = new Date(); // addLogSequence(request, { // action: "database", // status: "success", @@ -2781,6 +2840,8 @@ export class DevelopmentController extends Controller { development.createdFullName = request.user.name; development.lastUpdateUserId = request.user.sub; development.lastUpdateFullName = request.user.name; + development.createdAt = new Date(); + development.lastUpdatedAt = new Date(); development.isProfile = false; // addLogSequence(request, { // action: "database", @@ -2789,7 +2850,6 @@ export class DevelopmentController extends Controller { // }); await this.developmentHistoryRepository.save(development, { data: request }); setLogDataDiff(request, { before, after: development }); - console.log(development.isProfile); status = development.isProfile; }); } else { @@ -2815,6 +2875,8 @@ export class DevelopmentController extends Controller { development.createdFullName = request.user.name; development.lastUpdateUserId = request.user.sub; development.lastUpdateFullName = request.user.name; + development.createdAt = new Date(); + development.lastUpdatedAt = new Date(); development.isProfile = true; // addLogSequence(request, { // action: "database", @@ -2855,6 +2917,8 @@ export class DevelopmentController extends Controller { development.createdFullName = request.user.name; development.lastUpdateUserId = request.user.sub; development.lastUpdateFullName = request.user.name; + development.createdAt = new Date(); + development.lastUpdatedAt = new Date(); development.isProfile = false; // addLogSequence(request, { // action: "database", diff --git a/src/controllers/DevelopmentEmployeeHistoryController.ts b/src/controllers/DevelopmentEmployeeHistoryController.ts index 1ee5004..d3a351d 100644 --- a/src/controllers/DevelopmentEmployeeHistoryController.ts +++ b/src/controllers/DevelopmentEmployeeHistoryController.ts @@ -124,6 +124,8 @@ export class DevelopmentEmployeeHistoryController extends Controller { development.createdFullName = request.user.name; development.lastUpdateUserId = request.user.sub; development.lastUpdateFullName = request.user.name; + development.createdAt = new Date(); + development.lastUpdatedAt = new Date(); // addLogSequence(request, { // action: "database", // status: "success", @@ -196,6 +198,7 @@ export class DevelopmentEmployeeHistoryController extends Controller { development.posLevelId = null; development.lastUpdateUserId = request.user.sub; development.lastUpdateFullName = request.user.name; + development.lastUpdatedAt = new Date(); // addLogSequence(request, { // action: "database", // status: "success", diff --git a/src/controllers/DevelopmentHistoryController.ts b/src/controllers/DevelopmentHistoryController.ts index 547312b..af42286 100644 --- a/src/controllers/DevelopmentHistoryController.ts +++ b/src/controllers/DevelopmentHistoryController.ts @@ -120,6 +120,8 @@ export class DevelopmentOfficerHistoryController extends Controller { development.createdFullName = request.user.name; development.lastUpdateUserId = request.user.sub; development.lastUpdateFullName = request.user.name; + development.createdAt = new Date(); + development.lastUpdatedAt = new Date(); // addLogSequence(request, { // action: "database", // status: "success", @@ -188,6 +190,7 @@ export class DevelopmentOfficerHistoryController extends Controller { development.type = type; development.lastUpdateUserId = request.user.sub; development.lastUpdateFullName = request.user.name; + development.lastUpdatedAt = new Date(); // addLogSequence(request, { // action: "database", // status: "success", diff --git a/src/controllers/DevelopmentScholarshipController.ts b/src/controllers/DevelopmentScholarshipController.ts index 779f291..772d73f 100644 --- a/src/controllers/DevelopmentScholarshipController.ts +++ b/src/controllers/DevelopmentScholarshipController.ts @@ -73,6 +73,8 @@ export class DevelopmentScholarshipController extends Controller { development.createdFullName = request.user.name; development.lastUpdateUserId = request.user.sub; development.lastUpdateFullName = request.user.name; + development.createdAt = new Date(); + development.lastUpdatedAt = new Date(); await this.developmentScholarshipRepository.save(development, { data: request }); setLogDataDiff(request, { before, after: development }); return new HttpSuccess(development.id); @@ -118,6 +120,7 @@ export class DevelopmentScholarshipController extends Controller { Object.assign(development, requestBody); development.lastUpdateUserId = request.user.sub; development.lastUpdateFullName = request.user.name; + development.lastUpdatedAt = new Date(); await this.developmentScholarshipRepository.save(development, { data: request }); setLogDataDiff(request, { before, after: development }); return new HttpSuccess(development.id); @@ -563,6 +566,7 @@ export class DevelopmentScholarshipController extends Controller { Object.assign(getDevelopment, requestBody); getDevelopment.lastUpdateUserId = request.user.sub; getDevelopment.lastUpdateFullName = request.user.name; + getDevelopment.lastUpdatedAt = new Date(); await this.developmentScholarshipRepository.save(getDevelopment, { data: request }); setLogDataDiff(request, { before, after: getDevelopment }); return new HttpSuccess(getDevelopment.id); @@ -646,6 +650,9 @@ export class DevelopmentScholarshipController extends Controller { }); } else if (_status == "NOTGRADUATE") { getDevelopment.status = _status; + getDevelopment.lastUpdateUserId = request.user.sub; + getDevelopment.lastUpdateFullName = request.user.name; + getDevelopment.lastUpdatedAt = new Date(); await this.developmentScholarshipRepository.save(getDevelopment, { data: request }); } else { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบสถานะนี้ในระบบ"); diff --git a/src/controllers/PortfolioController.ts b/src/controllers/PortfolioController.ts index df0aa98..68de02e 100644 --- a/src/controllers/PortfolioController.ts +++ b/src/controllers/PortfolioController.ts @@ -106,6 +106,8 @@ export class PortfolioController extends Controller { _portfolio.createdFullName = request.user.name; _portfolio.lastUpdateUserId = request.user.sub; _portfolio.lastUpdateFullName = request.user.name; + _portfolio.createdAt = new Date(); + _portfolio.lastUpdatedAt = new Date(); // addLogSequence(request, { // action: "database", // status: "success", @@ -143,6 +145,7 @@ export class PortfolioController extends Controller { _portfolio.lastUpdateUserId = request.user.sub; _portfolio.lastUpdateFullName = request.user.name; + _portfolio.lastUpdatedAt = new Date(); Object.assign(_portfolio, requestBody); // addLogSequence(request, { // action: "database", diff --git a/src/controllers/StrategyController.ts b/src/controllers/StrategyController.ts index f0d781f..39529b0 100644 --- a/src/controllers/StrategyController.ts +++ b/src/controllers/StrategyController.ts @@ -222,6 +222,8 @@ export class StrategyController extends Controller { strategyChild.createdFullName = request.user.name; strategyChild.lastUpdateUserId = request.user.sub; strategyChild.lastUpdateFullName = request.user.name; + strategyChild.createdAt = new Date(); + strategyChild.lastUpdatedAt = new Date(); // addLogSequence(request, { // action: "database", // status: "success", @@ -303,6 +305,7 @@ export class StrategyController extends Controller { } strategyChild.lastUpdateUserId = request.user.sub; strategyChild.lastUpdateFullName = request.user.name; + strategyChild.lastUpdatedAt = new Date(); // addLogSequence(request, { // action: "remove", From 8c39019f4a18597146bc7cdb546ba26aa13d6f4e Mon Sep 17 00:00:00 2001 From: kittapath Date: Tue, 3 Sep 2024 15:18:30 +0700 Subject: [PATCH 150/250] delete import dont use --- src/controllers/DevelopmentController.ts | 4 +-- .../DevelopmentEmployeeHistoryController.ts | 3 +- .../DevelopmentHistoryController.ts | 3 +- .../DevelopmentScholarshipController.ts | 3 +- src/controllers/MyController.ts | 2 +- src/controllers/PortfolioController.ts | 2 +- src/controllers/ReportController.ts | 31 ++----------------- 7 files changed, 9 insertions(+), 39 deletions(-) diff --git a/src/controllers/DevelopmentController.ts b/src/controllers/DevelopmentController.ts index ac8db88..da7f1d2 100644 --- a/src/controllers/DevelopmentController.ts +++ b/src/controllers/DevelopmentController.ts @@ -27,7 +27,6 @@ import { UpdateDevelopment5, UpdateDevelopment7, UpdateDevelopment8, - UpdateDevelopment8_1, } from "../entities/Development"; import { ActualPeople, CreateActualPeople } from "../entities/ActualPeople"; import { CreatePlannedPeople, PlannedPeople } from "../entities/PlannedPeople"; @@ -38,7 +37,6 @@ import { PosType } from "../entities/PosType"; import { PosLevel } from "../entities/PosLevel"; import { PlannedGoalPosition } from "../entities/PlannedGoalPosition"; import { - CreateDevelopmentHistory, CreateDevelopmentHistoryOBO, DevelopmentHistory, } from "../entities/DevelopmentHistory"; @@ -59,7 +57,7 @@ import CallAPI from "../interfaces/call-api"; import { UseInterceptors } from "@nestjs/common"; import { FileInterceptor } from "@nestjs/platform-express"; import * as xlsx from "xlsx"; -import { addLogSequence, setLogDataDiff } from "../interfaces/utils"; +import { setLogDataDiff } from "../interfaces/utils"; import { RequestWithUser } from "../middlewares/user"; import { DevelopmentRisk, UpdateDevelopmentRisk } from "../entities/DevelopmentRisk"; import { DevelopmentOther, UpdateDevelopmentOther } from "../entities/DevelopmentOther"; diff --git a/src/controllers/DevelopmentEmployeeHistoryController.ts b/src/controllers/DevelopmentEmployeeHistoryController.ts index d3a351d..8d25e7c 100644 --- a/src/controllers/DevelopmentEmployeeHistoryController.ts +++ b/src/controllers/DevelopmentEmployeeHistoryController.ts @@ -10,7 +10,6 @@ import { Body, Path, Request, - Query, } from "tsoa"; import { AppDataSource } from "../database/data-source"; import { Brackets, Not } from "typeorm"; @@ -26,7 +25,7 @@ import { import { EmployeePosType } from "../entities/EmployeePosType"; import { EmployeePosLevel } from "../entities/EmployeePosLevel"; import { RequestWithUser } from "../middlewares/user"; -import { addLogSequence, setLogDataDiff } from "../interfaces/utils"; +import { setLogDataDiff } from "../interfaces/utils"; import permission from "../interfaces/permission"; @Route("api/v1/development/history/employee") diff --git a/src/controllers/DevelopmentHistoryController.ts b/src/controllers/DevelopmentHistoryController.ts index af42286..dfefb2e 100644 --- a/src/controllers/DevelopmentHistoryController.ts +++ b/src/controllers/DevelopmentHistoryController.ts @@ -10,7 +10,6 @@ import { Body, Path, Request, - Query, } from "tsoa"; import { AppDataSource } from "../database/data-source"; import { Brackets, Not } from "typeorm"; @@ -26,7 +25,7 @@ import { import { PosType } from "../entities/PosType"; import { PosLevel } from "../entities/PosLevel"; import { RequestWithUser } from "../middlewares/user"; -import { addLogSequence, setLogDataDiff } from "../interfaces/utils"; +import { setLogDataDiff } from "../interfaces/utils"; import permission from "../interfaces/permission"; @Route("api/v1/development/history/officer") diff --git a/src/controllers/DevelopmentScholarshipController.ts b/src/controllers/DevelopmentScholarshipController.ts index 772d73f..b6bdd6e 100644 --- a/src/controllers/DevelopmentScholarshipController.ts +++ b/src/controllers/DevelopmentScholarshipController.ts @@ -27,8 +27,7 @@ import { PosType } from "../entities/PosType"; import { PosLevel } from "../entities/PosLevel"; import CallAPI from "../interfaces/call-api"; import { RequestWithUser } from "../middlewares/user"; -import { addLogSequence, setLogDataDiff } from "../interfaces/utils"; -import { request } from "axios"; +import { setLogDataDiff } from "../interfaces/utils"; import permission from "../interfaces/permission"; @Route("api/v1/development/scholarship") diff --git a/src/controllers/MyController.ts b/src/controllers/MyController.ts index 2e5f1bd..7f14906 100644 --- a/src/controllers/MyController.ts +++ b/src/controllers/MyController.ts @@ -1,4 +1,4 @@ -import { Controller, Get, Post, Put, Delete, Patch, Route, Security, Tags } from "tsoa"; +import { Controller, Get, Route, Security, Tags } from "tsoa"; @Route("/hello") @Tags("Test") diff --git a/src/controllers/PortfolioController.ts b/src/controllers/PortfolioController.ts index 68de02e..e4d174c 100644 --- a/src/controllers/PortfolioController.ts +++ b/src/controllers/PortfolioController.ts @@ -20,7 +20,7 @@ import HttpError from "../interfaces/http-error"; import { Not } from "typeorm"; import { CreatePortfolio, Portfolio } from "../entities/Portfolio"; import { RequestWithUser } from "../middlewares/user"; -import { addLogSequence, setLogDataDiff } from "../interfaces/utils"; +import { setLogDataDiff } from "../interfaces/utils"; @Route("api/v1/development/portfolio") @Tags("Portfolio") diff --git a/src/controllers/ReportController.ts b/src/controllers/ReportController.ts index e1bbd9b..ba4dd6d 100644 --- a/src/controllers/ReportController.ts +++ b/src/controllers/ReportController.ts @@ -1,28 +1,10 @@ -import { - Controller, - Get, - Post, - Put, - Delete, - Route, - Security, - Tags, - Body, - Path, - Request, - Query, -} from "tsoa"; +import { Controller, Get, Post, Route, Security, Tags, Body, Path } from "tsoa"; import { AppDataSource } from "../database/data-source"; -import { Brackets, Not } from "typeorm"; import HttpSuccess from "../interfaces/http-success"; import HttpError from "../interfaces/http-error"; import HttpStatusCode from "../interfaces/http-status"; import { Development } from "../entities/Development"; -import { - CreateDevelopmentHistory, - DevelopmentHistory, - UpdateDevelopmentHistory, -} from "../entities/DevelopmentHistory"; +import { DevelopmentHistory } from "../entities/DevelopmentHistory"; import { PosType } from "../entities/PosType"; import { PosLevel } from "../entities/PosLevel"; import Extension from "../interfaces/extension"; @@ -31,10 +13,6 @@ import { DevelopmentScholarship } from "../entities/DevelopmentScholarship"; @Tags("Report") @Security("bearerAuth") export class ReportController extends Controller { - private developmentHistoryRepository = AppDataSource.getRepository(DevelopmentHistory); - private developmentRepository = AppDataSource.getRepository(Development); - private posTypeRepository = AppDataSource.getRepository(PosType); - private posLevelRepository = AppDataSource.getRepository(PosLevel); private developmentScholarshipRepository = AppDataSource.getRepository(DevelopmentScholarship); /** @@ -285,10 +263,7 @@ export class ReportController extends Controller { getDevelopment.graduatedDate == null ? "" : Extension.ToThaiNumber(Extension.ToThaiFullDate3(getDevelopment.graduatedDate)), - graduatedReason: - getDevelopment.graduatedReason == null - ? "" - : getDevelopment.graduatedReason, + graduatedReason: getDevelopment.graduatedReason == null ? "" : getDevelopment.graduatedReason, useOfficialTime: getDevelopment.useOfficialTime, useOffTime: getDevelopment.useOfficialTime == true ? "🗹 ใช้ ☐ ไม่ใช้" : "☐ ใช้ 🗹 ไม่ใช้", isGraduated: getDevelopment.isGraduated, From 78ce7fa6126cb89c47176803731b7a16a2deb0bf Mon Sep 17 00:00:00 2001 From: kittapath Date: Tue, 3 Sep 2024 19:08:13 +0700 Subject: [PATCH 151/250] =?UTF-8?q?=E0=B9=81=E0=B8=81=E0=B9=89=20import=20?= =?UTF-8?q?data=20=E0=B9=84=E0=B8=A1=E0=B8=9E=E0=B8=9A=E0=B8=82=E0=B9=89?= =?UTF-8?q?=E0=B8=AD=E0=B8=A1=E0=B8=B9=E0=B8=A5=E0=B9=83=E0=B8=99=E0=B8=97?= =?UTF-8?q?=E0=B8=B0=E0=B9=80=E0=B8=9A=E0=B8=B5=E0=B8=A2=E0=B8=99=E0=B8=9B?= =?UTF-8?q?=E0=B8=A3=E0=B8=B0=E0=B8=A7=E0=B8=B1=E0=B8=95=E0=B8=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/DevelopmentController.ts | 52 ++++++++++++++++--- .../DevelopmentScholarshipController.ts | 46 ++++++++++++++++ 2 files changed, 92 insertions(+), 6 deletions(-) diff --git a/src/controllers/DevelopmentController.ts b/src/controllers/DevelopmentController.ts index da7f1d2..eb3ceea 100644 --- a/src/controllers/DevelopmentController.ts +++ b/src/controllers/DevelopmentController.ts @@ -36,10 +36,7 @@ import { Province } from "../entities/Province"; import { PosType } from "../entities/PosType"; import { PosLevel } from "../entities/PosLevel"; import { PlannedGoalPosition } from "../entities/PlannedGoalPosition"; -import { - CreateDevelopmentHistoryOBO, - DevelopmentHistory, -} from "../entities/DevelopmentHistory"; +import { CreateDevelopmentHistoryOBO, DevelopmentHistory } from "../entities/DevelopmentHistory"; import { DevelopmentProjectType } from "../entities/DevelopmentProjectType"; import { CreateDevelopmentEvaluation, @@ -2544,7 +2541,7 @@ export class DevelopmentController extends Controller { return; } if (item["ประเภท"] == undefined) return; - if (item["ประเภท"] == "ข้าราชการกรุงเทพมหานครสามัญ") { + if (item["ประเภท"] == "ข้าราชการกรุงเทพมหานครสามัญ" || item["ประเภท"] == "ขรก.กทม. สามัญ") { await new CallAPI() .GetData(request, `/org/unauthorize/officer/citizen/${item["รหัสประจำตัวประชาชน"]}`) .then(async (x: any) => { @@ -2628,7 +2625,7 @@ export class DevelopmentController extends Controller { await this.developmentHistoryRepository.save(development, { data: request }); setLogDataDiff(request, { before, after: development }); }); - } else { + } else if (item["ประเภท"] == "ลูกจ้างประจำ") { await new CallAPI() .GetData(request, `/org/unauthorize/employee/citizen/${item["รหัสประจำตัวประชาชน"]}`) .then(async (x: any) => { @@ -2712,6 +2709,49 @@ export class DevelopmentController extends Controller { await this.developmentHistoryRepository.save(development, { data: request }); setLogDataDiff(request, { before, after: development }); }); + } else { + let development = new DevelopmentHistory(); + let _null: any = null; + development.prefix = item["คำนำหน้า"] == undefined ? null : item["คำนำหน้า"]; + development.firstName = item["ชื่อ"] == undefined ? null : item["ชื่อ"]; + development.lastName = item["นามสกุล"] == undefined ? null : item["นามสกุล"]; + development.position = item["ตำแหน่ง"] == undefined ? null : item["ตำแหน่ง"]; + development.org = item["สังกัด"] == undefined ? null : item["สังกัด"]; + development.dateStart = + item["วันที่เริ่มต้น"] == undefined ? null : item["วันที่เริ่มต้น"]; + development.dateEnd = item["วันที่สิ้นสุด"] == undefined ? null : item["วันที่สิ้นสุด"]; + development.citizenId = + item["รหัสประจำตัวประชาชน"] == undefined ? _null : item["รหัสประจำตัวประชาชน"]; + development.type = "OTHER"; + development.order = + item["เลขที่คำสั่ง/เลขที่หนังสืออนุมัติ"] == undefined + ? null + : item["เลขที่คำสั่ง/เลขที่หนังสืออนุมัติ"]; + development.dateOrder = + item["คำสั่งลงวันที่/หนังสืออนุมัติลงวันที่"] == undefined + ? _null + : new Date(item["คำสั่งลงวันที่/หนังสืออนุมัติลงวันที่"]); + development.trainingDays = + item["จำนวนวันที่อบรม"] == undefined ? null : item["จำนวนวันที่อบรม"]; + development.posLevelId = null; + development.posTypeId = null; + development.employeePosLevelId = null; + development.employeePosTypeId = null; + development.developmentId = id; + development.createdUserId = request.user.sub; + development.createdFullName = request.user.name; + development.lastUpdateUserId = request.user.sub; + development.lastUpdateFullName = request.user.name; + development.createdAt = new Date(); + development.lastUpdatedAt = new Date(); + development.isProfile = false; + // addLogSequence(request, { + // action: "database", + // status: "success", + // description: "Store DevelopmentHistory.", + // }); + await this.developmentHistoryRepository.save(development, { data: request }); + setLogDataDiff(request, { before, after: development }); } }), ); diff --git a/src/controllers/DevelopmentScholarshipController.ts b/src/controllers/DevelopmentScholarshipController.ts index b6bdd6e..e12a503 100644 --- a/src/controllers/DevelopmentScholarshipController.ts +++ b/src/controllers/DevelopmentScholarshipController.ts @@ -359,6 +359,52 @@ export class DevelopmentScholarshipController extends Controller { return new HttpSuccess(formattedData); } + /** + * API แก้ไขทุนการศึกษา/ฝึกอบรม + * + * @summary DEV_012 - แก้ไขทุนการศึกษา/ฝึกอบรม #12 + * + * @param {string} id Id ข้าราชการฯที่ได้รับทุนการศึกษา + */ + @Put("admin/{id}") + async UpdateDevelopmentScholarshipAdminById( + @Path() id: string, + @Body() requestBody: UpdateDevelopmentScholarship, + @Request() request: RequestWithUser, + ) { + await new permission().PermissionUpdate(request, "SYS_DEV_SCHOLARSHIP"); + const development = await this.developmentScholarshipRepository.findOne({ + where: { id: id }, + }); + if (!development) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลทุนการศึกษา/ฝึกอบรมนี้"); + } + if (requestBody.posTypeId != null) { + const checkId = await this.posTypeRepository.findOne({ + where: { id: requestBody.posTypeId }, + }); + if (!checkId) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลประเภทตำแหน่ง"); + } + } + if (requestBody.posLevelId != null) { + const checkId = await this.posLevelRepository.findOne({ + where: { id: requestBody.posLevelId }, + }); + if (!checkId) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลระดับตำแหน่ง"); + } + } + const before = structuredClone(development); + Object.assign(development, requestBody); + development.lastUpdateUserId = request.user.sub; + development.lastUpdateFullName = request.user.name; + development.lastUpdatedAt = new Date(); + await this.developmentScholarshipRepository.save(development, { data: request }); + setLogDataDiff(request, { before, after: development }); + return new HttpSuccess(development.id); + } + /** * API รายละเอียดทุนการศึกษา/ฝึกอบรม ADMIN * From 28f8c87feaf69fc8d70d3e0d131621dae068e89c Mon Sep 17 00:00:00 2001 From: kittapath Date: Wed, 4 Sep 2024 09:57:05 +0700 Subject: [PATCH 152/250] =?UTF-8?q?=E0=B8=84=E0=B9=89=E0=B8=99=E0=B8=AB?= =?UTF-8?q?=E0=B8=B2=E0=B8=A5=E0=B8=B8=E0=B8=81=E0=B8=88=E0=B9=89=E0=B8=B2?= =?UTF-8?q?=E0=B8=87=E0=B8=9B=E0=B8=A3=E0=B8=B0=E0=B8=88=E0=B8=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/DevelopmentController.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/controllers/DevelopmentController.ts b/src/controllers/DevelopmentController.ts index eb3ceea..af8f250 100644 --- a/src/controllers/DevelopmentController.ts +++ b/src/controllers/DevelopmentController.ts @@ -2627,7 +2627,7 @@ export class DevelopmentController extends Controller { }); } else if (item["ประเภท"] == "ลูกจ้างประจำ") { await new CallAPI() - .GetData(request, `/org/unauthorize/employee/citizen/${item["รหัสประจำตัวประชาชน"]}`) + .GetData(request, `/org/unauthorize/employee-prem/citizen/${item["รหัสประจำตัวประชาชน"]}`) .then(async (x: any) => { let development = Object.assign(new DevelopmentHistory(), x); development.dateStart = From a6493dcb62be3200b0f2392616219fa022061ea7 Mon Sep 17 00:00:00 2001 From: kittapath Date: Wed, 4 Sep 2024 16:17:51 +0700 Subject: [PATCH 153/250] =?UTF-8?q?=E0=B9=81=E0=B8=81=E0=B9=89=E0=B8=AA?= =?UTF-8?q?=E0=B8=B4=E0=B8=97=E0=B8=98=E0=B8=B4=E0=B9=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/interfaces/permission.ts | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) diff --git a/src/interfaces/permission.ts b/src/interfaces/permission.ts index 1669018..2ea6b91 100644 --- a/src/interfaces/permission.ts +++ b/src/interfaces/permission.ts @@ -45,20 +45,9 @@ class CheckAuth { return null; } return await new CallAPI() - .GetData(req, "/org/permission/org") + .GetData(req, `/org/permission/org/${action}/${system}`) .then(async (x) => { - let privilege = null; - if (action.trim().toLocaleUpperCase() == "CREATE") - privilege = await this.PermissionCreate(req, system); - if (action.trim().toLocaleUpperCase() == "DELETE") - privilege = await this.PermissionDelete(req, system); - if (action.trim().toLocaleUpperCase() == "GET") - privilege = await this.PermissionGet(req, system); - if (action.trim().toLocaleUpperCase() == "LIST") - privilege = await this.PermissionList(req, system); - if (action.trim().toLocaleUpperCase() == "UPDATE") - privilege = await this.PermissionUpdate(req, system); - + let privilege = x.privilege; let data: any = { root: [null], child1: [null], From ea776021e33bd31847784ab510c97651f940358f Mon Sep 17 00:00:00 2001 From: kittapath Date: Fri, 6 Sep 2024 15:25:15 +0700 Subject: [PATCH 154/250] =?UTF-8?q?=E0=B9=81=E0=B8=81=E0=B9=89=20=E0=B8=AA?= =?UTF-8?q?=E0=B8=B4=E0=B8=97=E0=B8=98=E0=B8=B4=E0=B9=8C=E0=B9=83=E0=B8=AB?= =?UTF-8?q?=E0=B9=89=E0=B8=84=E0=B9=89=E0=B8=99=E0=B9=84=E0=B8=A7=E0=B8=82?= =?UTF-8?q?=E0=B8=B6=E0=B9=89=E0=B8=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/entities/Development.ts | 4 +-- src/entities/Province.ts | 2 +- src/interfaces/permission.ts | 52 ++++++++++++++++++++++-------------- 3 files changed, 35 insertions(+), 23 deletions(-) diff --git a/src/entities/Development.ts b/src/entities/Development.ts index 0a6fecd..eb4b00e 100644 --- a/src/entities/Development.ts +++ b/src/entities/Development.ts @@ -1,4 +1,4 @@ -import { Entity, Column, ManyToOne, JoinColumn, OneToMany, Double, ManyToMany } from "typeorm"; +import { Entity, Column, ManyToOne, JoinColumn, OneToMany, Double } from "typeorm"; import { EntityBase } from "./base/Base"; import { Province } from "./Province"; import { ActualPeople, CreateActualPeople } from "./ActualPeople"; @@ -8,7 +8,7 @@ import { CreatePlannedGoal, PlannedGoal } from "./PlannedGoal"; import { DevelopmentHistory } from "./DevelopmentHistory"; import { DevelopmentProjectType } from "./DevelopmentProjectType"; import { DevelopmentProjectTechniquePlanned } from "./DevelopmentProjectTechniquePlanned"; -import { CreateDevelopmentEvaluation, DevelopmentEvaluation } from "./DevelopmentEvaluation"; +import { DevelopmentEvaluation } from "./DevelopmentEvaluation"; import { CreateDevelopmentAddress, DevelopmentAddress } from "./DevelopmentAddress"; import { DevelopmentProjectTechniqueActual } from "./DevelopmentProjectTechniqueActual"; import { StrategyChild5 } from "./StrategyChild5"; diff --git a/src/entities/Province.ts b/src/entities/Province.ts index 7ba8848..a826b67 100644 --- a/src/entities/Province.ts +++ b/src/entities/Province.ts @@ -1,4 +1,4 @@ -import { Entity, Column, OneToMany, ManyToMany, JoinTable } from "typeorm"; +import { Entity, Column, OneToMany } from "typeorm"; import { EntityBase } from "./base/Base"; import { Development } from "./Development"; import { DevelopmentAddress } from "./DevelopmentAddress"; diff --git a/src/interfaces/permission.ts b/src/interfaces/permission.ts index 2ea6b91..fb2d669 100644 --- a/src/interfaces/permission.ts +++ b/src/interfaces/permission.ts @@ -42,12 +42,30 @@ class CheckAuth { req.headers["api_key"] && req.headers["api_key"] == process.env.API_KEY ) { - return null; + return { + root: null, + child1: null, + child2: null, + child3: null, + child4: null, + }; } return await new CallAPI() - .GetData(req, `/org/permission/org/${action}/${system}`) + .GetData(req, `/org/permission/org/${system}/${action}`) .then(async (x) => { + console.log(x); let privilege = x.privilege; + // if (action.trim().toLocaleUpperCase() == "CREATE") + // privilege = await this.PermissionCreate(req, system); + // if (action.trim().toLocaleUpperCase() == "DELETE") + // privilege = await this.PermissionDelete(req, system); + // if (action.trim().toLocaleUpperCase() == "GET") + // privilege = await this.PermissionGet(req, system); + // if (action.trim().toLocaleUpperCase() == "LIST") + // privilege = await this.PermissionList(req, system); + // if (action.trim().toLocaleUpperCase() == "UPDATE") + // privilege = await this.PermissionUpdate(req, system); + let data: any = { root: [null], child1: [null], @@ -124,25 +142,19 @@ class CheckAuth { return true; } return await new CallAPI() - .GetData(req, `/org/permission/user/${profileId}`) + .GetData(req, `/org/permission/user/${system}/${action}/${profileId}`) .then(async (x) => { - let org = { - root: [null], - child1: [null], - child2: [null], - child3: [null], - child4: [null], - }; - if (action.trim().toLocaleUpperCase() == "CREATE") - org = await this.PermissionOrgCreate(req, system); - if (action.trim().toLocaleUpperCase() == "DELETE") - org = await this.PermissionOrgDelete(req, system); - if (action.trim().toLocaleUpperCase() == "GET") - org = await this.PermissionOrgGet(req, system); - if (action.trim().toLocaleUpperCase() == "LIST") - org = await this.PermissionOrgList(req, system); - if (action.trim().toLocaleUpperCase() == "UPDATE") - org = await this.PermissionOrgUpdate(req, system); + let org = x.org; + // if (action.trim().toLocaleUpperCase() == "CREATE") + // org = await this.PermissionOrgCreate(req, system); + // if (action.trim().toLocaleUpperCase() == "DELETE") + // org = await this.PermissionOrgDelete(req, system); + // if (action.trim().toLocaleUpperCase() == "GET") + // org = await this.PermissionOrgGet(req, system); + // if (action.trim().toLocaleUpperCase() == "LIST") + // org = await this.PermissionOrgList(req, system); + // if (action.trim().toLocaleUpperCase() == "UPDATE") + // org = await this.PermissionOrgUpdate(req, system); if (org.root != null) if (x.orgRootId != org.root[0]) throw "ไม่มีสิทธิ์เข้าถึงข้อมูล"; if (org.child1 != null) From 9fdb2ef2e7d63bc238b42e65cc7f984cc3f2c118 Mon Sep 17 00:00:00 2001 From: AdisakKanthawilang Date: Thu, 12 Sep 2024 14:16:43 +0700 Subject: [PATCH 155/250] =?UTF-8?q?=E0=B9=80=E0=B8=9E=E0=B8=B4=E0=B9=88?= =?UTF-8?q?=E0=B8=A1=20parth=20api=20=E0=B9=83=E0=B8=8A=E0=B9=88=E0=B8=8B?= =?UTF-8?q?=E0=B9=89=E0=B8=B3=E0=B8=81=E0=B8=B1=E0=B8=99=E0=B9=83=E0=B8=99?= =?UTF-8?q?=E0=B8=AB=E0=B8=A5=E0=B8=B2=E0=B8=A2=E0=B9=80=E0=B8=A1=E0=B8=99?= =?UTF-8?q?=E0=B8=B9=20(=E0=B8=82=E0=B9=89=E0=B8=AD=E0=B8=A1=E0=B8=B9?= =?UTF-8?q?=E0=B8=A5=E0=B9=81=E0=B8=9A=E0=B8=9A=E0=B8=9B=E0=B8=99=E0=B8=B0?= =?UTF-8?q?=E0=B9=80=E0=B8=A1=E0=B8=B4=E0=B8=99>>>=E0=B8=95=E0=B8=B1?= =?UTF-8?q?=E0=B8=A7=E0=B8=8A=E0=B8=B5=E0=B9=89=E0=B8=A7=E0=B8=B1=E0=B8=94?= =?UTF-8?q?(=E0=B8=A3=E0=B8=B2=E0=B8=A2=E0=B8=A5=E0=B8=B0=E0=B9=80?= =?UTF-8?q?=E0=B8=AD=E0=B8=B5=E0=B8=A2=E0=B8=94=E0=B9=81=E0=B8=A5=E0=B8=B0?= =?UTF-8?q?=E0=B9=81=E0=B8=81=E0=B9=89=E0=B9=84=E0=B8=82=E0=B8=82=E0=B9=89?= =?UTF-8?q?=E0=B8=AD=E0=B8=A1=E0=B8=B9=E0=B8=A5))?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/StrategyController.ts | 50 +++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/src/controllers/StrategyController.ts b/src/controllers/StrategyController.ts index f0d781f..b4a03db 100644 --- a/src/controllers/StrategyController.ts +++ b/src/controllers/StrategyController.ts @@ -20,6 +20,55 @@ export class StrategyController extends Controller { private strategy3Repo = AppDataSource.getRepository(StrategyChild3); private strategy4Repo = AppDataSource.getRepository(StrategyChild4); private strategy5Repo = AppDataSource.getRepository(StrategyChild5); + + @Get("indicator") + public async listStrategyChild(@Request() request: RequestWithUser) { + let _data = await new permission().PermissionList(request, "SYS_EVA_INDICATOR"); + const listStrategyChild1 = await this.strategy1Repo.find({ + relations: [ + "strategyChild2s", + "strategyChild2s.strategyChild3s", + "strategyChild2s.strategyChild3s.strategyChild4s", + "strategyChild2s.strategyChild3s.strategyChild4s.strategyChild5s", + ], + order: { createdAt: "ASC" }, + }); + + const formattedData = listStrategyChild1.map((item) => ({ + id: item.id, + level: 1, + name: item.strategyChild1Name, + children: item.strategyChild2s.map((child2) => ({ + id: child2.id, + level: 2, + name: child2.strategyChild2Name, + children: child2.strategyChild3s + ? child2.strategyChild3s.map((child3) => ({ + id: child3.id, + level: 3, + name: child3.strategyChild3Name, + children: child3.strategyChild4s + ? child3.strategyChild4s.map((child4) => ({ + id: child4.id, + level: 4, + name: child4.strategyChild4Name, + children: child4.strategyChild5s + ? child4.strategyChild5s.map((child5) => ({ + id: child5.id, + level: 5, + name: child5.strategyChild5Name, + })) + : [], + })) + : [], + })) + : [], + })), + })); + + return new HttpSuccess(formattedData); + } + @Get("edit") public async listStrategyChild1Edit(@Request() request: RequestWithUser) { let _data = await new permission().PermissionList(request, "SYS_EVA_STRATIGIC"); @@ -71,6 +120,7 @@ export class StrategyController extends Controller { return new HttpSuccess(formattedData); } + @Get() public async listStrategyChild1(@Request() request: RequestWithUser) { const listStrategyChild1 = await this.strategy1Repo.find({ From e27e74559f831b562234b4a2737985fd7fe757cd Mon Sep 17 00:00:00 2001 From: AdisakKanthawilang Date: Fri, 13 Sep 2024 09:44:53 +0700 Subject: [PATCH 156/250] =?UTF-8?q?=E0=B9=81=E0=B8=81=E0=B9=89=E0=B9=84?= =?UTF-8?q?=E0=B8=82=E0=B8=8A=E0=B8=B7=E0=B9=88=E0=B8=AD=E0=B8=AA=E0=B8=B4?= =?UTF-8?q?=E0=B8=97=E0=B8=98=E0=B8=B4=E0=B9=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/DevelopmentController.ts | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/src/controllers/DevelopmentController.ts b/src/controllers/DevelopmentController.ts index af8f250..0a48802 100644 --- a/src/controllers/DevelopmentController.ts +++ b/src/controllers/DevelopmentController.ts @@ -1530,7 +1530,8 @@ export class DevelopmentController extends Controller { */ @Get("tab7/{id}") async GetDevelopemtTab7ById(@Request() request: RequestWithUser, @Path() id: string) { - await new permission().PermissionGet(request, "SYS_DEV_SCHOLARSHIP"); + // await new permission().PermissionGet(request, "SYS_DEV_SCHOLARSHIP"); + await new permission().PermissionGet(request, "SYS_DEV_PROJECT"); const getDevelopment = await this.developmentRepository.findOne({ where: { id }, }); @@ -1555,7 +1556,8 @@ export class DevelopmentController extends Controller { */ @Get("tab8/{id}") async GetDevelopemtTab8ById(@Request() request: RequestWithUser, @Path() id: string) { - await new permission().PermissionGet(request, "SYS_DEV_SCHOLARSHIP"); + // await new permission().PermissionGet(request, "SYS_DEV_SCHOLARSHIP"); + await new permission().PermissionGet(request, "SYS_DEV_PROJECT"); const getDevelopment = await this.developmentRepository.findOne({ relations: ["developmentRisks"], where: { id: id }, @@ -2003,7 +2005,8 @@ export class DevelopmentController extends Controller { */ @Get("tab1/{id}") async GetDevelopemtTab1ById(@Request() request: RequestWithUser, @Path() id: string) { - await new permission().PermissionGet(request, "SYS_DEV_SCHOLARSHIP"); + // await new permission().PermissionGet(request, "SYS_DEV_SCHOLARSHIP"); + await new permission().PermissionGet(request, "SYS_DEV_PROJECT"); const getDevelopment = await this.developmentRepository.findOne({ where: { id: id }, }); @@ -2056,7 +2059,8 @@ export class DevelopmentController extends Controller { */ @Get("tab2/{id}") async GetDevelopemtTab2ById(@Request() request: RequestWithUser, @Path() id: string) { - await new permission().PermissionGet(request, "SYS_DEV_SCHOLARSHIP"); + // await new permission().PermissionGet(request, "SYS_DEV_SCHOLARSHIP"); + await new permission().PermissionGet(request, "SYS_DEV_PROJECT"); const getDevelopment = await this.developmentRepository.findOne({ where: { id: id }, relations: [ @@ -2151,7 +2155,8 @@ export class DevelopmentController extends Controller { */ @Get("tab3/{id}") async GetDevelopemtTab3ById(@Request() request: RequestWithUser, @Path() id: string) { - await new permission().PermissionGet(request, "SYS_DEV_SCHOLARSHIP"); + // await new permission().PermissionGet(request, "SYS_DEV_SCHOLARSHIP"); + await new permission().PermissionGet(request, "SYS_DEV_PROJECT"); const getDevelopment = await this.developmentRepository.findOne({ where: { id: id }, relations: [ @@ -2260,7 +2265,8 @@ export class DevelopmentController extends Controller { */ @Get("tab4/{id}") async GetDevelopemtTab4ById(@Request() request: RequestWithUser, @Path() id: string) { - await new permission().PermissionGet(request, "SYS_DEV_SCHOLARSHIP"); + // await new permission().PermissionGet(request, "SYS_DEV_SCHOLARSHIP"); + await new permission().PermissionGet(request, "SYS_DEV_PROJECT"); const getDevelopment = await this.developmentRepository.findOne({ where: { id: id }, relations: ["developmentEvaluations"], @@ -2293,7 +2299,8 @@ export class DevelopmentController extends Controller { */ @Get("tab5/{id}") async GetDevelopemtTab5ById(@Request() request: RequestWithUser, @Path() id: string) { - await new permission().PermissionGet(request, "SYS_DEV_SCHOLARSHIP"); + // await new permission().PermissionGet(request, "SYS_DEV_SCHOLARSHIP"); + await new permission().PermissionGet(request, "SYS_DEV_PROJECT"); const getDevelopment = await this.developmentRepository.findOne({ relations: ["developmentOthers"], where: { id: id }, From 0be33a3f3a0071333b4b1eec13e9bbd69de96956 Mon Sep 17 00:00:00 2001 From: AdisakKanthawilang Date: Fri, 13 Sep 2024 11:07:04 +0700 Subject: [PATCH 157/250] =?UTF-8?q?=E0=B9=81=E0=B8=81=E0=B9=89=E0=B9=80?= =?UTF-8?q?=E0=B8=AA=E0=B9=89=E0=B8=99=20/api/v1/development/strategy/edit?= =?UTF-8?q?=20=E0=B9=80=E0=B8=9E=E0=B8=B4=E0=B9=88=E0=B8=A1=20/{page}?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/StrategyController.ts | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/controllers/StrategyController.ts b/src/controllers/StrategyController.ts index a0ed9eb..066b942 100644 --- a/src/controllers/StrategyController.ts +++ b/src/controllers/StrategyController.ts @@ -1,4 +1,4 @@ -import { Body, Controller, Delete, Get, Patch, Post, Request, Route, Security, Tags } from "tsoa"; +import { Body, Controller, Delete, Get, Patch, Path, Post, Request, Route, Security, Tags } from "tsoa"; import { AppDataSource } from "../database/data-source"; import { StrategyChild1 } from "../entities/StrategyChild1"; import { StrategyChild2 } from "../entities/StrategyChild2"; @@ -20,7 +20,7 @@ export class StrategyController extends Controller { private strategy3Repo = AppDataSource.getRepository(StrategyChild3); private strategy4Repo = AppDataSource.getRepository(StrategyChild4); private strategy5Repo = AppDataSource.getRepository(StrategyChild5); - + @Get("indicator") public async listStrategyChild(@Request() request: RequestWithUser) { let _data = await new permission().PermissionList(request, "SYS_EVA_INDICATOR"); @@ -69,9 +69,18 @@ export class StrategyController extends Controller { return new HttpSuccess(formattedData); } - @Get("edit") - public async listStrategyChild1Edit(@Request() request: RequestWithUser) { - let _data = await new permission().PermissionList(request, "SYS_EVA_STRATIGIC"); + @Get("edit/{page}") + public async listStrategyChild1Edit(@Request() request: RequestWithUser, @Path() page: string) { + let _page = page.trim().toUpperCase(); + if (_page == "STRATEGIC") { + await new permission().PermissionList(request, "SYS_EVA_STRATIGIC"); + } else if (_page == "DEVELOP") { + await new permission().PermissionGet(request, "SYS_DEV_PROJECT"); + } else if (_page == "INDICATOR") { + await new permission().PermissionGet(request, "SYS_EVA_INDICATOR"); + } else { + await new permission().PermissionList(request, "SYS_EVA_STRATIGIC"); + } const listStrategyChild1 = await this.strategy1Repo.find({ relations: [ "strategyChild2s", From f8a91f60ba07101fc767041895bb6b29e71e2b6f Mon Sep 17 00:00:00 2001 From: kittapath Date: Mon, 30 Sep 2024 09:45:36 +0700 Subject: [PATCH 158/250] =?UTF-8?q?=E0=B9=81=E0=B8=81=E0=B9=89=20call=20ap?= =?UTF-8?q?i?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/interfaces/call-api.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/interfaces/call-api.ts b/src/interfaces/call-api.ts index 78f0f14..f3d1b6f 100644 --- a/src/interfaces/call-api.ts +++ b/src/interfaces/call-api.ts @@ -17,7 +17,7 @@ import { addLogSequence } from "./utils"; class CallAPI { //Get public async GetData(request: any, @Path() path: any) { - const token = request.headers.authorization; + const token = "Bearer " + request.headers.authorization.replace("Bearer ", ""); const url = process.env.API_URL + path; try { const response = await axios.get(url, { @@ -54,7 +54,7 @@ class CallAPI { } //Post 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; try { const response = await axios.post(url, sendData, { From aa3bbac5a5ebee7b40ce3000497073519dfee72c Mon Sep 17 00:00:00 2001 From: AdisakKanthawilang Date: Mon, 30 Sep 2024 15:30:04 +0700 Subject: [PATCH 159/250] add search #619 --- src/controllers/PortfolioController.ts | 41 +++++++++++++++++--------- 1 file changed, 27 insertions(+), 14 deletions(-) diff --git a/src/controllers/PortfolioController.ts b/src/controllers/PortfolioController.ts index e4d174c..7eac17d 100644 --- a/src/controllers/PortfolioController.ts +++ b/src/controllers/PortfolioController.ts @@ -12,6 +12,7 @@ import { SuccessResponse, Response, Get, + Query, } from "tsoa"; import { AppDataSource } from "../database/data-source"; import HttpSuccess from "../interfaces/http-success"; @@ -21,6 +22,7 @@ import { Not } from "typeorm"; import { CreatePortfolio, Portfolio } from "../entities/Portfolio"; import { RequestWithUser } from "../middlewares/user"; import { setLogDataDiff } from "../interfaces/utils"; +import { Brackets } from "typeorm"; @Route("api/v1/development/portfolio") @Tags("Portfolio") @@ -40,20 +42,31 @@ export class PortfolioController extends Controller { * */ @Get() - async GetResult(@Request() request: RequestWithUser) { - const _portfolio = await this.portfolioRepository.find({ - where: { createdUserId: request.user.sub }, - select: [ - "id", - "name", - "detail", - "createdAt", - "lastUpdatedAt", - "createdFullName", - "lastUpdateFullName", - ], - order: { name: "ASC" }, - }); + async GetResult(@Request() request: RequestWithUser, @Query("keyword") keyword?: string) { + const _portfolio = await this.portfolioRepository + .createQueryBuilder("portfolio") + .select([ + "portfolio.id", + "portfolio.name", + "portfolio.detail", + "portfolio.createdAt", + "portfolio.lastUpdatedAt", + "portfolio.createdFullName", + "portfolio.lastUpdateFullName", + ]) + .where("portfolio.createdUserId = :userId", { userId: request.user.sub }) + .andWhere( + new Brackets((qb) => { + qb.where(keyword != null && keyword != "" ? "portfolio.name LIKE :keyword" : "1=1", { + keyword: `%${keyword}%`, + }).orWhere(keyword != null && keyword != "" ? "portfolio.detail LIKE :keyword" : "1=1", { + keyword: `%${keyword}%`, + }); + }), + ) + .getMany(); + + return new HttpSuccess(_portfolio); } From a5b57f287d9f5301a69724127e659d35bd158464 Mon Sep 17 00:00:00 2001 From: AdisakKanthawilang Date: Mon, 30 Sep 2024 17:01:31 +0700 Subject: [PATCH 160/250] fix --- src/controllers/PortfolioController.ts | 61 ++++++++++++++++---------- 1 file changed, 37 insertions(+), 24 deletions(-) diff --git a/src/controllers/PortfolioController.ts b/src/controllers/PortfolioController.ts index 7eac17d..c690fa1 100644 --- a/src/controllers/PortfolioController.ts +++ b/src/controllers/PortfolioController.ts @@ -42,31 +42,44 @@ export class PortfolioController extends Controller { * */ @Get() - async GetResult(@Request() request: RequestWithUser, @Query("keyword") keyword?: string) { - const _portfolio = await this.portfolioRepository - .createQueryBuilder("portfolio") - .select([ - "portfolio.id", - "portfolio.name", - "portfolio.detail", - "portfolio.createdAt", - "portfolio.lastUpdatedAt", - "portfolio.createdFullName", - "portfolio.lastUpdateFullName", - ]) - .where("portfolio.createdUserId = :userId", { userId: request.user.sub }) - .andWhere( - new Brackets((qb) => { - qb.where(keyword != null && keyword != "" ? "portfolio.name LIKE :keyword" : "1=1", { - keyword: `%${keyword}%`, - }).orWhere(keyword != null && keyword != "" ? "portfolio.detail LIKE :keyword" : "1=1", { - keyword: `%${keyword}%`, - }); - }), - ) - .getMany(); - + async GetResult(@Request() request: RequestWithUser) { + const _portfolio = await this.portfolioRepository.find({ + where: { createdUserId: request.user.sub }, + select: [ + "id", + "name", + "detail", + "createdAt", + "lastUpdatedAt", + "createdFullName", + "lastUpdateFullName", + ], + order: { name: "ASC" }, + }); + // const _portfolio = await this.portfolioRepository + // .createQueryBuilder("portfolio") + // .select([ + // "portfolio.id", + // "portfolio.name", + // "portfolio.detail", + // "portfolio.createdAt", + // "portfolio.lastUpdatedAt", + // "portfolio.createdFullName", + // "portfolio.lastUpdateFullName", + // ]) + // .where("portfolio.createdUserId = :userId", { userId: request.user.sub }) + // .andWhere( + // new Brackets((qb) => { + // qb.where(keyword != null && keyword != "" ? "portfolio.name LIKE :keyword" : "1=1", { + // keyword: `%${keyword}%`, + // }).orWhere(keyword != null && keyword != "" ? "portfolio.detail LIKE :keyword" : "1=1", { + // keyword: `%${keyword}%`, + // }); + // }), + // ) + // .getMany(); + return new HttpSuccess(_portfolio); } From e87e760075ae072507545b33db42e09fd7ab2d55 Mon Sep 17 00:00:00 2001 From: kittapath Date: Tue, 1 Oct 2024 00:41:09 +0700 Subject: [PATCH 161/250] comment --- src/controllers/DevelopmentController.ts | 91 +++++++++++++++++++++++- src/entities/DevelopmentHistory.ts | 7 +- src/interfaces/call-api.ts | 14 +--- 3 files changed, 97 insertions(+), 15 deletions(-) diff --git a/src/controllers/DevelopmentController.ts b/src/controllers/DevelopmentController.ts index 0a48802..1a37ea2 100644 --- a/src/controllers/DevelopmentController.ts +++ b/src/controllers/DevelopmentController.ts @@ -2344,6 +2344,7 @@ export class DevelopmentController extends Controller { relations: ["posLevel", "posType", "employeePosLevel", "employeePosType"], order: { isDone: "ASC", + isDoneIDP: "ASC", citizenId: "ASC", }, }); @@ -2380,6 +2381,7 @@ export class DevelopmentController extends Controller { dateStart: item.dateStart, dateEnd: item.dateEnd, isDone: item.isDone, + isDoneIDP: item.isDoneIDP, isProfile: item.isProfile, })); return new HttpSuccess(_getDevelopment); @@ -2461,6 +2463,90 @@ export class DevelopmentController extends Controller { return new HttpSuccess(getDevelopment); } + /** + * API รายละเอียดโครงการ/หลักสูตรการฝึกอบรม tab6 IDP ส่งบันทึกทะเบียนประวัติ + * + * @summary DEV_00 - รายละเอียดโครงการ/หลักสูตรการฝึกอบรมtab6 IDP ส่งบันทึกทะเบียนประวัติ # + * + * @param {string} id Id โครงการ + */ + @Get("tab6/done-idp/{id}") + async GetDevelopemtTab6IDPDoneById(@Path() id: string, @Request() request: RequestWithUser) { + const getDevelopment = await this.developmentHistoryRepository.find({ + where: { developmentId: id, isDoneIDP: false }, + relations: ["development"], + }); + await Promise.all( + getDevelopment.map(async (x) => { + const _data = Object.assign(new DevelopmentHistory(), x); + if (x.type == "OFFICER") { + await new CallAPI() + .PostData(request, "/org/profile/development", { + type: "DEVELOP", + profileId: x.profileId, + name: "", + target: "", + // achievement10: x.development.achievement10, + // achievement5: x.development.achievement5, + // achievement0: x.development.achievement0, + kpiDevelopmentId: x.development.id, + reasonDevelopment70: x.development.reasonActual70, + reasonDevelopment20: x.development.reasonActual20, + reasonDevelopment10: x.development.reasonActual10, + isDevelopment70: false, + isDevelopment20: false, + isDevelopment10: false, + // summary: x.development.summary, + // point: x.development.point, + }) + .then((x) => { + _data.isDoneIDP = true; + }) + .catch((x) => { + _data.isDoneIDP = false; + }); + } else if (x.type == "EMPLOYEE") { + await new CallAPI() + .PostData(request, "/org/profile-employee/development", { + type: "DEVELOP", + profileEmployeeId: x.profileId, + name: "", + target: "", + // achievement10: x.development.achievement10, + // achievement5: x.development.achievement5, + // achievement0: x.development.achievement0, + kpiDevelopmentId: x.development.id, + reasonDevelopment70: x.development.reasonActual70, + reasonDevelopment20: x.development.reasonActual20, + reasonDevelopment10: x.development.reasonActual10, + isDevelopment70: false, + isDevelopment20: false, + isDevelopment10: false, + // summary: x.development.summary, + // point: x.development.point, + }) + .then((x) => { + _data.isDoneIDP = true; + }) + .catch((x) => { + _data.isDoneIDP = false; + }); + } + + _data.lastUpdateUserId = request.user.sub; + _data.lastUpdateFullName = request.user.name; + _data.lastUpdatedAt = new Date(); + // addLogSequence(request, { + // action: "database", + // status: "success", + // description: "Store DevelopmentHistory.", + // }); + await this.developmentHistoryRepository.save(_data, { data: request }); + }), + ); + return new HttpSuccess(getDevelopment); + } + /** * API list หน่วยงาน * @@ -2634,7 +2720,10 @@ export class DevelopmentController extends Controller { }); } else if (item["ประเภท"] == "ลูกจ้างประจำ") { await new CallAPI() - .GetData(request, `/org/unauthorize/employee-prem/citizen/${item["รหัสประจำตัวประชาชน"]}`) + .GetData( + request, + `/org/unauthorize/employee-prem/citizen/${item["รหัสประจำตัวประชาชน"]}`, + ) .then(async (x: any) => { let development = Object.assign(new DevelopmentHistory(), x); development.dateStart = diff --git a/src/entities/DevelopmentHistory.ts b/src/entities/DevelopmentHistory.ts index f283e28..eeb61a1 100644 --- a/src/entities/DevelopmentHistory.ts +++ b/src/entities/DevelopmentHistory.ts @@ -216,6 +216,12 @@ export class DevelopmentHistory extends EntityBase { }) isDone: boolean; + @Column({ + comment: "บันทึก IDP ที่ทะเบียนประวัติ", + default: false, + }) + isDoneIDP: boolean; + @Column({ comment: "มีข้อมูลอยู่ในทะเบียนประวัติ", default: false, @@ -320,4 +326,3 @@ export class CreateDevelopmentHistoryOBO { @Column() dateEnd: Date | null; } - diff --git a/src/interfaces/call-api.ts b/src/interfaces/call-api.ts index f3d1b6f..711dc95 100644 --- a/src/interfaces/call-api.ts +++ b/src/interfaces/call-api.ts @@ -1,16 +1,4 @@ -import { - Controller, - Request, - Get, - Post, - Put, - Delete, - Patch, - Route, - Security, - Tags, - Path, -} from "tsoa"; +import { Path } from "tsoa"; import axios from "axios"; import { addLogSequence } from "./utils"; From 306902156897ef0cd954f16b30d5a32f5de903b8 Mon Sep 17 00:00:00 2001 From: kittapath Date: Tue, 1 Oct 2024 01:03:13 +0700 Subject: [PATCH 162/250] no message --- .../1723605750693-import0508241320.ts | 28 ------------------- ...429-update_developmentHis_add_isDoneIDP.ts | 14 ++++++++++ 2 files changed, 14 insertions(+), 28 deletions(-) delete mode 100644 src/migration/1723605750693-import0508241320.ts create mode 100644 src/migration/1727719189429-update_developmentHis_add_isDoneIDP.ts diff --git a/src/migration/1723605750693-import0508241320.ts b/src/migration/1723605750693-import0508241320.ts deleted file mode 100644 index 97a5c4b..0000000 --- a/src/migration/1723605750693-import0508241320.ts +++ /dev/null @@ -1,28 +0,0 @@ -import { MigrationInterface, QueryRunner } from "typeorm"; - -export class Import05082413201723605750693 implements MigrationInterface { - name = 'Import05082413201723605750693' - - public async up(queryRunner: QueryRunner): Promise { - await queryRunner.query(`CREATE TABLE \`developmentRisk\` (\`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', \`issues\` varchar(255) NULL COMMENT 'ประเด็นความเสี่ยง', \`chance\` int NULL COMMENT 'โอกาสที่จะเกิด', \`effects\` int NULL COMMENT 'ผลกระทบจากการเกิด', \`riskLevel\` varchar(255) NULL COMMENT 'ระดับความเสี่ยง', \`riskManagement\` varchar(255) NULL COMMENT 'เเนวทางการบริหารความเสี่ยง', \`developmentId\` varchar(255) NULL COMMENT 'คีย์นอก(FK)ของตาราง development', PRIMARY KEY (\`id\`)) ENGINE=InnoDB`); - await queryRunner.query(`CREATE TABLE \`developmentOther\` (\`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', \`topicAcademic\` varchar(255) NULL COMMENT 'หัวข้อ/ประเด็นการฝึกอบรม ศึกษาดูงาน', \`addressAcademic\` varchar(255) NULL COMMENT 'สถานที่ฝึกอบรม ศึกษาดูงาน', \`provinceActualId\` varchar(255) NULL COMMENT 'จังหวัด(ข้อมูลวิชาการ)', \`developmentId\` varchar(255) NULL COMMENT 'คีย์นอก(FK)ของตาราง development', PRIMARY KEY (\`id\`)) ENGINE=InnoDB`); - await queryRunner.query(`ALTER TABLE \`development\` ADD \`progressTracking\` longtext NULL COMMENT 'การติดตามความก้าวหน้า'`); - await queryRunner.query(`ALTER TABLE \`development\` ADD \`projectEvaluation\` longtext NULL COMMENT 'การประเมินผลโครงการ'`); - await queryRunner.query(`ALTER TABLE \`development\` ADD \`obstacle\` longtext NULL COMMENT 'ปัญหาอุปสรรค'`); - await queryRunner.query(`ALTER TABLE \`development\` ADD \`suggestion\` longtext NULL COMMENT 'ข้อเสนอแนะ'`); - await queryRunner.query(`ALTER TABLE \`developmentRisk\` ADD CONSTRAINT \`FK_b1990ff92f534f65a4653ef1671\` FOREIGN KEY (\`developmentId\`) REFERENCES \`development\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`); - await queryRunner.query(`ALTER TABLE \`developmentOther\` ADD CONSTRAINT \`FK_d5dfdb7ca0d11c0cdf3b3a55e6f\` FOREIGN KEY (\`developmentId\`) REFERENCES \`development\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`); - } - - public async down(queryRunner: QueryRunner): Promise { - await queryRunner.query(`ALTER TABLE \`developmentOther\` DROP FOREIGN KEY \`FK_d5dfdb7ca0d11c0cdf3b3a55e6f\``); - await queryRunner.query(`ALTER TABLE \`developmentRisk\` DROP FOREIGN KEY \`FK_b1990ff92f534f65a4653ef1671\``); - await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`suggestion\``); - await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`obstacle\``); - await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`projectEvaluation\``); - await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`progressTracking\``); - await queryRunner.query(`DROP TABLE \`developmentOther\``); - await queryRunner.query(`DROP TABLE \`developmentRisk\``); - } - -} diff --git a/src/migration/1727719189429-update_developmentHis_add_isDoneIDP.ts b/src/migration/1727719189429-update_developmentHis_add_isDoneIDP.ts new file mode 100644 index 0000000..c577bb8 --- /dev/null +++ b/src/migration/1727719189429-update_developmentHis_add_isDoneIDP.ts @@ -0,0 +1,14 @@ +import { MigrationInterface, QueryRunner } from "typeorm"; + +export class UpdateDevelopmentHisAddIsDoneIDP1727719189429 implements MigrationInterface { + name = 'UpdateDevelopmentHisAddIsDoneIDP1727719189429' + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`developmentHistory\` ADD \`isDoneIDP\` tinyint NOT NULL COMMENT 'บันทึก IDP ที่ทะเบียนประวัติ' DEFAULT 0`); + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`developmentHistory\` DROP COLUMN \`isDoneIDP\``); + } + +} From 2dce85a207793b6974ed4a60d96486a8c09ad504 Mon Sep 17 00:00:00 2001 From: kittapath Date: Tue, 1 Oct 2024 01:14:18 +0700 Subject: [PATCH 163/250] no message --- src/controllers/DevelopmentController.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/controllers/DevelopmentController.ts b/src/controllers/DevelopmentController.ts index 1a37ea2..c476bc3 100644 --- a/src/controllers/DevelopmentController.ts +++ b/src/controllers/DevelopmentController.ts @@ -2474,7 +2474,7 @@ export class DevelopmentController extends Controller { async GetDevelopemtTab6IDPDoneById(@Path() id: string, @Request() request: RequestWithUser) { const getDevelopment = await this.developmentHistoryRepository.find({ where: { developmentId: id, isDoneIDP: false }, - relations: ["development"], + relations: ["development", "development.developmentProjectTechniqueActuals"], }); await Promise.all( getDevelopment.map(async (x) => { @@ -2498,6 +2498,9 @@ export class DevelopmentController extends Controller { isDevelopment10: false, // summary: x.development.summary, // point: x.development.point, + developmentProjects: x.development.developmentProjectTechniqueActuals.map( + (x) => x.name, + ), }) .then((x) => { _data.isDoneIDP = true; @@ -2524,6 +2527,9 @@ export class DevelopmentController extends Controller { isDevelopment10: false, // summary: x.development.summary, // point: x.development.point, + developmentProjects: x.development.developmentProjectTechniqueActuals.map( + (x) => x.name, + ), }) .then((x) => { _data.isDoneIDP = true; From 1deee019b2b760edd070bbb622d490da6a7a98f2 Mon Sep 17 00:00:00 2001 From: kittapath Date: Tue, 1 Oct 2024 10:31:25 +0700 Subject: [PATCH 164/250] =?UTF-8?q?=E0=B9=81=E0=B8=81=E0=B9=89=E0=B8=9F?= =?UTF-8?q?=E0=B8=B4=E0=B8=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/DevelopmentController.ts | 43 +++++++++------ src/entities/Development.ts | 55 ++++++++++++++++++- ...update_development_add_isReasonActual70.ts | 24 ++++++++ 3 files changed, 102 insertions(+), 20 deletions(-) create mode 100644 src/migration/1727753251629-update_development_add_isReasonActual70.ts diff --git a/src/controllers/DevelopmentController.ts b/src/controllers/DevelopmentController.ts index c476bc3..154e511 100644 --- a/src/controllers/DevelopmentController.ts +++ b/src/controllers/DevelopmentController.ts @@ -2189,9 +2189,15 @@ export class DevelopmentController extends Controller { reasonActual70: getDevelopment.reasonActual70, reasonActual20: getDevelopment.reasonActual20, reasonActual10: getDevelopment.reasonActual10, + isReasonActual70: getDevelopment.isReasonActual70, + isReasonActual20: getDevelopment.isReasonActual20, + isReasonActual10: getDevelopment.isReasonActual10, reasonPlanned70: getDevelopment.reasonPlanned70, reasonPlanned20: getDevelopment.reasonPlanned20, reasonPlanned10: getDevelopment.reasonPlanned10, + isReasonPlanned70: getDevelopment.isReasonPlanned70, + isReasonPlanned20: getDevelopment.isReasonPlanned20, + isReasonPlanned10: getDevelopment.isReasonPlanned10, developmentProjectTechniqueActuals: getDevelopment.developmentProjectTechniqueActuals .map((x) => x.name) .sort(), @@ -2244,6 +2250,9 @@ export class DevelopmentController extends Controller { reasonActual70: getDevelopment.reasonActual70, reasonActual20: getDevelopment.reasonActual20, reasonActual10: getDevelopment.reasonActual10, + isReasonActual70: getDevelopment.isReasonActual70, + isReasonActual20: getDevelopment.isReasonActual20, + isReasonActual10: getDevelopment.isReasonActual10, developmentProjectTechniqueActuals: getDevelopment.developmentProjectTechniqueActuals .map((x) => x.name) .sort(), @@ -2484,20 +2493,20 @@ export class DevelopmentController extends Controller { .PostData(request, "/org/profile/development", { type: "DEVELOP", profileId: x.profileId, - name: "", - target: "", - // achievement10: x.development.achievement10, - // achievement5: x.development.achievement5, - // achievement0: x.development.achievement0, + name: x.development.projectName, + achievement10: null, + achievement5: null, + achievement0: null, kpiDevelopmentId: x.development.id, reasonDevelopment70: x.development.reasonActual70, reasonDevelopment20: x.development.reasonActual20, reasonDevelopment10: x.development.reasonActual10, - isDevelopment70: false, - isDevelopment20: false, - isDevelopment10: false, - // summary: x.development.summary, - // point: x.development.point, + isDevelopment70: x.development.isReasonActual70, + isDevelopment20: x.development.isReasonActual20, + isDevelopment10: x.development.isReasonActual10, + developmentTarget: null, + developmentResults: null, + developmentReport: null, developmentProjects: x.development.developmentProjectTechniqueActuals.map( (x) => x.name, ), @@ -2513,11 +2522,10 @@ export class DevelopmentController extends Controller { .PostData(request, "/org/profile-employee/development", { type: "DEVELOP", profileEmployeeId: x.profileId, - name: "", - target: "", - // achievement10: x.development.achievement10, - // achievement5: x.development.achievement5, - // achievement0: x.development.achievement0, + name: x.development.projectName, + achievement10: null, + achievement5: null, + achievement0: null, kpiDevelopmentId: x.development.id, reasonDevelopment70: x.development.reasonActual70, reasonDevelopment20: x.development.reasonActual20, @@ -2525,8 +2533,9 @@ export class DevelopmentController extends Controller { isDevelopment70: false, isDevelopment20: false, isDevelopment10: false, - // summary: x.development.summary, - // point: x.development.point, + developmentTarget: null, + developmentResults: null, + developmentReport: null, developmentProjects: x.development.developmentProjectTechniqueActuals.map( (x) => x.name, ), diff --git a/src/entities/Development.ts b/src/entities/Development.ts index eb4b00e..0604367 100644 --- a/src/entities/Development.ts +++ b/src/entities/Development.ts @@ -294,6 +294,25 @@ export class Development extends EntityBase { }) reasonPlanned10: string; + @Column({ + comment: "รายละเอียดอื่นๆ 70 แผน", + default: false, + }) + isReasonPlanned70: boolean; + + @Column({ + comment: "รายละเอียดอื่นๆ 20 แผน", + default: false, + }) + isReasonPlanned20: boolean; + + @Column({ + nullable: true, + comment: "รายละเอียดอื่นๆ 10 แผน", + default: null, + }) + isReasonPlanned10: string; + @OneToMany( () => DevelopmentProjectTechniquePlanned, (developmentProjectTechniquePlanned: DevelopmentProjectTechniquePlanned) => @@ -322,6 +341,25 @@ export class Development extends EntityBase { }) reasonActual10: string; + @Column({ + comment: "รายละเอียดอื่นๆ 70 จริง", + default: false, + }) + isReasonActual70: boolean; + + @Column({ + comment: "รายละเอียดอื่นๆ 20 จริง", + default: false, + }) + isReasonActual20: boolean; + + @Column({ + nullable: true, + comment: "รายละเอียดอื่นๆ 10 จริง", + default: null, + }) + isReasonActual10: string; + @OneToMany( () => DevelopmentProjectTechniqueActual, (developmentProjectTechniqueActual: DevelopmentProjectTechniqueActual) => @@ -775,6 +813,12 @@ export class UpdateDevelopment3 { @Column() reasonPlanned10?: string; @Column() + isReasonPlanned70?: string; + @Column() + isReasonPlanned20?: string; + @Column() + isReasonPlanned10?: string; + @Column() isBackActual?: boolean | null; @Column() isHoldActual?: boolean | null; @@ -793,6 +837,12 @@ export class UpdateDevelopment3 { @Column() reasonActual10?: string; @Column() + isReasonActual70?: boolean; + @Column() + isReasonActual20?: boolean; + @Column() + isReasonActual10?: boolean; + @Column() strategyChildPlannedId?: string | null; @Column() strategyChildPlannedNode?: number | null; @@ -810,7 +860,6 @@ export class UpdateDevelopment4 { @Column() projectEvaluation: string | null; //end - } export class UpdateDevelopment5 { //new @@ -866,7 +915,7 @@ export class UpdateDevelopment8_1 { //end } -export class UpdateDevelopment8{ +export class UpdateDevelopment8 { @Column() expect: string | null; -} \ No newline at end of file +} diff --git a/src/migration/1727753251629-update_development_add_isReasonActual70.ts b/src/migration/1727753251629-update_development_add_isReasonActual70.ts new file mode 100644 index 0000000..32c8f84 --- /dev/null +++ b/src/migration/1727753251629-update_development_add_isReasonActual70.ts @@ -0,0 +1,24 @@ +import { MigrationInterface, QueryRunner } from "typeorm"; + +export class UpdateDevelopmentAddIsReasonActual701727753251629 implements MigrationInterface { + name = 'UpdateDevelopmentAddIsReasonActual701727753251629' + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`development\` ADD \`isReasonPlanned70\` tinyint NOT NULL COMMENT 'รายละเอียดอื่นๆ 70 แผน' DEFAULT 0`); + await queryRunner.query(`ALTER TABLE \`development\` ADD \`isReasonPlanned20\` tinyint NOT NULL COMMENT 'รายละเอียดอื่นๆ 20 แผน' DEFAULT 0`); + await queryRunner.query(`ALTER TABLE \`development\` ADD \`isReasonPlanned10\` varchar(255) NULL COMMENT 'รายละเอียดอื่นๆ 10 แผน'`); + await queryRunner.query(`ALTER TABLE \`development\` ADD \`isReasonActual70\` tinyint NOT NULL COMMENT 'รายละเอียดอื่นๆ 70 จริง' DEFAULT 0`); + await queryRunner.query(`ALTER TABLE \`development\` ADD \`isReasonActual20\` tinyint NOT NULL COMMENT 'รายละเอียดอื่นๆ 20 จริง' DEFAULT 0`); + await queryRunner.query(`ALTER TABLE \`development\` ADD \`isReasonActual10\` varchar(255) NULL COMMENT 'รายละเอียดอื่นๆ 10 จริง'`); + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`isReasonActual10\``); + await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`isReasonActual20\``); + await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`isReasonActual70\``); + await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`isReasonPlanned10\``); + await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`isReasonPlanned20\``); + await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`isReasonPlanned70\``); + } + +} From 2b1b5f25668c768c73186c621c141268f5228747 Mon Sep 17 00:00:00 2001 From: kittapath Date: Tue, 1 Oct 2024 10:59:49 +0700 Subject: [PATCH 165/250] no message --- src/entities/Development.ts | 10 ++++------ ...update_development_add_isReasonActual10.ts | 20 +++++++++++++++++++ 2 files changed, 24 insertions(+), 6 deletions(-) create mode 100644 src/migration/1727755044851-update_development_add_isReasonActual10.ts diff --git a/src/entities/Development.ts b/src/entities/Development.ts index 0604367..b807734 100644 --- a/src/entities/Development.ts +++ b/src/entities/Development.ts @@ -307,11 +307,10 @@ export class Development extends EntityBase { isReasonPlanned20: boolean; @Column({ - nullable: true, comment: "รายละเอียดอื่นๆ 10 แผน", - default: null, + default: false, }) - isReasonPlanned10: string; + isReasonPlanned10: boolean; @OneToMany( () => DevelopmentProjectTechniquePlanned, @@ -354,11 +353,10 @@ export class Development extends EntityBase { isReasonActual20: boolean; @Column({ - nullable: true, comment: "รายละเอียดอื่นๆ 10 จริง", - default: null, + default: false, }) - isReasonActual10: string; + isReasonActual10: boolean; @OneToMany( () => DevelopmentProjectTechniqueActual, diff --git a/src/migration/1727755044851-update_development_add_isReasonActual10.ts b/src/migration/1727755044851-update_development_add_isReasonActual10.ts new file mode 100644 index 0000000..a5a0c33 --- /dev/null +++ b/src/migration/1727755044851-update_development_add_isReasonActual10.ts @@ -0,0 +1,20 @@ +import { MigrationInterface, QueryRunner } from "typeorm"; + +export class UpdateDevelopmentAddIsReasonActual101727755044851 implements MigrationInterface { + name = 'UpdateDevelopmentAddIsReasonActual101727755044851' + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`isReasonPlanned10\``); + await queryRunner.query(`ALTER TABLE \`development\` ADD \`isReasonPlanned10\` tinyint NOT NULL COMMENT 'รายละเอียดอื่นๆ 10 แผน' DEFAULT 0`); + await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`isReasonActual10\``); + await queryRunner.query(`ALTER TABLE \`development\` ADD \`isReasonActual10\` tinyint NOT NULL COMMENT 'รายละเอียดอื่นๆ 10 จริง' DEFAULT 0`); + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`isReasonActual10\``); + await queryRunner.query(`ALTER TABLE \`development\` ADD \`isReasonActual10\` varchar(255) NULL COMMENT 'รายละเอียดอื่นๆ 10 จริง'`); + await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`isReasonPlanned10\``); + await queryRunner.query(`ALTER TABLE \`development\` ADD \`isReasonPlanned10\` varchar(255) NULL COMMENT 'รายละเอียดอื่นๆ 10 แผน'`); + } + +} From c0f387bda5bb43320d458ea841cce9cce75f95fd Mon Sep 17 00:00:00 2001 From: AdisakKanthawilang Date: Thu, 3 Oct 2024 15:14:12 +0700 Subject: [PATCH 166/250] fix search --- src/controllers/DevelopmentHistoryController.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/controllers/DevelopmentHistoryController.ts b/src/controllers/DevelopmentHistoryController.ts index dfefb2e..8387de4 100644 --- a/src/controllers/DevelopmentHistoryController.ts +++ b/src/controllers/DevelopmentHistoryController.ts @@ -326,6 +326,14 @@ export class DevelopmentOfficerHistoryController extends Controller { { keyword: `%${body.keyword}%`, }, + ) + .orWhere( + body.keyword != null && body.keyword != "" + ? "developmentHistory.citizenId LIKE :keyword" + : "1=1", + { + keyword: `%${body.keyword}%`, + }, ); }), ) From e0f37dda4a018d325f8d1aa26d89ae5b25cb0433 Mon Sep 17 00:00:00 2001 From: AdisakKanthawilang Date: Thu, 3 Oct 2024 15:20:33 +0700 Subject: [PATCH 167/250] =?UTF-8?q?fix=20=E0=B9=80=E0=B8=9E=E0=B8=B4?= =?UTF-8?q?=E0=B9=88=E0=B8=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/DevelopmentEmployeeHistoryController.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/controllers/DevelopmentEmployeeHistoryController.ts b/src/controllers/DevelopmentEmployeeHistoryController.ts index 8d25e7c..794a7d7 100644 --- a/src/controllers/DevelopmentEmployeeHistoryController.ts +++ b/src/controllers/DevelopmentEmployeeHistoryController.ts @@ -331,6 +331,14 @@ export class DevelopmentEmployeeHistoryController extends Controller { { keyword: `%${body.keyword}%`, }, + ) + .orWhere( + body.keyword != null && body.keyword != "" + ? "developmentHistory.citizenId LIKE :keyword" + : "1=1", + { + keyword: `%${body.keyword}%`, + }, ); }), ) From aa5e69776e8929b1afa86130da1ade5e9f040351 Mon Sep 17 00:00:00 2001 From: kittapath Date: Tue, 22 Oct 2024 08:21:07 +0700 Subject: [PATCH 168/250] check workflow --- src/controllers/DevelopmentController.ts | 28 ++++---- .../DevelopmentEmployeeHistoryController.ts | 3 +- .../DevelopmentHistoryController.ts | 4 +- .../DevelopmentScholarshipController.ts | 5 +- src/controllers/StrategyController.ts | 14 +++- src/interfaces/permission.ts | 64 ++++++++++--------- 6 files changed, 69 insertions(+), 49 deletions(-) diff --git a/src/controllers/DevelopmentController.ts b/src/controllers/DevelopmentController.ts index 154e511..68fa72f 100644 --- a/src/controllers/DevelopmentController.ts +++ b/src/controllers/DevelopmentController.ts @@ -1530,8 +1530,8 @@ export class DevelopmentController extends Controller { */ @Get("tab7/{id}") async GetDevelopemtTab7ById(@Request() request: RequestWithUser, @Path() id: string) { - // await new permission().PermissionGet(request, "SYS_DEV_SCHOLARSHIP"); - await new permission().PermissionGet(request, "SYS_DEV_PROJECT"); + let _workflow = await new permission().Workflow(request, id, "SYS_DEV_PROJECT"); + if (_workflow == false) await new permission().PermissionGet(request, "SYS_DEV_PROJECT"); const getDevelopment = await this.developmentRepository.findOne({ where: { id }, }); @@ -1556,8 +1556,8 @@ export class DevelopmentController extends Controller { */ @Get("tab8/{id}") async GetDevelopemtTab8ById(@Request() request: RequestWithUser, @Path() id: string) { - // await new permission().PermissionGet(request, "SYS_DEV_SCHOLARSHIP"); - await new permission().PermissionGet(request, "SYS_DEV_PROJECT"); + let _workflow = await new permission().Workflow(request, id, "SYS_DEV_PROJECT"); + if (_workflow == false) await new permission().PermissionGet(request, "SYS_DEV_PROJECT"); const getDevelopment = await this.developmentRepository.findOne({ relations: ["developmentRisks"], where: { id: id }, @@ -2005,8 +2005,8 @@ export class DevelopmentController extends Controller { */ @Get("tab1/{id}") async GetDevelopemtTab1ById(@Request() request: RequestWithUser, @Path() id: string) { - // await new permission().PermissionGet(request, "SYS_DEV_SCHOLARSHIP"); - await new permission().PermissionGet(request, "SYS_DEV_PROJECT"); + let _workflow = await new permission().Workflow(request, id, "SYS_DEV_PROJECT"); + if (_workflow == false) await new permission().PermissionGet(request, "SYS_DEV_PROJECT"); const getDevelopment = await this.developmentRepository.findOne({ where: { id: id }, }); @@ -2059,8 +2059,8 @@ export class DevelopmentController extends Controller { */ @Get("tab2/{id}") async GetDevelopemtTab2ById(@Request() request: RequestWithUser, @Path() id: string) { - // await new permission().PermissionGet(request, "SYS_DEV_SCHOLARSHIP"); - await new permission().PermissionGet(request, "SYS_DEV_PROJECT"); + let _workflow = await new permission().Workflow(request, id, "SYS_DEV_PROJECT"); + if (_workflow == false) await new permission().PermissionGet(request, "SYS_DEV_PROJECT"); const getDevelopment = await this.developmentRepository.findOne({ where: { id: id }, relations: [ @@ -2155,8 +2155,8 @@ export class DevelopmentController extends Controller { */ @Get("tab3/{id}") async GetDevelopemtTab3ById(@Request() request: RequestWithUser, @Path() id: string) { - // await new permission().PermissionGet(request, "SYS_DEV_SCHOLARSHIP"); - await new permission().PermissionGet(request, "SYS_DEV_PROJECT"); + let _workflow = await new permission().Workflow(request, id, "SYS_DEV_PROJECT"); + if (_workflow == false) await new permission().PermissionGet(request, "SYS_DEV_PROJECT"); const getDevelopment = await this.developmentRepository.findOne({ where: { id: id }, relations: [ @@ -2274,8 +2274,8 @@ export class DevelopmentController extends Controller { */ @Get("tab4/{id}") async GetDevelopemtTab4ById(@Request() request: RequestWithUser, @Path() id: string) { - // await new permission().PermissionGet(request, "SYS_DEV_SCHOLARSHIP"); - await new permission().PermissionGet(request, "SYS_DEV_PROJECT"); + let _workflow = await new permission().Workflow(request, id, "SYS_DEV_PROJECT"); + if (_workflow == false) await new permission().PermissionGet(request, "SYS_DEV_PROJECT"); const getDevelopment = await this.developmentRepository.findOne({ where: { id: id }, relations: ["developmentEvaluations"], @@ -2308,8 +2308,8 @@ export class DevelopmentController extends Controller { */ @Get("tab5/{id}") async GetDevelopemtTab5ById(@Request() request: RequestWithUser, @Path() id: string) { - // await new permission().PermissionGet(request, "SYS_DEV_SCHOLARSHIP"); - await new permission().PermissionGet(request, "SYS_DEV_PROJECT"); + let _workflow = await new permission().Workflow(request, id, "SYS_DEV_PROJECT"); + if (_workflow == false) await new permission().PermissionGet(request, "SYS_DEV_PROJECT"); const getDevelopment = await this.developmentRepository.findOne({ relations: ["developmentOthers"], where: { id: id }, diff --git a/src/controllers/DevelopmentEmployeeHistoryController.ts b/src/controllers/DevelopmentEmployeeHistoryController.ts index 794a7d7..42e34a1 100644 --- a/src/controllers/DevelopmentEmployeeHistoryController.ts +++ b/src/controllers/DevelopmentEmployeeHistoryController.ts @@ -370,7 +370,8 @@ export class DevelopmentEmployeeHistoryController extends Controller { */ @Get("{id}") async GetDevelopemtHistoryById(@Request() request: RequestWithUser, @Path() id: string) { - await new permission().PermissionGet(request, "SYS_DEV_HISTORY_EMP"); + let _workflow = await new permission().Workflow(request, id, "SYS_DEV_HISTORY_EMP"); + if (_workflow == false) await new permission().PermissionGet(request, "SYS_DEV_HISTORY_EMP"); const type = "EMPLOYEE"; const getDevelopment = await this.developmentHistoryRepository.findOne({ relations: ["development", "employeePosLevel", "employeePosType"], diff --git a/src/controllers/DevelopmentHistoryController.ts b/src/controllers/DevelopmentHistoryController.ts index 8387de4..8f436a5 100644 --- a/src/controllers/DevelopmentHistoryController.ts +++ b/src/controllers/DevelopmentHistoryController.ts @@ -366,7 +366,9 @@ export class DevelopmentOfficerHistoryController extends Controller { */ @Get("{id}") async GetDevelopemtHistoryById(@Request() request: RequestWithUser, @Path() id: string) { - await new permission().PermissionGet(request, "SYS_DEV_HISTORY_OFFICER"); + let _workflow = await new permission().Workflow(request, id, "SYS_DEV_HISTORY_OFFICER"); + if (_workflow == false) + await new permission().PermissionGet(request, "SYS_DEV_HISTORY_OFFICER"); const type = "OFFICER"; const getDevelopment = await this.developmentHistoryRepository.findOne({ relations: ["development", "posLevel", "posType"], diff --git a/src/controllers/DevelopmentScholarshipController.ts b/src/controllers/DevelopmentScholarshipController.ts index e12a503..e92d2ef 100644 --- a/src/controllers/DevelopmentScholarshipController.ts +++ b/src/controllers/DevelopmentScholarshipController.ts @@ -253,7 +253,7 @@ export class DevelopmentScholarshipController extends Controller { */ @Get("{id}") async GetDevelopemtScholarshipById(@Request() request: RequestWithUser, @Path() id: string) { - // await new permission().PermissionGet(request, "SYS_DEV_SCHOLARSHIP");//USER + //await new permission().PermissionGet(request, "SYS_DEV_SCHOLARSHIP"); //USER const getDevelopment = await this.developmentScholarshipRepository.findOne({ relations: ["posLevel", "posType", "posLevelguarantor", "posTypeguarantor"], where: { id: id }, @@ -414,7 +414,8 @@ export class DevelopmentScholarshipController extends Controller { */ @Get("admin/{id}") async GetDevelopemtScholarshipAdminById(@Request() request: RequestWithUser, @Path() id: string) { - await new permission().PermissionGet(request, "SYS_DEV_SCHOLARSHIP"); + let _workflow = await new permission().Workflow(request, id, "SYS_DEV_SCHOLARSHIP"); + if (_workflow == false) await new permission().PermissionGet(request, "SYS_DEV_SCHOLARSHIP"); const getDevelopment = await this.developmentScholarshipRepository.findOne({ relations: ["posLevel", "posType", "posLevelguarantor", "posTypeguarantor"], where: { id: id }, diff --git a/src/controllers/StrategyController.ts b/src/controllers/StrategyController.ts index 066b942..ce1cbd2 100644 --- a/src/controllers/StrategyController.ts +++ b/src/controllers/StrategyController.ts @@ -1,4 +1,16 @@ -import { Body, Controller, Delete, Get, Patch, Path, Post, Request, Route, Security, Tags } from "tsoa"; +import { + Body, + Controller, + Delete, + Get, + Patch, + Path, + Post, + Request, + Route, + Security, + Tags, +} from "tsoa"; import { AppDataSource } from "../database/data-source"; import { StrategyChild1 } from "../entities/StrategyChild1"; import { StrategyChild2 } from "../entities/StrategyChild2"; diff --git a/src/interfaces/permission.ts b/src/interfaces/permission.ts index fb2d669..870d2fe 100644 --- a/src/interfaces/permission.ts +++ b/src/interfaces/permission.ts @@ -53,18 +53,7 @@ class CheckAuth { return await new CallAPI() .GetData(req, `/org/permission/org/${system}/${action}`) .then(async (x) => { - console.log(x); let privilege = x.privilege; - // if (action.trim().toLocaleUpperCase() == "CREATE") - // privilege = await this.PermissionCreate(req, system); - // if (action.trim().toLocaleUpperCase() == "DELETE") - // privilege = await this.PermissionDelete(req, system); - // if (action.trim().toLocaleUpperCase() == "GET") - // privilege = await this.PermissionGet(req, system); - // if (action.trim().toLocaleUpperCase() == "LIST") - // privilege = await this.PermissionList(req, system); - // if (action.trim().toLocaleUpperCase() == "UPDATE") - // privilege = await this.PermissionUpdate(req, system); let data: any = { root: [null], @@ -72,6 +61,7 @@ class CheckAuth { child2: [null], child3: [null], child4: [null], + privilege: [null], }; let node = 4; if (x.orgChild1Id == null) { @@ -83,13 +73,23 @@ class CheckAuth { } else if (x.orgChild4Id == null) { node = 3; } - if (privilege == "ROOT") { + 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 = { @@ -98,6 +98,7 @@ class CheckAuth { 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 = { @@ -106,16 +107,9 @@ class CheckAuth { child2: [x.orgChild2Id], child3: [x.orgChild3Id], child4: [x.orgChild4Id], + privilege: "NORMAL", }; } else if (privilege == "SPECIFIC") { - } else if (privilege == "OWNER") { - data = { - root: null, - child1: null, - child2: null, - child3: null, - child4: null, - }; } return data; @@ -145,16 +139,6 @@ class CheckAuth { .GetData(req, `/org/permission/user/${system}/${action}/${profileId}`) .then(async (x) => { let org = x.org; - // if (action.trim().toLocaleUpperCase() == "CREATE") - // org = await this.PermissionOrgCreate(req, system); - // if (action.trim().toLocaleUpperCase() == "DELETE") - // org = await this.PermissionOrgDelete(req, system); - // if (action.trim().toLocaleUpperCase() == "GET") - // org = await this.PermissionOrgGet(req, system); - // if (action.trim().toLocaleUpperCase() == "LIST") - // org = await this.PermissionOrgList(req, system); - // if (action.trim().toLocaleUpperCase() == "UPDATE") - // org = await this.PermissionOrgUpdate(req, system); if (org.root != null) if (x.orgRootId != org.root[0]) throw "ไม่มีสิทธิ์เข้าถึงข้อมูล"; if (org.child1 != null) @@ -176,6 +160,26 @@ class CheckAuth { } }); } + 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 PermissionCreate(req: RequestWithUser, system: string) { return await this.Permission(req, system, "CREATE"); } From 650cd842af0c53b27c5a35845a7fc75d409cce2c Mon Sep 17 00:00:00 2001 From: AdisakKanthawilang Date: Fri, 25 Oct 2024 14:28:24 +0700 Subject: [PATCH 169/250] add root id for log --- package-lock.json | 51 +++++++++++++++++++++++++++++++ package.json | 3 +- src/interfaces/call-api.ts | 6 ++-- src/interfaces/permission.ts | 59 ++++++++++++++++++++++++++++++++++++ src/middlewares/logs.ts | 12 ++++++-- 5 files changed, 124 insertions(+), 7 deletions(-) diff --git a/package-lock.json b/package-lock.json index 349ccc2..4ec9070 100644 --- a/package-lock.json +++ b/package-lock.json @@ -21,6 +21,7 @@ "mysql2": "^3.9.1", "node-cron": "^3.0.3", "promise.any": "^2.0.6", + "redis": "~3.1.2", "reflect-metadata": "^0.2.1", "swagger-ui-express": "^5.0.0", "tsoa": "^6.0.1", @@ -3609,6 +3610,56 @@ "node": ">=8.10.0" } }, + "node_modules/redis": { + "version": "3.1.2", + "resolved": "https://registry.npmjs.org/redis/-/redis-3.1.2.tgz", + "integrity": "sha512-grn5KoZLr/qrRQVwoSkmzdbw6pwF+/rwODtrOr6vuBRiR/f3rjSTGupbF90Zpqm2oenix8Do6RV7pYEkGwlKkw==", + "dependencies": { + "denque": "^1.5.0", + "redis-commands": "^1.7.0", + "redis-errors": "^1.2.0", + "redis-parser": "^3.0.0" + }, + "engines": { + "node": ">=10" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/node-redis" + } + }, + "node_modules/redis-commands": { + "version": "1.7.0", + "resolved": "https://registry.npmjs.org/redis-commands/-/redis-commands-1.7.0.tgz", + "integrity": "sha512-nJWqw3bTFy21hX/CPKHth6sfhZbdiHP6bTawSgQBlKOVRG7EZkfHbbHwQJnrE4vsQf0CMNE+3gJ4Fmm16vdVlQ==" + }, + "node_modules/redis-errors": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/redis-errors/-/redis-errors-1.2.0.tgz", + "integrity": "sha512-1qny3OExCf0UvUV/5wpYKf2YwPcOqXzkwKKSmKHiE6ZMQs5heeE/c8eXK+PNllPvmjgAbfnsbpkGZWy8cBpn9w==", + "engines": { + "node": ">=4" + } + }, + "node_modules/redis-parser": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/redis-parser/-/redis-parser-3.0.0.tgz", + "integrity": "sha512-DJnGAeenTdpMEH6uAJRK/uiyEIH9WVsUmoLwzudwGJUwZPp80PDBWPHXSAGNPwNvIXAbe7MSUB1zQFugFml66A==", + "dependencies": { + "redis-errors": "^1.0.0" + }, + "engines": { + "node": ">=4" + } + }, + "node_modules/redis/node_modules/denque": { + "version": "1.5.1", + "resolved": "https://registry.npmjs.org/denque/-/denque-1.5.1.tgz", + "integrity": "sha512-XwE+iZ4D6ZUB7mfYRMb5wByE8L74HCn30FBN7sWnXksWc1LO1bPDl67pBR9o/kC4z/xSNAwkMYcGgqDV3BE3Hw==", + "engines": { + "node": ">=0.10" + } + }, "node_modules/reflect-metadata": { "version": "0.2.1", "resolved": "https://registry.npmjs.org/reflect-metadata/-/reflect-metadata-0.2.1.tgz", diff --git a/package.json b/package.json index 67445e7..9f2d6c7 100644 --- a/package.json +++ b/package.json @@ -44,6 +44,7 @@ "tsoa": "^6.0.1", "typeorm": "^0.3.19", "typeorm-cli": "^1.0.7", - "xlsx": "^0.18.5" + "xlsx": "^0.18.5", + "redis": "~3.1.2" } } diff --git a/src/interfaces/call-api.ts b/src/interfaces/call-api.ts index 711dc95..3748715 100644 --- a/src/interfaces/call-api.ts +++ b/src/interfaces/call-api.ts @@ -4,7 +4,7 @@ import { addLogSequence } from "./utils"; class CallAPI { //Get - public async GetData(request: any, @Path() path: any) { + 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 { @@ -15,7 +15,7 @@ class CallAPI { api_key: process.env.API_KEY, }, }); - addLogSequence(request, { + if(log) addLogSequence(request, { action: "request", status: "success", description: "connected", @@ -27,7 +27,7 @@ class CallAPI { }); return response.data.result; } catch (error) { - addLogSequence(request, { + if(log) addLogSequence(request, { action: "request", status: "error", description: "unconnected", diff --git a/src/interfaces/permission.ts b/src/interfaces/permission.ts index 870d2fe..407c08f 100644 --- a/src/interfaces/permission.ts +++ b/src/interfaces/permission.ts @@ -3,8 +3,11 @@ 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") && @@ -180,6 +183,62 @@ class CheckAuth { 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 { + // await new CallAPI() + // .GetData( + // { + // headers: { authorization: token }, + // }, `/org/permission/checkOrg/${keycloakId}`,false) + // .then((x) => { + // console.log("[In Then]"); + // console.log("[res]",x); + // let data: any = { + // orgRootId: x.orgRootId, + // orgChild1Id: x.orgChild1Id, + // orgChild2Id: x.orgChild2Id, + // orgChild3Id: x.orgChild3Id, + // orgChild4Id: x.orgChild4Id, + // }; + // console.log("[data]",data); + // return data; + // }, + // ) + // .catch((error) => { + // console.error("Error calling API:", error); + // }); + 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"); } diff --git a/src/middlewares/logs.ts b/src/middlewares/logs.ts index e5acc5b..308df41 100644 --- a/src/middlewares/logs.ts +++ b/src/middlewares/logs.ts @@ -1,5 +1,6 @@ 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."); @@ -22,7 +23,7 @@ const elasticsearch = new Client({ async function logMiddleware(req: Request, res: Response, next: NextFunction) { if (!req.url.startsWith("/api/")) return next(); - let data: any; + let data: any; const originalJson = res.json; @@ -36,7 +37,7 @@ async function logMiddleware(req: Request, res: Response, next: NextFunction) { req.app.locals.logData = {}; - res.on("finish", () => { + res.on("finish", async() => { if (!req.url.startsWith("/api/")) return; const level = LOG_LEVEL_MAP[process.env.LOG_LEVEL ?? "debug"] || 4; @@ -44,10 +45,15 @@ async function logMiddleware(req: Request, res: Response, next: NextFunction) { 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: "development", startTimeStamp: timestamp, endTimeStamp: new Date().toISOString(), From 786da6091093fa4d1ed351a08e43afae02265d85 Mon Sep 17 00:00:00 2001 From: AdisakKanthawilang Date: Fri, 22 Nov 2024 11:16:57 +0700 Subject: [PATCH 170/250] =?UTF-8?q?=E0=B8=A3=E0=B8=B0=E0=B8=9A=E0=B8=9A?= =?UTF-8?q?=E0=B8=9E=E0=B8=B1=E0=B8=92=E0=B8=99=E0=B8=B2=E0=B8=9A=E0=B8=B8?= =?UTF-8?q?=E0=B8=84=E0=B8=A5=E0=B8=B2=E0=B8=81=E0=B8=A3>>=E0=B8=AD?= =?UTF-8?q?=E0=B8=B1=E0=B8=9B=E0=B9=82=E0=B8=AB=E0=B8=A5=E0=B8=94=E0=B9=84?= =?UTF-8?q?=E0=B8=9F=E0=B8=A5=E0=B9=8C=E0=B8=A3=E0=B8=B2=E0=B8=A2=E0=B8=8A?= =?UTF-8?q?=E0=B8=B7=E0=B9=88=E0=B8=AD=E0=B8=9C=E0=B8=B9=E0=B9=89=E0=B8=9C?= =?UTF-8?q?=E0=B9=88=E0=B8=B2=E0=B8=99=E0=B8=81=E0=B8=B2=E0=B8=A3=E0=B8=9D?= =?UTF-8?q?=E0=B8=B6=E0=B8=81=E0=B8=AD=E0=B8=9A=E0=B8=A3=E0=B8=A1=20(?= =?UTF-8?q?=E0=B8=A5=E0=B8=B9=E0=B8=81=E0=B8=88=E0=B9=89=E0=B8=B2=E0=B8=87?= =?UTF-8?q?=E0=B8=9B=E0=B8=A3=E0=B8=B0=E0=B8=88=E0=B8=B3)=20#803?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/DevelopmentController.ts | 27 ------------------------ 1 file changed, 27 deletions(-) diff --git a/src/controllers/DevelopmentController.ts b/src/controllers/DevelopmentController.ts index 68fa72f..9a46f05 100644 --- a/src/controllers/DevelopmentController.ts +++ b/src/controllers/DevelopmentController.ts @@ -2620,33 +2620,6 @@ export class DevelopmentController extends Controller { ); if (oldProfile != null) { if (oldProfile.isDone == true) return; - oldProfile.dateStart = - item["วันที่เริ่มต้น"] == undefined ? null : item["วันที่เริ่มต้น"]; - oldProfile.dateEnd = item["วันที่สิ้นสุด"] == undefined ? null : item["วันที่สิ้นสุด"]; - oldProfile.order = - item["เลขที่คำสั่ง/เลขที่หนังสืออนุมัติ"] == undefined - ? null - : item["เลขที่คำสั่ง/เลขที่หนังสืออนุมัติ"]; - oldProfile.dateOrder = - item["คำสั่งลงวันที่/หนังสืออนุมัติลงวันที่"] == undefined - ? null - : new Date(item["คำสั่งลงวันที่/หนังสืออนุมัติลงวันที่"]); - oldProfile.trainingDays = - item["จำนวนวันที่อบรม"] == undefined ? null : item["จำนวนวันที่อบรม"]; - oldProfile.createdUserId = request.user.sub; - oldProfile.createdFullName = request.user.name; - oldProfile.lastUpdateUserId = request.user.sub; - oldProfile.lastUpdateFullName = request.user.name; - oldProfile.createdAt = new Date(); - oldProfile.lastUpdatedAt = new Date(); - // addLogSequence(request, { - // action: "database", - // status: "success", - // description: "Store DevelopmentHistory.", - // }); - await this.developmentHistoryRepository.save(oldProfile, { data: request }); - setLogDataDiff(request, { before, after: oldProfile }); - return; } if (item["ประเภท"] == undefined) return; if (item["ประเภท"] == "ข้าราชการกรุงเทพมหานครสามัญ" || item["ประเภท"] == "ขรก.กทม. สามัญ") { From 483e64ffe33e1587b941b80b4bbb583ccd58481d Mon Sep 17 00:00:00 2001 From: Bright Date: Wed, 27 Nov 2024 13:43:01 +0700 Subject: [PATCH 171/250] =?UTF-8?q?sort=20=E0=B9=80=E0=B8=A3=E0=B8=B5?= =?UTF-8?q?=E0=B8=A2=E0=B8=87=E0=B8=88=E0=B8=B2=E0=B8=81=E0=B8=A7=E0=B8=B1?= =?UTF-8?q?=E0=B8=99=E0=B8=97=E0=B8=B5=E0=B9=88=E0=B8=AA=E0=B8=A3=E0=B9=89?= =?UTF-8?q?=E0=B8=B2=E0=B8=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/PortfolioController.ts | 26 +------------------------- 1 file changed, 1 insertion(+), 25 deletions(-) diff --git a/src/controllers/PortfolioController.ts b/src/controllers/PortfolioController.ts index c690fa1..d027420 100644 --- a/src/controllers/PortfolioController.ts +++ b/src/controllers/PortfolioController.ts @@ -54,32 +54,8 @@ export class PortfolioController extends Controller { "createdFullName", "lastUpdateFullName", ], - order: { name: "ASC" }, + order: { createdAt: "DESC" }, }); - - // const _portfolio = await this.portfolioRepository - // .createQueryBuilder("portfolio") - // .select([ - // "portfolio.id", - // "portfolio.name", - // "portfolio.detail", - // "portfolio.createdAt", - // "portfolio.lastUpdatedAt", - // "portfolio.createdFullName", - // "portfolio.lastUpdateFullName", - // ]) - // .where("portfolio.createdUserId = :userId", { userId: request.user.sub }) - // .andWhere( - // new Brackets((qb) => { - // qb.where(keyword != null && keyword != "" ? "portfolio.name LIKE :keyword" : "1=1", { - // keyword: `%${keyword}%`, - // }).orWhere(keyword != null && keyword != "" ? "portfolio.detail LIKE :keyword" : "1=1", { - // keyword: `%${keyword}%`, - // }); - // }), - // ) - // .getMany(); - return new HttpSuccess(_portfolio); } From 06d6c07d3f62a7fabb30eb17b42033c65c2e04ce Mon Sep 17 00:00:00 2001 From: Bright Date: Wed, 27 Nov 2024 15:35:04 +0700 Subject: [PATCH 172/250] =?UTF-8?q?sort=20=E0=B9=80=E0=B8=A3=E0=B8=B5?= =?UTF-8?q?=E0=B8=A2=E0=B8=87=E0=B8=88=E0=B8=B2=E0=B8=81=E0=B8=A7=E0=B8=B1?= =?UTF-8?q?=E0=B8=99=E0=B8=97=E0=B8=B5=E0=B9=88=E0=B8=AA=E0=B8=A3=E0=B9=89?= =?UTF-8?q?=E0=B8=B2=E0=B8=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/DevelopmentScholarshipController.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/controllers/DevelopmentScholarshipController.ts b/src/controllers/DevelopmentScholarshipController.ts index e92d2ef..74a1d74 100644 --- a/src/controllers/DevelopmentScholarshipController.ts +++ b/src/controllers/DevelopmentScholarshipController.ts @@ -550,6 +550,7 @@ export class DevelopmentScholarshipController extends Controller { { scholarshipType: type }, ) .select(["id", "scholarshipYear", "scholarshipYear", "scholarshipType", "fundType"]) + .orderBy("developmentScholarship.createdAt", "DESC") .getRawMany(); return new HttpSuccess(getDevelopment); From 531ebab3beddae76586b8a84ded6fb8e6e5514d7 Mon Sep 17 00:00:00 2001 From: Bright Date: Thu, 28 Nov 2024 14:43:01 +0700 Subject: [PATCH 173/250] =?UTF-8?q?fix=20=E0=B9=80=E0=B8=8A=E0=B9=87?= =?UTF-8?q?=E0=B8=84=20=E0=B8=A3=E0=B8=B0=E0=B8=9A=E0=B8=9A=E0=B8=9E?= =?UTF-8?q?=E0=B8=B1=E0=B8=92=E0=B8=99=E0=B8=B2=20#811?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DevelopmentEmployeeHistoryController.ts | 38 +++++-------------- .../DevelopmentHistoryController.ts | 30 ++------------- 2 files changed, 13 insertions(+), 55 deletions(-) diff --git a/src/controllers/DevelopmentEmployeeHistoryController.ts b/src/controllers/DevelopmentEmployeeHistoryController.ts index 42e34a1..82d2f9a 100644 --- a/src/controllers/DevelopmentEmployeeHistoryController.ts +++ b/src/controllers/DevelopmentEmployeeHistoryController.ts @@ -270,36 +270,12 @@ export class DevelopmentEmployeeHistoryController extends Controller { new Brackets((qb) => { qb.where( body.keyword != null && body.keyword != "" - ? "developmentHistory.prefix LIKE :keyword" + ? "CONCAT(developmentHistory.prefix, developmentHistory.firstName, ' ', developmentHistory.lastName) LIKE :keyword" : "1=1", { keyword: `%${body.keyword}%`, }, ) - .orWhere( - body.keyword != null && body.keyword != "" - ? "developmentHistory.firstName LIKE :keyword" - : "1=1", - { - keyword: `%${body.keyword}%`, - }, - ) - .orWhere( - body.keyword != null && body.keyword != "" - ? "developmentHistory.lastName LIKE :keyword" - : "1=1", - { - keyword: `%${body.keyword}%`, - }, - ) - .orWhere( - body.keyword != null && body.keyword != "" - ? "developmentHistory.position LIKE :keyword" - : "1=1", - { - keyword: `%${body.keyword}%`, - }, - ) .orWhere( body.keyword != null && body.keyword != "" ? "developmentHistory.position LIKE :keyword" @@ -350,11 +326,15 @@ export class DevelopmentEmployeeHistoryController extends Controller { const formattedData = development.map((item) => ({ id: item.id, citizenId: item.citizenId, - fullName: item.prefix + item.firstName + " " + item.lastName, + fullName: item.prefix != null && item.firstName != null && item.lastName != null + ? `${item?.prefix}${item?.firstName} ${item?.lastName}` + : "", position: item.position, year: item.development.year, posType: item.employeePosType ? item.employeePosType.posTypeName : null, - posLevel: item.employeePosLevel ? item.employeePosLevel.posLevelName : null, + posLevel: item.employeePosType && item.employeePosLevel + ? `${item.employeePosType.posTypeShortName}${item.employeePosLevel.posLevelName}` + : null, projectName: item.development.projectName, })); @@ -391,8 +371,8 @@ export class DevelopmentEmployeeHistoryController extends Controller { position: getDevelopment.position, posLevelId: getDevelopment.employeePosLevelId, posLevelName: - getDevelopment.employeePosLevel != null - ? getDevelopment.employeePosLevel.posLevelName + getDevelopment.employeePosType != null && getDevelopment.employeePosLevel != null + ? `${getDevelopment.employeePosType.posTypeShortName} ${getDevelopment.employeePosLevel.posLevelName}` : null, posTypeId: getDevelopment.employeePosTypeId, posTypeName: diff --git a/src/controllers/DevelopmentHistoryController.ts b/src/controllers/DevelopmentHistoryController.ts index 8f436a5..33f512a 100644 --- a/src/controllers/DevelopmentHistoryController.ts +++ b/src/controllers/DevelopmentHistoryController.ts @@ -265,36 +265,12 @@ export class DevelopmentOfficerHistoryController extends Controller { new Brackets((qb) => { qb.where( body.keyword != null && body.keyword != "" - ? "developmentHistory.prefix LIKE :keyword" + ? "CONCAT(developmentHistory.prefix, developmentHistory.firstName, ' ', developmentHistory.lastName) LIKE :keyword" : "1=1", { keyword: `%${body.keyword}%`, }, ) - .orWhere( - body.keyword != null && body.keyword != "" - ? "developmentHistory.firstName LIKE :keyword" - : "1=1", - { - keyword: `%${body.keyword}%`, - }, - ) - .orWhere( - body.keyword != null && body.keyword != "" - ? "developmentHistory.lastName LIKE :keyword" - : "1=1", - { - keyword: `%${body.keyword}%`, - }, - ) - .orWhere( - body.keyword != null && body.keyword != "" - ? "developmentHistory.position LIKE :keyword" - : "1=1", - { - keyword: `%${body.keyword}%`, - }, - ) .orWhere( body.keyword != null && body.keyword != "" ? "developmentHistory.position LIKE :keyword" @@ -344,7 +320,9 @@ export class DevelopmentOfficerHistoryController extends Controller { const formattedData = development.map((item) => ({ id: item.id, citizenId: item.citizenId, - fullName: item.prefix + item.firstName + " " + item.lastName, + fullName: item.prefix == null && item.firstName == null && item.lastName == null + ? "" + : `${item?.prefix}${item?.firstName} ${item?.lastName}`, position: item.position, year: item.development.year, root: item.development.root, //test From 74693935513bb8d20c6f6e8232fab311a8c8b243 Mon Sep 17 00:00:00 2001 From: Bright Date: Thu, 28 Nov 2024 17:22:28 +0700 Subject: [PATCH 174/250] =?UTF-8?q?=E0=B9=80=E0=B8=8A=E0=B9=87=E0=B8=84=20?= =?UTF-8?q?=E0=B8=A3=E0=B8=B0=E0=B8=9A=E0=B8=9A=E0=B8=9E=E0=B8=B1=E0=B8=92?= =?UTF-8?q?=E0=B8=99=E0=B8=B2=20#811?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/DevelopmentEmployeeHistoryController.ts | 3 ++- src/controllers/DevelopmentHistoryController.ts | 1 + src/controllers/DevelopmentScholarshipController.ts | 1 + 3 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/controllers/DevelopmentEmployeeHistoryController.ts b/src/controllers/DevelopmentEmployeeHistoryController.ts index 82d2f9a..f0ea6aa 100644 --- a/src/controllers/DevelopmentEmployeeHistoryController.ts +++ b/src/controllers/DevelopmentEmployeeHistoryController.ts @@ -318,6 +318,7 @@ export class DevelopmentEmployeeHistoryController extends Controller { ); }), ) + .orderBy("development.year", "DESC") .orderBy("developmentHistory.createdAt", "DESC") .skip((body.page - 1) * body.pageSize) .take(body.pageSize) @@ -333,7 +334,7 @@ export class DevelopmentEmployeeHistoryController extends Controller { year: item.development.year, posType: item.employeePosType ? item.employeePosType.posTypeName : null, posLevel: item.employeePosType && item.employeePosLevel - ? `${item.employeePosType.posTypeShortName}${item.employeePosLevel.posLevelName}` + ? `${item.employeePosType.posTypeShortName} ${item.employeePosLevel.posLevelName}` : null, projectName: item.development.projectName, })); diff --git a/src/controllers/DevelopmentHistoryController.ts b/src/controllers/DevelopmentHistoryController.ts index 33f512a..6a942f2 100644 --- a/src/controllers/DevelopmentHistoryController.ts +++ b/src/controllers/DevelopmentHistoryController.ts @@ -313,6 +313,7 @@ export class DevelopmentOfficerHistoryController extends Controller { ); }), ) + .orderBy("development.year", "DESC") .orderBy("developmentHistory.createdAt", "DESC") .skip((body.page - 1) * body.pageSize) .take(body.pageSize) diff --git a/src/controllers/DevelopmentScholarshipController.ts b/src/controllers/DevelopmentScholarshipController.ts index 74a1d74..9599867 100644 --- a/src/controllers/DevelopmentScholarshipController.ts +++ b/src/controllers/DevelopmentScholarshipController.ts @@ -226,6 +226,7 @@ export class DevelopmentScholarshipController extends Controller { ); }), ) + .orderBy("developmentScholarship.scholarshipYear", "DESC") .orderBy("developmentScholarship.createdAt", "DESC") .skip((page - 1) * pageSize) .take(pageSize) From 1837cf09ac882aac51e322d47879f9e4cf37b26a Mon Sep 17 00:00:00 2001 From: Bright Date: Thu, 28 Nov 2024 17:49:15 +0700 Subject: [PATCH 175/250] fix order --- src/controllers/DevelopmentController.ts | 4 ++-- src/controllers/DevelopmentEmployeeHistoryController.ts | 2 +- src/controllers/DevelopmentHistoryController.ts | 2 +- src/controllers/DevelopmentScholarshipController.ts | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/controllers/DevelopmentController.ts b/src/controllers/DevelopmentController.ts index 9a46f05..b131536 100644 --- a/src/controllers/DevelopmentController.ts +++ b/src/controllers/DevelopmentController.ts @@ -1757,7 +1757,7 @@ export class DevelopmentController extends Controller { }) .select(["development.id", "development.projectName", "development.year"]) .orderBy("development.year", "DESC") - .orderBy("development.createdAt", "DESC") + .addOrderBy("development.createdAt", "DESC") .getManyAndCount(); return new HttpSuccess({ data: development, total }); @@ -1944,7 +1944,7 @@ export class DevelopmentController extends Controller { "development.child4", ]) .orderBy("development.year", "DESC") - .orderBy("development.createdAt", "DESC") + .addOrderBy("development.createdAt", "DESC") .skip((page - 1) * pageSize) .take(pageSize) .getManyAndCount(); diff --git a/src/controllers/DevelopmentEmployeeHistoryController.ts b/src/controllers/DevelopmentEmployeeHistoryController.ts index f0ea6aa..45a4970 100644 --- a/src/controllers/DevelopmentEmployeeHistoryController.ts +++ b/src/controllers/DevelopmentEmployeeHistoryController.ts @@ -319,7 +319,7 @@ export class DevelopmentEmployeeHistoryController extends Controller { }), ) .orderBy("development.year", "DESC") - .orderBy("developmentHistory.createdAt", "DESC") + .addOrderBy("developmentHistory.createdAt", "DESC") .skip((body.page - 1) * body.pageSize) .take(body.pageSize) .getManyAndCount(); diff --git a/src/controllers/DevelopmentHistoryController.ts b/src/controllers/DevelopmentHistoryController.ts index 6a942f2..c8928c9 100644 --- a/src/controllers/DevelopmentHistoryController.ts +++ b/src/controllers/DevelopmentHistoryController.ts @@ -314,7 +314,7 @@ export class DevelopmentOfficerHistoryController extends Controller { }), ) .orderBy("development.year", "DESC") - .orderBy("developmentHistory.createdAt", "DESC") + .addOrderBy("developmentHistory.createdAt", "DESC") .skip((body.page - 1) * body.pageSize) .take(body.pageSize) .getManyAndCount(); diff --git a/src/controllers/DevelopmentScholarshipController.ts b/src/controllers/DevelopmentScholarshipController.ts index 9599867..b095ba8 100644 --- a/src/controllers/DevelopmentScholarshipController.ts +++ b/src/controllers/DevelopmentScholarshipController.ts @@ -227,7 +227,7 @@ export class DevelopmentScholarshipController extends Controller { }), ) .orderBy("developmentScholarship.scholarshipYear", "DESC") - .orderBy("developmentScholarship.createdAt", "DESC") + .addOrderBy("developmentScholarship.createdAt", "DESC") .skip((page - 1) * pageSize) .take(pageSize) .getManyAndCount(); From 837925b926d4283897e81c42e433100766e42170 Mon Sep 17 00:00:00 2001 From: kittapath Date: Tue, 3 Dec 2024 13:38:05 +0700 Subject: [PATCH 176/250] test build --- .github/workflows/release.yaml | 1 + Dockerfile | 35 ---------------------------------- docker/Dockerfile | 34 +++++++++++++++++++++++++++++++++ 3 files changed, 35 insertions(+), 35 deletions(-) delete mode 100644 Dockerfile create mode 100644 docker/Dockerfile diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 0c083cc..7c5469f 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -52,6 +52,7 @@ jobs: 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 diff --git a/Dockerfile b/Dockerfile deleted file mode 100644 index 4ca0f48..0000000 --- a/Dockerfile +++ /dev/null @@ -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" ] \ No newline at end of file diff --git a/docker/Dockerfile b/docker/Dockerfile new file mode 100644 index 0000000..07492be --- /dev/null +++ b/docker/Dockerfile @@ -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" ] From 263cae0c559921461c30d5bb5bda9c79084ba593 Mon Sep 17 00:00:00 2001 From: kittapath Date: Sat, 7 Dec 2024 09:31:49 +0700 Subject: [PATCH 177/250] test build discord --- .github/workflows/release.yaml | 61 ++++++++++++++++++++++------------ 1 file changed, 40 insertions(+), 21 deletions(-) diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 7c5469f..2f29d54 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -1,5 +1,5 @@ -name: release-test -run-name: release-test ${{ github.actor }} +name: release +run-name: release ${{ github.actor }} on: push: tags: @@ -9,11 +9,11 @@ env: REGISTRY: docker.frappet.com IMAGE_NAME: ehr/bma-ehr-development-service DEPLOY_HOST: frappet.com - # COMPOSE_PATH: /home/frappet/docker/bma-ehr COMPOSE_PATH: /home/frappet/docker/bma/bma-ehr-development + 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 - release-test: + release: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 @@ -67,22 +67,41 @@ jobs: docker compose pull docker compose up -d echo "${{ steps.gen_ver.outputs.image_ver }}"> success - - uses: snow-actions/line-notify@v1.1.0 + - name: Notify Discord Success 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}} + run: | + curl -H "Content-Type: application/json" \ + -X POST \ + -d '{ + "embeds": [{ + "title": "✅ Deployment Success!", + "description": "**Details:**\n- Image: `${{env.IMAGE_NAME}}`\n- Version: `${{ steps.gen_ver.outputs.image_ver }}`\n- Deployed by: `${{github.actor}}`", + "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() + run: | + curl -H "Content-Type: application/json" \ + -X POST \ + -d '{ + "embeds": [{ + "title": "❌ Deployment Failed!", + "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 }} From 0c646b7c6eda9bdb86f95fd337c93e8a9a317eb1 Mon Sep 17 00:00:00 2001 From: AdisakKanthawilang Date: Wed, 11 Dec 2024 13:51:56 +0700 Subject: [PATCH 178/250] add status --- src/controllers/DevelopmentScholarshipController.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/controllers/DevelopmentScholarshipController.ts b/src/controllers/DevelopmentScholarshipController.ts index b095ba8..117dfb3 100644 --- a/src/controllers/DevelopmentScholarshipController.ts +++ b/src/controllers/DevelopmentScholarshipController.ts @@ -240,6 +240,7 @@ export class DevelopmentScholarshipController extends Controller { posType: item.posType ? item.posType.posTypeName : null, posLevel: item.posLevel ? item.posLevel.posLevelName : null, posExecutive: item.posExecutive, + status: item.status, })); return new HttpSuccess({ data: formattedData, total }); From 3a7a4069368bebe39f3c236adeeddce49965ea67 Mon Sep 17 00:00:00 2001 From: Suchin Sapphasitthatha Date: Thu, 12 Dec 2024 07:02:13 +0000 Subject: [PATCH 179/250] add CI --- .onedev-buildspec.yml | 102 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 102 insertions(+) create mode 100644 .onedev-buildspec.yml diff --git a/.onedev-buildspec.yml b/.onedev-buildspec.yml new file mode 100644 index 0000000..0eef9fb --- /dev/null +++ b/.onedev-buildspec.yml @@ -0,0 +1,102 @@ +version: 37 +jobs: +- name: CI for UAT + steps: + - !CheckoutStep + name: checkout code + cloneCredential: !DefaultCredential {} + withLfs: false + withSubmodules: false + condition: ALL_PREVIOUS_STEPS_WERE_SUCCESSFUL + - !GenerateChecksumStep + name: generate package checksum + files: package-lock.json yarn.lock + targetFile: checksum + condition: ALL_PREVIOUS_STEPS_WERE_SUCCESSFUL + - !SetupCacheStep + name: set up npm cache + key: node_modules_@file:checksum@ + loadKeys: + - node_modules + paths: + - node_modules + uploadStrategy: UPLOAD_IF_NOT_HIT + condition: ALL_PREVIOUS_STEPS_WERE_SUCCESSFUL + - !SetBuildVersionStep + name: set build version + buildVersion: '@tag@' + condition: ALL_PREVIOUS_STEPS_WERE_SUCCESSFUL + - !CommandStep + name: build & test + runInContainer: true + image: node + interpreter: !DefaultInterpreter + commands: | + npm install + npm run build + useTTY: true + condition: ALL_PREVIOUS_STEPS_WERE_SUCCESSFUL + - !BuildImageStep + name: build docker image + dockerfile: ./docker/Dockerfile + output: !RegistryOutput + tags: hrms-git.chin.in.th/bma-hrms/hrms-api-dev:@build_version@ hrms-git.chin.in.th/bma-hrms/hrms-api-dev:latest + condition: ALL_PREVIOUS_STEPS_WERE_SUCCESSFUL + triggers: + - !TagCreateTrigger + tags: uat-* + branches: main + retryCondition: never + maxRetries: 3 + retryDelay: 30 + timeout: 14400 +- name: CI for PROD + steps: + - !CheckoutStep + name: checkout code + cloneCredential: !DefaultCredential {} + withLfs: false + withSubmodules: false + condition: ALL_PREVIOUS_STEPS_WERE_SUCCESSFUL + - !GenerateChecksumStep + name: generate package checksum + files: package-lock.json yarn.lock + targetFile: checksum + condition: ALL_PREVIOUS_STEPS_WERE_SUCCESSFUL + - !SetupCacheStep + name: set up npm cache + key: node_modules_@file:checksum@ + loadKeys: + - node_modules + paths: + - node_modules + uploadStrategy: UPLOAD_IF_NOT_HIT + condition: ALL_PREVIOUS_STEPS_WERE_SUCCESSFUL + - !SetBuildVersionStep + name: set build version + buildVersion: '@tag@' + condition: ALL_PREVIOUS_STEPS_WERE_SUCCESSFUL + - !CommandStep + name: build & test + runInContainer: true + image: node + interpreter: !DefaultInterpreter + commands: | + npm install + npm run build + useTTY: true + condition: ALL_PREVIOUS_STEPS_WERE_SUCCESSFUL + - !BuildImageStep + name: build docker image + dockerfile: ./docker/Dockerfile + output: !RegistryOutput + tags: hrms-git.bangkok.go.th/bma-hrms/hrms-api-dev:@build_version@ hrms-git.bangkok.go.th/bma-hrms/hrms-api-dev:latest + condition: ALL_PREVIOUS_STEPS_WERE_SUCCESSFUL + triggers: + - !TagCreateTrigger + tags: prod-* + branches: main + retryCondition: never + maxRetries: 3 + retryDelay: 30 + timeout: 14400 From 86a5cd7fb5f7649612aa0585062f1ed6bf32c126 Mon Sep 17 00:00:00 2001 From: kittapath Date: Sat, 14 Dec 2024 01:04:10 +0700 Subject: [PATCH 180/250] edit permission --- src/interfaces/permission.ts | 35 +++++++---------------------------- 1 file changed, 7 insertions(+), 28 deletions(-) diff --git a/src/interfaces/permission.ts b/src/interfaces/permission.ts index 407c08f..d462e4c 100644 --- a/src/interfaces/permission.ts +++ b/src/interfaces/permission.ts @@ -183,7 +183,7 @@ class CheckAuth { return false; }); } - public async checkOrg(token: any,keycloakId: string) { + public async checkOrg(token: any, keycloakId: string) { const redisClient = await this.redis.createClient({ host: process.env.REDIS_HOST, port: process.env.REDIS_PORT, @@ -193,37 +193,16 @@ class CheckAuth { if (reply != null) { reply = JSON.parse(reply); } else { - // await new CallAPI() - // .GetData( - // { - // headers: { authorization: token }, - // }, `/org/permission/checkOrg/${keycloakId}`,false) - // .then((x) => { - // console.log("[In Then]"); - // console.log("[res]",x); - // let data: any = { - // orgRootId: x.orgRootId, - // orgChild1Id: x.orgChild1Id, - // orgChild2Id: x.orgChild2Id, - // orgChild3Id: x.orgChild3Id, - // orgChild4Id: x.orgChild4Id, - // }; - // console.log("[data]",data); - // return data; - // }, - // ) - // .catch((error) => { - // console.error("Error calling API:", error); - // }); + if (!keycloakId) throw "Error calling API No KeycloakId"; try { const x = await new CallAPI().GetData( { headers: { authorization: token }, - }, - `/org/permission/checkOrg/${keycloakId}`, - false + }, + `/org/permission/checkOrg/${keycloakId}`, + false, ); - + const data = { orgRootId: x.orgRootId, orgChild1Id: x.orgChild1Id, @@ -231,7 +210,7 @@ class CheckAuth { orgChild3Id: x.orgChild3Id, orgChild4Id: x.orgChild4Id, }; - + return data; } catch (error) { console.error("Error calling API:", error); From e251b16c117f09ec5123942a7fcdc6d6161dde52 Mon Sep 17 00:00:00 2001 From: kittapath Date: Wed, 18 Dec 2024 18:59:44 +0700 Subject: [PATCH 181/250] =?UTF-8?q?=E0=B9=81=E0=B8=81=E0=B9=89=20=20throw?= =?UTF-8?q?=20error?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/interfaces/permission.ts | 18 ++++---- src/middlewares/logs.ts | 80 ++++++++++++++++++++---------------- 2 files changed, 54 insertions(+), 44 deletions(-) diff --git a/src/interfaces/permission.ts b/src/interfaces/permission.ts index d462e4c..b55d8e7 100644 --- a/src/interfaces/permission.ts +++ b/src/interfaces/permission.ts @@ -189,12 +189,12 @@ class CheckAuth { 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 { - if (!keycloakId) throw "Error calling API No KeycloakId"; - try { + try { + let reply = await getAsync("org_" + keycloakId); + if (reply != null) { + reply = JSON.parse(reply); + } else { + if (!keycloakId) throw new Error("No KeycloakId provided"); const x = await new CallAPI().GetData( { headers: { authorization: token }, @@ -212,10 +212,10 @@ class CheckAuth { }; return data; - } catch (error) { - console.error("Error calling API:", error); - throw error; } + } catch (error) { + console.error("Error calling API:", error); + throw error; } } public async PermissionCreate(req: RequestWithUser, system: string) { diff --git a/src/middlewares/logs.ts b/src/middlewares/logs.ts index 308df41..b1d83ba 100644 --- a/src/middlewares/logs.ts +++ b/src/middlewares/logs.ts @@ -19,12 +19,10 @@ const LOG_LEVEL_MAP: Record = { 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; - + let data: any; const originalJson = res.json; res.json = function (v: any) { @@ -37,41 +35,53 @@ async function logMiddleware(req: Request, res: Response, next: NextFunction) { req.app.locals.logData = {}; - res.on("finish", async() => { - if (!req.url.startsWith("/api/")) return; + res.on("finish", async () => { + try { + 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 === 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: "development", - 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, - }; + if (level === 1 && res.statusCode < 500) return; + if (level === 2 && res.statusCode < 400) return; + if (level === 3 && res.statusCode < 200) return; - elasticsearch.index({ - index: ELASTICSEARCH_INDEX, - document: obj, - }); + const token = req.headers["authorization"]; + let rootId = null; + + try { + rootId = token + ? await new permission().checkOrg(token, req.app.locals.logData.userId) + : null; + } catch (err) { + console.warn("Error fetching rootId:", err); + } + + const obj = { + logType: res.statusCode >= 500 ? "error" : res.statusCode >= 400 ? "warning" : "info", + ip: req.ip, + 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, + }; + + // Send log to Elasticsearch + await elasticsearch.index({ + index: ELASTICSEARCH_INDEX, + document: obj, + }); + } catch (err) { + console.error("Error in logMiddleware:", err); + } }); return next(); From eb1264b8851196576749ba48caea7ef49d9f7d23 Mon Sep 17 00:00:00 2001 From: AdisakKanthawilang Date: Thu, 19 Dec 2024 10:31:21 +0700 Subject: [PATCH 182/250] #857 (4),(5) --- .../DevelopmentEmployeeHistoryController.ts | 35 +++++++++++++------ .../DevelopmentHistoryController.ts | 16 ++++++--- 2 files changed, 35 insertions(+), 16 deletions(-) diff --git a/src/controllers/DevelopmentEmployeeHistoryController.ts b/src/controllers/DevelopmentEmployeeHistoryController.ts index 45a4970..65dadc1 100644 --- a/src/controllers/DevelopmentEmployeeHistoryController.ts +++ b/src/controllers/DevelopmentEmployeeHistoryController.ts @@ -327,15 +327,17 @@ export class DevelopmentEmployeeHistoryController extends Controller { const formattedData = development.map((item) => ({ id: item.id, citizenId: item.citizenId, - fullName: item.prefix != null && item.firstName != null && item.lastName != null - ? `${item?.prefix}${item?.firstName} ${item?.lastName}` - : "", + fullName: + item.prefix != null && item.firstName != null && item.lastName != null + ? `${item?.prefix}${item?.firstName} ${item?.lastName}` + : "", position: item.position, year: item.development.year, posType: item.employeePosType ? item.employeePosType.posTypeName : null, - posLevel: item.employeePosType && item.employeePosLevel - ? `${item.employeePosType.posTypeShortName} ${item.employeePosLevel.posLevelName}` - : null, + posLevel: + item.employeePosType && item.employeePosLevel + ? `${item.employeePosType.posTypeShortName} ${item.employeePosLevel.posLevelName}` + : null, projectName: item.development.projectName, })); @@ -355,7 +357,12 @@ export class DevelopmentEmployeeHistoryController extends Controller { if (_workflow == false) await new permission().PermissionGet(request, "SYS_DEV_HISTORY_EMP"); const type = "EMPLOYEE"; const getDevelopment = await this.developmentHistoryRepository.findOne({ - relations: ["development", "employeePosLevel", "employeePosType"], + relations: [ + "development", + "development.developmentOthers", + "employeePosLevel", + "employeePosType", + ], where: { id: id, type: type }, }); if (!getDevelopment) { @@ -389,14 +396,20 @@ export class DevelopmentEmployeeHistoryController extends Controller { dateStart: getDevelopment.development != null ? getDevelopment.development.dateStart : null, dateEnd: getDevelopment.development != null ? getDevelopment.development.dateEnd : null, totalDate: getDevelopment.development != null ? getDevelopment.development.totalDate : null, - addressAcademic: - getDevelopment.development != null ? getDevelopment.development.addressAcademic : null, - topicAcademic: - getDevelopment.development != null ? getDevelopment.development.topicAcademic : null, + // addressAcademic: + // getDevelopment.development != null ? getDevelopment.development.addressAcademic : null, + // topicAcademic: + // getDevelopment.development != null ? getDevelopment.development.topicAcademic : null, dateStudyStart: getDevelopment.development != null ? getDevelopment.development.dateStudyStart : null, dateStudyEnd: getDevelopment.development != null ? getDevelopment.development.dateStudyEnd : null, + academic: getDevelopment.development?.developmentOthers + ? getDevelopment.development.developmentOthers.map((dev) => ({ + topicAcademic: dev.topicAcademic, + addressAcademic: dev.addressAcademic, + })) + : [], }; return new HttpSuccess(formattedData); diff --git a/src/controllers/DevelopmentHistoryController.ts b/src/controllers/DevelopmentHistoryController.ts index c8928c9..368858f 100644 --- a/src/controllers/DevelopmentHistoryController.ts +++ b/src/controllers/DevelopmentHistoryController.ts @@ -350,7 +350,7 @@ export class DevelopmentOfficerHistoryController extends Controller { await new permission().PermissionGet(request, "SYS_DEV_HISTORY_OFFICER"); const type = "OFFICER"; const getDevelopment = await this.developmentHistoryRepository.findOne({ - relations: ["development", "posLevel", "posType"], + relations: ["development", "development.developmentOthers","posLevel", "posType"], where: { id: id, type: type }, }); if (!getDevelopment) { @@ -381,14 +381,20 @@ export class DevelopmentOfficerHistoryController extends Controller { dateStart: getDevelopment.development != null ? getDevelopment.development.dateStart : null, dateEnd: getDevelopment.development != null ? getDevelopment.development.dateEnd : null, totalDate: getDevelopment.development != null ? getDevelopment.development.totalDate : null, - addressAcademic: - getDevelopment.development != null ? getDevelopment.development.addressAcademic : null, - topicAcademic: - getDevelopment.development != null ? getDevelopment.development.topicAcademic : null, + // addressAcademic: + // getDevelopment.development != null ? getDevelopment.development.addressAcademic : null, + // topicAcademic: + // getDevelopment.development != null ? getDevelopment.development.topicAcademic : null, dateStudyStart: getDevelopment.development != null ? getDevelopment.development.dateStudyStart : null, dateStudyEnd: getDevelopment.development != null ? getDevelopment.development.dateStudyEnd : null, + academic: getDevelopment.development?.developmentOthers + ? getDevelopment.development.developmentOthers.map(dev => ({ + topicAcademic: dev.topicAcademic, + addressAcademic: dev.addressAcademic + })) + : [] }; return new HttpSuccess(formattedData); From 48dcb3582a2e30c23c91865a851bed8e0e5173f2 Mon Sep 17 00:00:00 2001 From: AdisakKanthawilang Date: Thu, 19 Dec 2024 11:14:57 +0700 Subject: [PATCH 183/250] add relation --- src/entities/DevelopmentOther.ts | 4 ++++ src/entities/Province.ts | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/src/entities/DevelopmentOther.ts b/src/entities/DevelopmentOther.ts index 4315669..0e627f0 100644 --- a/src/entities/DevelopmentOther.ts +++ b/src/entities/DevelopmentOther.ts @@ -36,6 +36,10 @@ export class DevelopmentOther extends EntityBase { @ManyToOne(() => Development, (development: Development) => development.developmentOthers) @JoinColumn({ name: "developmentId" }) development: Development; + + @ManyToOne(() => Province, (province: Province) => province.developmentOthers) + @JoinColumn({ name: "developmentId" }) + province: Province; } export class UpdateDevelopmentOther { diff --git a/src/entities/Province.ts b/src/entities/Province.ts index a826b67..f697b97 100644 --- a/src/entities/Province.ts +++ b/src/entities/Province.ts @@ -2,6 +2,7 @@ import { Entity, Column, OneToMany } from "typeorm"; import { EntityBase } from "./base/Base"; import { Development } from "./Development"; import { DevelopmentAddress } from "./DevelopmentAddress"; +import { DevelopmentOther } from "./DevelopmentOther"; @Entity("province") export class Province extends EntityBase { @@ -21,6 +22,9 @@ export class Province extends EntityBase { @OneToMany(() => Development, (development: Development) => development.provinceActual) developmentActuals: Development[]; + + @OneToMany(() => DevelopmentOther, (developmentOther: DevelopmentOther) => developmentOther.province) + developmentOthers: Development[]; } export class CreateProvince { From c0e38237a6dfbbc7cd109792ecc31df48790d269 Mon Sep 17 00:00:00 2001 From: kittapath Date: Thu, 19 Dec 2024 11:41:06 +0700 Subject: [PATCH 184/250] api clear db --- src/controllers/DevelopmentController.ts | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/controllers/DevelopmentController.ts b/src/controllers/DevelopmentController.ts index b131536..2364ddc 100644 --- a/src/controllers/DevelopmentController.ts +++ b/src/controllers/DevelopmentController.ts @@ -91,6 +91,17 @@ export class DevelopmentController extends Controller { private strategyChild4Repository = AppDataSource.getRepository(StrategyChild4); private strategyChild5Repository = AppDataSource.getRepository(StrategyChild5); + /** + * API ล้างข้อมูล + * + * @summary ล้างข้อมูล + * + */ + @Get("clear-db") + async ClearDb() { + return new HttpSuccess(); + } + /** * API เพิ่มโครงการ/หลักสูตรการฝึกอบรม * From a648fb3f243d998d66c9408fc2764b48a40c0ae5 Mon Sep 17 00:00:00 2001 From: kittapath Date: Thu, 19 Dec 2024 11:45:31 +0700 Subject: [PATCH 185/250] migrate --- ...427091-update_devorder_add_relation_province.ts | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 src/migration/1734583427091-update_devorder_add_relation_province.ts diff --git a/src/migration/1734583427091-update_devorder_add_relation_province.ts b/src/migration/1734583427091-update_devorder_add_relation_province.ts new file mode 100644 index 0000000..9084218 --- /dev/null +++ b/src/migration/1734583427091-update_devorder_add_relation_province.ts @@ -0,0 +1,14 @@ +import { MigrationInterface, QueryRunner } from "typeorm"; + +export class UpdateDevorderAddRelationProvince1734583427091 implements MigrationInterface { + name = 'UpdateDevorderAddRelationProvince1734583427091' + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`developmentOther\` ADD CONSTRAINT \`FK_d5dfdb7ca0d11c0cdf3b3a55e6f\` FOREIGN KEY (\`developmentId\`) REFERENCES \`province\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`); + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`developmentOther\` DROP FOREIGN KEY \`FK_d5dfdb7ca0d11c0cdf3b3a55e6f\``); + } + +} From 964e938bb2cec6d7e4658e6b7920d71dfaa26701 Mon Sep 17 00:00:00 2001 From: AdisakKanthawilang Date: Thu, 19 Dec 2024 12:41:48 +0700 Subject: [PATCH 186/250] fix #857 --- .../DevelopmentEmployeeHistoryController.ts | 9 +++++ .../DevelopmentHistoryController.ts | 34 ++++++++++++++----- src/entities/DevelopmentOther.ts | 2 +- ...1-update_devorder_add_relation_province.ts | 14 -------- ...pdate_development_add_relation_province.ts | 14 ++++++++ 5 files changed, 49 insertions(+), 24 deletions(-) delete mode 100644 src/migration/1734583427091-update_devorder_add_relation_province.ts create mode 100644 src/migration/1734586571465-update_development_add_relation_province.ts diff --git a/src/controllers/DevelopmentEmployeeHistoryController.ts b/src/controllers/DevelopmentEmployeeHistoryController.ts index 65dadc1..2d35b66 100644 --- a/src/controllers/DevelopmentEmployeeHistoryController.ts +++ b/src/controllers/DevelopmentEmployeeHistoryController.ts @@ -360,10 +360,18 @@ export class DevelopmentEmployeeHistoryController extends Controller { relations: [ "development", "development.developmentOthers", + "development.developmentOthers.province", "employeePosLevel", "employeePosType", ], where: { id: id, type: type }, + order: { + development:{ + developmentOthers: { + createdAt: "ASC" + } + } + } }); if (!getDevelopment) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลประวัติการฝึกอบรม/ดูงานนี้"); @@ -408,6 +416,7 @@ export class DevelopmentEmployeeHistoryController extends Controller { ? getDevelopment.development.developmentOthers.map((dev) => ({ topicAcademic: dev.topicAcademic, addressAcademic: dev.addressAcademic, + Province: dev.province.name })) : [], }; diff --git a/src/controllers/DevelopmentHistoryController.ts b/src/controllers/DevelopmentHistoryController.ts index 368858f..c8589df 100644 --- a/src/controllers/DevelopmentHistoryController.ts +++ b/src/controllers/DevelopmentHistoryController.ts @@ -27,6 +27,7 @@ import { PosLevel } from "../entities/PosLevel"; import { RequestWithUser } from "../middlewares/user"; import { setLogDataDiff } from "../interfaces/utils"; import permission from "../interfaces/permission"; +import { Province } from "../entities/Province"; @Route("api/v1/development/history/officer") @Tags("DevelopmentOfficerHistory") @@ -321,9 +322,10 @@ export class DevelopmentOfficerHistoryController extends Controller { const formattedData = development.map((item) => ({ id: item.id, citizenId: item.citizenId, - fullName: item.prefix == null && item.firstName == null && item.lastName == null - ? "" - : `${item?.prefix}${item?.firstName} ${item?.lastName}`, + fullName: + item.prefix == null && item.firstName == null && item.lastName == null + ? "" + : `${item?.prefix}${item?.firstName} ${item?.lastName}`, position: item.position, year: item.development.year, root: item.development.root, //test @@ -350,8 +352,21 @@ export class DevelopmentOfficerHistoryController extends Controller { await new permission().PermissionGet(request, "SYS_DEV_HISTORY_OFFICER"); const type = "OFFICER"; const getDevelopment = await this.developmentHistoryRepository.findOne({ - relations: ["development", "development.developmentOthers","posLevel", "posType"], + relations: [ + "development", + "development.developmentOthers", + "development.developmentOthers.province", + "posLevel", + "posType", + ], where: { id: id, type: type }, + order: { + development: { + developmentOthers: { + createdAt: "ASC", + }, + }, + }, }); if (!getDevelopment) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลประวัติการฝึกอบรม/ดูงานนี้"); @@ -389,12 +404,13 @@ export class DevelopmentOfficerHistoryController extends Controller { getDevelopment.development != null ? getDevelopment.development.dateStudyStart : null, dateStudyEnd: getDevelopment.development != null ? getDevelopment.development.dateStudyEnd : null, - academic: getDevelopment.development?.developmentOthers - ? getDevelopment.development.developmentOthers.map(dev => ({ + academic: getDevelopment.development?.developmentOthers + ? getDevelopment.development.developmentOthers.map((dev) => ({ topicAcademic: dev.topicAcademic, - addressAcademic: dev.addressAcademic - })) - : [] + addressAcademic: dev.addressAcademic, + Province: dev.province.name, + })) + : [], }; return new HttpSuccess(formattedData); diff --git a/src/entities/DevelopmentOther.ts b/src/entities/DevelopmentOther.ts index 0e627f0..7cf0da1 100644 --- a/src/entities/DevelopmentOther.ts +++ b/src/entities/DevelopmentOther.ts @@ -38,7 +38,7 @@ export class DevelopmentOther extends EntityBase { development: Development; @ManyToOne(() => Province, (province: Province) => province.developmentOthers) - @JoinColumn({ name: "developmentId" }) + @JoinColumn({ name: "provinceActualId" }) province: Province; } diff --git a/src/migration/1734583427091-update_devorder_add_relation_province.ts b/src/migration/1734583427091-update_devorder_add_relation_province.ts deleted file mode 100644 index 9084218..0000000 --- a/src/migration/1734583427091-update_devorder_add_relation_province.ts +++ /dev/null @@ -1,14 +0,0 @@ -import { MigrationInterface, QueryRunner } from "typeorm"; - -export class UpdateDevorderAddRelationProvince1734583427091 implements MigrationInterface { - name = 'UpdateDevorderAddRelationProvince1734583427091' - - public async up(queryRunner: QueryRunner): Promise { - await queryRunner.query(`ALTER TABLE \`developmentOther\` ADD CONSTRAINT \`FK_d5dfdb7ca0d11c0cdf3b3a55e6f\` FOREIGN KEY (\`developmentId\`) REFERENCES \`province\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`); - } - - public async down(queryRunner: QueryRunner): Promise { - await queryRunner.query(`ALTER TABLE \`developmentOther\` DROP FOREIGN KEY \`FK_d5dfdb7ca0d11c0cdf3b3a55e6f\``); - } - -} diff --git a/src/migration/1734586571465-update_development_add_relation_province.ts b/src/migration/1734586571465-update_development_add_relation_province.ts new file mode 100644 index 0000000..6b37a7f --- /dev/null +++ b/src/migration/1734586571465-update_development_add_relation_province.ts @@ -0,0 +1,14 @@ +import { MigrationInterface, QueryRunner } from "typeorm"; + +export class UpdateDevelopmentAddRelationProvince1734586571465 implements MigrationInterface { + name = 'UpdateDevelopmentAddRelationProvince1734586571465' + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`developmentOther\` ADD CONSTRAINT \`FK_47bbbecaea9b7b31d2536054656\` FOREIGN KEY (\`provinceActualId\`) REFERENCES \`province\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`); + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`developmentOther\` DROP FOREIGN KEY \`FK_47bbbecaea9b7b31d2536054656\``); + } + +} From d00e64d7df04db60766361b71104b29bbcd580c2 Mon Sep 17 00:00:00 2001 From: AdisakKanthawilang Date: Thu, 19 Dec 2024 12:57:14 +0700 Subject: [PATCH 187/250] no message --- src/controllers/DevelopmentEmployeeHistoryController.ts | 2 +- src/controllers/DevelopmentHistoryController.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/controllers/DevelopmentEmployeeHistoryController.ts b/src/controllers/DevelopmentEmployeeHistoryController.ts index 2d35b66..3d152ea 100644 --- a/src/controllers/DevelopmentEmployeeHistoryController.ts +++ b/src/controllers/DevelopmentEmployeeHistoryController.ts @@ -416,7 +416,7 @@ export class DevelopmentEmployeeHistoryController extends Controller { ? getDevelopment.development.developmentOthers.map((dev) => ({ topicAcademic: dev.topicAcademic, addressAcademic: dev.addressAcademic, - Province: dev.province.name + province: dev.province.name })) : [], }; diff --git a/src/controllers/DevelopmentHistoryController.ts b/src/controllers/DevelopmentHistoryController.ts index c8589df..dec3501 100644 --- a/src/controllers/DevelopmentHistoryController.ts +++ b/src/controllers/DevelopmentHistoryController.ts @@ -408,7 +408,7 @@ export class DevelopmentOfficerHistoryController extends Controller { ? getDevelopment.development.developmentOthers.map((dev) => ({ topicAcademic: dev.topicAcademic, addressAcademic: dev.addressAcademic, - Province: dev.province.name, + province: dev.province.name, })) : [], }; From fe9eca9b33ca4c8451605c580ecd6c43d3d6e2c3 Mon Sep 17 00:00:00 2001 From: AdisakKanthawilang Date: Thu, 19 Dec 2024 13:26:30 +0700 Subject: [PATCH 188/250] #857 (9) --- src/controllers/DevelopmentController.ts | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/src/controllers/DevelopmentController.ts b/src/controllers/DevelopmentController.ts index 2364ddc..a5d6fdf 100644 --- a/src/controllers/DevelopmentController.ts +++ b/src/controllers/DevelopmentController.ts @@ -59,6 +59,7 @@ import { RequestWithUser } from "../middlewares/user"; import { DevelopmentRisk, UpdateDevelopmentRisk } from "../entities/DevelopmentRisk"; import { DevelopmentOther, UpdateDevelopmentOther } from "../entities/DevelopmentOther"; import permission from "../interfaces/permission"; +import { Brackets } from "typeorm"; @Route("api/v1/development/main") @Tags("Development") @@ -1941,9 +1942,21 @@ export class DevelopmentController extends Controller { .andWhere(status != undefined ? "development.status LIKE :status" : "1=1", { status: `%${status}%`, }) - .andWhere(keyword != undefined ? "development.projectName LIKE :keyword" : "1=1", { - keyword: `%${keyword}%`, - }) + .andWhere( + keyword != undefined + ? new Brackets ((qb) => { + qb.where("development.projectName LIKE :keyword") + .orWhere("development.root LIKE :keyword") + .orWhere("development.child1 LIKE :keyword") + .orWhere("development.child2 LIKE :keyword") + .orWhere("development.child3 LIKE :keyword") + .orWhere("development.child4 LIKE :keyword"); + }) + : "1=1", + { + keyword: `%${keyword}%`, + }, + ) .select([ "development.id", "development.projectName", From e094c0ad07ed16365054cc6db47d523250703f8b Mon Sep 17 00:00:00 2001 From: Bright Date: Thu, 19 Dec 2024 17:00:41 +0700 Subject: [PATCH 189/250] =?UTF-8?q?=E0=B9=81=E0=B8=81=E0=B9=89=E0=B8=97?= =?UTF-8?q?=E0=B8=B0=E0=B9=80=E0=B8=9A=E0=B8=B5=E0=B8=A2=E0=B8=99=E0=B8=9B?= =?UTF-8?q?=E0=B8=A3=E0=B8=B0=E0=B8=A7=E0=B8=B1=E0=B8=95=E0=B8=B4=20Indivi?= =?UTF-8?q?dual=20Development=20Plan=20#875?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/DevelopmentController.ts | 52 ++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/src/controllers/DevelopmentController.ts b/src/controllers/DevelopmentController.ts index a5d6fdf..2e9bd9c 100644 --- a/src/controllers/DevelopmentController.ts +++ b/src/controllers/DevelopmentController.ts @@ -2606,6 +2606,58 @@ export class DevelopmentController extends Controller { return new HttpSuccess(getOrg); } + @Get("registry/{type}/{developmentId}") + async developmentDetail( + @Path() developmentId: string, + @Path() type: string, + @Request() request: RequestWithUser + ) { + const getDevelopment = await this.developmentRepository.findOne({ + where: { id: developmentId }, + relations: [ + "developmentProjectTypes", + "developmentProjectTechniquePlanneds", + "developmentProjectTechniqueActuals", + "developmentAddresss", + ], + }); + if (!getDevelopment) + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงการ/หลักสูตรการฝึกอบรมนี้"); + + if (type.trim().toLocaleUpperCase() == "OFFICER") { + let _workflow = await new permission().Workflow(request, developmentId, "SYS_REGISTRY_OFFICER"); + if (_workflow == false) await new permission().PermissionGet(request, "SYS_REGISTRY_OFFICER"); + } else if (type.trim().toLocaleUpperCase() == "USER") { + } else { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่สามารถเข้าถึงข้อมูลนี้ได้"); + } + + let _getDevelopment: any = { + id: getDevelopment.id, + evaluationId: null, + target: null, + summary: null, + point: null, + name: getDevelopment.projectName, + achievement10: "มีผลการพัฒนาและมีการดำเนินการตามเป้าหมายการนำไปพัฒนางาน1", + achievement5: "มีผลการพัฒนาแต่ยังไม่ได้ดำเนินการตามเป้าหมายการนำไปพัฒนางาน", + achievement0: "ไม่ได้ดำเนินการพัฒนา", + isDevelopment70: getDevelopment.isReasonActual70, + isDevelopment20: getDevelopment.isReasonActual20, + isDevelopment10: getDevelopment.isReasonActual10, + reasonDevelopment70: getDevelopment.reasonActual70, + reasonDevelopment20: getDevelopment.reasonActual20, + reasonDevelopment10: getDevelopment.reasonActual10, + selectType: "PROJECT", + selectTypeYear: getDevelopment.year, + selectTypeId: null, + developmentProjects : getDevelopment.developmentProjectTechniqueActuals + .map((x) => x.name) + .sort(), + }; + return new HttpSuccess(_getDevelopment); + } + /** * API upload User * From 03e6a62c0a585f5a02d0822b48f8cfed3c846de4 Mon Sep 17 00:00:00 2001 From: Bright Date: Thu, 19 Dec 2024 17:32:00 +0700 Subject: [PATCH 190/250] no message --- src/controllers/DevelopmentController.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/controllers/DevelopmentController.ts b/src/controllers/DevelopmentController.ts index 2e9bd9c..f2b456a 100644 --- a/src/controllers/DevelopmentController.ts +++ b/src/controllers/DevelopmentController.ts @@ -2639,7 +2639,7 @@ export class DevelopmentController extends Controller { summary: null, point: null, name: getDevelopment.projectName, - achievement10: "มีผลการพัฒนาและมีการดำเนินการตามเป้าหมายการนำไปพัฒนางาน1", + achievement10: "มีผลการพัฒนาและมีการดำเนินการตามเป้าหมายการนำไปพัฒนางาน", achievement5: "มีผลการพัฒนาแต่ยังไม่ได้ดำเนินการตามเป้าหมายการนำไปพัฒนางาน", achievement0: "ไม่ได้ดำเนินการพัฒนา", isDevelopment70: getDevelopment.isReasonActual70, From 3f988d8bb62603d63eecc86d61f15170532ec107 Mon Sep 17 00:00:00 2001 From: kittapath Date: Fri, 20 Dec 2024 10:03:51 +0700 Subject: [PATCH 191/250] edit log --- src/middlewares/logs.ts | 2 +- ...465-update_development_add_relation_province.ts | 14 -------------- 2 files changed, 1 insertion(+), 15 deletions(-) delete mode 100644 src/migration/1734586571465-update_development_add_relation_province.ts diff --git a/src/middlewares/logs.ts b/src/middlewares/logs.ts index b1d83ba..fb2b6e2 100644 --- a/src/middlewares/logs.ts +++ b/src/middlewares/logs.ts @@ -60,7 +60,7 @@ async function logMiddleware(req: Request, res: Response, next: NextFunction) { logType: res.statusCode >= 500 ? "error" : res.statusCode >= 400 ? "warning" : "info", ip: req.ip, rootId: rootId?.orgRootId ?? null, - systemName: "evaluation", + systemName: "development", startTimeStamp: timestamp, endTimeStamp: new Date().toISOString(), processTime: performance.now() - start, diff --git a/src/migration/1734586571465-update_development_add_relation_province.ts b/src/migration/1734586571465-update_development_add_relation_province.ts deleted file mode 100644 index 6b37a7f..0000000 --- a/src/migration/1734586571465-update_development_add_relation_province.ts +++ /dev/null @@ -1,14 +0,0 @@ -import { MigrationInterface, QueryRunner } from "typeorm"; - -export class UpdateDevelopmentAddRelationProvince1734586571465 implements MigrationInterface { - name = 'UpdateDevelopmentAddRelationProvince1734586571465' - - public async up(queryRunner: QueryRunner): Promise { - await queryRunner.query(`ALTER TABLE \`developmentOther\` ADD CONSTRAINT \`FK_47bbbecaea9b7b31d2536054656\` FOREIGN KEY (\`provinceActualId\`) REFERENCES \`province\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`); - } - - public async down(queryRunner: QueryRunner): Promise { - await queryRunner.query(`ALTER TABLE \`developmentOther\` DROP FOREIGN KEY \`FK_47bbbecaea9b7b31d2536054656\``); - } - -} From 127a994801eed79de944e8d64b745ad6582aa066 Mon Sep 17 00:00:00 2001 From: kittapath Date: Thu, 26 Dec 2024 22:17:57 +0700 Subject: [PATCH 192/250] no message --- src/controllers/DevelopmentController.ts | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/src/controllers/DevelopmentController.ts b/src/controllers/DevelopmentController.ts index f2b456a..c8fa4d7 100644 --- a/src/controllers/DevelopmentController.ts +++ b/src/controllers/DevelopmentController.ts @@ -1944,7 +1944,7 @@ export class DevelopmentController extends Controller { }) .andWhere( keyword != undefined - ? new Brackets ((qb) => { + ? new Brackets((qb) => { qb.where("development.projectName LIKE :keyword") .orWhere("development.root LIKE :keyword") .orWhere("development.child1 LIKE :keyword") @@ -2610,7 +2610,7 @@ export class DevelopmentController extends Controller { async developmentDetail( @Path() developmentId: string, @Path() type: string, - @Request() request: RequestWithUser + @Request() request: RequestWithUser, ) { const getDevelopment = await this.developmentRepository.findOne({ where: { id: developmentId }, @@ -2625,13 +2625,17 @@ export class DevelopmentController extends Controller { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงการ/หลักสูตรการฝึกอบรมนี้"); if (type.trim().toLocaleUpperCase() == "OFFICER") { - let _workflow = await new permission().Workflow(request, developmentId, "SYS_REGISTRY_OFFICER"); + let _workflow = await new permission().Workflow( + request, + developmentId, + "SYS_REGISTRY_OFFICER", + ); if (_workflow == false) await new permission().PermissionGet(request, "SYS_REGISTRY_OFFICER"); } else if (type.trim().toLocaleUpperCase() == "USER") { } else { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่สามารถเข้าถึงข้อมูลนี้ได้"); } - + let _getDevelopment: any = { id: getDevelopment.id, evaluationId: null, @@ -2651,7 +2655,7 @@ export class DevelopmentController extends Controller { selectType: "PROJECT", selectTypeYear: getDevelopment.year, selectTypeId: null, - developmentProjects : getDevelopment.developmentProjectTechniqueActuals + developmentProjects: getDevelopment.developmentProjectTechniqueActuals .map((x) => x.name) .sort(), }; @@ -2698,11 +2702,12 @@ export class DevelopmentController extends Controller { if (oldProfile.isDone == true) return; } if (item["ประเภท"] == undefined) return; + let development = Object.assign(new DevelopmentHistory(), oldProfile); if (item["ประเภท"] == "ข้าราชการกรุงเทพมหานครสามัญ" || item["ประเภท"] == "ขรก.กทม. สามัญ") { await new CallAPI() .GetData(request, `/org/unauthorize/officer/citizen/${item["รหัสประจำตัวประชาชน"]}`) .then(async (x: any) => { - let development = Object.assign(new DevelopmentHistory(), x); + development = Object.assign(development, x); development.dateStart = item["วันที่เริ่มต้น"] == undefined ? null : item["วันที่เริ่มต้น"]; development.dateEnd = @@ -2738,7 +2743,6 @@ export class DevelopmentController extends Controller { setLogDataDiff(request, { before, after: development }); }) .catch(async (x) => { - let development = new DevelopmentHistory(); let _null: any = null; development.prefix = item["คำนำหน้า"] == undefined ? null : item["คำนำหน้า"]; development.firstName = item["ชื่อ"] == undefined ? null : item["ชื่อ"]; @@ -2789,7 +2793,7 @@ export class DevelopmentController extends Controller { `/org/unauthorize/employee-prem/citizen/${item["รหัสประจำตัวประชาชน"]}`, ) .then(async (x: any) => { - let development = Object.assign(new DevelopmentHistory(), x); + development = Object.assign(development, x); development.dateStart = item["วันที่เริ่มต้น"] == undefined ? null : item["วันที่เริ่มต้น"]; development.dateEnd = @@ -2825,7 +2829,6 @@ export class DevelopmentController extends Controller { setLogDataDiff(request, { before, after: development }); }) .catch(async (x) => { - let development = new DevelopmentHistory(); let _null: any = null; development.prefix = item["คำนำหน้า"] == undefined ? null : item["คำนำหน้า"]; development.firstName = item["ชื่อ"] == undefined ? null : item["ชื่อ"]; From 4e59f476768d7af732cc561d3b45faa442635740 Mon Sep 17 00:00:00 2001 From: kittapath Date: Thu, 26 Dec 2024 23:05:35 +0700 Subject: [PATCH 193/250] no message --- src/controllers/DevelopmentController.ts | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/controllers/DevelopmentController.ts b/src/controllers/DevelopmentController.ts index c8fa4d7..be7ecc6 100644 --- a/src/controllers/DevelopmentController.ts +++ b/src/controllers/DevelopmentController.ts @@ -2788,10 +2788,7 @@ export class DevelopmentController extends Controller { }); } else if (item["ประเภท"] == "ลูกจ้างประจำ") { await new CallAPI() - .GetData( - request, - `/org/unauthorize/employee-prem/citizen/${item["รหัสประจำตัวประชาชน"]}`, - ) + .GetData(request, `/org/unauthorize/employee/citizen/${item["รหัสประจำตัวประชาชน"]}`) .then(async (x: any) => { development = Object.assign(development, x); development.dateStart = From 668b05a511f68d4b194222a97d828d7a400606b6 Mon Sep 17 00:00:00 2001 From: kittapath Date: Thu, 26 Dec 2024 23:31:05 +0700 Subject: [PATCH 194/250] no message --- src/controllers/DevelopmentController.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/controllers/DevelopmentController.ts b/src/controllers/DevelopmentController.ts index be7ecc6..38fddc8 100644 --- a/src/controllers/DevelopmentController.ts +++ b/src/controllers/DevelopmentController.ts @@ -2554,9 +2554,9 @@ export class DevelopmentController extends Controller { reasonDevelopment70: x.development.reasonActual70, reasonDevelopment20: x.development.reasonActual20, reasonDevelopment10: x.development.reasonActual10, - isDevelopment70: false, - isDevelopment20: false, - isDevelopment10: false, + isDevelopment70: x.development.isReasonActual70, + isDevelopment20: x.development.isReasonActual20, + isDevelopment10: x.development.isReasonActual10, developmentTarget: null, developmentResults: null, developmentReport: null, From 19598f1f81342ab20e5d1cc481bee5e835df5821 Mon Sep 17 00:00:00 2001 From: kittapath Date: Fri, 17 Jan 2025 17:52:13 +0700 Subject: [PATCH 195/250] update province --- src/controllers/DevelopmentController.ts | 39 +++++++++---------- .../DevelopmentEmployeeHistoryController.ts | 13 +++---- .../DevelopmentHistoryController.ts | 11 +----- src/entities/Development.ts | 5 --- src/entities/DevelopmentAddress.ts | 10 +++-- src/entities/DevelopmentOther.ts | 12 +++--- src/entities/DevelopmentRisk.ts | 7 ++-- src/entities/Province.ts | 12 ------ ...11015155-update_delete_dev_provincename.ts | 22 +++++++++++ 9 files changed, 64 insertions(+), 67 deletions(-) create mode 100644 src/migration/1737111015155-update_delete_dev_provincename.ts diff --git a/src/controllers/DevelopmentController.ts b/src/controllers/DevelopmentController.ts index 38fddc8..454a843 100644 --- a/src/controllers/DevelopmentController.ts +++ b/src/controllers/DevelopmentController.ts @@ -32,7 +32,6 @@ import { ActualPeople, CreateActualPeople } from "../entities/ActualPeople"; import { CreatePlannedPeople, PlannedPeople } from "../entities/PlannedPeople"; import { ActualGoal, CreateActualGoal } from "../entities/ActualGoal"; import { CreatePlannedGoal, PlannedGoal } from "../entities/PlannedGoal"; -import { Province } from "../entities/Province"; import { PosType } from "../entities/PosType"; import { PosLevel } from "../entities/PosLevel"; import { PlannedGoalPosition } from "../entities/PlannedGoalPosition"; @@ -83,7 +82,6 @@ export class DevelopmentController extends Controller { private actualGoalRepository = AppDataSource.getRepository(ActualGoal); private plannedGoalRepository = AppDataSource.getRepository(PlannedGoal); private plannedGoalPositionRepository = AppDataSource.getRepository(PlannedGoalPosition); - private provinceRepository = AppDataSource.getRepository(Province); private posTypeRepository = AppDataSource.getRepository(PosType); private posLevelRepository = AppDataSource.getRepository(PosLevel); private strategyChild1Repository = AppDataSource.getRepository(StrategyChild1); @@ -1224,19 +1222,14 @@ export class DevelopmentController extends Controller { // const before = structuredClone(development); await Promise.all( requestBody.developmentAddresss.map(async (x) => { - let _null: any = null; const data = Object.assign(new DevelopmentAddress(), x); - if (x.provinceId != null) { - const chkProvince = await this.provinceRepository.findOne({ - where: { - id: x.provinceId, - }, - }); - if (chkProvince == null) { - data.provinceId = _null; - } - } if (x.address) { + await new CallAPI() + .GetData(request, `/org/metadata/province/${x.provinceId}`) + .then(async (item) => { + data.provinceName = item.name; + }) + .catch(async (x) => {}); data.developmentId = development.id; data.createdUserId = request.user.sub; data.createdFullName = request.user.name; @@ -1433,16 +1426,14 @@ export class DevelopmentController extends Controller { if (!development) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงการ/หลักสูตรการฝึกอบรมนี้"); } - if (requestBody.provinceActualId != null) { - const checkId = await this.provinceRepository.findOne({ - where: { id: requestBody.provinceActualId }, - }); - if (!checkId) { - throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลจังหวัดข้อมูลด้านวิชาการ"); - } - } const before = structuredClone(development); const data = Object.assign(new DevelopmentOther(), requestBody); + await new CallAPI() + .GetData(request, `/org/metadata/province/${requestBody.provinceActualId}`) + .then(async (item) => { + data.provinceActualName = item.name; + }) + .catch(async (x) => {}); data.createdUserId = request.user.sub; data.createdFullName = request.user.name; data.lastUpdateUserId = request.user.sub; @@ -1496,6 +1487,12 @@ export class DevelopmentController extends Controller { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลความเสี่ยงของโครงการ"); } Object.assign(development, requestBody); + await new CallAPI() + .GetData(request, `/org/metadata/province/${requestBody.provinceActualId}`) + .then(async (item) => { + development.provinceActualName = item.name; + }) + .catch(async (x) => {}); development.lastUpdateUserId = request.user.sub; development.lastUpdateFullName = request.user.name; development.lastUpdatedAt = new Date(); diff --git a/src/controllers/DevelopmentEmployeeHistoryController.ts b/src/controllers/DevelopmentEmployeeHistoryController.ts index 3d152ea..2b8054f 100644 --- a/src/controllers/DevelopmentEmployeeHistoryController.ts +++ b/src/controllers/DevelopmentEmployeeHistoryController.ts @@ -360,18 +360,17 @@ export class DevelopmentEmployeeHistoryController extends Controller { relations: [ "development", "development.developmentOthers", - "development.developmentOthers.province", "employeePosLevel", "employeePosType", ], where: { id: id, type: type }, order: { - development:{ + development: { developmentOthers: { - createdAt: "ASC" - } - } - } + createdAt: "ASC", + }, + }, + }, }); if (!getDevelopment) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลประวัติการฝึกอบรม/ดูงานนี้"); @@ -416,7 +415,7 @@ export class DevelopmentEmployeeHistoryController extends Controller { ? getDevelopment.development.developmentOthers.map((dev) => ({ topicAcademic: dev.topicAcademic, addressAcademic: dev.addressAcademic, - province: dev.province.name + province: dev.provinceActualName, })) : [], }; diff --git a/src/controllers/DevelopmentHistoryController.ts b/src/controllers/DevelopmentHistoryController.ts index dec3501..e546a0c 100644 --- a/src/controllers/DevelopmentHistoryController.ts +++ b/src/controllers/DevelopmentHistoryController.ts @@ -27,7 +27,6 @@ import { PosLevel } from "../entities/PosLevel"; import { RequestWithUser } from "../middlewares/user"; import { setLogDataDiff } from "../interfaces/utils"; import permission from "../interfaces/permission"; -import { Province } from "../entities/Province"; @Route("api/v1/development/history/officer") @Tags("DevelopmentOfficerHistory") @@ -352,13 +351,7 @@ export class DevelopmentOfficerHistoryController extends Controller { await new permission().PermissionGet(request, "SYS_DEV_HISTORY_OFFICER"); const type = "OFFICER"; const getDevelopment = await this.developmentHistoryRepository.findOne({ - relations: [ - "development", - "development.developmentOthers", - "development.developmentOthers.province", - "posLevel", - "posType", - ], + relations: ["development", "development.developmentOthers", "posLevel", "posType"], where: { id: id, type: type }, order: { development: { @@ -408,7 +401,7 @@ export class DevelopmentOfficerHistoryController extends Controller { ? getDevelopment.development.developmentOthers.map((dev) => ({ topicAcademic: dev.topicAcademic, addressAcademic: dev.addressAcademic, - province: dev.province.name, + province: dev.provinceActualName, })) : [], }; diff --git a/src/entities/Development.ts b/src/entities/Development.ts index b807734..cd4b339 100644 --- a/src/entities/Development.ts +++ b/src/entities/Development.ts @@ -1,6 +1,5 @@ import { Entity, Column, ManyToOne, JoinColumn, OneToMany, Double } from "typeorm"; import { EntityBase } from "./base/Base"; -import { Province } from "./Province"; import { ActualPeople, CreateActualPeople } from "./ActualPeople"; import { CreatePlannedPeople, PlannedPeople } from "./PlannedPeople"; import { ActualGoal, CreateActualGoal } from "./ActualGoal"; @@ -566,10 +565,6 @@ export class Development extends EntityBase { }) provinceActualId: string; - @ManyToOne(() => Province, (province: Province) => province.developmentActuals) - @JoinColumn({ name: "provinceActualId" }) - provinceActual: Province; - @Column({ nullable: true, type: "datetime", diff --git a/src/entities/DevelopmentAddress.ts b/src/entities/DevelopmentAddress.ts index 37be847..1629293 100644 --- a/src/entities/DevelopmentAddress.ts +++ b/src/entities/DevelopmentAddress.ts @@ -1,7 +1,6 @@ import { Entity, Column, ManyToOne, JoinColumn } from "typeorm"; import { EntityBase } from "./base/Base"; import { Development } from "./Development"; -import { Province } from "./Province"; @Entity("developmentAddress") export class DevelopmentAddress extends EntityBase { @@ -19,9 +18,12 @@ export class DevelopmentAddress extends EntityBase { }) provinceId: string; - @ManyToOne(() => Province, (province: Province) => province.developmentAddresss) - @JoinColumn({ name: "provinceId" }) - province: Province; + @Column({ + nullable: true, + comment: "โครงการ/หลักสูตรการฝึกอบรม", + default: null, + }) + provinceName: string; @Column({ nullable: true, diff --git a/src/entities/DevelopmentOther.ts b/src/entities/DevelopmentOther.ts index 7cf0da1..98e145a 100644 --- a/src/entities/DevelopmentOther.ts +++ b/src/entities/DevelopmentOther.ts @@ -1,7 +1,6 @@ import { Entity, Column, ManyToOne, JoinColumn } from "typeorm"; import { EntityBase } from "./base/Base"; import { Development } from "./Development"; -import { Province } from "./Province"; @Entity("developmentOther") export class DevelopmentOther extends EntityBase { @@ -26,6 +25,13 @@ export class DevelopmentOther extends EntityBase { }) provinceActualId: string; + @Column({ + nullable: true, + comment: "จังหวัด(ข้อมูลวิชาการ)", + default: null, + }) + provinceActualName: string; + @Column({ nullable: true, comment: "คีย์นอก(FK)ของตาราง development", @@ -36,10 +42,6 @@ export class DevelopmentOther extends EntityBase { @ManyToOne(() => Development, (development: Development) => development.developmentOthers) @JoinColumn({ name: "developmentId" }) development: Development; - - @ManyToOne(() => Province, (province: Province) => province.developmentOthers) - @JoinColumn({ name: "provinceActualId" }) - province: Province; } export class UpdateDevelopmentOther { diff --git a/src/entities/DevelopmentRisk.ts b/src/entities/DevelopmentRisk.ts index e12c614..b146cba 100644 --- a/src/entities/DevelopmentRisk.ts +++ b/src/entities/DevelopmentRisk.ts @@ -1,7 +1,6 @@ import { Entity, Column, ManyToOne, JoinColumn } from "typeorm"; import { EntityBase } from "./base/Base"; import { Development } from "./Development"; -import { Province } from "./Province"; @Entity("developmentRisk") export class DevelopmentRisk extends EntityBase { @@ -47,9 +46,9 @@ export class DevelopmentRisk extends EntityBase { }) developmentId: string; - @ManyToOne(() => Development, (development: Development) => development.developmentRisks) - @JoinColumn({ name: "developmentId" }) - development: Development; + @ManyToOne(() => Development, (development: Development) => development.developmentRisks) + @JoinColumn({ name: "developmentId" }) + development: Development; } export class UpdateDevelopmentRisk { diff --git a/src/entities/Province.ts b/src/entities/Province.ts index f697b97..080a8c6 100644 --- a/src/entities/Province.ts +++ b/src/entities/Province.ts @@ -13,18 +13,6 @@ export class Province extends EntityBase { default: null, }) name: string; - - @OneToMany( - () => DevelopmentAddress, - (developmentAddress: DevelopmentAddress) => developmentAddress.province, - ) - developmentAddresss: DevelopmentAddress[]; - - @OneToMany(() => Development, (development: Development) => development.provinceActual) - developmentActuals: Development[]; - - @OneToMany(() => DevelopmentOther, (developmentOther: DevelopmentOther) => developmentOther.province) - developmentOthers: Development[]; } export class CreateProvince { diff --git a/src/migration/1737111015155-update_delete_dev_provincename.ts b/src/migration/1737111015155-update_delete_dev_provincename.ts new file mode 100644 index 0000000..9f0b4e5 --- /dev/null +++ b/src/migration/1737111015155-update_delete_dev_provincename.ts @@ -0,0 +1,22 @@ +import { MigrationInterface, QueryRunner } from "typeorm"; + +export class UpdateDeleteDevProvincename1737111015155 implements MigrationInterface { + name = 'UpdateDeleteDevProvincename1737111015155' + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`developmentAddress\` DROP FOREIGN KEY \`FK_e2721b3f440256b56ce83a04fb2\``); + await queryRunner.query(`ALTER TABLE \`developmentOther\` DROP FOREIGN KEY \`FK_47bbbecaea9b7b31d2536054656\``); + await queryRunner.query(`ALTER TABLE \`development\` DROP FOREIGN KEY \`FK_bdafbb824b88c3bdb73adf7f220\``); + await queryRunner.query(`ALTER TABLE \`developmentAddress\` ADD \`provinceName\` varchar(255) NULL COMMENT 'โครงการ/หลักสูตรการฝึกอบรม'`); + await queryRunner.query(`ALTER TABLE \`developmentOther\` ADD \`provinceActualName\` varchar(255) NULL COMMENT 'จังหวัด(ข้อมูลวิชาการ)'`); + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`developmentOther\` DROP COLUMN \`provinceActualName\``); + await queryRunner.query(`ALTER TABLE \`developmentAddress\` DROP COLUMN \`provinceName\``); + await queryRunner.query(`ALTER TABLE \`development\` ADD CONSTRAINT \`FK_bdafbb824b88c3bdb73adf7f220\` FOREIGN KEY (\`provinceActualId\`) REFERENCES \`province\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`); + await queryRunner.query(`ALTER TABLE \`developmentOther\` ADD CONSTRAINT \`FK_47bbbecaea9b7b31d2536054656\` FOREIGN KEY (\`provinceActualId\`) REFERENCES \`province\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`); + await queryRunner.query(`ALTER TABLE \`developmentAddress\` ADD CONSTRAINT \`FK_e2721b3f440256b56ce83a04fb2\` FOREIGN KEY (\`provinceId\`) REFERENCES \`province\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`); + } + +} From 005e7582bfea2df51797e16a2abef20aa1b8b289 Mon Sep 17 00:00:00 2001 From: AdisakKanthawilang Date: Fri, 17 Jan 2025 20:02:52 +0700 Subject: [PATCH 196/250] #826 checkpoint --- src/controllers/ReportController.ts | 215 +++++++++++++++++++++++++++- 1 file changed, 214 insertions(+), 1 deletion(-) diff --git a/src/controllers/ReportController.ts b/src/controllers/ReportController.ts index ba4dd6d..95e852c 100644 --- a/src/controllers/ReportController.ts +++ b/src/controllers/ReportController.ts @@ -9,6 +9,7 @@ import { PosType } from "../entities/PosType"; import { PosLevel } from "../entities/PosLevel"; import Extension from "../interfaces/extension"; import { DevelopmentScholarship } from "../entities/DevelopmentScholarship"; +import { IsNull, Not } from "typeorm"; @Route("api/v1/development/report") @Tags("Report") @Security("bearerAuth") @@ -24,16 +25,228 @@ export class ReportController extends Controller { */ @Get("main") async GetReportDevelopemtMain(/*@Path() type: string*/) { + // const _type = type.trim().toUpperCase(); const formattedData = { org: "_type", }; + //ตารางรายละเอียด กับ แบบรายงาน + const dataDevelopment = await AppDataSource.getRepository(Development) + .createQueryBuilder("development") + .leftJoinAndSelect("development.developmentHistorys", "history") + .leftJoinAndSelect("development.developmentPlannedGoals", "planGoals") + .leftJoinAndSelect("development.strategyChild1Actual", "strategy1") + .leftJoinAndSelect("development.strategyChild2Actual", "strategy2") + .leftJoinAndSelect("development.strategyChild3Actual", "strategy3") + .leftJoinAndSelect("development.strategyChild4Actual", "strategy4") + .leftJoinAndSelect("development.strategyChild5Actual", "strategy5") + .where("development.status = :status", { status: "FINISH" }) + .andWhere("development.strategyChild1ActualId IS NOT NULL") + .select([ + "development.id AS id", + "development.projectName AS projectName", + "development.year AS year", + "development.totalDate AS totalDate", + "development.budget AS budget", + "SUM(DISTINCT planGoals.amount) AS goalParticipants", + "COUNT(DISTINCT history.id) AS actualParticipants", + "strategy1.strategyChild1Name AS strategy1", + "strategy2.strategyChild2Name AS strategy2", + "strategy3.strategyChild3Name AS strategy3", + "strategy4.strategyChild4Name AS strategy4", + "strategy5.strategyChild5Name AS strategy5", + "development.accept AS acceptBudget", + "development.receive AS receiveBudget", + "development.obstacle AS obstacle", + "development.root AS root", + ]) + .groupBy("development.id") + .getRawMany(); + + const mappedDataDev = dataDevelopment.map((item, index) => { + let budget = null; + if (item.budget == "REGULATIONBUDGET") { + budget = "งบตามข้อบัญญัติ"; + }else if (item.budget == "OTHERBUDGET") { + budget = "เงินนอกงบประมาณ"; + }else if (item.budget == "BANGKOKBUDGET") { + budget = "ไม่ใช้งบประมาณ"; + } + return { + strategy: item.strategy1, + projectName: item.projectName, + totalDate: item.totalDate != null && item.totalDate != "" ? Extension.ToThaiNumber(item.totalDate.toString()): "-", + goalParticipants: item.goalParticipants != null && item.goalParticipants != "" ? Extension.ToThaiNumber(item.goalParticipants.toString()): "-", + actualParticipants: item.actualParticipants != null && item.actualParticipants != "" ? Extension.ToThaiNumber(item.actualParticipants.toString()): "-", + budget: budget, + acceptBudget: item.acceptBudget != null && item.acceptBudget != "" ? Extension.ToThaiNumber(item.acceptBudget.toString()): "-", + receiveBudget: item.receiveBudget != null && item.receiveBudget != "" ? Extension.ToThaiNumber(item.receiveBudget.toString()): "-", + obstacle: item.obstacle, + root: item.root, + output: "-", + outcome: "-", + position: "-", + indicators: "-", + devResult: "-", + positionActual: "-", + }; + }); + + const resultAllStrategy = await AppDataSource.getRepository(Development) + .createQueryBuilder("development") + .leftJoinAndSelect("development.strategyChild1Actual", "strategy1") + .where("development.status = :status", { status: "FINISH" }) + .andWhere("development.strategyChild1ActualId IS NOT NULL") + .select([ + "development.rootId AS rootId", + "development.strategyChild1ActualId AS strategyId", + "strategy1.strategyChild1Name AS strategyName", + "COUNT(development.id) AS devCount", + "SUM(development.receive) AS receiveBudget", + "development.root AS root", + ]) + .groupBy("development.rootId, development.strategyChild1ActualId, strategy1.strategyChild1Name, development.root") + .orderBy("strategy1.createdAt", "ASC") + .getRawMany(); + + interface Strategy { + strategyId: string; + strategyName: string; + devCount: string; + receiveBudget: string; + sumDev: string; + sumTraget: string; + sumBudget: string; + sumRowDev: string, + sumRowTarget: string, + sumRowBudget: string, + } + + interface GroupedData { + rootId: string; + root: string; + strategy: Strategy[]; + } + + // สมมติว่า 'resultAllStrategy' ถูกกำหนดไว้แล้วและมีข้อมูลที่คุณให้มา + const groupedData: GroupedData[] = resultAllStrategy.reduce((acc: GroupedData[], item) => { + const existingRoot = acc.find(entry => entry.rootId === item.rootId); + + if (existingRoot) { + existingRoot.strategy.push({ + strategyId: item.strategyId, + strategyName: item.strategyName, + devCount: item.devCount?Extension.ToThaiNumber(item.devCount.toString()):"0", + receiveBudget: item.receiveBudget?Extension.ToThaiNumber(item.receiveBudget.toString()):"0", + sumDev: "", + sumTraget: "", + sumBudget: "", + sumRowDev:"", + sumRowTarget:"", + sumRowBudget:"", + }); + } else { + acc.push({ + rootId: item.rootId, + root: item.root, + strategy: [{ + strategyId: item.strategyId, + strategyName: item.strategyName, + devCount: item.devCount?Extension.ToThaiNumber(item.devCount.toString()):"0", + receiveBudget: item.receiveBudget?Extension.ToThaiNumber(item.receiveBudget.toString()):"0", + sumDev: "", + sumTraget: "", + sumBudget: "", + sumRowDev:"", + sumRowTarget:"", + sumRowBudget:"", + }] + }); + } + + return acc; + }, []); + + // ตอนนี้คุณสามารถ map ข้อมูลใน 'groupedData' เพื่อสร้าง 'formattedData' ได้แล้ว + const reformattedData = groupedData.map((group,x) => { + const formattedGroup = { + rowNo: x?Extension.ToThaiNumber((x + 1).toString()):Extension.ToThaiNumber("๑"), + rootId: group.rootId, + root: group.root, + strategy: Array(4).fill(null).map((_, index) => { + const strategy = group.strategy[index] || { + strategyName: "0", + devCount: "0", + target: "0", + receiveBudget: "0", + sumDev: "0", + sumTraget: "0", + sumBudget: "0", + sumRowDev:"0", + sumRowTarget:"0", + sumRowBudget:"0", + }; + + return { + [`strategyName${index + 1}`]: strategy.strategyName ?? "0", + [`devCount${index + 1}`]: strategy.devCount ?? "0", + [`target${index + 1}`]: "0", + [`receiveBudget${index + 1}`]: strategy.receiveBudget ?? "0", + [`sumDev${index + 1}`]: strategy.sumDev ?? "0", + [`sumTraget${index + 1}`]: strategy.sumTraget ?? "0", + [`sumBudget${index + 1}`]: strategy.sumBudget ?? "0", + [`sumRowDev`]: strategy.sumRowDev ?? "0", + [`sumRowTarget`]: strategy.sumRowTarget ?? "0", + [`sumRowBudget`]: strategy.sumRowBudget ?? "0", + }; + }), + }; + + return formattedGroup; + }); + + + // const fmdata = reformattedData.map(rfmData => { + // return { + // rowNo: rfmData.rowNo, + // rootId: rfmData.rootId, + // root: rfmData.root, + // strategy: [ + // { + // strategyName1: rfmData.strategy[0].strategyName1, + // devCount1: rfmData.strategy[0].devCount1, + // target1: rfmData.strategy[0].target1, + // receiveBudget1: rfmData.strategy[0].receiveBudget1 + // }, + // { + // strategyName2: rfmData.strategy[1].strategyName2, + // devCount2: rfmData.strategy[1].devCount2, + // target2: rfmData.strategy[1].target2, + // receiveBudget2: rfmData.strategy[1].receiveBudget2 + // }, + // { + // strategyName3: rfmData.strategy[2].strategyName3, + // devCount3: rfmData.strategy[2].devCount3, + // target3: rfmData.strategy[2].target3, + // receiveBudget3: rfmData.strategy[2].receiveBudget3 + // }, + // { + // strategyName4: rfmData.strategy[3].strategyName4, + // devCount4: rfmData.strategy[3].devCount4, + // target4: rfmData.strategy[3].target4, + // receiveBudget4: rfmData.strategy[3].receiveBudget4 + // } + // ], + // }; + // }); + return new HttpSuccess({ template: "development", reportName: "development", data: { - data: formattedData, + data: mappedDataDev, + resultAllStrategy: reformattedData, }, }); } From 9c1dc78eedada122717d9c3729beb103b418a60c Mon Sep 17 00:00:00 2001 From: AdisakKanthawilang Date: Mon, 20 Jan 2025 13:23:31 +0700 Subject: [PATCH 197/250] reformat code --- src/controllers/ReportController.ts | 59 ++++++----------------------- 1 file changed, 11 insertions(+), 48 deletions(-) diff --git a/src/controllers/ReportController.ts b/src/controllers/ReportController.ts index 95e852c..4a5a689 100644 --- a/src/controllers/ReportController.ts +++ b/src/controllers/ReportController.ts @@ -129,7 +129,6 @@ export class ReportController extends Controller { strategy: Strategy[]; } - // สมมติว่า 'resultAllStrategy' ถูกกำหนดไว้แล้วและมีข้อมูลที่คุณให้มา const groupedData: GroupedData[] = resultAllStrategy.reduce((acc: GroupedData[], item) => { const existingRoot = acc.find(entry => entry.rootId === item.rootId); @@ -168,7 +167,6 @@ export class ReportController extends Controller { return acc; }, []); - // ตอนนี้คุณสามารถ map ข้อมูลใน 'groupedData' เพื่อสร้าง 'formattedData' ได้แล้ว const reformattedData = groupedData.map((group,x) => { const formattedGroup = { rowNo: x?Extension.ToThaiNumber((x + 1).toString()):Extension.ToThaiNumber("๑"), @@ -189,58 +187,23 @@ export class ReportController extends Controller { }; return { - [`strategyName${index + 1}`]: strategy.strategyName ?? "0", - [`devCount${index + 1}`]: strategy.devCount ?? "0", - [`target${index + 1}`]: "0", - [`receiveBudget${index + 1}`]: strategy.receiveBudget ?? "0", - [`sumDev${index + 1}`]: strategy.sumDev ?? "0", - [`sumTraget${index + 1}`]: strategy.sumTraget ?? "0", - [`sumBudget${index + 1}`]: strategy.sumBudget ?? "0", - [`sumRowDev`]: strategy.sumRowDev ?? "0", - [`sumRowTarget`]: strategy.sumRowTarget ?? "0", - [`sumRowBudget`]: strategy.sumRowBudget ?? "0", - }; + [`strategyName${index + 1}`]: strategy.strategyName ?? "", + [`devCount${index + 1}`]: strategy.devCount ?? "", + [`target${index + 1}`]: "", + [`receiveBudget${index + 1}`]: strategy.receiveBudget ?? "", + [`sumDev${index + 1}`]: strategy.sumDev ?? "", + [`sumTraget${index + 1}`]: strategy.sumTraget ?? "", + [`sumBudget${index + 1}`]: strategy.sumBudget ?? "", + [`sumRowDev`]: strategy.sumRowDev ?? "", + [`sumRowTarget`]: strategy.sumRowTarget ?? "", + [`sumRowBudget`]: strategy.sumRowBudget ?? "", + }; }), }; return formattedGroup; }); - - // const fmdata = reformattedData.map(rfmData => { - // return { - // rowNo: rfmData.rowNo, - // rootId: rfmData.rootId, - // root: rfmData.root, - // strategy: [ - // { - // strategyName1: rfmData.strategy[0].strategyName1, - // devCount1: rfmData.strategy[0].devCount1, - // target1: rfmData.strategy[0].target1, - // receiveBudget1: rfmData.strategy[0].receiveBudget1 - // }, - // { - // strategyName2: rfmData.strategy[1].strategyName2, - // devCount2: rfmData.strategy[1].devCount2, - // target2: rfmData.strategy[1].target2, - // receiveBudget2: rfmData.strategy[1].receiveBudget2 - // }, - // { - // strategyName3: rfmData.strategy[2].strategyName3, - // devCount3: rfmData.strategy[2].devCount3, - // target3: rfmData.strategy[2].target3, - // receiveBudget3: rfmData.strategy[2].receiveBudget3 - // }, - // { - // strategyName4: rfmData.strategy[3].strategyName4, - // devCount4: rfmData.strategy[3].devCount4, - // target4: rfmData.strategy[3].target4, - // receiveBudget4: rfmData.strategy[3].receiveBudget4 - // } - // ], - // }; - // }); - return new HttpSuccess({ template: "development", reportName: "development", From f4140f45f83ba9ae57f36d30d8ad0fc898a2c2a2 Mon Sep 17 00:00:00 2001 From: kittapath Date: Mon, 20 Jan 2025 14:51:17 +0700 Subject: [PATCH 198/250] report tamplate --- src/controllers/ReportController.ts | 295 +++++++++++++++------------- 1 file changed, 161 insertions(+), 134 deletions(-) diff --git a/src/controllers/ReportController.ts b/src/controllers/ReportController.ts index 95e852c..ecf51be 100644 --- a/src/controllers/ReportController.ts +++ b/src/controllers/ReportController.ts @@ -25,7 +25,6 @@ export class ReportController extends Controller { */ @Get("main") async GetReportDevelopemtMain(/*@Path() type: string*/) { - // const _type = type.trim().toUpperCase(); const formattedData = { org: "_type", @@ -52,9 +51,9 @@ export class ReportController extends Controller { "SUM(DISTINCT planGoals.amount) AS goalParticipants", "COUNT(DISTINCT history.id) AS actualParticipants", "strategy1.strategyChild1Name AS strategy1", - "strategy2.strategyChild2Name AS strategy2", - "strategy3.strategyChild3Name AS strategy3", - "strategy4.strategyChild4Name AS strategy4", + "strategy2.strategyChild2Name AS strategy2", + "strategy3.strategyChild3Name AS strategy3", + "strategy4.strategyChild4Name AS strategy4", "strategy5.strategyChild5Name AS strategy5", "development.accept AS acceptBudget", "development.receive AS receiveBudget", @@ -64,117 +63,142 @@ export class ReportController extends Controller { .groupBy("development.id") .getRawMany(); - const mappedDataDev = dataDevelopment.map((item, index) => { - let budget = null; - if (item.budget == "REGULATIONBUDGET") { - budget = "งบตามข้อบัญญัติ"; - }else if (item.budget == "OTHERBUDGET") { - budget = "เงินนอกงบประมาณ"; - }else if (item.budget == "BANGKOKBUDGET") { - budget = "ไม่ใช้งบประมาณ"; - } - return { - strategy: item.strategy1, - projectName: item.projectName, - totalDate: item.totalDate != null && item.totalDate != "" ? Extension.ToThaiNumber(item.totalDate.toString()): "-", - goalParticipants: item.goalParticipants != null && item.goalParticipants != "" ? Extension.ToThaiNumber(item.goalParticipants.toString()): "-", - actualParticipants: item.actualParticipants != null && item.actualParticipants != "" ? Extension.ToThaiNumber(item.actualParticipants.toString()): "-", - budget: budget, - acceptBudget: item.acceptBudget != null && item.acceptBudget != "" ? Extension.ToThaiNumber(item.acceptBudget.toString()): "-", - receiveBudget: item.receiveBudget != null && item.receiveBudget != "" ? Extension.ToThaiNumber(item.receiveBudget.toString()): "-", - obstacle: item.obstacle, - root: item.root, - output: "-", - outcome: "-", - position: "-", - indicators: "-", - devResult: "-", - positionActual: "-", - }; - }); + const mappedDataDev = dataDevelopment.map((item, index) => { + let budget = null; + if (item.budget == "REGULATIONBUDGET") { + budget = "งบตามข้อบัญญัติ"; + } else if (item.budget == "OTHERBUDGET") { + budget = "เงินนอกงบประมาณ"; + } else if (item.budget == "BANGKOKBUDGET") { + budget = "ไม่ใช้งบประมาณ"; + } + return { + strategy: item.strategy1, + projectName: item.projectName, + totalDate: + item.totalDate != null && item.totalDate != "" + ? Extension.ToThaiNumber(item.totalDate.toString()) + : "-", + goalParticipants: + item.goalParticipants != null && item.goalParticipants != "" + ? Extension.ToThaiNumber(item.goalParticipants.toString()) + : "-", + actualParticipants: + item.actualParticipants != null && item.actualParticipants != "" + ? Extension.ToThaiNumber(item.actualParticipants.toString()) + : "-", + budget: budget, + acceptBudget: + item.acceptBudget != null && item.acceptBudget != "" + ? Extension.ToThaiNumber(item.acceptBudget.toString()) + : "-", + receiveBudget: + item.receiveBudget != null && item.receiveBudget != "" + ? Extension.ToThaiNumber(item.receiveBudget.toString()) + : "-", + obstacle: item.obstacle, + root: item.root, + output: "-", + outcome: "-", + position: "-", + indicators: "-", + devResult: "-", + positionActual: "-", + }; + }); - const resultAllStrategy = await AppDataSource.getRepository(Development) + const resultAllStrategy = await AppDataSource.getRepository(Development) .createQueryBuilder("development") .leftJoinAndSelect("development.strategyChild1Actual", "strategy1") .where("development.status = :status", { status: "FINISH" }) .andWhere("development.strategyChild1ActualId IS NOT NULL") .select([ "development.rootId AS rootId", - "development.strategyChild1ActualId AS strategyId", + "development.strategyChild1ActualId AS strategyId", "strategy1.strategyChild1Name AS strategyName", "COUNT(development.id) AS devCount", "SUM(development.receive) AS receiveBudget", "development.root AS root", ]) - .groupBy("development.rootId, development.strategyChild1ActualId, strategy1.strategyChild1Name, development.root") + .groupBy( + "development.rootId, development.strategyChild1ActualId, strategy1.strategyChild1Name, development.root", + ) .orderBy("strategy1.createdAt", "ASC") .getRawMany(); - - interface Strategy { - strategyId: string; - strategyName: string; - devCount: string; - receiveBudget: string; - sumDev: string; - sumTraget: string; - sumBudget: string; - sumRowDev: string, - sumRowTarget: string, - sumRowBudget: string, - } - - interface GroupedData { - rootId: string; - root: string; - strategy: Strategy[]; - } - - // สมมติว่า 'resultAllStrategy' ถูกกำหนดไว้แล้วและมีข้อมูลที่คุณให้มา - const groupedData: GroupedData[] = resultAllStrategy.reduce((acc: GroupedData[], item) => { - const existingRoot = acc.find(entry => entry.rootId === item.rootId); - if (existingRoot) { - existingRoot.strategy.push({ - strategyId: item.strategyId, - strategyName: item.strategyName, - devCount: item.devCount?Extension.ToThaiNumber(item.devCount.toString()):"0", - receiveBudget: item.receiveBudget?Extension.ToThaiNumber(item.receiveBudget.toString()):"0", - sumDev: "", - sumTraget: "", - sumBudget: "", - sumRowDev:"", - sumRowTarget:"", - sumRowBudget:"", - }); - } else { - acc.push({ - rootId: item.rootId, - root: item.root, - strategy: [{ + interface Strategy { + strategyId: string; + strategyName: string; + devCount: string; + receiveBudget: string; + sumDev: string; + sumTraget: string; + sumBudget: string; + sumRowDev: string; + sumRowTarget: string; + sumRowBudget: string; + } + + interface GroupedData { + rootId: string; + root: string; + strategy: Strategy[]; + } + + // สมมติว่า 'resultAllStrategy' ถูกกำหนดไว้แล้วและมีข้อมูลที่คุณให้มา + const groupedData: GroupedData[] = resultAllStrategy.reduce((acc: GroupedData[], item) => { + const existingRoot = acc.find((entry) => entry.rootId === item.rootId); + + if (existingRoot) { + existingRoot.strategy.push({ + strategyId: item.strategyId, + strategyName: item.strategyName, + devCount: item.devCount ? Extension.ToThaiNumber(item.devCount.toString()) : "0", + receiveBudget: item.receiveBudget + ? Extension.ToThaiNumber(item.receiveBudget.toString()) + : "0", + sumDev: "", + sumTraget: "", + sumBudget: "", + sumRowDev: "", + sumRowTarget: "", + sumRowBudget: "", + }); + } else { + acc.push({ + rootId: item.rootId, + root: item.root, + strategy: [ + { strategyId: item.strategyId, strategyName: item.strategyName, - devCount: item.devCount?Extension.ToThaiNumber(item.devCount.toString()):"0", - receiveBudget: item.receiveBudget?Extension.ToThaiNumber(item.receiveBudget.toString()):"0", + devCount: item.devCount ? Extension.ToThaiNumber(item.devCount.toString()) : "0", + receiveBudget: item.receiveBudget + ? Extension.ToThaiNumber(item.receiveBudget.toString()) + : "0", sumDev: "", sumTraget: "", sumBudget: "", - sumRowDev:"", - sumRowTarget:"", - sumRowBudget:"", - }] - }); - } + sumRowDev: "", + sumRowTarget: "", + sumRowBudget: "", + }, + ], + }); + } - return acc; - }, []); + return acc; + }, []); - // ตอนนี้คุณสามารถ map ข้อมูลใน 'groupedData' เพื่อสร้าง 'formattedData' ได้แล้ว - const reformattedData = groupedData.map((group,x) => { - const formattedGroup = { - rowNo: x?Extension.ToThaiNumber((x + 1).toString()):Extension.ToThaiNumber("๑"), - rootId: group.rootId, - root: group.root, - strategy: Array(4).fill(null).map((_, index) => { + // ตอนนี้คุณสามารถ map ข้อมูลใน 'groupedData' เพื่อสร้าง 'formattedData' ได้แล้ว + const reformattedData = groupedData.map((group, x) => { + const formattedGroup = { + rowNo: x ? Extension.ToThaiNumber((x + 1).toString()) : Extension.ToThaiNumber("๑"), + rootId: group.rootId, + root: group.root, + strategy: Array(4) + .fill(null) + .map((_, index) => { const strategy = group.strategy[index] || { strategyName: "0", devCount: "0", @@ -183,9 +207,9 @@ export class ReportController extends Controller { sumDev: "0", sumTraget: "0", sumBudget: "0", - sumRowDev:"0", - sumRowTarget:"0", - sumRowBudget:"0", + sumRowDev: "0", + sumRowTarget: "0", + sumRowBudget: "0", }; return { @@ -201,46 +225,45 @@ export class ReportController extends Controller { [`sumRowBudget`]: strategy.sumRowBudget ?? "0", }; }), - }; + }; - return formattedGroup; - }); + return formattedGroup; + }); + + // const fmdata = reformattedData.map(rfmData => { + // return { + // rowNo: rfmData.rowNo, + // rootId: rfmData.rootId, + // root: rfmData.root, + // strategy: [ + // { + // strategyName1: rfmData.strategy[0].strategyName1, + // devCount1: rfmData.strategy[0].devCount1, + // target1: rfmData.strategy[0].target1, + // receiveBudget1: rfmData.strategy[0].receiveBudget1 + // }, + // { + // strategyName2: rfmData.strategy[1].strategyName2, + // devCount2: rfmData.strategy[1].devCount2, + // target2: rfmData.strategy[1].target2, + // receiveBudget2: rfmData.strategy[1].receiveBudget2 + // }, + // { + // strategyName3: rfmData.strategy[2].strategyName3, + // devCount3: rfmData.strategy[2].devCount3, + // target3: rfmData.strategy[2].target3, + // receiveBudget3: rfmData.strategy[2].receiveBudget3 + // }, + // { + // strategyName4: rfmData.strategy[3].strategyName4, + // devCount4: rfmData.strategy[3].devCount4, + // target4: rfmData.strategy[3].target4, + // receiveBudget4: rfmData.strategy[3].receiveBudget4 + // } + // ], + // }; + // }); - - // const fmdata = reformattedData.map(rfmData => { - // return { - // rowNo: rfmData.rowNo, - // rootId: rfmData.rootId, - // root: rfmData.root, - // strategy: [ - // { - // strategyName1: rfmData.strategy[0].strategyName1, - // devCount1: rfmData.strategy[0].devCount1, - // target1: rfmData.strategy[0].target1, - // receiveBudget1: rfmData.strategy[0].receiveBudget1 - // }, - // { - // strategyName2: rfmData.strategy[1].strategyName2, - // devCount2: rfmData.strategy[1].devCount2, - // target2: rfmData.strategy[1].target2, - // receiveBudget2: rfmData.strategy[1].receiveBudget2 - // }, - // { - // strategyName3: rfmData.strategy[2].strategyName3, - // devCount3: rfmData.strategy[2].devCount3, - // target3: rfmData.strategy[2].target3, - // receiveBudget3: rfmData.strategy[2].receiveBudget3 - // }, - // { - // strategyName4: rfmData.strategy[3].strategyName4, - // devCount4: rfmData.strategy[3].devCount4, - // target4: rfmData.strategy[3].target4, - // receiveBudget4: rfmData.strategy[3].receiveBudget4 - // } - // ], - // }; - // }); - return new HttpSuccess({ template: "development", reportName: "development", @@ -432,6 +455,10 @@ export class ReportController extends Controller { getDevelopment.scholarshipType = "ฝึกอบรมในประเทศที่ส่งไปพัฒนากับหน่วยวงานภายนอก (หลักสูตรประเภทนักบริหาร)"; break; + case "RESEARCH": + getDevelopment.scholarshipType = + "ศึกษา ฝึกอบรม ประชุม ดูงาน และปฏิบัติการวิจัย ณ ต่างประเทศ"; + break; default: break; } From d95b1a41290dd9ac02ea910523ef8d4ad12ad820 Mon Sep 17 00:00:00 2001 From: AdisakKanthawilang Date: Mon, 20 Jan 2025 18:20:09 +0700 Subject: [PATCH 199/250] checkpoint report --- src/controllers/ReportController.ts | 110 ++++++++++++++++++++-------- 1 file changed, 79 insertions(+), 31 deletions(-) diff --git a/src/controllers/ReportController.ts b/src/controllers/ReportController.ts index 4a5a689..6bcf86a 100644 --- a/src/controllers/ReportController.ts +++ b/src/controllers/ReportController.ts @@ -136,8 +136,8 @@ export class ReportController extends Controller { existingRoot.strategy.push({ strategyId: item.strategyId, strategyName: item.strategyName, - devCount: item.devCount?Extension.ToThaiNumber(item.devCount.toString()):"0", - receiveBudget: item.receiveBudget?Extension.ToThaiNumber(item.receiveBudget.toString()):"0", + devCount: item.devCount?item.devCount:"-", + receiveBudget: item.receiveBudget?item.receiveBudget:"-", sumDev: "", sumTraget: "", sumBudget: "", @@ -152,8 +152,8 @@ export class ReportController extends Controller { strategy: [{ strategyId: item.strategyId, strategyName: item.strategyName, - devCount: item.devCount?Extension.ToThaiNumber(item.devCount.toString()):"0", - receiveBudget: item.receiveBudget?Extension.ToThaiNumber(item.receiveBudget.toString()):"0", + devCount: item.devCount?item.devCount:"-", + receiveBudget: item.receiveBudget?item.receiveBudget:"-", sumDev: "", sumTraget: "", sumBudget: "", @@ -166,39 +166,74 @@ export class ReportController extends Controller { return acc; }, []); - const reformattedData = groupedData.map((group,x) => { + const sumRowDev = (group.strategy[0] && group.strategy[0].devCount !== "-" ? Number(group.strategy[0].devCount) : 0) + + (group.strategy[1] && group.strategy[1].devCount !== "-" ? Number(group.strategy[1].devCount) : 0) + + (group.strategy[2] && group.strategy[2].devCount !== "-" ? Number(group.strategy[2].devCount) : 0); + (group.strategy[3] && group.strategy[3].devCount !== "-" ? Number(group.strategy[3].devCount) : 0); + const sumRowBudget = (group.strategy[0] && group.strategy[0].receiveBudget !== "-" ? Number(group.strategy[0].receiveBudget) : 0) + + (group.strategy[1] && group.strategy[1].receiveBudget !== "-" ? Number(group.strategy[1].receiveBudget) : 0) + + (group.strategy[2] && group.strategy[2].receiveBudget !== "-" ? Number(group.strategy[2].receiveBudget) : 0); + (group.strategy[3] && group.strategy[3].receiveBudget !== "-" ? Number(group.strategy[3].receiveBudget) : 0); + const formattedGroup = { rowNo: x?Extension.ToThaiNumber((x + 1).toString()):Extension.ToThaiNumber("๑"), rootId: group.rootId, root: group.root, - strategy: Array(4).fill(null).map((_, index) => { - const strategy = group.strategy[index] || { - strategyName: "0", - devCount: "0", - target: "0", - receiveBudget: "0", - sumDev: "0", - sumTraget: "0", - sumBudget: "0", - sumRowDev:"0", - sumRowTarget:"0", - sumRowBudget:"0", - }; + strategyName1: group.strategy[0]&&group.strategy[0].strategyName?group.strategy[0].strategyName:"-", + devCount1: group.strategy[0]&&group.strategy[0].devCount?Extension.ToThaiNumber(group.strategy[0].devCount.toString()):"-", + target1: "-", + receiveBudget1: group.strategy[0]&&group.strategy[0].receiveBudget?Extension.ToThaiNumber(group.strategy[0].receiveBudget.toString()):"-", + - return { - [`strategyName${index + 1}`]: strategy.strategyName ?? "", - [`devCount${index + 1}`]: strategy.devCount ?? "", - [`target${index + 1}`]: "", - [`receiveBudget${index + 1}`]: strategy.receiveBudget ?? "", - [`sumDev${index + 1}`]: strategy.sumDev ?? "", - [`sumTraget${index + 1}`]: strategy.sumTraget ?? "", - [`sumBudget${index + 1}`]: strategy.sumBudget ?? "", - [`sumRowDev`]: strategy.sumRowDev ?? "", - [`sumRowTarget`]: strategy.sumRowTarget ?? "", - [`sumRowBudget`]: strategy.sumRowBudget ?? "", - }; - }), + strategyName2: group.strategy[1]&&group.strategy[1].strategyName?group.strategy[1].strategyName:"-", + devCount2: group.strategy[1]&&group.strategy[1].devCount?Extension.ToThaiNumber(group.strategy[1].devCount.toString()):"-", + target2: "-", + receiveBudget2: group.strategy[1]&&group.strategy[1].receiveBudget?Extension.ToThaiNumber(group.strategy[1].receiveBudget.toString()):"-", + + + strategyName3: group.strategy[2]&&group.strategy[2].strategyName?group.strategy[2].strategyName:"-", + devCount3: group.strategy[2]&&group.strategy[2].devCount?Extension.ToThaiNumber(group.strategy[2].devCount.toString()):"-", + target3: "-", + receiveBudget3: group.strategy[2]&&group.strategy[2].receiveBudget?Extension.ToThaiNumber(group.strategy[2].receiveBudget.toString()):"-", + + + strategyName4: group.strategy[3]&&group.strategy[3].strategyName?group.strategy[3].strategyName:"-", + devCount4: group.strategy[3]&&group.strategy[3].devCount?Extension.ToThaiNumber(group.strategy[3].devCount.toString()):"-", + target4: "-", + receiveBudget4: group.strategy[3]&&group.strategy[3].receiveBudget?Extension.ToThaiNumber(group.strategy[3].receiveBudget.toString()):"-", + + + sumRowDev: sumRowDev?Extension.ToThaiNumber(sumRowDev.toString()):"-", + sumRowTarget: "-", + sumRowBudget: sumRowBudget?Extension.ToThaiNumber(sumRowBudget.toString()):"-", + // strategy: Array(4).fill(null).map((_, index) => { + // const strategy = group.strategy[index] || { + // strategyName: "", + // devCount: "", + // target: "", + // receiveBudget: "", + // sumDev: "", + // sumTraget: "", + // sumBudget: "", + // sumRowDev: "", + // sumRowTarget: "", + // sumRowBudget: "", + // }; + + // return { + // [`strategyName${index + 1}`]: strategy.strategyName ?? "", + // [`devCount${index + 1}`]: strategy.devCount ?? "", + // [`target${index + 1}`]: "", + // [`receiveBudget${index + 1}`]: strategy.receiveBudget ?? "", + // [`sumDev${index + 1}`]: strategy.sumDev ?? "", + // [`sumTraget${index + 1}`]: strategy.sumTraget ?? "", + // [`sumBudget${index + 1}`]: strategy.sumBudget ?? "", + // [`sumRowDev`]: strategy.sumRowDev ?? "", + // [`sumRowTarget`]: strategy.sumRowTarget ?? "", + // [`sumRowBudget`]: strategy.sumRowBudget ?? "", + // }; + // }), }; return formattedGroup; @@ -210,6 +245,19 @@ export class ReportController extends Controller { data: { data: mappedDataDev, resultAllStrategy: reformattedData, + sumDev1: "-", + sumTraget1: "-", + sumBudget1: "-", + sumDev2: "-", + sumTraget2: "-", + sumBudget2: "-", + sumDev3: "-", + sumTraget3: "-", + sumBudget3: "-", + sumDev4: "-", + sumTraget4: "-", + sumBudget4: "-", + }, }); } From f517b14eab80c2d44b6ba432378d4dd8d0d36c4b Mon Sep 17 00:00:00 2001 From: AdisakKanthawilang Date: Tue, 21 Jan 2025 09:22:42 +0700 Subject: [PATCH 200/250] fix --- src/controllers/ReportController.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/controllers/ReportController.ts b/src/controllers/ReportController.ts index 6bcf86a..87c2203 100644 --- a/src/controllers/ReportController.ts +++ b/src/controllers/ReportController.ts @@ -443,6 +443,10 @@ export class ReportController extends Controller { getDevelopment.scholarshipType = "ฝึกอบรมในประเทศที่ส่งไปพัฒนากับหน่วยวงานภายนอก (หลักสูตรประเภทนักบริหาร)"; break; + case "RESEARCH": + getDevelopment.scholarshipType = + "ศึกษา ฝึกอบรม ประชุม ดูงาน และปฏิบัติการวิจัย ณ ต่างประเทศ"; + break; default: break; } From dd8996336bb8766b2bbb85c5be8d149b9343d005 Mon Sep 17 00:00:00 2001 From: AdisakKanthawilang Date: Tue, 21 Jan 2025 11:00:27 +0700 Subject: [PATCH 201/250] report --- src/controllers/ReportController.ts | 104 ++++++++++++++++++++-------- 1 file changed, 75 insertions(+), 29 deletions(-) diff --git a/src/controllers/ReportController.ts b/src/controllers/ReportController.ts index 87c2203..2cdb73a 100644 --- a/src/controllers/ReportController.ts +++ b/src/controllers/ReportController.ts @@ -76,12 +76,12 @@ export class ReportController extends Controller { return { strategy: item.strategy1, projectName: item.projectName, - totalDate: item.totalDate != null && item.totalDate != "" ? Extension.ToThaiNumber(item.totalDate.toString()): "-", - goalParticipants: item.goalParticipants != null && item.goalParticipants != "" ? Extension.ToThaiNumber(item.goalParticipants.toString()): "-", - actualParticipants: item.actualParticipants != null && item.actualParticipants != "" ? Extension.ToThaiNumber(item.actualParticipants.toString()): "-", + totalDate: item.totalDate != null && item.totalDate != "" ? Extension.ToThaiNumber(item.totalDate.toLocaleString()): "-", + goalParticipants: item.goalParticipants != null && item.goalParticipants != "" ? Extension.ToThaiNumber(item.goalParticipants.toLocaleString()): "-", + actualParticipants: item.actualParticipants != null && item.actualParticipants != "" ? Extension.ToThaiNumber(item.actualParticipants.toLocaleString()): "-", budget: budget, - acceptBudget: item.acceptBudget != null && item.acceptBudget != "" ? Extension.ToThaiNumber(item.acceptBudget.toString()): "-", - receiveBudget: item.receiveBudget != null && item.receiveBudget != "" ? Extension.ToThaiNumber(item.receiveBudget.toString()): "-", + acceptBudget: item.acceptBudget != null && item.acceptBudget != "" ? Extension.ToThaiNumber(item.acceptBudget.toLocaleString()): "-", + receiveBudget: item.receiveBudget != null && item.receiveBudget != "" ? Extension.ToThaiNumber(item.receiveBudget.toLocaleString()): "-", obstacle: item.obstacle, root: item.root, output: "-", @@ -166,6 +166,18 @@ export class ReportController extends Controller { return acc; }, []); + let sumDev1 = 0; + let sumTraget1 = 0; + let sumBudget1 = 0; + let sumDev2 = 0; + let sumTraget2 = 0; + let sumBudget2 = 0; + let sumDev3 = 0; + let sumTraget3 = 0; + let sumBudget3 = 0; + let sumDev4 = 0; + let sumTraget4 = 0; + let sumBudget4 = 0; const reformattedData = groupedData.map((group,x) => { const sumRowDev = (group.strategy[0] && group.strategy[0].devCount !== "-" ? Number(group.strategy[0].devCount) : 0) + (group.strategy[1] && group.strategy[1].devCount !== "-" ? Number(group.strategy[1].devCount) : 0) + @@ -175,38 +187,70 @@ export class ReportController extends Controller { (group.strategy[1] && group.strategy[1].receiveBudget !== "-" ? Number(group.strategy[1].receiveBudget) : 0) + (group.strategy[2] && group.strategy[2].receiveBudget !== "-" ? Number(group.strategy[2].receiveBudget) : 0); (group.strategy[3] && group.strategy[3].receiveBudget !== "-" ? Number(group.strategy[3].receiveBudget) : 0); - + sumDev1 = groupedData.reduce((sum, group) => { + const devCount = group.strategy[0] && group.strategy[0].devCount !== "-" ? Number(group.strategy[0].devCount) : 0; + return sum + devCount; + }, 0); + sumBudget1 = groupedData.reduce((sum, group) => { + const devCount = group.strategy[0] && group.strategy[0].receiveBudget !== "-" ? Number(group.strategy[0].receiveBudget) : 0; + return sum + devCount; + }, 0); + sumDev2 = groupedData.reduce((sum, group) => { + const devCount = group.strategy[1] && group.strategy[1].devCount !== "-" ? Number(group.strategy[1].devCount) : 0; + return sum + devCount; + }, 0); + sumBudget2 = groupedData.reduce((sum, group) => { + const devCount = group.strategy[1] && group.strategy[1].receiveBudget !== "-" ? Number(group.strategy[1].receiveBudget) : 0; + return sum + devCount; + }, 0); + sumDev3 = groupedData.reduce((sum, group) => { + const devCount = group.strategy[2] && group.strategy[2].devCount !== "-" ? Number(group.strategy[2].devCount) : 0; + return sum + devCount; + }, 0); + sumBudget3 = groupedData.reduce((sum, group) => { + const devCount = group.strategy[2] && group.strategy[2].receiveBudget !== "-" ? Number(group.strategy[2].receiveBudget) : 0; + return sum + devCount; + }, 0); + sumDev4 = groupedData.reduce((sum, group) => { + const devCount = group.strategy[3] && group.strategy[3].devCount !== "-" ? Number(group.strategy[3].devCount) : 0; + return sum + devCount; + }, 0); + sumBudget4 = groupedData.reduce((sum, group) => { + const devCount = group.strategy[3] && group.strategy[3].receiveBudget !== "-" ? Number(group.strategy[3].receiveBudget) : 0; + return sum + devCount; + }, 0); + const formattedGroup = { rowNo: x?Extension.ToThaiNumber((x + 1).toString()):Extension.ToThaiNumber("๑"), rootId: group.rootId, root: group.root, strategyName1: group.strategy[0]&&group.strategy[0].strategyName?group.strategy[0].strategyName:"-", - devCount1: group.strategy[0]&&group.strategy[0].devCount?Extension.ToThaiNumber(group.strategy[0].devCount.toString()):"-", + devCount1: group.strategy[0]&&group.strategy[0].devCount?Extension.ToThaiNumber(group.strategy[0].devCount.toLocaleString()):"-", target1: "-", - receiveBudget1: group.strategy[0]&&group.strategy[0].receiveBudget?Extension.ToThaiNumber(group.strategy[0].receiveBudget.toString()):"-", + receiveBudget1: group.strategy[0]&&group.strategy[0].receiveBudget?Extension.ToThaiNumber(group.strategy[0].receiveBudget.toLocaleString()):"-", strategyName2: group.strategy[1]&&group.strategy[1].strategyName?group.strategy[1].strategyName:"-", - devCount2: group.strategy[1]&&group.strategy[1].devCount?Extension.ToThaiNumber(group.strategy[1].devCount.toString()):"-", + devCount2: group.strategy[1]&&group.strategy[1].devCount?Extension.ToThaiNumber(group.strategy[1].devCount.toLocaleString()):"-", target2: "-", - receiveBudget2: group.strategy[1]&&group.strategy[1].receiveBudget?Extension.ToThaiNumber(group.strategy[1].receiveBudget.toString()):"-", + receiveBudget2: group.strategy[1]&&group.strategy[1].receiveBudget?Extension.ToThaiNumber(group.strategy[1].receiveBudget.toLocaleString()):"-", strategyName3: group.strategy[2]&&group.strategy[2].strategyName?group.strategy[2].strategyName:"-", - devCount3: group.strategy[2]&&group.strategy[2].devCount?Extension.ToThaiNumber(group.strategy[2].devCount.toString()):"-", + devCount3: group.strategy[2]&&group.strategy[2].devCount?Extension.ToThaiNumber(group.strategy[2].devCount.toLocaleString()):"-", target3: "-", - receiveBudget3: group.strategy[2]&&group.strategy[2].receiveBudget?Extension.ToThaiNumber(group.strategy[2].receiveBudget.toString()):"-", + receiveBudget3: group.strategy[2]&&group.strategy[2].receiveBudget?Extension.ToThaiNumber(group.strategy[2].receiveBudget.toLocaleString()):"-", strategyName4: group.strategy[3]&&group.strategy[3].strategyName?group.strategy[3].strategyName:"-", - devCount4: group.strategy[3]&&group.strategy[3].devCount?Extension.ToThaiNumber(group.strategy[3].devCount.toString()):"-", + devCount4: group.strategy[3]&&group.strategy[3].devCount?Extension.ToThaiNumber(group.strategy[3].devCount.toLocaleString()):"-", target4: "-", - receiveBudget4: group.strategy[3]&&group.strategy[3].receiveBudget?Extension.ToThaiNumber(group.strategy[3].receiveBudget.toString()):"-", + receiveBudget4: group.strategy[3]&&group.strategy[3].receiveBudget?Extension.ToThaiNumber(group.strategy[3].receiveBudget.toLocaleString()):"-", - sumRowDev: sumRowDev?Extension.ToThaiNumber(sumRowDev.toString()):"-", + sumRowDev: sumRowDev?Extension.ToThaiNumber(sumRowDev.toLocaleString()):"-", sumRowTarget: "-", - sumRowBudget: sumRowBudget?Extension.ToThaiNumber(sumRowBudget.toString()):"-", + sumRowBudget: sumRowBudget?Extension.ToThaiNumber(sumRowBudget.toLocaleString()):"-", // strategy: Array(4).fill(null).map((_, index) => { // const strategy = group.strategy[index] || { // strategyName: "", @@ -245,19 +289,21 @@ export class ReportController extends Controller { data: { data: mappedDataDev, resultAllStrategy: reformattedData, - sumDev1: "-", - sumTraget1: "-", - sumBudget1: "-", - sumDev2: "-", - sumTraget2: "-", - sumBudget2: "-", - sumDev3: "-", - sumTraget3: "-", - sumBudget3: "-", - sumDev4: "-", - sumTraget4: "-", - sumBudget4: "-", - + sumDev1: Extension.ToThaiNumber(sumDev1.toLocaleString())??"-", + sumTraget1: Extension.ToThaiNumber(sumTraget1.toLocaleString())??"-", + sumBudget1: Extension.ToThaiNumber(sumBudget1.toLocaleString())??"-", + sumDev2: Extension.ToThaiNumber(sumDev2.toLocaleString())??"-", + sumTraget2: Extension.ToThaiNumber(sumTraget2.toLocaleString())??"-", + sumBudget2: Extension.ToThaiNumber(sumBudget2.toLocaleString())??"-", + sumDev3: Extension.ToThaiNumber(sumDev3.toLocaleString())??"-", + sumTraget3: Extension.ToThaiNumber(sumTraget3.toLocaleString())??"-", + sumBudget3: Extension.ToThaiNumber(sumBudget3.toLocaleString())??"-", + sumDev4: Extension.ToThaiNumber(sumDev4.toLocaleString())??"-", + sumTraget4: Extension.ToThaiNumber(sumTraget4.toLocaleString())??"-", + sumBudget4: Extension.ToThaiNumber(sumBudget4.toLocaleString())??"-", + sumAllDev: Extension.ToThaiNumber((sumDev1 + sumDev2 + sumDev3 + sumDev4).toLocaleString())??"-", + sumTraget: Extension.ToThaiNumber((sumTraget1 +sumTraget2 +sumTraget3 +sumTraget4).toLocaleString())??"-", + sumAllBudget: Extension.ToThaiNumber((sumBudget1 + sumBudget2 + sumBudget3 + sumBudget4).toLocaleString())??"-", }, }); } From 3e57b67432cc8afd6d2368d32078c0ffd6ee2fe3 Mon Sep 17 00:00:00 2001 From: kittapath Date: Thu, 30 Jan 2025 08:53:02 +0700 Subject: [PATCH 202/250] search by ancestorDNA --- src/controllers/DevelopmentController.ts | 30 +++++++++++++--- src/entities/Development.ts | 35 +++++++++++++++++++ .../1738201344610-Updatedevadddna.ts | 28 +++++++++++++++ 3 files changed, 88 insertions(+), 5 deletions(-) create mode 100644 src/migration/1738201344610-Updatedevadddna.ts diff --git a/src/controllers/DevelopmentController.ts b/src/controllers/DevelopmentController.ts index 454a843..99eda37 100644 --- a/src/controllers/DevelopmentController.ts +++ b/src/controllers/DevelopmentController.ts @@ -139,18 +139,23 @@ export class DevelopmentController extends Controller { .then((x) => { development.root = x.root; development.rootId = x.rootId; + development.rootDnaId = x.rootDnaId; development.rootShortName = x.rootShortName; development.child1 = x.child1; development.child1Id = x.child1Id; + development.child1DnaId = x.child1DnaId; development.child1ShortName = x.child1ShortName; development.child2 = x.child2; development.child2Id = x.child2Id; + development.child2DnaId = x.child2DnaId; development.child2ShortName = x.child2ShortName; development.child3 = x.child3; development.child3Id = x.child3Id; + development.child3DnaId = x.child3DnaId; development.child3ShortName = x.child3ShortName; development.child4 = x.child4; development.child4Id = x.child4Id; + development.child4DnaId = x.child4DnaId; development.child4ShortName = x.child4ShortName; }) .catch((error) => { @@ -228,18 +233,23 @@ export class DevelopmentController extends Controller { .then((x) => { development.root = x.root; development.rootId = x.rootId; + development.rootDnaId = x.rootDnaId; development.rootShortName = x.rootShortName; development.child1 = x.child1; development.child1Id = x.child1Id; + development.child1DnaId = x.child1DnaId; development.child1ShortName = x.child1ShortName; development.child2 = x.child2; development.child2Id = x.child2Id; + development.child2DnaId = x.child2DnaId; development.child2ShortName = x.child2ShortName; development.child3 = x.child3; development.child3Id = x.child3Id; + development.child3DnaId = x.child3DnaId; development.child3ShortName = x.child3ShortName; development.child4 = x.child4; development.child4Id = x.child4Id; + development.child4DnaId = x.child4DnaId; development.child4ShortName = x.child4ShortName; }) .catch((x) => {}); @@ -248,42 +258,52 @@ export class DevelopmentController extends Controller { case 0: { development.child1 = _null; development.child1Id = _null; + development.child1DnaId = _null; development.child1ShortName = _null; development.child2 = _null; development.child2Id = _null; + development.child2DnaId = _null; development.child2ShortName = _null; development.child3 = _null; development.child3Id = _null; + development.child3DnaId = _null; development.child3ShortName = _null; development.child4 = _null; development.child4Id = _null; + development.child4DnaId = _null; development.child4ShortName = _null; break; } case 1: { development.child2 = _null; development.child2Id = _null; + development.child2DnaId = _null; development.child2ShortName = _null; development.child3 = _null; development.child3Id = _null; + development.child3DnaId = _null; development.child3ShortName = _null; development.child4 = _null; development.child4Id = _null; + development.child4DnaId = _null; development.child4ShortName = _null; break; } case 2: { development.child3 = _null; development.child3Id = _null; + development.child3DnaId = _null; development.child3ShortName = _null; development.child4 = _null; development.child4Id = _null; + development.child4DnaId = _null; development.child4ShortName = _null; break; } case 3: { development.child4 = _null; development.child4Id = _null; + development.child4DnaId = _null; development.child4ShortName = _null; break; } @@ -1923,14 +1943,14 @@ export class DevelopmentController extends Controller { .andWhere( node != undefined && node != null ? node == 4 - ? "development.child4Id LIKE :nodeId" + ? "development.child4DnaId LIKE :nodeId" : node == 3 - ? "development.child3Id LIKE :nodeId" + ? "development.child3DnaId LIKE :nodeId" : node == 2 - ? "development.child2Id LIKE :nodeId" + ? "development.child2DnaId LIKE :nodeId" : node == 1 - ? "development.child1Id LIKE :nodeId" - : "development.rootId LIKE :nodeId" + ? "development.child1DnaId LIKE :nodeId" + : "development.rootDnaId LIKE :nodeId" : "1=1", { nodeId: `${nodeId}`, diff --git a/src/entities/Development.ts b/src/entities/Development.ts index cd4b339..94f773b 100644 --- a/src/entities/Development.ts +++ b/src/entities/Development.ts @@ -27,6 +27,13 @@ export class Development extends EntityBase { }) rootId: string; + @Column({ + nullable: true, + comment: "id Dna หน่วยงาน", + default: null, + }) + rootDnaId: string; + @Column({ nullable: true, comment: "ชื่อหน่วยงาน", @@ -48,6 +55,13 @@ export class Development extends EntityBase { }) child1Id: string; + @Column({ + nullable: true, + comment: "id Dna หน่วยงาน child1", + default: null, + }) + child1DnaId: string; + @Column({ nullable: true, comment: "ชื่อหน่วยงาน child1", @@ -69,6 +83,13 @@ export class Development extends EntityBase { }) child2Id: string; + @Column({ + nullable: true, + comment: "id Dna หน่วยงาน child2", + default: null, + }) + child2DnaId: string; + @Column({ nullable: true, comment: "ชื่อหน่วยงาน child2", @@ -90,6 +111,13 @@ export class Development extends EntityBase { }) child3Id: string; + @Column({ + nullable: true, + comment: "id Dna หน่วยงาน child3", + default: null, + }) + child3DnaId: string; + @Column({ nullable: true, comment: "ชื่อหน่วยงาน child3", @@ -111,6 +139,13 @@ export class Development extends EntityBase { }) child4Id: string; + @Column({ + nullable: true, + comment: "id Dna หน่วยงาน child4", + default: null, + }) + child4DnaId: string; + @Column({ nullable: true, comment: "ชื่อหน่วยงาน child4", diff --git a/src/migration/1738201344610-Updatedevadddna.ts b/src/migration/1738201344610-Updatedevadddna.ts new file mode 100644 index 0000000..4b3ebc1 --- /dev/null +++ b/src/migration/1738201344610-Updatedevadddna.ts @@ -0,0 +1,28 @@ +import { MigrationInterface, QueryRunner } from "typeorm"; + +export class Updatedevadddna1738201344610 implements MigrationInterface { + name = 'Updatedevadddna1738201344610' + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(`DROP INDEX \`FK_e2721b3f440256b56ce83a04fb2\` ON \`developmentAddress\``); + await queryRunner.query(`DROP INDEX \`FK_47bbbecaea9b7b31d2536054656\` ON \`developmentOther\``); + await queryRunner.query(`DROP INDEX \`FK_bdafbb824b88c3bdb73adf7f220\` ON \`development\``); + await queryRunner.query(`ALTER TABLE \`development\` ADD \`rootDnaId\` varchar(255) NULL COMMENT 'id Dna หน่วยงาน'`); + await queryRunner.query(`ALTER TABLE \`development\` ADD \`child1DnaId\` varchar(255) NULL COMMENT 'id Dna หน่วยงาน child1'`); + await queryRunner.query(`ALTER TABLE \`development\` ADD \`child2DnaId\` varchar(255) NULL COMMENT 'id Dna หน่วยงาน child2'`); + await queryRunner.query(`ALTER TABLE \`development\` ADD \`child3DnaId\` varchar(255) NULL COMMENT 'id Dna หน่วยงาน child3'`); + await queryRunner.query(`ALTER TABLE \`development\` ADD \`child4DnaId\` varchar(255) NULL COMMENT 'id Dna หน่วยงาน child4'`); + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`child4DnaId\``); + await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`child3DnaId\``); + await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`child2DnaId\``); + await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`child1DnaId\``); + await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`rootDnaId\``); + await queryRunner.query(`CREATE INDEX \`FK_bdafbb824b88c3bdb73adf7f220\` ON \`development\` (\`provinceActualId\`)`); + await queryRunner.query(`CREATE INDEX \`FK_47bbbecaea9b7b31d2536054656\` ON \`developmentOther\` (\`provinceActualId\`)`); + await queryRunner.query(`CREATE INDEX \`FK_e2721b3f440256b56ce83a04fb2\` ON \`developmentAddress\` (\`provinceId\`)`); + } + +} From 4036194b558c80305fbe38cd87284916995b9944 Mon Sep 17 00:00:00 2001 From: kittapath Date: Mon, 3 Feb 2025 14:45:35 +0700 Subject: [PATCH 203/250] add dna --- src/controllers/DevelopmentController.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/controllers/DevelopmentController.ts b/src/controllers/DevelopmentController.ts index 99eda37..b2b7aaf 100644 --- a/src/controllers/DevelopmentController.ts +++ b/src/controllers/DevelopmentController.ts @@ -2056,21 +2056,27 @@ export class DevelopmentController extends Controller { } let node = null; let nodeId = null; + let nodeDnaId = null; if (getDevelopment.child4Id != null) { node = 4; nodeId = getDevelopment.child4Id; + nodeDnaId = getDevelopment.child4DnaId; } else if (getDevelopment.child3Id != null) { node = 3; nodeId = getDevelopment.child3Id; + nodeDnaId = getDevelopment.child3DnaId; } else if (getDevelopment.child2Id != null) { node = 2; nodeId = getDevelopment.child2Id; + nodeDnaId = getDevelopment.child2DnaId; } else if (getDevelopment.child1Id != null) { node = 1; nodeId = getDevelopment.child1Id; + nodeDnaId = getDevelopment.child1DnaId; } else if (getDevelopment.rootId != null) { node = 0; nodeId = getDevelopment.rootId; + nodeDnaId = getDevelopment.rootDnaId; } const formattedData = { @@ -2082,11 +2088,17 @@ export class DevelopmentController extends Controller { objective: getDevelopment.objective, node: node, nodeId: nodeId, + nodeDnaId: nodeDnaId, root: getDevelopment.rootId, child1: getDevelopment.child1Id, child2: getDevelopment.child2Id, child3: getDevelopment.child3Id, child4: getDevelopment.child4Id, + rootDna: getDevelopment.rootDnaId, + child1Dna: getDevelopment.child1DnaId, + child2Dna: getDevelopment.child2DnaId, + child3Dna: getDevelopment.child3DnaId, + child4Dna: getDevelopment.child4DnaId, }; return new HttpSuccess(formattedData); } From 4fdbc3fdcf2d61e0907bd0f1e5eb2d7b6dea24a1 Mon Sep 17 00:00:00 2001 From: AdisakKanthawilang Date: Tue, 11 Feb 2025 19:23:29 +0700 Subject: [PATCH 204/250] add report endpoint fund 3 - 10 --- src/controllers/ReportController.ts | 148 ++++++++++++++++++++++++++++ 1 file changed, 148 insertions(+) diff --git a/src/controllers/ReportController.ts b/src/controllers/ReportController.ts index 2cdb73a..05cfb00 100644 --- a/src/controllers/ReportController.ts +++ b/src/controllers/ReportController.ts @@ -555,4 +555,152 @@ export class ReportController extends Controller { data: formattedData, }); } + + /** + * API Report รายงานข้อมูลข้าราชการกรุงเทพมหานครสามัญที่ได้รับทุนการศึกษาในประเทศ + * + * @summary DEV_0xx - Report รายงานข้อมูลข้าราชการกรุงเทพมหานครสามัญที่ได้รับทุนการศึกษาในประเทศ #xx + * + */ + @Get("report3") + async report3() { + + + return new HttpSuccess({ + template: "reportFund3", + reportName: "reportFund3", + data: { + data: "", + }, + }); + } + /** + * API Report รายงานข้อมูลข้าราชการกรุงเทพมหานครสามัญที่ได้รับทุนฝึกอบรมในประเทศที่ส่งไปพัฒนากับหน่วยงานภายนอก (หลักสูตรที่ไม่มีการไปต่างประเทศ) + * + * @summary DEV_0xx - Report รายงานข้อมูลข้าราชการกรุงเทพมหานครสามัญที่ได้รับทุนฝึกอบรมในประเทศที่ส่งไปพัฒนากับหน่วยงานภายนอก (หลักสูตรที่ไม่มีการไปต่างประเทศ) #xx + * + */ + @Get("report4") + async report4() { + + + return new HttpSuccess({ + template: "reportFund4", + reportName: "reportFund4", + data: { + data: "", + }, + }); + } + /** + * API Report รายงานข้อมูลข้าราชการกรุงเทพมหานครสามัญที่ได้รับทุนฝึกอบรมในประเทศที่ส่งไปพัฒนากับหน่วยงานภายนอก (หลักสูตรที่มีการไปต่างประเทศ) + * + * @summary DEV_0xx - Report รายงานข้อมูลข้าราชการกรุงเทพมหานครสามัญที่ได้รับทุนฝึกอบรมในประเทศที่ส่งไปพัฒนากับหน่วยงานภายนอก (หลักสูตรที่มีการไปต่างประเทศ) #xx + * + */ + @Get("report5") + async report5() { + + + return new HttpSuccess({ + template: "reportFund5", + reportName: "reportFund5", + data: { + data: "", + }, + }); + } + /** + * API Report รายงานข้อมูลข้าราชการกรุงเทพมหานครสามัญ ที่ส่งไปพัฒนากับหน่วยงานภายนอก (หลักสูตรประเภทนักบริหาร) + * + * @summary DEV_0xx - Report รายงานข้อมูลข้าราชการกรุงเทพมหานครสามัญ ที่ส่งไปพัฒนากับหน่วยงานภายนอก (หลักสูตรประเภทนักบริหาร) #xx + * + */ + @Get("report6") + async report6() { + + + return new HttpSuccess({ + template: "reportFund6", + reportName: "reportFund6", + data: { + data: "", + }, + }); + } + /** + * API Report รายงานข้อมูลข้าราชการกรุงเทพมหานครสามัญที่ไปศึกษา ฝึกอบรม ประชุม ดูงาน และปฏิบัติการวิจัย ณ ต่างประเทศ + * + * @summary DEV_0xx - Report รายงานข้อมูลข้าราชการกรุงเทพมหานครสามัญที่ไปศึกษา ฝึกอบรม ประชุม ดูงาน และปฏิบัติการวิจัย ณ ต่างประเทศ #xx + * + */ + @Get("report7") + async report7() { + + + return new HttpSuccess({ + template: "reportFund7", + reportName: "reportFund7", + data: { + data: "", + }, + }); + } + /** + * API Report รายงานข้อมูลข้าราชการกรุงเทพมหานครสามัญที่ได้รับทุนไปศึกษา + * + * @summary DEV_0xx - Report รายงานข้อมูลข้าราชการกรุงเทพมหานครสามัญที่ได้รับทุนไปศึกษา#xx + * + */ + @Get("report8") + async report8() { + + + return new HttpSuccess({ + template: "reportFund8", + reportName: "reportFund8", + data: { + data: "", + }, + }); + } + /** + * API Report รายงานสถิติข้อมูลการฝึกอบรม ศึกษาดูงาน ของข้าราชการกรุงเทพมหานครสามัญ + * + * @summary DEV_0xx - Report รายงานสถิติข้อมูลการฝึกอบรม ศึกษาดูงาน ของข้าราชการกรุงเทพมหานครสามัญ #xx + * + */ + @Get("report9") + async report9() { + + + return new HttpSuccess({ + template: "reportFund9", + reportName: "reportFund9", + data: { + data: "", + }, + }); + } + /** + * API Report รายงานสถิติข้อมูลการศึกษาต่อของข้าราชการกรุงเทพมหานครสามัญ + * + * @summary DEV_0xx - Report รายงานสถิติข้อมูลการศึกษาต่อของข้าราชการกรุงเทพมหานครสามัญ #xx + * + */ + @Get("report10") + async report10() { + + + return new HttpSuccess({ + template: "reportFund", + reportName: "reportFund10", + data: { + data: "", + }, + }); + } + } + + \ No newline at end of file From f8c2433927f8ff93505e0ccc2086dbb088a4c86b Mon Sep 17 00:00:00 2001 From: AdisakKanthawilang Date: Tue, 11 Feb 2025 19:49:41 +0700 Subject: [PATCH 205/250] fix --- src/controllers/ReportController.ts | 88 +++-------------------------- 1 file changed, 8 insertions(+), 80 deletions(-) diff --git a/src/controllers/ReportController.ts b/src/controllers/ReportController.ts index 05cfb00..26a76b1 100644 --- a/src/controllers/ReportController.ts +++ b/src/controllers/ReportController.ts @@ -557,9 +557,9 @@ export class ReportController extends Controller { } /** - * API Report รายงานข้อมูลข้าราชการกรุงเทพมหานครสามัญที่ได้รับทุนการศึกษาในประเทศ + * API Report รายงานข้อมูลข้าราชการกรุงเทพมหานครสามัญที่ได้รับทุนการศึกษา * - * @summary DEV_0xx - Report รายงานข้อมูลข้าราชการกรุงเทพมหานครสามัญที่ได้รับทุนการศึกษาในประเทศ #xx + * @summary DEV_0xx - Report รายงานข้อมูลข้าราชการกรุงเทพมหานครสามัญที่ได้รับทุนการศึกษา #xx * */ @Get("report3") @@ -575,9 +575,9 @@ export class ReportController extends Controller { }); } /** - * API Report รายงานข้อมูลข้าราชการกรุงเทพมหานครสามัญที่ได้รับทุนฝึกอบรมในประเทศที่ส่งไปพัฒนากับหน่วยงานภายนอก (หลักสูตรที่ไม่มีการไปต่างประเทศ) + * API Report รายงานข้อมูลข้าราชการกรุงเทพมหานครสามัญ ที่ส่งไปพัฒนากับหน่วยงานภายนอก * - * @summary DEV_0xx - Report รายงานข้อมูลข้าราชการกรุงเทพมหานครสามัญที่ได้รับทุนฝึกอบรมในประเทศที่ส่งไปพัฒนากับหน่วยงานภายนอก (หลักสูตรที่ไม่มีการไปต่างประเทศ) #xx + * @summary DEV_0xx - Report รายงานข้อมูลข้าราชการกรุงเทพมหานครสามัญ ที่ส่งไปพัฒนากับหน่วยงานภายนอก #xx * */ @Get("report4") @@ -593,9 +593,9 @@ export class ReportController extends Controller { }); } /** - * API Report รายงานข้อมูลข้าราชการกรุงเทพมหานครสามัญที่ได้รับทุนฝึกอบรมในประเทศที่ส่งไปพัฒนากับหน่วยงานภายนอก (หลักสูตรที่มีการไปต่างประเทศ) + * API Report รายงานข้อมูลข้าราชการกรุงเทพมหานครสามัญที่ไปศึกษา ฝึกอบรม ประชุม ดูงาน และปฏิบัติการวิจัย ณ ต่างประเทศ * - * @summary DEV_0xx - Report รายงานข้อมูลข้าราชการกรุงเทพมหานครสามัญที่ได้รับทุนฝึกอบรมในประเทศที่ส่งไปพัฒนากับหน่วยงานภายนอก (หลักสูตรที่มีการไปต่างประเทศ) #xx + * @summary DEV_0xx - Report รายงานข้อมูลข้าราชการกรุงเทพมหานครสามัญที่ไปศึกษา ฝึกอบรม ประชุม ดูงาน และปฏิบัติการวิจัย ณ ต่างประเทศ #xx * */ @Get("report5") @@ -611,9 +611,9 @@ export class ReportController extends Controller { }); } /** - * API Report รายงานข้อมูลข้าราชการกรุงเทพมหานครสามัญ ที่ส่งไปพัฒนากับหน่วยงานภายนอก (หลักสูตรประเภทนักบริหาร) + * API Report รายงานสถิติข้อมูลการศึกษาต่อ การฝึกอบรม ศึกษาดูงาน ของข้าราชการกรุงเทพมหานครสามัญ * - * @summary DEV_0xx - Report รายงานข้อมูลข้าราชการกรุงเทพมหานครสามัญ ที่ส่งไปพัฒนากับหน่วยงานภายนอก (หลักสูตรประเภทนักบริหาร) #xx + * @summary DEV_0xx - Report รายงานสถิติข้อมูลการศึกษาต่อ การฝึกอบรม ศึกษาดูงาน ของข้าราชการกรุงเทพมหานครสามัญ #xx * */ @Get("report6") @@ -628,78 +628,6 @@ export class ReportController extends Controller { }, }); } - /** - * API Report รายงานข้อมูลข้าราชการกรุงเทพมหานครสามัญที่ไปศึกษา ฝึกอบรม ประชุม ดูงาน และปฏิบัติการวิจัย ณ ต่างประเทศ - * - * @summary DEV_0xx - Report รายงานข้อมูลข้าราชการกรุงเทพมหานครสามัญที่ไปศึกษา ฝึกอบรม ประชุม ดูงาน และปฏิบัติการวิจัย ณ ต่างประเทศ #xx - * - */ - @Get("report7") - async report7() { - - - return new HttpSuccess({ - template: "reportFund7", - reportName: "reportFund7", - data: { - data: "", - }, - }); - } - /** - * API Report รายงานข้อมูลข้าราชการกรุงเทพมหานครสามัญที่ได้รับทุนไปศึกษา - * - * @summary DEV_0xx - Report รายงานข้อมูลข้าราชการกรุงเทพมหานครสามัญที่ได้รับทุนไปศึกษา#xx - * - */ - @Get("report8") - async report8() { - - - return new HttpSuccess({ - template: "reportFund8", - reportName: "reportFund8", - data: { - data: "", - }, - }); - } - /** - * API Report รายงานสถิติข้อมูลการฝึกอบรม ศึกษาดูงาน ของข้าราชการกรุงเทพมหานครสามัญ - * - * @summary DEV_0xx - Report รายงานสถิติข้อมูลการฝึกอบรม ศึกษาดูงาน ของข้าราชการกรุงเทพมหานครสามัญ #xx - * - */ - @Get("report9") - async report9() { - - - return new HttpSuccess({ - template: "reportFund9", - reportName: "reportFund9", - data: { - data: "", - }, - }); - } - /** - * API Report รายงานสถิติข้อมูลการศึกษาต่อของข้าราชการกรุงเทพมหานครสามัญ - * - * @summary DEV_0xx - Report รายงานสถิติข้อมูลการศึกษาต่อของข้าราชการกรุงเทพมหานครสามัญ #xx - * - */ - @Get("report10") - async report10() { - - - return new HttpSuccess({ - template: "reportFund", - reportName: "reportFund10", - data: { - data: "", - }, - }); - } } From 6e374d7992a61f76b36c76a20fbcbb3e32cb0f2e Mon Sep 17 00:00:00 2001 From: Bright Date: Thu, 13 Feb 2025 10:28:05 +0700 Subject: [PATCH 206/250] report 3 (test) --- src/controllers/ReportController.ts | 32 +++++++++++++++++++++++++---- 1 file changed, 28 insertions(+), 4 deletions(-) diff --git a/src/controllers/ReportController.ts b/src/controllers/ReportController.ts index 26a76b1..deb87af 100644 --- a/src/controllers/ReportController.ts +++ b/src/controllers/ReportController.ts @@ -1,4 +1,4 @@ -import { Controller, Get, Post, Route, Security, Tags, Body, Path } from "tsoa"; +import { Controller, Get, Post, Route, Security, Tags, Body, Path, Query } from "tsoa"; import { AppDataSource } from "../database/data-source"; import HttpSuccess from "../interfaces/http-success"; import HttpError from "../interfaces/http-error"; @@ -563,14 +563,38 @@ export class ReportController extends Controller { * */ @Get("report3") - async report3() { - + async report3( + @Query("year") year: number, + @Query("rootId") rootId?: string, + ) { + const [development, total] = await AppDataSource.getRepository(DevelopmentScholarship) + .createQueryBuilder("developmentScholarship") + .leftJoinAndSelect("developmentScholarship.posLevel", "posLevel") + .leftJoinAndSelect("developmentScholarship.posType", "posType") + .andWhere( + year !== 0 && year != null && year != undefined + ? "developmentScholarship.scholarshipYear = :scholarshipYear" + : "1=1", + { scholarshipYear: year }, + ) + .andWhere( + rootId != "" && rootId != null && rootId != undefined + ? "developmentScholarship.rootId = :rootId" + : "1=1", + { rootId: rootId }, + ) + .orderBy("developmentScholarship.scholarshipYear", "DESC") + .addOrderBy("developmentScholarship.createdAt", "DESC") + .getManyAndCount(); return new HttpSuccess({ template: "reportFund3", reportName: "reportFund3", data: { - data: "", + year: year ? Extension.ToThaiNumber(year.toString()) : "-", + root: null, + developments: development, + total: total }, }); } From 5882e21a41536cdb457539dd881b1b1bce6e90ea Mon Sep 17 00:00:00 2001 From: Bright Date: Thu, 13 Feb 2025 11:15:13 +0700 Subject: [PATCH 207/250] update report3 --- src/controllers/ReportController.ts | 78 ++++++++++++++++++++--------- 1 file changed, 55 insertions(+), 23 deletions(-) diff --git a/src/controllers/ReportController.ts b/src/controllers/ReportController.ts index deb87af..5aaa802 100644 --- a/src/controllers/ReportController.ts +++ b/src/controllers/ReportController.ts @@ -567,34 +567,66 @@ export class ReportController extends Controller { @Query("year") year: number, @Query("rootId") rootId?: string, ) { - const [development, total] = await AppDataSource.getRepository(DevelopmentScholarship) - .createQueryBuilder("developmentScholarship") - .leftJoinAndSelect("developmentScholarship.posLevel", "posLevel") - .leftJoinAndSelect("developmentScholarship.posType", "posType") - .andWhere( - year !== 0 && year != null && year != undefined - ? "developmentScholarship.scholarshipYear = :scholarshipYear" - : "1=1", - { scholarshipYear: year }, - ) - .andWhere( - rootId != "" && rootId != null && rootId != undefined - ? "developmentScholarship.rootId = :rootId" - : "1=1", - { rootId: rootId }, - ) - .orderBy("developmentScholarship.scholarshipYear", "DESC") - .addOrderBy("developmentScholarship.createdAt", "DESC") - .getManyAndCount(); + const developments = await AppDataSource.getRepository(DevelopmentScholarship) + .createQueryBuilder("developmentScholarship") + .leftJoinAndSelect("developmentScholarship.posLevel", "posLevel") + .leftJoinAndSelect("developmentScholarship.posType", "posType") + .andWhere( + year !== 0 && year != null && year != undefined + ? "developmentScholarship.scholarshipYear = :scholarshipYear" + : "1=1", + { scholarshipYear: year }, + ) + .andWhere( + rootId != "" && rootId != null && rootId != undefined + ? "developmentScholarship.rootId = :rootId" + : "1=1", + { rootId: rootId }, + ) + .orderBy("developmentScholarship.scholarshipYear", "DESC") + .addOrderBy("developmentScholarship.createdAt", "DESC") + .getMany(); + + const mapData = developments.map((item, idx:number) => ({ + no: Extension.ToThaiNumber((idx+1).toString()), + institution: item.educationalInstitution ? item.educationalInstitution : "-", + scholarshipType: item.scholarshipType ? item.scholarshipType : "-", + degreeLevel: item.degreeLevel ? item.degreeLevel : "-", + course: item.course ? item.course : "-", + field: item.field ? item.field : "-", + fullName: `${item.prefix}${item.firstName} ${item.lastName}`, + position: item.position ? item.position : "-", + posLevel: item.posLevel ? item.posLevel.posLevelName : "-", + totalPeriod: item.totalPeriod ? item.totalPeriod : "-", + budgetApprove: item.budgetApprove ? Extension.ToThaiNumber(item.budgetApprove.toString()) : "๐" //toLocaleString + })); + + const sum = developments + .filter(x => x.budgetApprove) + .reduce((acc, item) => acc + (Number(item.budgetApprove)), 0); return new HttpSuccess({ template: "reportFund3", reportName: "reportFund3", data: { - year: year ? Extension.ToThaiNumber(year.toString()) : "-", - root: null, - developments: development, - total: total + year: year ? Extension.ToThaiNumber((year+543).toString()) : "-", + root: developments.length > 0 ? developments[0].root : "-", + data: mapData.length > 0 + ? mapData + : [{ + no: "-", + institution: "-", + scholarshipType: "-", + degreeLevel: "-", + course: "-", + field: "-", + fullName: "-", + position: "-", + posLevel: "-", + totalPeriod: "-", + budgetApprove: "-", + }], + sum: sum ? Extension.ToThaiNumber(sum.toString()): "-" }, }); } From a455c14ce6d7850169545357e9afd7510df25564 Mon Sep 17 00:00:00 2001 From: AdisakKanthawilang Date: Thu, 13 Feb 2025 17:34:19 +0700 Subject: [PATCH 208/250] update --- src/controllers/ReportController.ts | 116 +++++++++++++++++++++++- src/entities/view/viewDevScholarship.ts | 26 ++++++ src/interfaces/extension.ts | 43 +++++++++ 3 files changed, 182 insertions(+), 3 deletions(-) create mode 100644 src/entities/view/viewDevScholarship.ts diff --git a/src/controllers/ReportController.ts b/src/controllers/ReportController.ts index deb87af..5819489 100644 --- a/src/controllers/ReportController.ts +++ b/src/controllers/ReportController.ts @@ -623,14 +623,75 @@ export class ReportController extends Controller { * */ @Get("report5") - async report5() { + async report5( + @Query("year") year: number, + // @Query("rootId") rootId: string, + ) { + + const [development, total] = await AppDataSource.getRepository(DevelopmentScholarship) + .createQueryBuilder("developmentScholarship") + .leftJoinAndSelect("developmentScholarship.posLevel", "posLevel") + .leftJoinAndSelect("developmentScholarship.posType", "posType") + .leftJoinAndSelect("developmentScholarship.posLevelguarantor", "posLevelguarantor") + .leftJoinAndSelect("developmentScholarship.posTypeguarantor", "posTypeguarantor") + // .where("developmentScholarship.rootId = :rootId", { rootId: rootId }) + .andWhere( + year !== 0 && year != null && year != undefined + ? "developmentScholarship.scholarshipYear = :scholarshipYear" + : "1=1", + { scholarshipYear: year }, + ) + .andWhere( + "developmentScholarship.scholarshipType = :scholarshipType", { scholarshipType: "RESEARCH" }, + ) + .orderBy("developmentScholarship.scholarshipYear", "DESC") + .addOrderBy("developmentScholarship.createdAt", "DESC") + .getManyAndCount(); + + const totalBudgetApprove = development.reduce((sum, item) => sum + Number(item.budgetApprove), 0); + const formattedData = development.map((item, index) => { + const rawPath = [ + item.course == "-" ? null : item.course, + item.field == "-" ? null : item.course + ]; + + const courseAndfield = rawPath + .filter((path) => path !== undefined && path !== null) + .join("/"); + + const date = [ + Extension.ToThaiNumber(Extension.ToThaiShortDate(item.startDate)), + Extension.ToThaiNumber(Extension.ToThaiShortDate(item.endDate)) + ]; + + const dateDulation = date + .filter((path) => path !== undefined && path !== null) + .join(" - "); + + return { + no: Extension.ToThaiNumber((index + 1).toString()), + id: item.id, + studyTopic: item.studyTopic ? item.studyTopic : "-", + fullName: item.prefix + item.firstName + " " + item.lastName, + position: item.position, + posLevel: item.posLevel ? item.posLevel.posLevelName : "-", + courseAndfield: courseAndfield ?? "-", + place: item.studyPlace ? item.studyPlace : "-", + country: item.studyCountry ? item.studyCountry : "-", + startAndendDate: dateDulation, + budgetApprove: item.budgetApprove ? Extension.ToThaiNumber(item.budgetApprove.toString()) : "-", + }; + }); return new HttpSuccess({ template: "reportFund5", reportName: "reportFund5", data: { - data: "", + year: Extension.ToThaiNumber(year.toString()), + data: formattedData, + total: Extension.ToThaiNumber(total.toString()), + totalBudgetApprove: Extension.ToThaiNumber(totalBudgetApprove.toString()), }, }); } @@ -641,8 +702,57 @@ export class ReportController extends Controller { * */ @Get("report6") - async report6() { + async report6( + @Query("year") year: number, + ) { + const degree = [ + "ปริญญาเอก", + "ปริญญาโท", + "ปริญญาตรี", + "ปวส.", + "ปวช.", + "ม.6", + "ม.3", + ]; + + + // const totalBudgetApprove = development.reduce((sum, item) => sum + Number(item.budgetApprove), 0); + // const formattedData = development.map((item, index) => { + // const rawPath = [ + // item.course == "-" ? null : item.course, + // item.field == "-" ? null : item.course + // ]; + // const courseAndfield = rawPath + // .filter((path) => path !== undefined && path !== null) + // .join("/"); + + // const date = [ + // Extension.ToThaiNumber(Extension.ToThaiShortDate(item.startDate)), + // Extension.ToThaiNumber(Extension.ToThaiShortDate(item.endDate)) + // ]; + + // const dateDulation = date + // .filter((path) => path !== undefined && path !== null) + // .join(" - "); + + // return { + // no: Extension.ToThaiNumber((index + 1).toString()), + // id: item.id, + // rootId: item.rootId, + // root: item.root, + // degree: item.degreeLevel, + // // studyTopic: item.studyTopic ? item.studyTopic : "-", + // // fullName: item.prefix + item.firstName + " " + item.lastName, + // // position: item.position, + // // posLevel: item.posLevel ? item.posLevel.posLevelName : "-", + // // courseAndfield: courseAndfield ?? "-", + // // place: item.studyPlace ? item.studyPlace : "-", + // // country: item.studyCountry ? item.studyCountry : "-", + // // startAndendDate: dateDulation, + // // budgetApprove: item.budgetApprove ? Extension.ToThaiNumber(item.budgetApprove.toString()) : "-", + // }; + // }); return new HttpSuccess({ template: "reportFund6", diff --git a/src/entities/view/viewDevScholarship.ts b/src/entities/view/viewDevScholarship.ts new file mode 100644 index 0000000..4b66501 --- /dev/null +++ b/src/entities/view/viewDevScholarship.ts @@ -0,0 +1,26 @@ +import { ViewColumn, ViewEntity } from "typeorm"; + +@ViewEntity({ + expression: `SELECT MAX(\`rootId\`) AS rootId, + MAX(\`root\`) AS root,\`degreeLevel\`, + COUNT(*) AS numberOfRecords, + COUNT(DISTINCT \`scholarshipType\`) AS numberOfScholarshipTypes, + SUM(\`budgetApprove\`) AS totalBudgetApprove + FROM \`developmentScholarship\` + GROUP BY \`rootId\`,\`degreeLevel\` + `, +}) + +export class viewProfileEvaluation { + @ViewColumn() + rootId: string; + @ViewColumn() + root: string; + @ViewColumn() + numberOfRecords: number; + @ViewColumn() + numberOfScholarshipTypes: number; + @ViewColumn() + totalBudgetApprove: number; + } + diff --git a/src/interfaces/extension.ts b/src/interfaces/extension.ts index 5de8bd4..f8a28d1 100644 --- a/src/interfaces/extension.ts +++ b/src/interfaces/extension.ts @@ -30,6 +30,37 @@ class Extension { } } + 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; @@ -86,6 +117,18 @@ class Extension { } return sum; } + + 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) + ); + } + } export default Extension; From 92855fac400ddb93d927a14c7ba96d73d66f6ba1 Mon Sep 17 00:00:00 2001 From: Bright Date: Thu, 13 Feb 2025 17:38:17 +0700 Subject: [PATCH 209/250] update 3 4 --- src/controllers/ReportController.ts | 155 ++++++++++++++++++++++++++-- 1 file changed, 148 insertions(+), 7 deletions(-) diff --git a/src/controllers/ReportController.ts b/src/controllers/ReportController.ts index 5aaa802..9c367fe 100644 --- a/src/controllers/ReportController.ts +++ b/src/controllers/ReportController.ts @@ -586,11 +586,23 @@ export class ReportController extends Controller { .orderBy("developmentScholarship.scholarshipYear", "DESC") .addOrderBy("developmentScholarship.createdAt", "DESC") .getMany(); - + const mapData = developments.map((item, idx:number) => ({ no: Extension.ToThaiNumber((idx+1).toString()), institution: item.educationalInstitution ? item.educationalInstitution : "-", - scholarshipType: item.scholarshipType ? item.scholarshipType : "-", + scholarshipType: item.scholarshipType ? + item.scholarshipType == "DOMESTICE" + ? "การศึกษาในประเทศ" + : item.scholarshipType == "NOABROAD" + ? "ฝึกอบรมในประเทศที่ส่งไปพัฒนากับหน่วยวงานภายนอก (หลักสูตรที่ไม่มีการไปต่างประเทศ)" + : item.scholarshipType == "ABROAD" + ? "ฝึกอบรมในประเทศที่ส่งไปพัฒนากับหน่วยวงานภายนอก (หลักสูตรที่มีการไปต่างประเทศ)" + : item.scholarshipType == "EXECUTIVE" + ? "ฝึกอบรมในประเทศที่ส่งไปพัฒนากับหน่วยวงานภายนอก (หลักสูตรประเภทนักบริหาร)" + : item.scholarshipType == "RESEARCH" + ? "ศึกษา ฝึกอบรม ประชุม ดูงาน และปฏิบัติการวิจัย ณ ต่างประเทศ" + : "-" + : "-", degreeLevel: item.degreeLevel ? item.degreeLevel : "-", course: item.course ? item.course : "-", field: item.field ? item.field : "-", @@ -598,7 +610,7 @@ export class ReportController extends Controller { position: item.position ? item.position : "-", posLevel: item.posLevel ? item.posLevel.posLevelName : "-", totalPeriod: item.totalPeriod ? item.totalPeriod : "-", - budgetApprove: item.budgetApprove ? Extension.ToThaiNumber(item.budgetApprove.toString()) : "๐" //toLocaleString + budgetApprove: item.budgetApprove ? Extension.ToThaiNumber(item.budgetApprove.toLocaleString()) : "๐" })); const sum = developments @@ -610,7 +622,7 @@ export class ReportController extends Controller { reportName: "reportFund3", data: { year: year ? Extension.ToThaiNumber((year+543).toString()) : "-", - root: developments.length > 0 ? developments[0].root : "-", + root: rootId ? developments.length > 0 ? developments.find(x => x.root != "")?.root: "-" : "-", data: mapData.length > 0 ? mapData : [{ @@ -626,7 +638,7 @@ export class ReportController extends Controller { totalPeriod: "-", budgetApprove: "-", }], - sum: sum ? Extension.ToThaiNumber(sum.toString()): "-" + sum: sum ? Extension.ToThaiNumber(sum.toLocaleString()): "-" }, }); } @@ -637,14 +649,143 @@ export class ReportController extends Controller { * */ @Get("report4") - async report4() { + async report4( + @Query("year") year: number, + ) { + const developments = await AppDataSource.getRepository(DevelopmentScholarship) + .createQueryBuilder("developmentScholarship") + .andWhere( + year !== 0 && year != null && year != undefined + ? "developmentScholarship.scholarshipYear = :scholarshipYear" + : "1=1", + { scholarshipYear: year }, + ) + .orderBy("developmentScholarship.scholarshipYear", "DESC") + .addOrderBy("developmentScholarship.createdAt", "DESC") + .getMany(); + // const _develop = await this.developmentScholarshipRepository.find({ + // where: { + // scholarshipYear: year ? year : Not(IsNull()) + // }, + // order: { "scholarshipYear" : "DESC" } + // }) + const groupDevelopment = Array.isArray(developments) && developments.length > 0 + ? developments.reduce((acc:any, current:any, idx:number) => { + const root = current.root || ""; + if (!acc[root]) { + acc[root] = { + // rootId, + no: (idx+1), + root: root, + Bachelor : 0, + BachelorHight: 0, + Master: 0, + Doctor: 0, + DomesticeCourseCount: 0, + DomesticeProfileCount: 0, + DomesticeBudgetApprove: 0, + NoAbroadCourseCount: 0, + NoAbroadDProfileCount: 0, + NoAbroadBudgetApprove: 0, + AbroadCourseCount: 0, + AbroadProfileCount: 0, + AbroadBudgetApprove: 0, + ExecutiveCourseCount: 0, + ExecutiveProfileCount: 0, + ExecutiveBudgetApprove: 0, + TotalCourseCount: 0, + TotalProfileCount: 0, + TotalBudgetApprove: 0, + }; + } + + switch (current.scholarshipType) { + case "DOMESTICE": + acc[root].DomesticeCourseCount++; + acc[root].DomesticeProfileCount++; + acc[root].DomesticeBudgetApprove += current.budgetApprove || 0; + break; + case "NOABROAD": + acc[root].NoAbroadCourseCount++; + acc[root].NoAbroadProfileCount++; + acc[root].NoAbroadBudgetApprove += current.budgetApprove || 0; + break; + case "ABROAD": + acc[root].AbroadCourseCount++; + acc[root].AbroadProfileCount++; + acc[root].AbroadBudgetApprove += current.budgetApprove || 0; + break; + case "EXECUTIVE": + acc[root].ExecutiveCourseCount++; + acc[root].ExecutiveProfileCount++; + acc[root].ExecutiveBudgetApprove += current.budgetApprove || 0; + break; + } + + acc[root].TotalCourseCount = acc[root].DomesticeCourseCount + acc[root].NoAbroadCourseCount + acc[root].AbroadCourseCount + acc[root].ExecutiveCourseCount; + acc[root].TotalProfileCount = acc[root].DomesticeProfileCount + acc[root].NoAbroadProfileCount + acc[root].AbroadProfileCount + acc[root].ExecutiveProfileCount; + acc[root].TotalBudgetApprove = acc[root].DomesticeBudgetApprove + acc[root].NoAbroadBudgetApprove + acc[root].AbroadBudgetApprove + acc[root].ExecutiveBudgetApprove; + + return acc; + }, {}) + : []; + + const _group = Object.values(groupDevelopment); return new HttpSuccess({ template: "reportFund4", reportName: "reportFund4", data: { - data: "", + year: year ? Extension.ToThaiNumber((year+543).toString()) : "-", + data: Array.isArray(_group) + ? _group.map((x:any, idx:number) => ({ + // no: Extension.ToThaiNumber((idx+1).toString()), + // root: x.root ? x.root : "-", + // Bachelor : "-", + // BachelorHight: "-", + // Master: "-", + // Doctor: "-", + // DomesticeCourseCount: x.DomesticeCourseCount ? Extension.ToThaiNumber(x.DomesticeCourseCount) : "๐", + // DomesticeProfileCount: x.DomesticeProfileCount ? Extension.ToThaiNumber(x.DomesticeProfileCount) : "๐", + // DomesticeBudgetApprove: x.DomesticeBudgetApprove ? Extension.ToThaiNumber(x.DomesticeBudgetApprove) : "๐", + // NoAbroadCourseCount: x.NoAbroadCourseCount ? Extension.ToThaiNumber(x.NoAbroadCourseCount) : "๐", + // NoAbroadDProfileCount: x.NoAbroadDProfileCount ? Extension.ToThaiNumber(x.NoAbroadDProfileCount) : "๐", + // NoAbroadBudgetApprove: x.NoAbroadBudgetApprove ? Extension.ToThaiNumber(x.NoAbroadBudgetApprove) : "๐", + // AbroadCourseCount: x.AbroadCourseCount ? Extension.ToThaiNumber(x.AbroadCourseCount) : "๐", + // AbroadProfileCount: x.AbroadProfileCount ? Extension.ToThaiNumber(x.AbroadProfileCount) : "๐", + // AbroadBudgetApprove: x.AbroadBudgetApprove ? Extension.ToThaiNumber(x.AbroadBudgetApprove) : "๐", + // ExecutiveCourseCount: x.ExecutiveCourseCount ? Extension.ToThaiNumber(x.ExecutiveCourseCount) : "๐", + // ExecutiveProfileCount: x.ExecutiveProfileCount ? Extension.ToThaiNumber(x.ExecutiveProfileCount) : "๐", + // ExecutiveBudgetApprove: x.ExecutiveBudgetApprove ? Extension.ToThaiNumber(x.ExecutiveBudgetApprove) : "๐", + // TotalCourseCount: x.TotalCourseCount ? Extension.ToThaiNumber(x.TotalCourseCount) : "๐", + // TotalProfileCount: x.TotalProfileCount ? Extension.ToThaiNumber(x.TotalProfileCount) : "๐", + // TotalBudgetApprove: x.TotalBudgetApprove ? Extension.ToThaiNumber(x.TotalBudgetApprove) : "๐", + })) + : [{ + no: "-", + root: "-", + Bachelor : "-", + BachelorHight: "-", + Master: "-", + Doctor: "-", + DomesticeCourseCount: "-", + DomesticeProfileCount: "-", + DomesticeBudgetApprove: "-", + NoAbroadCourseCount: "-", + NoAbroadDProfileCount: "-", + NoAbroadBudgetApprove: "-", + AbroadCourseCount: "-", + AbroadProfileCount: "-", + AbroadBudgetApprove: "-", + ExecutiveCourseCount: "-", + ExecutiveProfileCount: "-", + ExecutiveBudgetApprove: "-", + TotalCourseCount: "-", + TotalProfileCount: "-", + TotalBudgetApprove: "-", + }], + totalRoot: Array.isArray(_group) ? Extension.ToThaiNumber(_group.length.toLocaleString()) : "-" }, }); } From 88af7fcbb04baff75ade9ba5da6fd9e5157e382b Mon Sep 17 00:00:00 2001 From: Bright Date: Thu, 13 Feb 2025 17:53:34 +0700 Subject: [PATCH 210/250] migrate --- src/controllers/ReportController.ts | 48 +++++++++++------------ src/migration/1739443292907-updateView.ts | 23 +++++++++++ 2 files changed, 47 insertions(+), 24 deletions(-) create mode 100644 src/migration/1739443292907-updateView.ts diff --git a/src/controllers/ReportController.ts b/src/controllers/ReportController.ts index deb9e91..966c571 100644 --- a/src/controllers/ReportController.ts +++ b/src/controllers/ReportController.ts @@ -676,7 +676,6 @@ export class ReportController extends Controller { const root = current.root || ""; if (!acc[root]) { acc[root] = { - // rootId, no: (idx+1), root: root, Bachelor : 0, @@ -739,29 +738,30 @@ export class ReportController extends Controller { data: { year: year ? Extension.ToThaiNumber((year+543).toString()) : "-", data: Array.isArray(_group) - ? _group.map((x:any, idx:number) => ({ - // no: Extension.ToThaiNumber((idx+1).toString()), - // root: x.root ? x.root : "-", - // Bachelor : "-", - // BachelorHight: "-", - // Master: "-", - // Doctor: "-", - // DomesticeCourseCount: x.DomesticeCourseCount ? Extension.ToThaiNumber(x.DomesticeCourseCount) : "๐", - // DomesticeProfileCount: x.DomesticeProfileCount ? Extension.ToThaiNumber(x.DomesticeProfileCount) : "๐", - // DomesticeBudgetApprove: x.DomesticeBudgetApprove ? Extension.ToThaiNumber(x.DomesticeBudgetApprove) : "๐", - // NoAbroadCourseCount: x.NoAbroadCourseCount ? Extension.ToThaiNumber(x.NoAbroadCourseCount) : "๐", - // NoAbroadDProfileCount: x.NoAbroadDProfileCount ? Extension.ToThaiNumber(x.NoAbroadDProfileCount) : "๐", - // NoAbroadBudgetApprove: x.NoAbroadBudgetApprove ? Extension.ToThaiNumber(x.NoAbroadBudgetApprove) : "๐", - // AbroadCourseCount: x.AbroadCourseCount ? Extension.ToThaiNumber(x.AbroadCourseCount) : "๐", - // AbroadProfileCount: x.AbroadProfileCount ? Extension.ToThaiNumber(x.AbroadProfileCount) : "๐", - // AbroadBudgetApprove: x.AbroadBudgetApprove ? Extension.ToThaiNumber(x.AbroadBudgetApprove) : "๐", - // ExecutiveCourseCount: x.ExecutiveCourseCount ? Extension.ToThaiNumber(x.ExecutiveCourseCount) : "๐", - // ExecutiveProfileCount: x.ExecutiveProfileCount ? Extension.ToThaiNumber(x.ExecutiveProfileCount) : "๐", - // ExecutiveBudgetApprove: x.ExecutiveBudgetApprove ? Extension.ToThaiNumber(x.ExecutiveBudgetApprove) : "๐", - // TotalCourseCount: x.TotalCourseCount ? Extension.ToThaiNumber(x.TotalCourseCount) : "๐", - // TotalProfileCount: x.TotalProfileCount ? Extension.ToThaiNumber(x.TotalProfileCount) : "๐", - // TotalBudgetApprove: x.TotalBudgetApprove ? Extension.ToThaiNumber(x.TotalBudgetApprove) : "๐", - })) + ? _group + // ? _group.map((x:any) => ({ + // no: x.no ? Extension.ToThaiNumber(x.no) : "-", + // root: x.root ? x.root : "-", + // Bachelor : "-", + // BachelorHight: "-", + // Master: "-", + // Doctor: "-", + // DomesticeCourseCount: x.DomesticeCourseCount ? Extension.ToThaiNumber(x.DomesticeCourseCount) : "-", + // DomesticeProfileCount: x.DomesticeProfileCount ? Extension.ToThaiNumber(x.DomesticeProfileCount) : "-", + // DomesticeBudgetApprove: x.DomesticeBudgetApprove ? Extension.ToThaiNumber(x.DomesticeBudgetApprove) : "-", + // NoAbroadCourseCount: x.NoAbroadCourseCount ? Extension.ToThaiNumber(x.NoAbroadCourseCount) : "-", + // NoAbroadDProfileCount: x.NoAbroadDProfileCount ? Extension.ToThaiNumber(x.NoAbroadDProfileCount) : "-", + // NoAbroadBudgetApprove: x.NoAbroadBudgetApprove ? Extension.ToThaiNumber(x.NoAbroadBudgetApprove) : "-", + // AbroadCourseCount: x.AbroadCourseCount ? Extension.ToThaiNumber(x.AbroadCourseCount) : "-", + // AbroadProfileCount: x.AbroadProfileCount ? Extension.ToThaiNumber(x.AbroadProfileCount) : "-", + // AbroadBudgetApprove: x.AbroadBudgetApprove ? Extension.ToThaiNumber(x.AbroadBudgetApprove) : "-", + // ExecutiveCourseCount: x.ExecutiveCourseCount ? Extension.ToThaiNumber(x.ExecutiveCourseCount) : "-", + // ExecutiveProfileCount: x.ExecutiveProfileCount ? Extension.ToThaiNumber(x.ExecutiveProfileCount) : "-", + // ExecutiveBudgetApprove: x.ExecutiveBudgetApprove ? Extension.ToThaiNumber(x.ExecutiveBudgetApprove) : "-", + // TotalCourseCount: x.TotalCourseCount ? Extension.ToThaiNumber(x.TotalCourseCount) : "-", + // TotalProfileCount: x.TotalProfileCount ? Extension.ToThaiNumber(x.TotalProfileCount) : "-", + // TotalBudgetApprove: x.TotalBudgetApprove ? Extension.ToThaiNumber(x.TotalBudgetApprove) : "-", + // })) : [{ no: "-", root: "-", diff --git a/src/migration/1739443292907-updateView.ts b/src/migration/1739443292907-updateView.ts new file mode 100644 index 0000000..abfef72 --- /dev/null +++ b/src/migration/1739443292907-updateView.ts @@ -0,0 +1,23 @@ +import { MigrationInterface, QueryRunner } from "typeorm"; + +export class UpdateView1739443292907 implements MigrationInterface { + name = 'UpdateView1739443292907' + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(`CREATE VIEW \`view_profile_evaluation\` AS SELECT MAX(\`rootId\`) AS rootId, + MAX(\`root\`) AS root,\`degreeLevel\`, + COUNT(*) AS numberOfRecords, + COUNT(DISTINCT \`scholarshipType\`) AS numberOfScholarshipTypes, + SUM(\`budgetApprove\`) AS totalBudgetApprove + FROM \`developmentScholarship\` + GROUP BY \`rootId\`,\`degreeLevel\` + `); + await queryRunner.query(`INSERT INTO \`bma_ehr_development_demo\`.\`typeorm_metadata\`(\`database\`, \`schema\`, \`table\`, \`type\`, \`name\`, \`value\`) VALUES (DEFAULT, ?, DEFAULT, ?, ?, ?)`, ["bma_ehr_development_demo","VIEW","view_profile_evaluation","SELECT MAX(`rootId`) AS rootId, \n MAX(`root`) AS root,`degreeLevel`,\n COUNT(*) AS numberOfRecords, \n COUNT(DISTINCT `scholarshipType`) AS numberOfScholarshipTypes,\n SUM(`budgetApprove`) AS totalBudgetApprove\n FROM `developmentScholarship`\n GROUP BY `rootId`,`degreeLevel`"]); + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(`DELETE FROM \`bma_ehr_development_demo\`.\`typeorm_metadata\` WHERE \`type\` = ? AND \`name\` = ? AND \`schema\` = ?`, ["VIEW","view_profile_evaluation","bma_ehr_development_demo"]); + await queryRunner.query(`DROP VIEW \`view_profile_evaluation\``); + } + +} From 29fca33c2e6e3cb123edabbdf3299d12ded07f54 Mon Sep 17 00:00:00 2001 From: AdisakKanthawilang Date: Thu, 13 Feb 2025 18:01:34 +0700 Subject: [PATCH 211/250] fix --- src/entities/view/viewDevScholarship.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/entities/view/viewDevScholarship.ts b/src/entities/view/viewDevScholarship.ts index 4b66501..e85ef4e 100644 --- a/src/entities/view/viewDevScholarship.ts +++ b/src/entities/view/viewDevScholarship.ts @@ -11,7 +11,7 @@ import { ViewColumn, ViewEntity } from "typeorm"; `, }) -export class viewProfileEvaluation { +export class viewDevScholarship { @ViewColumn() rootId: string; @ViewColumn() From 4dc2f476d2290722862304d7e09edb88f84a02c9 Mon Sep 17 00:00:00 2001 From: Bright Date: Thu, 13 Feb 2025 18:07:32 +0700 Subject: [PATCH 212/250] update report + migrate --- src/controllers/ReportController.ts | 15 +++++++++------ src/migration/1739444714910-updateView.ts | 23 +++++++++++++++++++++++ 2 files changed, 32 insertions(+), 6 deletions(-) create mode 100644 src/migration/1739444714910-updateView.ts diff --git a/src/controllers/ReportController.ts b/src/controllers/ReportController.ts index 966c571..a28d90b 100644 --- a/src/controllers/ReportController.ts +++ b/src/controllers/ReportController.ts @@ -24,7 +24,10 @@ export class ReportController extends Controller { * @param {string} type type ประเภท report */ @Get("main") - async GetReportDevelopemtMain(/*@Path() type: string*/) { + async GetReportDevelopemtMain( + @Query("year") year?: number, + @Query("rootId") rootId?: string, + ) { // const _type = type.trim().toUpperCase(); const formattedData = { @@ -564,7 +567,7 @@ export class ReportController extends Controller { */ @Get("report3") async report3( - @Query("year") year: number, + @Query("year") year?: number, @Query("rootId") rootId?: string, ) { const developments = await AppDataSource.getRepository(DevelopmentScholarship) @@ -650,7 +653,7 @@ export class ReportController extends Controller { */ @Get("report4") async report4( - @Query("year") year: number, + @Query("year") year?: number, ) { const developments = await AppDataSource.getRepository(DevelopmentScholarship) .createQueryBuilder("developmentScholarship") @@ -797,7 +800,7 @@ export class ReportController extends Controller { */ @Get("report5") async report5( - @Query("year") year: number, + @Query("year") year?: number, // @Query("rootId") rootId: string, ) { @@ -861,7 +864,7 @@ export class ReportController extends Controller { template: "reportFund5", reportName: "reportFund5", data: { - year: Extension.ToThaiNumber(year.toString()), + year: year ? Extension.ToThaiNumber(year.toString()) : "-", data: formattedData, total: Extension.ToThaiNumber(total.toString()), totalBudgetApprove: Extension.ToThaiNumber(totalBudgetApprove.toString()), @@ -876,7 +879,7 @@ export class ReportController extends Controller { */ @Get("report6") async report6( - @Query("year") year: number, + @Query("year") year?: number, ) { const degree = [ "ปริญญาเอก", diff --git a/src/migration/1739444714910-updateView.ts b/src/migration/1739444714910-updateView.ts new file mode 100644 index 0000000..ab12b2e --- /dev/null +++ b/src/migration/1739444714910-updateView.ts @@ -0,0 +1,23 @@ +import { MigrationInterface, QueryRunner } from "typeorm"; + +export class UpdateView1739444714910 implements MigrationInterface { + name = 'UpdateView1739444714910' + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(`CREATE VIEW \`view_dev_scholarship\` AS SELECT MAX(\`rootId\`) AS rootId, + MAX(\`root\`) AS root,\`degreeLevel\`, + COUNT(*) AS numberOfRecords, + COUNT(DISTINCT \`scholarshipType\`) AS numberOfScholarshipTypes, + SUM(\`budgetApprove\`) AS totalBudgetApprove + FROM \`developmentScholarship\` + GROUP BY \`rootId\`,\`degreeLevel\` + `); + await queryRunner.query(`INSERT INTO \`bma_ehr_development_demo\`.\`typeorm_metadata\`(\`database\`, \`schema\`, \`table\`, \`type\`, \`name\`, \`value\`) VALUES (DEFAULT, ?, DEFAULT, ?, ?, ?)`, ["bma_ehr_development_demo","VIEW","view_dev_scholarship","SELECT MAX(`rootId`) AS rootId, \n MAX(`root`) AS root,`degreeLevel`,\n COUNT(*) AS numberOfRecords, \n COUNT(DISTINCT `scholarshipType`) AS numberOfScholarshipTypes,\n SUM(`budgetApprove`) AS totalBudgetApprove\n FROM `developmentScholarship`\n GROUP BY `rootId`,`degreeLevel`"]); + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(`DELETE FROM \`bma_ehr_development_demo\`.\`typeorm_metadata\` WHERE \`type\` = ? AND \`name\` = ? AND \`schema\` = ?`, ["VIEW","view_dev_scholarship","bma_ehr_development_demo"]); + await queryRunner.query(`DROP VIEW \`view_dev_scholarship\``); + } + +} From 08bf5e53c6e0e0cf2371479703be7a8ba6ab0c04 Mon Sep 17 00:00:00 2001 From: AdisakKanthawilang Date: Thu, 13 Feb 2025 18:08:39 +0700 Subject: [PATCH 213/250] fix --- src/controllers/ReportController.ts | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/controllers/ReportController.ts b/src/controllers/ReportController.ts index 966c571..7eac2d6 100644 --- a/src/controllers/ReportController.ts +++ b/src/controllers/ReportController.ts @@ -10,12 +10,13 @@ import { PosLevel } from "../entities/PosLevel"; import Extension from "../interfaces/extension"; import { DevelopmentScholarship } from "../entities/DevelopmentScholarship"; import { IsNull, Not } from "typeorm"; +import { viewDevScholarship } from "../entities/view/viewDevScholarship"; @Route("api/v1/development/report") @Tags("Report") @Security("bearerAuth") export class ReportController extends Controller { private developmentScholarshipRepository = AppDataSource.getRepository(DevelopmentScholarship); - + private viewDevScholarship = AppDataSource.getRepository(viewDevScholarship); /** * API Report รายการโครงการ/หลักสูตรการฝึกอบรมที่หน่วยงานของกรุงเทพมหานครเป็นผู้จัด * @@ -861,7 +862,7 @@ export class ReportController extends Controller { template: "reportFund5", reportName: "reportFund5", data: { - year: Extension.ToThaiNumber(year.toString()), + year: Extension.ToThaiNumber((year+543).toString()), data: formattedData, total: Extension.ToThaiNumber(total.toString()), totalBudgetApprove: Extension.ToThaiNumber(totalBudgetApprove.toString()), @@ -888,6 +889,12 @@ export class ReportController extends Controller { "ม.3", ]; + // const development = await this.viewDevScholarship.find({ + // where:{ + // degreeLevel: In(degree), + // } + // }) + // const totalBudgetApprove = development.reduce((sum, item) => sum + Number(item.budgetApprove), 0); // const formattedData = development.map((item, index) => { @@ -931,6 +938,7 @@ export class ReportController extends Controller { template: "reportFund6", reportName: "reportFund6", data: { + year: Extension.ToThaiNumber((year+543).toString()), data: "", }, }); From 896928d3c7e45be096885de678ecd0df6cffe0cf Mon Sep 17 00:00:00 2001 From: AdisakKanthawilang Date: Thu, 13 Feb 2025 18:43:36 +0700 Subject: [PATCH 214/250] update --- src/controllers/ReportController.ts | 60 +++++++++---------- src/entities/view/viewDevScholarship.ts | 2 + ...739446719623-update_viewDevScholarship.ts} | 12 ++-- 3 files changed, 37 insertions(+), 37 deletions(-) rename src/migration/{1739443292907-updateView.ts => 1739446719623-update_viewDevScholarship.ts} (51%) diff --git a/src/controllers/ReportController.ts b/src/controllers/ReportController.ts index 8e44261..2790f38 100644 --- a/src/controllers/ReportController.ts +++ b/src/controllers/ReportController.ts @@ -9,7 +9,7 @@ import { PosType } from "../entities/PosType"; import { PosLevel } from "../entities/PosLevel"; import Extension from "../interfaces/extension"; import { DevelopmentScholarship } from "../entities/DevelopmentScholarship"; -import { IsNull, Not } from "typeorm"; +import { In, IsNull, Not } from "typeorm"; import { viewDevScholarship } from "../entities/view/viewDevScholarship"; @Route("api/v1/development/report") @Tags("Report") @@ -742,30 +742,30 @@ export class ReportController extends Controller { data: { year: year ? Extension.ToThaiNumber((year+543).toString()) : "-", data: Array.isArray(_group) - ? _group - // ? _group.map((x:any) => ({ - // no: x.no ? Extension.ToThaiNumber(x.no) : "-", - // root: x.root ? x.root : "-", - // Bachelor : "-", - // BachelorHight: "-", - // Master: "-", - // Doctor: "-", - // DomesticeCourseCount: x.DomesticeCourseCount ? Extension.ToThaiNumber(x.DomesticeCourseCount) : "-", - // DomesticeProfileCount: x.DomesticeProfileCount ? Extension.ToThaiNumber(x.DomesticeProfileCount) : "-", - // DomesticeBudgetApprove: x.DomesticeBudgetApprove ? Extension.ToThaiNumber(x.DomesticeBudgetApprove) : "-", - // NoAbroadCourseCount: x.NoAbroadCourseCount ? Extension.ToThaiNumber(x.NoAbroadCourseCount) : "-", - // NoAbroadDProfileCount: x.NoAbroadDProfileCount ? Extension.ToThaiNumber(x.NoAbroadDProfileCount) : "-", - // NoAbroadBudgetApprove: x.NoAbroadBudgetApprove ? Extension.ToThaiNumber(x.NoAbroadBudgetApprove) : "-", - // AbroadCourseCount: x.AbroadCourseCount ? Extension.ToThaiNumber(x.AbroadCourseCount) : "-", - // AbroadProfileCount: x.AbroadProfileCount ? Extension.ToThaiNumber(x.AbroadProfileCount) : "-", - // AbroadBudgetApprove: x.AbroadBudgetApprove ? Extension.ToThaiNumber(x.AbroadBudgetApprove) : "-", - // ExecutiveCourseCount: x.ExecutiveCourseCount ? Extension.ToThaiNumber(x.ExecutiveCourseCount) : "-", - // ExecutiveProfileCount: x.ExecutiveProfileCount ? Extension.ToThaiNumber(x.ExecutiveProfileCount) : "-", - // ExecutiveBudgetApprove: x.ExecutiveBudgetApprove ? Extension.ToThaiNumber(x.ExecutiveBudgetApprove) : "-", - // TotalCourseCount: x.TotalCourseCount ? Extension.ToThaiNumber(x.TotalCourseCount) : "-", - // TotalProfileCount: x.TotalProfileCount ? Extension.ToThaiNumber(x.TotalProfileCount) : "-", - // TotalBudgetApprove: x.TotalBudgetApprove ? Extension.ToThaiNumber(x.TotalBudgetApprove) : "-", - // })) + // ? _group + ? _group.map((x:any) => ({ + no: x.no ? Extension.ToThaiNumber(x.no.toString()) : "-", + root: x.root ? x.root : "-", + Bachelor : "-", + BachelorHight: "-", + Master: "-", + Doctor: "-", + DomesticeCourseCount: x.DomesticeCourseCount ? Extension.ToThaiNumber(x.DomesticeCourseCount.toLocaleString()) : "-", + DomesticeProfileCount: x.DomesticeProfileCount ? Extension.ToThaiNumber(x.DomesticeProfileCount.toLocaleString()) : "-", + DomesticeBudgetApprove: x.DomesticeBudgetApprove ? Extension.ToThaiNumber(x.DomesticeBudgetApprove.toLocaleString()) : "-", + NoAbroadCourseCount: x.NoAbroadCourseCount ? Extension.ToThaiNumber(x.NoAbroadCourseCount.toLocaleString()) : "-", + NoAbroadDProfileCount: x.NoAbroadDProfileCount ? Extension.ToThaiNumber(x.NoAbroadDProfileCount.toLocaleString()) : "-", + NoAbroadBudgetApprove: x.NoAbroadBudgetApprove ? Extension.ToThaiNumber(x.NoAbroadBudgetApprove.toLocaleString()) : "-", + AbroadCourseCount: x.AbroadCourseCount ? Extension.ToThaiNumber(x.AbroadCourseCount.toLocaleString()) : "-", + AbroadProfileCount: x.AbroadProfileCount ? Extension.ToThaiNumber(x.AbroadProfileCount.toLocaleString()) : "-", + AbroadBudgetApprove: x.AbroadBudgetApprove ? Extension.ToThaiNumber(x.AbroadBudgetApprove.toLocaleString()) : "-", + ExecutiveCourseCount: x.ExecutiveCourseCount ? Extension.ToThaiNumber(x.ExecutiveCourseCount.toLocaleString()) : "-", + ExecutiveProfileCount: x.ExecutiveProfileCount ? Extension.ToThaiNumber(x.ExecutiveProfileCount.toLocaleString()) : "-", + ExecutiveBudgetApprove: x.ExecutiveBudgetApprove ? Extension.ToThaiNumber(x.ExecutiveBudgetApprove.toLocaleString()) : "-", + TotalCourseCount: x.TotalCourseCount ? Extension.ToThaiNumber(x.TotalCourseCount.toLocaleString()) : "-", + TotalProfileCount: x.TotalProfileCount ? Extension.ToThaiNumber(x.TotalProfileCount.toLocaleString()) : "-", + TotalBudgetApprove: x.TotalBudgetApprove ? Extension.ToThaiNumber(x.TotalBudgetApprove.toLocaleString()) : "-", + })) : [{ no: "-", root: "-", @@ -856,7 +856,7 @@ export class ReportController extends Controller { place: item.studyPlace ? item.studyPlace : "-", country: item.studyCountry ? item.studyCountry : "-", startAndendDate: dateDulation, - budgetApprove: item.budgetApprove ? Extension.ToThaiNumber(item.budgetApprove.toString()) : "-", + budgetApprove: item.budgetApprove ? Extension.ToThaiNumber(item.budgetApprove.toLocaleString()) : "-", }; }); @@ -867,8 +867,8 @@ export class ReportController extends Controller { data: { year: year?Extension.ToThaiNumber((year+543).toString()):"", data: formattedData, - total: Extension.ToThaiNumber(total.toString()), - totalBudgetApprove: Extension.ToThaiNumber(totalBudgetApprove.toString()), + total: Extension.ToThaiNumber(total.toLocaleString()), + totalBudgetApprove: Extension.ToThaiNumber(totalBudgetApprove.toLocaleString()), }, }); } @@ -893,9 +893,7 @@ export class ReportController extends Controller { ]; // const development = await this.viewDevScholarship.find({ - // where:{ - // degreeLevel: In(degree), - // } + // }) diff --git a/src/entities/view/viewDevScholarship.ts b/src/entities/view/viewDevScholarship.ts index e85ef4e..5d3ea65 100644 --- a/src/entities/view/viewDevScholarship.ts +++ b/src/entities/view/viewDevScholarship.ts @@ -17,6 +17,8 @@ export class viewDevScholarship { @ViewColumn() root: string; @ViewColumn() + degreeLevel: string; + @ViewColumn() numberOfRecords: number; @ViewColumn() numberOfScholarshipTypes: number; diff --git a/src/migration/1739443292907-updateView.ts b/src/migration/1739446719623-update_viewDevScholarship.ts similarity index 51% rename from src/migration/1739443292907-updateView.ts rename to src/migration/1739446719623-update_viewDevScholarship.ts index abfef72..9a1acbc 100644 --- a/src/migration/1739443292907-updateView.ts +++ b/src/migration/1739446719623-update_viewDevScholarship.ts @@ -1,10 +1,10 @@ import { MigrationInterface, QueryRunner } from "typeorm"; -export class UpdateView1739443292907 implements MigrationInterface { - name = 'UpdateView1739443292907' +export class UpdateViewDevScholarship1739446719623 implements MigrationInterface { + name = 'UpdateViewDevScholarship1739446719623' public async up(queryRunner: QueryRunner): Promise { - await queryRunner.query(`CREATE VIEW \`view_profile_evaluation\` AS SELECT MAX(\`rootId\`) AS rootId, + await queryRunner.query(`CREATE VIEW \`view_dev_scholarship\` AS SELECT MAX(\`rootId\`) AS rootId, MAX(\`root\`) AS root,\`degreeLevel\`, COUNT(*) AS numberOfRecords, COUNT(DISTINCT \`scholarshipType\`) AS numberOfScholarshipTypes, @@ -12,12 +12,12 @@ export class UpdateView1739443292907 implements MigrationInterface { FROM \`developmentScholarship\` GROUP BY \`rootId\`,\`degreeLevel\` `); - await queryRunner.query(`INSERT INTO \`bma_ehr_development_demo\`.\`typeorm_metadata\`(\`database\`, \`schema\`, \`table\`, \`type\`, \`name\`, \`value\`) VALUES (DEFAULT, ?, DEFAULT, ?, ?, ?)`, ["bma_ehr_development_demo","VIEW","view_profile_evaluation","SELECT MAX(`rootId`) AS rootId, \n MAX(`root`) AS root,`degreeLevel`,\n COUNT(*) AS numberOfRecords, \n COUNT(DISTINCT `scholarshipType`) AS numberOfScholarshipTypes,\n SUM(`budgetApprove`) AS totalBudgetApprove\n FROM `developmentScholarship`\n GROUP BY `rootId`,`degreeLevel`"]); + await queryRunner.query(`INSERT INTO \`bma_ehr_development_demo\`.\`typeorm_metadata\`(\`database\`, \`schema\`, \`table\`, \`type\`, \`name\`, \`value\`) VALUES (DEFAULT, ?, DEFAULT, ?, ?, ?)`, ["bma_ehr_development_demo","VIEW","view_dev_scholarship","SELECT MAX(`rootId`) AS rootId, \n MAX(`root`) AS root,`degreeLevel`,\n COUNT(*) AS numberOfRecords, \n COUNT(DISTINCT `scholarshipType`) AS numberOfScholarshipTypes,\n SUM(`budgetApprove`) AS totalBudgetApprove\n FROM `developmentScholarship`\n GROUP BY `rootId`,`degreeLevel`"]); } public async down(queryRunner: QueryRunner): Promise { - await queryRunner.query(`DELETE FROM \`bma_ehr_development_demo\`.\`typeorm_metadata\` WHERE \`type\` = ? AND \`name\` = ? AND \`schema\` = ?`, ["VIEW","view_profile_evaluation","bma_ehr_development_demo"]); - await queryRunner.query(`DROP VIEW \`view_profile_evaluation\``); + await queryRunner.query(`DELETE FROM \`bma_ehr_development_demo\`.\`typeorm_metadata\` WHERE \`type\` = ? AND \`name\` = ? AND \`schema\` = ?`, ["VIEW","view_dev_scholarship","bma_ehr_development_demo"]); + await queryRunner.query(`DROP VIEW \`view_dev_scholarship\``); } } From 724a41a6a0895fdc956d0fceff7454fd7eef8108 Mon Sep 17 00:00:00 2001 From: AdisakKanthawilang Date: Thu, 13 Feb 2025 20:02:25 +0700 Subject: [PATCH 215/250] update --- src/controllers/ReportController.ts | 126 ++++++++++++++++++---------- 1 file changed, 81 insertions(+), 45 deletions(-) diff --git a/src/controllers/ReportController.ts b/src/controllers/ReportController.ts index 2790f38..5fce29f 100644 --- a/src/controllers/ReportController.ts +++ b/src/controllers/ReportController.ts @@ -11,6 +11,7 @@ import Extension from "../interfaces/extension"; import { DevelopmentScholarship } from "../entities/DevelopmentScholarship"; import { In, IsNull, Not } from "typeorm"; import { viewDevScholarship } from "../entities/view/viewDevScholarship"; +import { isNotEmittedStatement } from "typescript"; @Route("api/v1/development/report") @Tags("Report") @Security("bearerAuth") @@ -886,61 +887,96 @@ export class ReportController extends Controller { "ปริญญาเอก", "ปริญญาโท", "ปริญญาตรี", - "ปวส.", - "ปวช.", - "ม.6", - "ม.3", ]; - // const development = await this.viewDevScholarship.find({ + const development = await this.viewDevScholarship.find({ + where: { + rootId: Not(IsNull()), + degreeLevel: In(degree), + }, + }); - // }) - - - // const totalBudgetApprove = development.reduce((sum, item) => sum + Number(item.budgetApprove), 0); - // const formattedData = development.map((item, index) => { - // const rawPath = [ - // item.course == "-" ? null : item.course, - // item.field == "-" ? null : item.course - // ]; + const groupedData = development.reduce((acc:any, item:any) => { + const { rootId, root, degreeLevel, scholarshipType, budgetApprove } = item; - // const courseAndfield = rawPath - // .filter((path) => path !== undefined && path !== null) - // .join("/"); - - // const date = [ - // Extension.ToThaiNumber(Extension.ToThaiShortDate(item.startDate)), - // Extension.ToThaiNumber(Extension.ToThaiShortDate(item.endDate)) - // ]; - - // const dateDulation = date - // .filter((path) => path !== undefined && path !== null) - // .join(" - "); - - // return { - // no: Extension.ToThaiNumber((index + 1).toString()), - // id: item.id, - // rootId: item.rootId, - // root: item.root, - // degree: item.degreeLevel, - // // studyTopic: item.studyTopic ? item.studyTopic : "-", - // // fullName: item.prefix + item.firstName + " " + item.lastName, - // // position: item.position, - // // posLevel: item.posLevel ? item.posLevel.posLevelName : "-", - // // courseAndfield: courseAndfield ?? "-", - // // place: item.studyPlace ? item.studyPlace : "-", - // // country: item.studyCountry ? item.studyCountry : "-", - // // startAndendDate: dateDulation, - // // budgetApprove: item.budgetApprove ? Extension.ToThaiNumber(item.budgetApprove.toString()) : "-", - // }; - // }); + if (!acc[rootId]) { + acc[rootId] = { + root, + rootId, + degreeLevel1: { + numberOfRecords: 0, + numberOfScholarshipTypes: 0, + totalBudgetApprove: 0, + }, + degreeLevel2: { + numberOfRecords: 0, + numberOfScholarshipTypes: 0, + totalBudgetApprove: 0, + }, + degreeLevel3: { + numberOfRecords: 0, + numberOfScholarshipTypes: 0, + totalBudgetApprove: 0, + }, + }; + } + + if (degreeLevel === "ปริญญาตรี") { + acc[rootId].degreeLevel1.numberOfRecords += Number(item.numberOfRecords); + acc[rootId].degreeLevel1.numberOfScholarshipTypes += Number(item.numberOfScholarshipTypes); + acc[rootId].degreeLevel1.totalBudgetApprove += Number(item.totalBudgetApprove); + } else if (degreeLevel === "ปริญญาโท") { + acc[rootId].degreeLevel2.numberOfRecords += Number(item.numberOfRecords); + acc[rootId].degreeLevel2.numberOfScholarshipTypes += Number(item.numberOfScholarshipTypes); + acc[rootId].degreeLevel2.totalBudgetApprove += Number(item.totalBudgetApprove); + } else if (degreeLevel === "ปริญญาเอก") { + acc[rootId].degreeLevel3.numberOfRecords += Number(item.numberOfRecords); + acc[rootId].degreeLevel3.numberOfScholarshipTypes += Number(item.numberOfScholarshipTypes); + acc[rootId].degreeLevel3.totalBudgetApprove += Number(item.totalBudgetApprove); + } + + return acc; + }, {}); + const formattedData = Object.values(groupedData).map((item: any, index: any) => { + const sumnumberOfRecords = item.degreeLevel1.numberOfRecords + item.degreeLevel2.numberOfRecords + item.degreeLevel3.numberOfRecords; + const sumnumberOfScholarshipTypes = item.degreeLevel1.numberOfScholarshipTypes + item.degreeLevel2.numberOfScholarshipTypes + item.degreeLevel3.numberOfScholarshipTypes; + const sumtotalBudgetApprove = item.degreeLevel1.totalBudgetApprove + item.degreeLevel2.totalBudgetApprove + item.degreeLevel3.totalBudgetApprove; + + return { + no: index ? Extension.ToThaiNumber((index + 1).toString()) : "๑", + rootId: item.rootId ? item.rootId : "-", + root: item.root ? item.root : "-", + degreeLevel1: "ปริญญาตรี", + numberOfRecords1: item.degreeLevel1.numberOfRecords ? Extension.ToThaiNumber(item.degreeLevel1.numberOfRecords.toString()) : "-", + numberOfScholarshipTypes1: item.degreeLevel1.numberOfScholarshipTypes ? Extension.ToThaiNumber(item.degreeLevel1.numberOfScholarshipTypes.toString()) : "-", + totalBudgetApprove1: item.degreeLevel1.totalBudgetApprove ? Extension.ToThaiNumber(item.degreeLevel1.totalBudgetApprove.toLocaleString()) : "-", + + degreeLevel2: "ปริญญาโท", + numberOfRecords2: item.degreeLevel2.numberOfRecords ? Extension.ToThaiNumber(item.degreeLevel2.numberOfRecords.toString()) : "-", + numberOfScholarshipTypes2: item.degreeLevel2.numberOfScholarshipTypes ? Extension.ToThaiNumber(item.degreeLevel2.numberOfScholarshipTypes.toString()) : "-", + totalBudgetApprove2: item.degreeLevel2.totalBudgetApprove ? Extension.ToThaiNumber(item.degreeLevel2.totalBudgetApprove.toLocaleString()) : "-", + + degreeLevel3: "ปริญญาเอก", + numberOfRecords3: item.degreeLevel3.numberOfRecords ? Extension.ToThaiNumber(item.degreeLevel3.numberOfRecords.toString()) : "-", + numberOfScholarshipTypes3: item.degreeLevel3.numberOfScholarshipTypes ? Extension.ToThaiNumber(item.degreeLevel3.numberOfScholarshipTypes.toString()) : "-", + totalBudgetApprove3: item.degreeLevel3.totalBudgetApprove ? Extension.ToThaiNumber(item.degreeLevel3.totalBudgetApprove.toLocaleString()) : "-", + + totalNumberOfRecords: Extension.ToThaiNumber(sumnumberOfRecords.toString()), + totalNumberOfScholarshipTypes: Extension.ToThaiNumber(sumnumberOfScholarshipTypes.toString()), + totalTotalBudgetApprove: Extension.ToThaiNumber(sumtotalBudgetApprove.toLocaleString()) + }; + }); + const uniqueRoots = new Set(formattedData.map(item => item.root)); + const numberOfORG = uniqueRoots.size; + return new HttpSuccess({ template: "reportFund6", reportName: "reportFund6", data: { year: year?Extension.ToThaiNumber((year+543).toString()):"", - data: "", + data: formattedData, + coutOrg: numberOfORG?Extension.ToThaiNumber(numberOfORG.toString())+" หน่วยงาน":"๐ หน่วยงาน" }, }); } From 00d0f1f0fbf1a1ce9f0d1f68b914b53d2ace2da6 Mon Sep 17 00:00:00 2001 From: kittapath Date: Thu, 13 Feb 2025 21:52:49 +0700 Subject: [PATCH 216/250] edit report if no value --- src/controllers/ReportController.ts | 1066 ++++++++++++++++----------- 1 file changed, 618 insertions(+), 448 deletions(-) diff --git a/src/controllers/ReportController.ts b/src/controllers/ReportController.ts index 5fce29f..bf63247 100644 --- a/src/controllers/ReportController.ts +++ b/src/controllers/ReportController.ts @@ -26,11 +26,7 @@ export class ReportController extends Controller { * @param {string} type type ประเภท report */ @Get("main") - async GetReportDevelopemtMain( - @Query("year") year?: number, - @Query("rootId") rootId?: string, - ) { - + async GetReportDevelopemtMain(@Query("year") year?: number, @Query("rootId") rootId?: string) { // const _type = type.trim().toUpperCase(); const formattedData = { org: "_type", @@ -57,9 +53,9 @@ export class ReportController extends Controller { "SUM(DISTINCT planGoals.amount) AS goalParticipants", "COUNT(DISTINCT history.id) AS actualParticipants", "strategy1.strategyChild1Name AS strategy1", - "strategy2.strategyChild2Name AS strategy2", - "strategy3.strategyChild3Name AS strategy3", - "strategy4.strategyChild4Name AS strategy4", + "strategy2.strategyChild2Name AS strategy2", + "strategy3.strategyChild3Name AS strategy3", + "strategy4.strategyChild4Name AS strategy4", "strategy5.strategyChild5Name AS strategy5", "development.accept AS acceptBudget", "development.receive AS receiveBudget", @@ -69,224 +65,317 @@ export class ReportController extends Controller { .groupBy("development.id") .getRawMany(); - const mappedDataDev = dataDevelopment.map((item, index) => { - let budget = null; - if (item.budget == "REGULATIONBUDGET") { - budget = "งบตามข้อบัญญัติ"; - }else if (item.budget == "OTHERBUDGET") { - budget = "เงินนอกงบประมาณ"; - }else if (item.budget == "BANGKOKBUDGET") { - budget = "ไม่ใช้งบประมาณ"; - } - return { - strategy: item.strategy1, - projectName: item.projectName, - totalDate: item.totalDate != null && item.totalDate != "" ? Extension.ToThaiNumber(item.totalDate.toLocaleString()): "-", - goalParticipants: item.goalParticipants != null && item.goalParticipants != "" ? Extension.ToThaiNumber(item.goalParticipants.toLocaleString()): "-", - actualParticipants: item.actualParticipants != null && item.actualParticipants != "" ? Extension.ToThaiNumber(item.actualParticipants.toLocaleString()): "-", - budget: budget, - acceptBudget: item.acceptBudget != null && item.acceptBudget != "" ? Extension.ToThaiNumber(item.acceptBudget.toLocaleString()): "-", - receiveBudget: item.receiveBudget != null && item.receiveBudget != "" ? Extension.ToThaiNumber(item.receiveBudget.toLocaleString()): "-", - obstacle: item.obstacle, - root: item.root, - output: "-", - outcome: "-", - position: "-", - indicators: "-", - devResult: "-", - positionActual: "-", - }; - }); + const mappedDataDev = dataDevelopment.map((item, index) => { + let budget = null; + if (item.budget == "REGULATIONBUDGET") { + budget = "งบตามข้อบัญญัติ"; + } else if (item.budget == "OTHERBUDGET") { + budget = "เงินนอกงบประมาณ"; + } else if (item.budget == "BANGKOKBUDGET") { + budget = "ไม่ใช้งบประมาณ"; + } + return { + strategy: item.strategy1, + projectName: item.projectName, + totalDate: + item.totalDate != null && item.totalDate != "" + ? Extension.ToThaiNumber(item.totalDate.toLocaleString()) + : "-", + goalParticipants: + item.goalParticipants != null && item.goalParticipants != "" + ? Extension.ToThaiNumber(item.goalParticipants.toLocaleString()) + : "-", + actualParticipants: + item.actualParticipants != null && item.actualParticipants != "" + ? Extension.ToThaiNumber(item.actualParticipants.toLocaleString()) + : "-", + budget: budget, + acceptBudget: + item.acceptBudget != null && item.acceptBudget != "" + ? Extension.ToThaiNumber(item.acceptBudget.toLocaleString()) + : "-", + receiveBudget: + item.receiveBudget != null && item.receiveBudget != "" + ? Extension.ToThaiNumber(item.receiveBudget.toLocaleString()) + : "-", + obstacle: item.obstacle, + root: item.root, + output: "-", + outcome: "-", + position: "-", + indicators: "-", + devResult: "-", + positionActual: "-", + }; + }); - const resultAllStrategy = await AppDataSource.getRepository(Development) + const resultAllStrategy = await AppDataSource.getRepository(Development) .createQueryBuilder("development") .leftJoinAndSelect("development.strategyChild1Actual", "strategy1") .where("development.status = :status", { status: "FINISH" }) .andWhere("development.strategyChild1ActualId IS NOT NULL") .select([ "development.rootId AS rootId", - "development.strategyChild1ActualId AS strategyId", + "development.strategyChild1ActualId AS strategyId", "strategy1.strategyChild1Name AS strategyName", "COUNT(development.id) AS devCount", "SUM(development.receive) AS receiveBudget", "development.root AS root", ]) - .groupBy("development.rootId, development.strategyChild1ActualId, strategy1.strategyChild1Name, development.root") + .groupBy( + "development.rootId, development.strategyChild1ActualId, strategy1.strategyChild1Name, development.root", + ) .orderBy("strategy1.createdAt", "ASC") .getRawMany(); - - interface Strategy { - strategyId: string; - strategyName: string; - devCount: string; - receiveBudget: string; - sumDev: string; - sumTraget: string; - sumBudget: string; - sumRowDev: string, - sumRowTarget: string, - sumRowBudget: string, - } - - interface GroupedData { - rootId: string; - root: string; - strategy: Strategy[]; - } - - const groupedData: GroupedData[] = resultAllStrategy.reduce((acc: GroupedData[], item) => { - const existingRoot = acc.find(entry => entry.rootId === item.rootId); - if (existingRoot) { - existingRoot.strategy.push({ - strategyId: item.strategyId, - strategyName: item.strategyName, - devCount: item.devCount?item.devCount:"-", - receiveBudget: item.receiveBudget?item.receiveBudget:"-", - sumDev: "", - sumTraget: "", - sumBudget: "", - sumRowDev:"", - sumRowTarget:"", - sumRowBudget:"", - }); - } else { - acc.push({ - rootId: item.rootId, - root: item.root, - strategy: [{ + interface Strategy { + strategyId: string; + strategyName: string; + devCount: string; + receiveBudget: string; + sumDev: string; + sumTraget: string; + sumBudget: string; + sumRowDev: string; + sumRowTarget: string; + sumRowBudget: string; + } + + interface GroupedData { + rootId: string; + root: string; + strategy: Strategy[]; + } + + const groupedData: GroupedData[] = resultAllStrategy.reduce((acc: GroupedData[], item) => { + const existingRoot = acc.find((entry) => entry.rootId === item.rootId); + + if (existingRoot) { + existingRoot.strategy.push({ + strategyId: item.strategyId, + strategyName: item.strategyName, + devCount: item.devCount ? item.devCount : "-", + receiveBudget: item.receiveBudget ? item.receiveBudget : "-", + sumDev: "", + sumTraget: "", + sumBudget: "", + sumRowDev: "", + sumRowTarget: "", + sumRowBudget: "", + }); + } else { + acc.push({ + rootId: item.rootId, + root: item.root, + strategy: [ + { strategyId: item.strategyId, strategyName: item.strategyName, - devCount: item.devCount?item.devCount:"-", - receiveBudget: item.receiveBudget?item.receiveBudget:"-", + devCount: item.devCount ? item.devCount : "-", + receiveBudget: item.receiveBudget ? item.receiveBudget : "-", sumDev: "", sumTraget: "", sumBudget: "", - sumRowDev:"", - sumRowTarget:"", - sumRowBudget:"", - }] - }); - } + sumRowDev: "", + sumRowTarget: "", + sumRowBudget: "", + }, + ], + }); + } - return acc; - }, []); - let sumDev1 = 0; - let sumTraget1 = 0; - let sumBudget1 = 0; - let sumDev2 = 0; - let sumTraget2 = 0; - let sumBudget2 = 0; - let sumDev3 = 0; - let sumTraget3 = 0; - let sumBudget3 = 0; - let sumDev4 = 0; - let sumTraget4 = 0; - let sumBudget4 = 0; - const reformattedData = groupedData.map((group,x) => { - const sumRowDev = (group.strategy[0] && group.strategy[0].devCount !== "-" ? Number(group.strategy[0].devCount) : 0) + - (group.strategy[1] && group.strategy[1].devCount !== "-" ? Number(group.strategy[1].devCount) : 0) + - (group.strategy[2] && group.strategy[2].devCount !== "-" ? Number(group.strategy[2].devCount) : 0); - (group.strategy[3] && group.strategy[3].devCount !== "-" ? Number(group.strategy[3].devCount) : 0); - const sumRowBudget = (group.strategy[0] && group.strategy[0].receiveBudget !== "-" ? Number(group.strategy[0].receiveBudget) : 0) + - (group.strategy[1] && group.strategy[1].receiveBudget !== "-" ? Number(group.strategy[1].receiveBudget) : 0) + - (group.strategy[2] && group.strategy[2].receiveBudget !== "-" ? Number(group.strategy[2].receiveBudget) : 0); - (group.strategy[3] && group.strategy[3].receiveBudget !== "-" ? Number(group.strategy[3].receiveBudget) : 0); - sumDev1 = groupedData.reduce((sum, group) => { - const devCount = group.strategy[0] && group.strategy[0].devCount !== "-" ? Number(group.strategy[0].devCount) : 0; - return sum + devCount; - }, 0); - sumBudget1 = groupedData.reduce((sum, group) => { - const devCount = group.strategy[0] && group.strategy[0].receiveBudget !== "-" ? Number(group.strategy[0].receiveBudget) : 0; - return sum + devCount; - }, 0); - sumDev2 = groupedData.reduce((sum, group) => { - const devCount = group.strategy[1] && group.strategy[1].devCount !== "-" ? Number(group.strategy[1].devCount) : 0; - return sum + devCount; - }, 0); - sumBudget2 = groupedData.reduce((sum, group) => { - const devCount = group.strategy[1] && group.strategy[1].receiveBudget !== "-" ? Number(group.strategy[1].receiveBudget) : 0; - return sum + devCount; - }, 0); - sumDev3 = groupedData.reduce((sum, group) => { - const devCount = group.strategy[2] && group.strategy[2].devCount !== "-" ? Number(group.strategy[2].devCount) : 0; - return sum + devCount; - }, 0); - sumBudget3 = groupedData.reduce((sum, group) => { - const devCount = group.strategy[2] && group.strategy[2].receiveBudget !== "-" ? Number(group.strategy[2].receiveBudget) : 0; - return sum + devCount; - }, 0); - sumDev4 = groupedData.reduce((sum, group) => { - const devCount = group.strategy[3] && group.strategy[3].devCount !== "-" ? Number(group.strategy[3].devCount) : 0; - return sum + devCount; - }, 0); - sumBudget4 = groupedData.reduce((sum, group) => { - const devCount = group.strategy[3] && group.strategy[3].receiveBudget !== "-" ? Number(group.strategy[3].receiveBudget) : 0; - return sum + devCount; - }, 0); - - const formattedGroup = { - rowNo: x?Extension.ToThaiNumber((x + 1).toString()):Extension.ToThaiNumber("๑"), - rootId: group.rootId, - root: group.root, - strategyName1: group.strategy[0]&&group.strategy[0].strategyName?group.strategy[0].strategyName:"-", - devCount1: group.strategy[0]&&group.strategy[0].devCount?Extension.ToThaiNumber(group.strategy[0].devCount.toLocaleString()):"-", - target1: "-", - receiveBudget1: group.strategy[0]&&group.strategy[0].receiveBudget?Extension.ToThaiNumber(group.strategy[0].receiveBudget.toLocaleString()):"-", - + return acc; + }, []); + let sumDev1 = 0; + let sumTraget1 = 0; + let sumBudget1 = 0; + let sumDev2 = 0; + let sumTraget2 = 0; + let sumBudget2 = 0; + let sumDev3 = 0; + let sumTraget3 = 0; + let sumBudget3 = 0; + let sumDev4 = 0; + let sumTraget4 = 0; + let sumBudget4 = 0; + const reformattedData = groupedData.map((group, x) => { + const sumRowDev = + (group.strategy[0] && group.strategy[0].devCount !== "-" + ? Number(group.strategy[0].devCount) + : 0) + + (group.strategy[1] && group.strategy[1].devCount !== "-" + ? Number(group.strategy[1].devCount) + : 0) + + (group.strategy[2] && group.strategy[2].devCount !== "-" + ? Number(group.strategy[2].devCount) + : 0); + group.strategy[3] && group.strategy[3].devCount !== "-" + ? Number(group.strategy[3].devCount) + : 0; + const sumRowBudget = + (group.strategy[0] && group.strategy[0].receiveBudget !== "-" + ? Number(group.strategy[0].receiveBudget) + : 0) + + (group.strategy[1] && group.strategy[1].receiveBudget !== "-" + ? Number(group.strategy[1].receiveBudget) + : 0) + + (group.strategy[2] && group.strategy[2].receiveBudget !== "-" + ? Number(group.strategy[2].receiveBudget) + : 0); + group.strategy[3] && group.strategy[3].receiveBudget !== "-" + ? Number(group.strategy[3].receiveBudget) + : 0; + sumDev1 = groupedData.reduce((sum, group) => { + const devCount = + group.strategy[0] && group.strategy[0].devCount !== "-" + ? Number(group.strategy[0].devCount) + : 0; + return sum + devCount; + }, 0); + sumBudget1 = groupedData.reduce((sum, group) => { + const devCount = + group.strategy[0] && group.strategy[0].receiveBudget !== "-" + ? Number(group.strategy[0].receiveBudget) + : 0; + return sum + devCount; + }, 0); + sumDev2 = groupedData.reduce((sum, group) => { + const devCount = + group.strategy[1] && group.strategy[1].devCount !== "-" + ? Number(group.strategy[1].devCount) + : 0; + return sum + devCount; + }, 0); + sumBudget2 = groupedData.reduce((sum, group) => { + const devCount = + group.strategy[1] && group.strategy[1].receiveBudget !== "-" + ? Number(group.strategy[1].receiveBudget) + : 0; + return sum + devCount; + }, 0); + sumDev3 = groupedData.reduce((sum, group) => { + const devCount = + group.strategy[2] && group.strategy[2].devCount !== "-" + ? Number(group.strategy[2].devCount) + : 0; + return sum + devCount; + }, 0); + sumBudget3 = groupedData.reduce((sum, group) => { + const devCount = + group.strategy[2] && group.strategy[2].receiveBudget !== "-" + ? Number(group.strategy[2].receiveBudget) + : 0; + return sum + devCount; + }, 0); + sumDev4 = groupedData.reduce((sum, group) => { + const devCount = + group.strategy[3] && group.strategy[3].devCount !== "-" + ? Number(group.strategy[3].devCount) + : 0; + return sum + devCount; + }, 0); + sumBudget4 = groupedData.reduce((sum, group) => { + const devCount = + group.strategy[3] && group.strategy[3].receiveBudget !== "-" + ? Number(group.strategy[3].receiveBudget) + : 0; + return sum + devCount; + }, 0); - strategyName2: group.strategy[1]&&group.strategy[1].strategyName?group.strategy[1].strategyName:"-", - devCount2: group.strategy[1]&&group.strategy[1].devCount?Extension.ToThaiNumber(group.strategy[1].devCount.toLocaleString()):"-", - target2: "-", - receiveBudget2: group.strategy[1]&&group.strategy[1].receiveBudget?Extension.ToThaiNumber(group.strategy[1].receiveBudget.toLocaleString()):"-", - + const formattedGroup = { + rowNo: x ? Extension.ToThaiNumber((x + 1).toString()) : Extension.ToThaiNumber("๑"), + rootId: group.rootId, + root: group.root, + strategyName1: + group.strategy[0] && group.strategy[0].strategyName + ? group.strategy[0].strategyName + : "-", + devCount1: + group.strategy[0] && group.strategy[0].devCount + ? Extension.ToThaiNumber(group.strategy[0].devCount.toLocaleString()) + : "-", + target1: "-", + receiveBudget1: + group.strategy[0] && group.strategy[0].receiveBudget + ? Extension.ToThaiNumber(group.strategy[0].receiveBudget.toLocaleString()) + : "-", - strategyName3: group.strategy[2]&&group.strategy[2].strategyName?group.strategy[2].strategyName:"-", - devCount3: group.strategy[2]&&group.strategy[2].devCount?Extension.ToThaiNumber(group.strategy[2].devCount.toLocaleString()):"-", - target3: "-", - receiveBudget3: group.strategy[2]&&group.strategy[2].receiveBudget?Extension.ToThaiNumber(group.strategy[2].receiveBudget.toLocaleString()):"-", - + strategyName2: + group.strategy[1] && group.strategy[1].strategyName + ? group.strategy[1].strategyName + : "-", + devCount2: + group.strategy[1] && group.strategy[1].devCount + ? Extension.ToThaiNumber(group.strategy[1].devCount.toLocaleString()) + : "-", + target2: "-", + receiveBudget2: + group.strategy[1] && group.strategy[1].receiveBudget + ? Extension.ToThaiNumber(group.strategy[1].receiveBudget.toLocaleString()) + : "-", - strategyName4: group.strategy[3]&&group.strategy[3].strategyName?group.strategy[3].strategyName:"-", - devCount4: group.strategy[3]&&group.strategy[3].devCount?Extension.ToThaiNumber(group.strategy[3].devCount.toLocaleString()):"-", - target4: "-", - receiveBudget4: group.strategy[3]&&group.strategy[3].receiveBudget?Extension.ToThaiNumber(group.strategy[3].receiveBudget.toLocaleString()):"-", - + strategyName3: + group.strategy[2] && group.strategy[2].strategyName + ? group.strategy[2].strategyName + : "-", + devCount3: + group.strategy[2] && group.strategy[2].devCount + ? Extension.ToThaiNumber(group.strategy[2].devCount.toLocaleString()) + : "-", + target3: "-", + receiveBudget3: + group.strategy[2] && group.strategy[2].receiveBudget + ? Extension.ToThaiNumber(group.strategy[2].receiveBudget.toLocaleString()) + : "-", - sumRowDev: sumRowDev?Extension.ToThaiNumber(sumRowDev.toLocaleString()):"-", - sumRowTarget: "-", - sumRowBudget: sumRowBudget?Extension.ToThaiNumber(sumRowBudget.toLocaleString()):"-", - // strategy: Array(4).fill(null).map((_, index) => { - // const strategy = group.strategy[index] || { - // strategyName: "", - // devCount: "", - // target: "", - // receiveBudget: "", - // sumDev: "", - // sumTraget: "", - // sumBudget: "", - // sumRowDev: "", - // sumRowTarget: "", - // sumRowBudget: "", - // }; + strategyName4: + group.strategy[3] && group.strategy[3].strategyName + ? group.strategy[3].strategyName + : "-", + devCount4: + group.strategy[3] && group.strategy[3].devCount + ? Extension.ToThaiNumber(group.strategy[3].devCount.toLocaleString()) + : "-", + target4: "-", + receiveBudget4: + group.strategy[3] && group.strategy[3].receiveBudget + ? Extension.ToThaiNumber(group.strategy[3].receiveBudget.toLocaleString()) + : "-", - // return { - // [`strategyName${index + 1}`]: strategy.strategyName ?? "", - // [`devCount${index + 1}`]: strategy.devCount ?? "", - // [`target${index + 1}`]: "", - // [`receiveBudget${index + 1}`]: strategy.receiveBudget ?? "", - // [`sumDev${index + 1}`]: strategy.sumDev ?? "", - // [`sumTraget${index + 1}`]: strategy.sumTraget ?? "", - // [`sumBudget${index + 1}`]: strategy.sumBudget ?? "", - // [`sumRowDev`]: strategy.sumRowDev ?? "", - // [`sumRowTarget`]: strategy.sumRowTarget ?? "", - // [`sumRowBudget`]: strategy.sumRowBudget ?? "", - // }; - // }), - }; + sumRowDev: sumRowDev ? Extension.ToThaiNumber(sumRowDev.toLocaleString()) : "-", + sumRowTarget: "-", + sumRowBudget: sumRowBudget ? Extension.ToThaiNumber(sumRowBudget.toLocaleString()) : "-", + // strategy: Array(4).fill(null).map((_, index) => { + // const strategy = group.strategy[index] || { + // strategyName: "", + // devCount: "", + // target: "", + // receiveBudget: "", + // sumDev: "", + // sumTraget: "", + // sumBudget: "", + // sumRowDev: "", + // sumRowTarget: "", + // sumRowBudget: "", + // }; - return formattedGroup; - }); + // return { + // [`strategyName${index + 1}`]: strategy.strategyName ?? "", + // [`devCount${index + 1}`]: strategy.devCount ?? "", + // [`target${index + 1}`]: "", + // [`receiveBudget${index + 1}`]: strategy.receiveBudget ?? "", + // [`sumDev${index + 1}`]: strategy.sumDev ?? "", + // [`sumTraget${index + 1}`]: strategy.sumTraget ?? "", + // [`sumBudget${index + 1}`]: strategy.sumBudget ?? "", + // [`sumRowDev`]: strategy.sumRowDev ?? "", + // [`sumRowTarget`]: strategy.sumRowTarget ?? "", + // [`sumRowBudget`]: strategy.sumRowBudget ?? "", + // }; + // }), + }; + + return formattedGroup; + }); return new HttpSuccess({ template: "development", @@ -294,21 +383,28 @@ export class ReportController extends Controller { data: { data: mappedDataDev, resultAllStrategy: reformattedData, - sumDev1: Extension.ToThaiNumber(sumDev1.toLocaleString())??"-", - sumTraget1: Extension.ToThaiNumber(sumTraget1.toLocaleString())??"-", - sumBudget1: Extension.ToThaiNumber(sumBudget1.toLocaleString())??"-", - sumDev2: Extension.ToThaiNumber(sumDev2.toLocaleString())??"-", - sumTraget2: Extension.ToThaiNumber(sumTraget2.toLocaleString())??"-", - sumBudget2: Extension.ToThaiNumber(sumBudget2.toLocaleString())??"-", - sumDev3: Extension.ToThaiNumber(sumDev3.toLocaleString())??"-", - sumTraget3: Extension.ToThaiNumber(sumTraget3.toLocaleString())??"-", - sumBudget3: Extension.ToThaiNumber(sumBudget3.toLocaleString())??"-", - sumDev4: Extension.ToThaiNumber(sumDev4.toLocaleString())??"-", - sumTraget4: Extension.ToThaiNumber(sumTraget4.toLocaleString())??"-", - sumBudget4: Extension.ToThaiNumber(sumBudget4.toLocaleString())??"-", - sumAllDev: Extension.ToThaiNumber((sumDev1 + sumDev2 + sumDev3 + sumDev4).toLocaleString())??"-", - sumTraget: Extension.ToThaiNumber((sumTraget1 +sumTraget2 +sumTraget3 +sumTraget4).toLocaleString())??"-", - sumAllBudget: Extension.ToThaiNumber((sumBudget1 + sumBudget2 + sumBudget3 + sumBudget4).toLocaleString())??"-", + sumDev1: Extension.ToThaiNumber(sumDev1.toLocaleString()) ?? "-", + sumTraget1: Extension.ToThaiNumber(sumTraget1.toLocaleString()) ?? "-", + sumBudget1: Extension.ToThaiNumber(sumBudget1.toLocaleString()) ?? "-", + sumDev2: Extension.ToThaiNumber(sumDev2.toLocaleString()) ?? "-", + sumTraget2: Extension.ToThaiNumber(sumTraget2.toLocaleString()) ?? "-", + sumBudget2: Extension.ToThaiNumber(sumBudget2.toLocaleString()) ?? "-", + sumDev3: Extension.ToThaiNumber(sumDev3.toLocaleString()) ?? "-", + sumTraget3: Extension.ToThaiNumber(sumTraget3.toLocaleString()) ?? "-", + sumBudget3: Extension.ToThaiNumber(sumBudget3.toLocaleString()) ?? "-", + sumDev4: Extension.ToThaiNumber(sumDev4.toLocaleString()) ?? "-", + sumTraget4: Extension.ToThaiNumber(sumTraget4.toLocaleString()) ?? "-", + sumBudget4: Extension.ToThaiNumber(sumBudget4.toLocaleString()) ?? "-", + sumAllDev: + Extension.ToThaiNumber((sumDev1 + sumDev2 + sumDev3 + sumDev4).toLocaleString()) ?? "-", + sumTraget: + Extension.ToThaiNumber( + (sumTraget1 + sumTraget2 + sumTraget3 + sumTraget4).toLocaleString(), + ) ?? "-", + sumAllBudget: + Extension.ToThaiNumber( + (sumBudget1 + sumBudget2 + sumBudget3 + sumBudget4).toLocaleString(), + ) ?? "-", }, }); } @@ -568,10 +664,7 @@ export class ReportController extends Controller { * */ @Get("report3") - async report3( - @Query("year") year?: number, - @Query("rootId") rootId?: string, - ) { + async report3(@Query("year") year?: number, @Query("rootId") rootId?: string) { const developments = await AppDataSource.getRepository(DevelopmentScholarship) .createQueryBuilder("developmentScholarship") .leftJoinAndSelect("developmentScholarship.posLevel", "posLevel") @@ -592,58 +685,67 @@ export class ReportController extends Controller { .addOrderBy("developmentScholarship.createdAt", "DESC") .getMany(); - const mapData = developments.map((item, idx:number) => ({ - no: Extension.ToThaiNumber((idx+1).toString()), - institution: item.educationalInstitution ? item.educationalInstitution : "-", - scholarshipType: item.scholarshipType ? - item.scholarshipType == "DOMESTICE" - ? "การศึกษาในประเทศ" - : item.scholarshipType == "NOABROAD" - ? "ฝึกอบรมในประเทศที่ส่งไปพัฒนากับหน่วยวงานภายนอก (หลักสูตรที่ไม่มีการไปต่างประเทศ)" - : item.scholarshipType == "ABROAD" - ? "ฝึกอบรมในประเทศที่ส่งไปพัฒนากับหน่วยวงานภายนอก (หลักสูตรที่มีการไปต่างประเทศ)" - : item.scholarshipType == "EXECUTIVE" - ? "ฝึกอบรมในประเทศที่ส่งไปพัฒนากับหน่วยวงานภายนอก (หลักสูตรประเภทนักบริหาร)" - : item.scholarshipType == "RESEARCH" - ? "ศึกษา ฝึกอบรม ประชุม ดูงาน และปฏิบัติการวิจัย ณ ต่างประเทศ" - : "-" - : "-", - degreeLevel: item.degreeLevel ? item.degreeLevel : "-", - course: item.course ? item.course : "-", - field: item.field ? item.field : "-", - fullName: `${item.prefix}${item.firstName} ${item.lastName}`, - position: item.position ? item.position : "-", - posLevel: item.posLevel ? item.posLevel.posLevelName : "-", - totalPeriod: item.totalPeriod ? item.totalPeriod : "-", - budgetApprove: item.budgetApprove ? Extension.ToThaiNumber(item.budgetApprove.toLocaleString()) : "๐" - })); - - const sum = developments - .filter(x => x.budgetApprove) - .reduce((acc, item) => acc + (Number(item.budgetApprove)), 0); + const mapData = developments.map((item, idx: number) => ({ + no: Extension.ToThaiNumber((idx + 1).toString()), + institution: item.educationalInstitution ? item.educationalInstitution : "-", + scholarshipType: item.scholarshipType + ? item.scholarshipType == "DOMESTICE" + ? "การศึกษาในประเทศ" + : item.scholarshipType == "NOABROAD" + ? "ฝึกอบรมในประเทศที่ส่งไปพัฒนากับหน่วยวงานภายนอก (หลักสูตรที่ไม่มีการไปต่างประเทศ)" + : item.scholarshipType == "ABROAD" + ? "ฝึกอบรมในประเทศที่ส่งไปพัฒนากับหน่วยวงานภายนอก (หลักสูตรที่มีการไปต่างประเทศ)" + : item.scholarshipType == "EXECUTIVE" + ? "ฝึกอบรมในประเทศที่ส่งไปพัฒนากับหน่วยวงานภายนอก (หลักสูตรประเภทนักบริหาร)" + : item.scholarshipType == "RESEARCH" + ? "ศึกษา ฝึกอบรม ประชุม ดูงาน และปฏิบัติการวิจัย ณ ต่างประเทศ" + : "-" + : "-", + degreeLevel: item.degreeLevel ? item.degreeLevel : "-", + course: item.course ? item.course : "-", + field: item.field ? item.field : "-", + fullName: `${item.prefix}${item.firstName} ${item.lastName}`, + position: item.position ? item.position : "-", + posLevel: item.posLevel ? item.posLevel.posLevelName : "-", + totalPeriod: item.totalPeriod ? item.totalPeriod : "-", + budgetApprove: item.budgetApprove + ? Extension.ToThaiNumber(item.budgetApprove.toLocaleString()) + : "๐", + })); + + const sum = developments + .filter((x) => x.budgetApprove) + .reduce((acc, item) => acc + Number(item.budgetApprove), 0); return new HttpSuccess({ template: "reportFund3", reportName: "reportFund3", data: { - year: year ? Extension.ToThaiNumber((year+543).toString()) : "-", - root: rootId ? developments.length > 0 ? developments.find(x => x.root != "")?.root: "-" : "-", - data: mapData.length > 0 - ? mapData - : [{ - no: "-", - institution: "-", - scholarshipType: "-", - degreeLevel: "-", - course: "-", - field: "-", - fullName: "-", - position: "-", - posLevel: "-", - totalPeriod: "-", - budgetApprove: "-", - }], - sum: sum ? Extension.ToThaiNumber(sum.toLocaleString()): "-" + year: year ? Extension.ToThaiNumber((year + 543).toString()) : "", + root: rootId + ? developments.length > 0 + ? developments.find((x) => x.root != "")?.root + : "" + : "", + data: + mapData.length > 0 + ? mapData + : [ + { + no: "", + institution: "", + scholarshipType: "", + degreeLevel: "", + course: "", + field: "", + fullName: "", + position: "", + posLevel: "", + totalPeriod: "", + budgetApprove: "", + }, + ], + sum: sum ? Extension.ToThaiNumber(sum.toLocaleString()) : "-", }, }); } @@ -654,9 +756,7 @@ export class ReportController extends Controller { * */ @Get("report4") - async report4( - @Query("year") year?: number, - ) { + async report4(@Query("year") year?: number) { const developments = await AppDataSource.getRepository(DevelopmentScholarship) .createQueryBuilder("developmentScholarship") .andWhere( @@ -668,7 +768,7 @@ export class ReportController extends Controller { .orderBy("developmentScholarship.scholarshipYear", "DESC") .addOrderBy("developmentScholarship.createdAt", "DESC") .getMany(); - + // const _develop = await this.developmentScholarshipRepository.find({ // where: { // scholarshipYear: year ? year : Not(IsNull()) @@ -676,121 +776,168 @@ export class ReportController extends Controller { // order: { "scholarshipYear" : "DESC" } // }) - const groupDevelopment = Array.isArray(developments) && developments.length > 0 - ? developments.reduce((acc:any, current:any, idx:number) => { - const root = current.root || ""; - if (!acc[root]) { - acc[root] = { - no: (idx+1), - root: root, - Bachelor : 0, - BachelorHight: 0, - Master: 0, - Doctor: 0, - DomesticeCourseCount: 0, - DomesticeProfileCount: 0, - DomesticeBudgetApprove: 0, - NoAbroadCourseCount: 0, - NoAbroadDProfileCount: 0, - NoAbroadBudgetApprove: 0, - AbroadCourseCount: 0, - AbroadProfileCount: 0, - AbroadBudgetApprove: 0, - ExecutiveCourseCount: 0, - ExecutiveProfileCount: 0, - ExecutiveBudgetApprove: 0, - TotalCourseCount: 0, - TotalProfileCount: 0, - TotalBudgetApprove: 0, - }; - } + const groupDevelopment = + Array.isArray(developments) && developments.length > 0 + ? developments.reduce((acc: any, current: any, idx: number) => { + const root = current.root || ""; + if (!acc[root]) { + acc[root] = { + no: idx + 1, + root: root, + Bachelor: 0, + BachelorHight: 0, + Master: 0, + Doctor: 0, + DomesticeCourseCount: 0, + DomesticeProfileCount: 0, + DomesticeBudgetApprove: 0, + NoAbroadCourseCount: 0, + NoAbroadDProfileCount: 0, + NoAbroadBudgetApprove: 0, + AbroadCourseCount: 0, + AbroadProfileCount: 0, + AbroadBudgetApprove: 0, + ExecutiveCourseCount: 0, + ExecutiveProfileCount: 0, + ExecutiveBudgetApprove: 0, + TotalCourseCount: 0, + TotalProfileCount: 0, + TotalBudgetApprove: 0, + }; + } - switch (current.scholarshipType) { - case "DOMESTICE": - acc[root].DomesticeCourseCount++; - acc[root].DomesticeProfileCount++; - acc[root].DomesticeBudgetApprove += current.budgetApprove || 0; - break; - case "NOABROAD": - acc[root].NoAbroadCourseCount++; - acc[root].NoAbroadProfileCount++; - acc[root].NoAbroadBudgetApprove += current.budgetApprove || 0; - break; - case "ABROAD": - acc[root].AbroadCourseCount++; - acc[root].AbroadProfileCount++; - acc[root].AbroadBudgetApprove += current.budgetApprove || 0; - break; - case "EXECUTIVE": - acc[root].ExecutiveCourseCount++; - acc[root].ExecutiveProfileCount++; - acc[root].ExecutiveBudgetApprove += current.budgetApprove || 0; - break; - } + switch (current.scholarshipType) { + case "DOMESTICE": + acc[root].DomesticeCourseCount++; + acc[root].DomesticeProfileCount++; + acc[root].DomesticeBudgetApprove += current.budgetApprove || 0; + break; + case "NOABROAD": + acc[root].NoAbroadCourseCount++; + acc[root].NoAbroadProfileCount++; + acc[root].NoAbroadBudgetApprove += current.budgetApprove || 0; + break; + case "ABROAD": + acc[root].AbroadCourseCount++; + acc[root].AbroadProfileCount++; + acc[root].AbroadBudgetApprove += current.budgetApprove || 0; + break; + case "EXECUTIVE": + acc[root].ExecutiveCourseCount++; + acc[root].ExecutiveProfileCount++; + acc[root].ExecutiveBudgetApprove += current.budgetApprove || 0; + break; + } - acc[root].TotalCourseCount = acc[root].DomesticeCourseCount + acc[root].NoAbroadCourseCount + acc[root].AbroadCourseCount + acc[root].ExecutiveCourseCount; - acc[root].TotalProfileCount = acc[root].DomesticeProfileCount + acc[root].NoAbroadProfileCount + acc[root].AbroadProfileCount + acc[root].ExecutiveProfileCount; - acc[root].TotalBudgetApprove = acc[root].DomesticeBudgetApprove + acc[root].NoAbroadBudgetApprove + acc[root].AbroadBudgetApprove + acc[root].ExecutiveBudgetApprove; + acc[root].TotalCourseCount = + acc[root].DomesticeCourseCount + + acc[root].NoAbroadCourseCount + + acc[root].AbroadCourseCount + + acc[root].ExecutiveCourseCount; + acc[root].TotalProfileCount = + acc[root].DomesticeProfileCount + + acc[root].NoAbroadProfileCount + + acc[root].AbroadProfileCount + + acc[root].ExecutiveProfileCount; + acc[root].TotalBudgetApprove = + acc[root].DomesticeBudgetApprove + + acc[root].NoAbroadBudgetApprove + + acc[root].AbroadBudgetApprove + + acc[root].ExecutiveBudgetApprove; - return acc; - }, {}) - : []; + return acc; + }, {}) + : []; const _group = Object.values(groupDevelopment); return new HttpSuccess({ template: "reportFund4", reportName: "reportFund4", data: { - year: year ? Extension.ToThaiNumber((year+543).toString()) : "-", - data: Array.isArray(_group) - // ? _group - ? _group.map((x:any) => ({ + year: year ? Extension.ToThaiNumber((year + 543).toString()) : "-", + data: Array.isArray(_group) + ? // ? _group + _group.map((x: any) => ({ no: x.no ? Extension.ToThaiNumber(x.no.toString()) : "-", - root: x.root ? x.root : "-", - Bachelor : "-", + root: x.root ? x.root : "ไม่พบหน่วยงาน", + Bachelor: "-", BachelorHight: "-", Master: "-", Doctor: "-", - DomesticeCourseCount: x.DomesticeCourseCount ? Extension.ToThaiNumber(x.DomesticeCourseCount.toLocaleString()) : "-", - DomesticeProfileCount: x.DomesticeProfileCount ? Extension.ToThaiNumber(x.DomesticeProfileCount.toLocaleString()) : "-", - DomesticeBudgetApprove: x.DomesticeBudgetApprove ? Extension.ToThaiNumber(x.DomesticeBudgetApprove.toLocaleString()) : "-", - NoAbroadCourseCount: x.NoAbroadCourseCount ? Extension.ToThaiNumber(x.NoAbroadCourseCount.toLocaleString()) : "-", - NoAbroadDProfileCount: x.NoAbroadDProfileCount ? Extension.ToThaiNumber(x.NoAbroadDProfileCount.toLocaleString()) : "-", - NoAbroadBudgetApprove: x.NoAbroadBudgetApprove ? Extension.ToThaiNumber(x.NoAbroadBudgetApprove.toLocaleString()) : "-", - AbroadCourseCount: x.AbroadCourseCount ? Extension.ToThaiNumber(x.AbroadCourseCount.toLocaleString()) : "-", - AbroadProfileCount: x.AbroadProfileCount ? Extension.ToThaiNumber(x.AbroadProfileCount.toLocaleString()) : "-", - AbroadBudgetApprove: x.AbroadBudgetApprove ? Extension.ToThaiNumber(x.AbroadBudgetApprove.toLocaleString()) : "-", - ExecutiveCourseCount: x.ExecutiveCourseCount ? Extension.ToThaiNumber(x.ExecutiveCourseCount.toLocaleString()) : "-", - ExecutiveProfileCount: x.ExecutiveProfileCount ? Extension.ToThaiNumber(x.ExecutiveProfileCount.toLocaleString()) : "-", - ExecutiveBudgetApprove: x.ExecutiveBudgetApprove ? Extension.ToThaiNumber(x.ExecutiveBudgetApprove.toLocaleString()) : "-", - TotalCourseCount: x.TotalCourseCount ? Extension.ToThaiNumber(x.TotalCourseCount.toLocaleString()) : "-", - TotalProfileCount: x.TotalProfileCount ? Extension.ToThaiNumber(x.TotalProfileCount.toLocaleString()) : "-", - TotalBudgetApprove: x.TotalBudgetApprove ? Extension.ToThaiNumber(x.TotalBudgetApprove.toLocaleString()) : "-", - })) - : [{ - no: "-", - root: "-", - Bachelor : "-", - BachelorHight: "-", - Master: "-", - Doctor: "-", - DomesticeCourseCount: "-", - DomesticeProfileCount: "-", - DomesticeBudgetApprove: "-", - NoAbroadCourseCount: "-", - NoAbroadDProfileCount: "-", - NoAbroadBudgetApprove: "-", - AbroadCourseCount: "-", - AbroadProfileCount: "-", - AbroadBudgetApprove: "-", - ExecutiveCourseCount: "-", - ExecutiveProfileCount: "-", - ExecutiveBudgetApprove: "-", - TotalCourseCount: "-", - TotalProfileCount: "-", - TotalBudgetApprove: "-", - }], - totalRoot: Array.isArray(_group) ? Extension.ToThaiNumber(_group.length.toLocaleString()) : "-" + DomesticeCourseCount: x.DomesticeCourseCount + ? Extension.ToThaiNumber(x.DomesticeCourseCount.toLocaleString()) + : "-", + DomesticeProfileCount: x.DomesticeProfileCount + ? Extension.ToThaiNumber(x.DomesticeProfileCount.toLocaleString()) + : "-", + DomesticeBudgetApprove: x.DomesticeBudgetApprove + ? Extension.ToThaiNumber(x.DomesticeBudgetApprove.toLocaleString()) + : "-", + NoAbroadCourseCount: x.NoAbroadCourseCount + ? Extension.ToThaiNumber(x.NoAbroadCourseCount.toLocaleString()) + : "-", + NoAbroadDProfileCount: x.NoAbroadDProfileCount + ? Extension.ToThaiNumber(x.NoAbroadDProfileCount.toLocaleString()) + : "-", + NoAbroadBudgetApprove: x.NoAbroadBudgetApprove + ? Extension.ToThaiNumber(x.NoAbroadBudgetApprove.toLocaleString()) + : "-", + AbroadCourseCount: x.AbroadCourseCount + ? Extension.ToThaiNumber(x.AbroadCourseCount.toLocaleString()) + : "-", + AbroadProfileCount: x.AbroadProfileCount + ? Extension.ToThaiNumber(x.AbroadProfileCount.toLocaleString()) + : "-", + AbroadBudgetApprove: x.AbroadBudgetApprove + ? Extension.ToThaiNumber(x.AbroadBudgetApprove.toLocaleString()) + : "-", + ExecutiveCourseCount: x.ExecutiveCourseCount + ? Extension.ToThaiNumber(x.ExecutiveCourseCount.toLocaleString()) + : "-", + ExecutiveProfileCount: x.ExecutiveProfileCount + ? Extension.ToThaiNumber(x.ExecutiveProfileCount.toLocaleString()) + : "-", + ExecutiveBudgetApprove: x.ExecutiveBudgetApprove + ? Extension.ToThaiNumber(x.ExecutiveBudgetApprove.toLocaleString()) + : "-", + TotalCourseCount: x.TotalCourseCount + ? Extension.ToThaiNumber(x.TotalCourseCount.toLocaleString()) + : "-", + TotalProfileCount: x.TotalProfileCount + ? Extension.ToThaiNumber(x.TotalProfileCount.toLocaleString()) + : "-", + TotalBudgetApprove: x.TotalBudgetApprove + ? Extension.ToThaiNumber(x.TotalBudgetApprove.toLocaleString()) + : "-", + })) + : [ + { + no: "-", + root: "-", + Bachelor: "-", + BachelorHight: "-", + Master: "-", + Doctor: "-", + DomesticeCourseCount: "-", + DomesticeProfileCount: "-", + DomesticeBudgetApprove: "-", + NoAbroadCourseCount: "-", + NoAbroadDProfileCount: "-", + NoAbroadBudgetApprove: "-", + AbroadCourseCount: "-", + AbroadProfileCount: "-", + AbroadBudgetApprove: "-", + ExecutiveCourseCount: "-", + ExecutiveProfileCount: "-", + ExecutiveBudgetApprove: "-", + TotalCourseCount: "-", + TotalProfileCount: "-", + TotalBudgetApprove: "-", + }, + ], + totalRoot: Array.isArray(_group) + ? Extension.ToThaiNumber(_group.length.toLocaleString()) + : "-", }, }); } @@ -805,46 +952,46 @@ export class ReportController extends Controller { @Query("year") year?: number, // @Query("rootId") rootId: string, ) { - const [development, total] = await AppDataSource.getRepository(DevelopmentScholarship) - .createQueryBuilder("developmentScholarship") - .leftJoinAndSelect("developmentScholarship.posLevel", "posLevel") - .leftJoinAndSelect("developmentScholarship.posType", "posType") - .leftJoinAndSelect("developmentScholarship.posLevelguarantor", "posLevelguarantor") - .leftJoinAndSelect("developmentScholarship.posTypeguarantor", "posTypeguarantor") - // .where("developmentScholarship.rootId = :rootId", { rootId: rootId }) - .andWhere( - year !== 0 && year != null && year != undefined - ? "developmentScholarship.scholarshipYear = :scholarshipYear" - : "1=1", - { scholarshipYear: year }, - ) - .andWhere( - "developmentScholarship.scholarshipType = :scholarshipType", { scholarshipType: "RESEARCH" }, - ) - .orderBy("developmentScholarship.scholarshipYear", "DESC") - .addOrderBy("developmentScholarship.createdAt", "DESC") - .getManyAndCount(); + .createQueryBuilder("developmentScholarship") + .leftJoinAndSelect("developmentScholarship.posLevel", "posLevel") + .leftJoinAndSelect("developmentScholarship.posType", "posType") + .leftJoinAndSelect("developmentScholarship.posLevelguarantor", "posLevelguarantor") + .leftJoinAndSelect("developmentScholarship.posTypeguarantor", "posTypeguarantor") + // .where("developmentScholarship.rootId = :rootId", { rootId: rootId }) + .andWhere( + year !== 0 && year != null && year != undefined + ? "developmentScholarship.scholarshipYear = :scholarshipYear" + : "1=1", + { scholarshipYear: year }, + ) + .andWhere("developmentScholarship.scholarshipType = :scholarshipType", { + scholarshipType: "RESEARCH", + }) + .orderBy("developmentScholarship.scholarshipYear", "DESC") + .addOrderBy("developmentScholarship.createdAt", "DESC") + .getManyAndCount(); - const totalBudgetApprove = development.reduce((sum, item) => sum + Number(item.budgetApprove), 0); + const totalBudgetApprove = development.reduce( + (sum, item) => sum + Number(item.budgetApprove), + 0, + ); const formattedData = development.map((item, index) => { const rawPath = [ item.course == "-" ? null : item.course, - item.field == "-" ? null : item.course + item.field == "-" ? null : item.course, ]; - + const courseAndfield = rawPath .filter((path) => path !== undefined && path !== null) .join("/"); - + const date = [ Extension.ToThaiNumber(Extension.ToThaiShortDate(item.startDate)), - Extension.ToThaiNumber(Extension.ToThaiShortDate(item.endDate)) + Extension.ToThaiNumber(Extension.ToThaiShortDate(item.endDate)), ]; - const dateDulation = date - .filter((path) => path !== undefined && path !== null) - .join(" - "); + const dateDulation = date.filter((path) => path !== undefined && path !== null).join(" - "); return { no: Extension.ToThaiNumber((index + 1).toString()), @@ -857,16 +1004,17 @@ export class ReportController extends Controller { place: item.studyPlace ? item.studyPlace : "-", country: item.studyCountry ? item.studyCountry : "-", startAndendDate: dateDulation, - budgetApprove: item.budgetApprove ? Extension.ToThaiNumber(item.budgetApprove.toLocaleString()) : "-", + budgetApprove: item.budgetApprove + ? Extension.ToThaiNumber(item.budgetApprove.toLocaleString()) + : "-", }; }); - return new HttpSuccess({ template: "reportFund5", reportName: "reportFund5", data: { - year: year?Extension.ToThaiNumber((year+543).toString()):"", + year: year ? Extension.ToThaiNumber((year + 543).toString()) : "", data: formattedData, total: Extension.ToThaiNumber(total.toLocaleString()), totalBudgetApprove: Extension.ToThaiNumber(totalBudgetApprove.toLocaleString()), @@ -880,14 +1028,8 @@ export class ReportController extends Controller { * */ @Get("report6") - async report6( - @Query("year") year?: number, - ) { - const degree = [ - "ปริญญาเอก", - "ปริญญาโท", - "ปริญญาตรี", - ]; + async report6(@Query("year") year?: number) { + const degree = ["ปริญญาเอก", "ปริญญาโท", "ปริญญาตรี"]; const development = await this.viewDevScholarship.find({ where: { @@ -895,10 +1037,10 @@ export class ReportController extends Controller { degreeLevel: In(degree), }, }); - - const groupedData = development.reduce((acc:any, item:any) => { + + const groupedData = development.reduce((acc: any, item: any) => { const { rootId, root, degreeLevel, scholarshipType, budgetApprove } = item; - + if (!acc[rootId]) { acc[rootId] = { root, @@ -920,67 +1062,95 @@ export class ReportController extends Controller { }, }; } - + if (degreeLevel === "ปริญญาตรี") { - acc[rootId].degreeLevel1.numberOfRecords += Number(item.numberOfRecords); - acc[rootId].degreeLevel1.numberOfScholarshipTypes += Number(item.numberOfScholarshipTypes); - acc[rootId].degreeLevel1.totalBudgetApprove += Number(item.totalBudgetApprove); + acc[rootId].degreeLevel1.numberOfRecords += Number(item.numberOfRecords); + acc[rootId].degreeLevel1.numberOfScholarshipTypes += Number(item.numberOfScholarshipTypes); + acc[rootId].degreeLevel1.totalBudgetApprove += Number(item.totalBudgetApprove); } else if (degreeLevel === "ปริญญาโท") { - acc[rootId].degreeLevel2.numberOfRecords += Number(item.numberOfRecords); - acc[rootId].degreeLevel2.numberOfScholarshipTypes += Number(item.numberOfScholarshipTypes); - acc[rootId].degreeLevel2.totalBudgetApprove += Number(item.totalBudgetApprove); + acc[rootId].degreeLevel2.numberOfRecords += Number(item.numberOfRecords); + acc[rootId].degreeLevel2.numberOfScholarshipTypes += Number(item.numberOfScholarshipTypes); + acc[rootId].degreeLevel2.totalBudgetApprove += Number(item.totalBudgetApprove); } else if (degreeLevel === "ปริญญาเอก") { - acc[rootId].degreeLevel3.numberOfRecords += Number(item.numberOfRecords); - acc[rootId].degreeLevel3.numberOfScholarshipTypes += Number(item.numberOfScholarshipTypes); - acc[rootId].degreeLevel3.totalBudgetApprove += Number(item.totalBudgetApprove); + acc[rootId].degreeLevel3.numberOfRecords += Number(item.numberOfRecords); + acc[rootId].degreeLevel3.numberOfScholarshipTypes += Number(item.numberOfScholarshipTypes); + acc[rootId].degreeLevel3.totalBudgetApprove += Number(item.totalBudgetApprove); } - + return acc; }, {}); const formattedData = Object.values(groupedData).map((item: any, index: any) => { - const sumnumberOfRecords = item.degreeLevel1.numberOfRecords + item.degreeLevel2.numberOfRecords + item.degreeLevel3.numberOfRecords; - const sumnumberOfScholarshipTypes = item.degreeLevel1.numberOfScholarshipTypes + item.degreeLevel2.numberOfScholarshipTypes + item.degreeLevel3.numberOfScholarshipTypes; - const sumtotalBudgetApprove = item.degreeLevel1.totalBudgetApprove + item.degreeLevel2.totalBudgetApprove + item.degreeLevel3.totalBudgetApprove; - + const sumnumberOfRecords = + item.degreeLevel1.numberOfRecords + + item.degreeLevel2.numberOfRecords + + item.degreeLevel3.numberOfRecords; + const sumnumberOfScholarshipTypes = + item.degreeLevel1.numberOfScholarshipTypes + + item.degreeLevel2.numberOfScholarshipTypes + + item.degreeLevel3.numberOfScholarshipTypes; + const sumtotalBudgetApprove = + item.degreeLevel1.totalBudgetApprove + + item.degreeLevel2.totalBudgetApprove + + item.degreeLevel3.totalBudgetApprove; + return { no: index ? Extension.ToThaiNumber((index + 1).toString()) : "๑", rootId: item.rootId ? item.rootId : "-", root: item.root ? item.root : "-", degreeLevel1: "ปริญญาตรี", - numberOfRecords1: item.degreeLevel1.numberOfRecords ? Extension.ToThaiNumber(item.degreeLevel1.numberOfRecords.toString()) : "-", - numberOfScholarshipTypes1: item.degreeLevel1.numberOfScholarshipTypes ? Extension.ToThaiNumber(item.degreeLevel1.numberOfScholarshipTypes.toString()) : "-", - totalBudgetApprove1: item.degreeLevel1.totalBudgetApprove ? Extension.ToThaiNumber(item.degreeLevel1.totalBudgetApprove.toLocaleString()) : "-", - + numberOfRecords1: item.degreeLevel1.numberOfRecords + ? Extension.ToThaiNumber(item.degreeLevel1.numberOfRecords.toString()) + : "-", + numberOfScholarshipTypes1: item.degreeLevel1.numberOfScholarshipTypes + ? Extension.ToThaiNumber(item.degreeLevel1.numberOfScholarshipTypes.toString()) + : "-", + totalBudgetApprove1: item.degreeLevel1.totalBudgetApprove + ? Extension.ToThaiNumber(item.degreeLevel1.totalBudgetApprove.toLocaleString()) + : "-", + degreeLevel2: "ปริญญาโท", - numberOfRecords2: item.degreeLevel2.numberOfRecords ? Extension.ToThaiNumber(item.degreeLevel2.numberOfRecords.toString()) : "-", - numberOfScholarshipTypes2: item.degreeLevel2.numberOfScholarshipTypes ? Extension.ToThaiNumber(item.degreeLevel2.numberOfScholarshipTypes.toString()) : "-", - totalBudgetApprove2: item.degreeLevel2.totalBudgetApprove ? Extension.ToThaiNumber(item.degreeLevel2.totalBudgetApprove.toLocaleString()) : "-", - + numberOfRecords2: item.degreeLevel2.numberOfRecords + ? Extension.ToThaiNumber(item.degreeLevel2.numberOfRecords.toString()) + : "-", + numberOfScholarshipTypes2: item.degreeLevel2.numberOfScholarshipTypes + ? Extension.ToThaiNumber(item.degreeLevel2.numberOfScholarshipTypes.toString()) + : "-", + totalBudgetApprove2: item.degreeLevel2.totalBudgetApprove + ? Extension.ToThaiNumber(item.degreeLevel2.totalBudgetApprove.toLocaleString()) + : "-", + degreeLevel3: "ปริญญาเอก", - numberOfRecords3: item.degreeLevel3.numberOfRecords ? Extension.ToThaiNumber(item.degreeLevel3.numberOfRecords.toString()) : "-", - numberOfScholarshipTypes3: item.degreeLevel3.numberOfScholarshipTypes ? Extension.ToThaiNumber(item.degreeLevel3.numberOfScholarshipTypes.toString()) : "-", - totalBudgetApprove3: item.degreeLevel3.totalBudgetApprove ? Extension.ToThaiNumber(item.degreeLevel3.totalBudgetApprove.toLocaleString()) : "-", - + numberOfRecords3: item.degreeLevel3.numberOfRecords + ? Extension.ToThaiNumber(item.degreeLevel3.numberOfRecords.toString()) + : "-", + numberOfScholarshipTypes3: item.degreeLevel3.numberOfScholarshipTypes + ? Extension.ToThaiNumber(item.degreeLevel3.numberOfScholarshipTypes.toString()) + : "-", + totalBudgetApprove3: item.degreeLevel3.totalBudgetApprove + ? Extension.ToThaiNumber(item.degreeLevel3.totalBudgetApprove.toLocaleString()) + : "-", + totalNumberOfRecords: Extension.ToThaiNumber(sumnumberOfRecords.toString()), - totalNumberOfScholarshipTypes: Extension.ToThaiNumber(sumnumberOfScholarshipTypes.toString()), - totalTotalBudgetApprove: Extension.ToThaiNumber(sumtotalBudgetApprove.toLocaleString()) + totalNumberOfScholarshipTypes: Extension.ToThaiNumber( + sumnumberOfScholarshipTypes.toString(), + ), + totalTotalBudgetApprove: Extension.ToThaiNumber(sumtotalBudgetApprove.toLocaleString()), }; }); - const uniqueRoots = new Set(formattedData.map(item => item.root)); + const uniqueRoots = new Set(formattedData.map((item) => item.root)); const numberOfORG = uniqueRoots.size; - + return new HttpSuccess({ template: "reportFund6", reportName: "reportFund6", data: { - year: year?Extension.ToThaiNumber((year+543).toString()):"", + year: year ? Extension.ToThaiNumber((year + 543).toString()) : "", data: formattedData, - coutOrg: numberOfORG?Extension.ToThaiNumber(numberOfORG.toString())+" หน่วยงาน":"๐ หน่วยงาน" + coutOrg: numberOfORG + ? Extension.ToThaiNumber(numberOfORG.toString()) + " หน่วยงาน" + : "๐ หน่วยงาน", }, }); } - } - - \ No newline at end of file From a003868b47d70a7eb2af9b3bb383c5ecb5f138f1 Mon Sep 17 00:00:00 2001 From: waruneeauy Date: Fri, 14 Mar 2025 15:18:48 +0700 Subject: [PATCH 217/250] fixing error redis --- src/interfaces/permission.ts | 32 +++++++++++++++++++++++++++----- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/src/interfaces/permission.ts b/src/interfaces/permission.ts index b55d8e7..cfe76e6 100644 --- a/src/interfaces/permission.ts +++ b/src/interfaces/permission.ts @@ -184,12 +184,34 @@ class CheckAuth { }); } 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); try { + // Validate required environment variables + const REDIS_HOST = process.env.REDIS_HOST; + const REDIS_PORT = process.env.REDIS_PORT ? Number(process.env.REDIS_PORT) : 6379; + + if (!REDIS_HOST) { + throw new Error("REDIS_HOST is not set in environment variables"); + } + + console.log(`[REDIS] Connecting to Redis at ${REDIS_HOST}:${REDIS_PORT}`); + + // Create Redis client + const redisClient = this.redis.createClient({ + socket: { + host: REDIS_HOST, + port: REDIS_PORT, + }, + }); + + redisClient.on("error", (err: any) => { + console.error("[REDIS] Connection error:", err.message); + }); + + await redisClient.connect(); + console.log("[REDIS] Connected successfully!"); + + const getAsync = promisify(redisClient.get).bind(redisClient); + let reply = await getAsync("org_" + keycloakId); if (reply != null) { reply = JSON.parse(reply); From a4ebb83184929b37ffe8147dd964b2728bddba09 Mon Sep 17 00:00:00 2001 From: kittapath Date: Fri, 14 Mar 2025 15:32:17 +0700 Subject: [PATCH 218/250] add pos exe --- src/controllers/DevelopmentController.ts | 1 + src/entities/PlannedGoalPosition.ts | 9 +++++++++ 2 files changed, 10 insertions(+) diff --git a/src/controllers/DevelopmentController.ts b/src/controllers/DevelopmentController.ts index b2b7aaf..2cd5f30 100644 --- a/src/controllers/DevelopmentController.ts +++ b/src/controllers/DevelopmentController.ts @@ -2188,6 +2188,7 @@ export class DevelopmentController extends Controller { position: x.plannedGoalPositions.map((y) => ({ id: y.id, position: y.position, + posExecutive: y.posExecutive, posTypeId: y.posTypePlannedId, posType: y.posTypePlanned == null ? null : y.posTypePlanned.posTypeName, posLevelId: y.posLevelPlannedId, diff --git a/src/entities/PlannedGoalPosition.ts b/src/entities/PlannedGoalPosition.ts index 01a088c..990c977 100644 --- a/src/entities/PlannedGoalPosition.ts +++ b/src/entities/PlannedGoalPosition.ts @@ -13,6 +13,13 @@ export class PlannedGoalPosition extends EntityBase { }) position: string; + @Column({ + nullable: true, + comment: "ตำแหน่งทางการบริหาร", + default: null, + }) + posExecutive: string; + @Column({ nullable: true, comment: "ประเภทตำแหน่ง", @@ -51,6 +58,8 @@ export class CreatePlannedGoalPosition { @Column() position: string | null; @Column() + posExecutive: string | null; + @Column() posTypePlannedId: string | null; @Column() posLevelPlannedId: string | null; From bd002135961d068e9877b6644f0ad49f82459d99 Mon Sep 17 00:00:00 2001 From: moss <> Date: Tue, 25 Mar 2025 10:32:06 +0700 Subject: [PATCH 219/250] =?UTF-8?q?sort=20=E0=B8=A2=E0=B8=B8=E0=B8=97?= =?UTF-8?q?=E0=B8=A8=E0=B8=B2=E0=B8=AA=E0=B8=95=E0=B8=A3=E0=B9=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/StrategyController.ts | 33 ++++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-) diff --git a/src/controllers/StrategyController.ts b/src/controllers/StrategyController.ts index ce1cbd2..a00f3cf 100644 --- a/src/controllers/StrategyController.ts +++ b/src/controllers/StrategyController.ts @@ -43,7 +43,16 @@ export class StrategyController extends Controller { "strategyChild2s.strategyChild3s.strategyChild4s", "strategyChild2s.strategyChild3s.strategyChild4s.strategyChild5s", ], - order: { createdAt: "ASC" }, + order: { + createdAt: "ASC", + strategyChild2s: { + createdAt: "ASC", + strategyChild3s: { + createdAt: "ASC", + strategyChild4s: { createdAt: "ASC", strategyChild5s: { createdAt: "ASC" } }, + }, + }, + }, }); const formattedData = listStrategyChild1.map((item) => ({ @@ -100,7 +109,16 @@ export class StrategyController extends Controller { "strategyChild2s.strategyChild3s.strategyChild4s", "strategyChild2s.strategyChild3s.strategyChild4s.strategyChild5s", ], - order: { createdAt: "ASC" }, + order: { + createdAt: "ASC", + strategyChild2s: { + createdAt: "ASC", + strategyChild3s: { + createdAt: "ASC", + strategyChild4s: { createdAt: "ASC", strategyChild5s: { createdAt: "ASC" } }, + }, + }, + }, }); // if (!listStrategyChild1 || listStrategyChild1.length === 0) { @@ -151,7 +169,16 @@ export class StrategyController extends Controller { "strategyChild2s.strategyChild3s.strategyChild4s", "strategyChild2s.strategyChild3s.strategyChild4s.strategyChild5s", ], - order: { createdAt: "ASC" }, + order: { + createdAt: "ASC", + strategyChild2s: { + createdAt: "ASC", + strategyChild3s: { + createdAt: "ASC", + strategyChild4s: { createdAt: "ASC", strategyChild5s: { createdAt: "ASC" } }, + }, + }, + }, }); // if (!listStrategyChild1 || listStrategyChild1.length === 0) { From 00f76bbd2b08eea89938d583603d22690fd04b7a Mon Sep 17 00:00:00 2001 From: moss <> Date: Thu, 27 Mar 2025 14:46:42 +0700 Subject: [PATCH 220/250] add sort --- src/controllers/StrategyController.ts | 142 ++++++++++++++++-- src/entities/StrategyChild1.ts | 7 + src/entities/StrategyChild2.ts | 7 + src/entities/StrategyChild3.ts | 7 + src/entities/StrategyChild4.ts | 7 + src/entities/StrategyChild5.ts | 7 + ...429-update_developmentHis_add_isDoneIDP.ts | 14 -- ...update_development_add_isReasonActual70.ts | 24 --- ...update_development_add_isReasonActual10.ts | 20 --- ...11015155-update_delete_dev_provincename.ts | 22 --- .../1738201344610-Updatedevadddna.ts | 28 ---- src/migration/1739444714910-updateView.ts | 23 --- ...1739446719623-update_viewDevScholarship.ts | 23 --- .../1743061489009-update_strategyadddorder.ts | 22 +++ 14 files changed, 187 insertions(+), 166 deletions(-) delete mode 100644 src/migration/1727719189429-update_developmentHis_add_isDoneIDP.ts delete mode 100644 src/migration/1727753251629-update_development_add_isReasonActual70.ts delete mode 100644 src/migration/1727755044851-update_development_add_isReasonActual10.ts delete mode 100644 src/migration/1737111015155-update_delete_dev_provincename.ts delete mode 100644 src/migration/1738201344610-Updatedevadddna.ts delete mode 100644 src/migration/1739444714910-updateView.ts delete mode 100644 src/migration/1739446719623-update_viewDevScholarship.ts create mode 100644 src/migration/1743061489009-update_strategyadddorder.ts diff --git a/src/controllers/StrategyController.ts b/src/controllers/StrategyController.ts index a00f3cf..5861879 100644 --- a/src/controllers/StrategyController.ts +++ b/src/controllers/StrategyController.ts @@ -6,6 +6,7 @@ import { Patch, Path, Post, + Put, Request, Route, Security, @@ -44,12 +45,12 @@ export class StrategyController extends Controller { "strategyChild2s.strategyChild3s.strategyChild4s.strategyChild5s", ], order: { - createdAt: "ASC", + order: "ASC", strategyChild2s: { - createdAt: "ASC", + order: "ASC", strategyChild3s: { - createdAt: "ASC", - strategyChild4s: { createdAt: "ASC", strategyChild5s: { createdAt: "ASC" } }, + order: "ASC", + strategyChild4s: { order: "ASC", strategyChild5s: { order: "ASC" } }, }, }, }, @@ -59,25 +60,30 @@ export class StrategyController extends Controller { id: item.id, level: 1, name: item.strategyChild1Name, + order: item.order, children: item.strategyChild2s.map((child2) => ({ id: child2.id, level: 2, name: child2.strategyChild2Name, + order: child2.order, children: child2.strategyChild3s ? child2.strategyChild3s.map((child3) => ({ id: child3.id, level: 3, name: child3.strategyChild3Name, + order: child3.order, children: child3.strategyChild4s ? child3.strategyChild4s.map((child4) => ({ id: child4.id, level: 4, name: child4.strategyChild4Name, + order: child4.order, children: child4.strategyChild5s ? child4.strategyChild5s.map((child5) => ({ id: child5.id, level: 5, name: child5.strategyChild5Name, + order: child5.order, })) : [], })) @@ -110,12 +116,12 @@ export class StrategyController extends Controller { "strategyChild2s.strategyChild3s.strategyChild4s.strategyChild5s", ], order: { - createdAt: "ASC", + order: "ASC", strategyChild2s: { - createdAt: "ASC", + order: "ASC", strategyChild3s: { - createdAt: "ASC", - strategyChild4s: { createdAt: "ASC", strategyChild5s: { createdAt: "ASC" } }, + order: "ASC", + strategyChild4s: { order: "ASC", strategyChild5s: { order: "ASC" } }, }, }, }, @@ -129,25 +135,30 @@ export class StrategyController extends Controller { id: item.id, level: 1, name: item.strategyChild1Name, + order: item.order, children: item.strategyChild2s.map((child2) => ({ id: child2.id, level: 2, name: child2.strategyChild2Name, + order: child2.order, children: child2.strategyChild3s ? child2.strategyChild3s.map((child3) => ({ id: child3.id, level: 3, name: child3.strategyChild3Name, + order: child3.order, children: child3.strategyChild4s ? child3.strategyChild4s.map((child4) => ({ id: child4.id, level: 4, name: child4.strategyChild4Name, + order: child4.order, children: child4.strategyChild5s ? child4.strategyChild5s.map((child5) => ({ id: child5.id, level: 5, name: child5.strategyChild5Name, + order: child5.order, })) : [], })) @@ -170,12 +181,12 @@ export class StrategyController extends Controller { "strategyChild2s.strategyChild3s.strategyChild4s.strategyChild5s", ], order: { - createdAt: "ASC", + order: "ASC", strategyChild2s: { - createdAt: "ASC", + order: "ASC", strategyChild3s: { - createdAt: "ASC", - strategyChild4s: { createdAt: "ASC", strategyChild5s: { createdAt: "ASC" } }, + order: "ASC", + strategyChild4s: { order: "ASC", strategyChild5s: { order: "ASC" } }, }, }, }, @@ -189,25 +200,30 @@ export class StrategyController extends Controller { id: item.id, level: 1, name: item.strategyChild1Name, + order: item.order, children: item.strategyChild2s.map((child2) => ({ id: child2.id, level: 2, name: child2.strategyChild2Name, + order: child2.order, children: child2.strategyChild3s ? child2.strategyChild3s.map((child3) => ({ id: child3.id, level: 3, name: child3.strategyChild3Name, + order: child3.order, children: child3.strategyChild4s ? child3.strategyChild4s.map((child4) => ({ id: child4.id, level: 4, name: child4.strategyChild4Name, + order: child4.order, children: child4.strategyChild5s ? child4.strategyChild5s.map((child5) => ({ id: child5.id, level: 5, name: child5.strategyChild5Name, + order: child5.order, })) : [], })) @@ -237,22 +253,30 @@ export class StrategyController extends Controller { switch (body.levelnode) { case 0: + const ckOrder = await this.strategy1Repo.findOne({ + order: { order: "DESC" }, + }); + strategyRepo = this.strategy1Repo; strategyRepo = this.strategy1Repo; repoSave = this.strategy1Repo; strategyChild = new StrategyChild1(); strategyChild.strategyChild1Name = body.name; + strategyChild.order = ckOrder ? ckOrder.order + 1 : 1; break; case 1: strategyRepo = this.strategy1Repo; repoSave = this.strategy2Repo; strategyChild = new StrategyChild2(); strategyChild.strategyChild2Name = body.name; + strategyChild.order = 1; if (body.idnode) { const chk1 = await this.strategy1Repo.findOne({ where: { id: body.idnode }, + order: { order: "DESC" }, }); if (chk1) { strategyChild.strategyChild1Id = chk1.id; + strategyChild.order = chk1 ? chk1.order + 1 : 1; } else { throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลยุทธศาสตร์"); } @@ -263,13 +287,16 @@ export class StrategyController extends Controller { repoSave = this.strategy3Repo; strategyChild = new StrategyChild3(); strategyChild.strategyChild3Name = body.name; + strategyChild.order = 1; if (body.idnode) { const chk2 = await this.strategy2Repo.findOne({ where: { id: body.idnode }, + order: { order: "DESC" }, }); if (chk2) { strategyChild.strategyChild1Id = chk2.strategyChild1Id; strategyChild.strategyChild2Id = chk2.id; + strategyChild.order = chk2 ? chk2.order + 1 : 1; } else { throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลยุทธศาสตร์"); } @@ -280,14 +307,17 @@ export class StrategyController extends Controller { repoSave = this.strategy4Repo; strategyChild = new StrategyChild4(); strategyChild.strategyChild4Name = body.name; + strategyChild.order = 1; if (body.idnode) { const chk3 = await this.strategy3Repo.findOne({ where: { id: body.idnode }, + order: { order: "DESC" }, }); if (chk3) { strategyChild.strategyChild1Id = chk3.strategyChild1Id; strategyChild.strategyChild2Id = chk3.strategyChild2Id; strategyChild.strategyChild3Id = chk3.id; + strategyChild.order = chk3 ? chk3.order + 1 : 1; } else { throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลยุทธศาสตร์"); } @@ -298,15 +328,18 @@ export class StrategyController extends Controller { repoSave = this.strategy5Repo; strategyChild = new StrategyChild5(); strategyChild.strategyChild5Name = body.name; + strategyChild.order = 1; if (body.idnode) { const chk4 = await this.strategy4Repo.findOne({ where: { id: body.idnode }, + order: { order: "DESC" }, }); if (chk4) { strategyChild.strategyChild1Id = chk4.strategyChild1Id; strategyChild.strategyChild2Id = chk4.strategyChild2Id; strategyChild.strategyChild3Id = chk4.strategyChild3Id; strategyChild.strategyChild4Id = chk4.id; + strategyChild.order = chk4 ? chk4.order + 1 : 1; } else { throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลยุทธศาสตร์"); } @@ -621,4 +654,89 @@ export class StrategyController extends Controller { throw new HttpError(HttpStatus.NOT_FOUND, "not found type: " + requestBody.strategy); } } + + /** + * API เรียงลำดับ + * + * @summary เรียงลำดับ (ADMIN) + * + */ + @Post("sort") + async sortNode( + @Body() requestBody: { strategy: number; strategyId: string[]; id: string | null }, + @Request() request: RequestWithUser, + ) { + switch (requestBody.strategy) { + case 1: { + const data = await this.strategy1Repo.find(); + if (data == null) { + throw new HttpError(HttpStatus.NOT_FOUND, "not found strategy1."); + } + const sortLevel = data.map((data) => ({ + ...data, + level: requestBody.strategyId.indexOf(data.id) + 1, + })); + await this.strategy1Repo.save(sortLevel); + return new HttpSuccess(sortLevel); + } + case 2: { + const data = await this.strategy2Repo.find({ + where: { id: requestBody.id ?? "" }, + }); + if (data == null) { + throw new HttpError(HttpStatus.NOT_FOUND, "not found strategy2."); + } + const sortLevel = data.map((data) => ({ + ...data, + level: requestBody.strategyId.indexOf(data.id) + 1, + })); + await this.strategy2Repo.save(sortLevel); + return new HttpSuccess(sortLevel); + } + case 3: { + const data = await this.strategy3Repo.find({ + where: { id: requestBody.id ?? "" }, + }); + if (data == null) { + throw new HttpError(HttpStatus.NOT_FOUND, "not found strategy3."); + } + const sortLevel = data.map((data) => ({ + ...data, + level: requestBody.strategyId.indexOf(data.id) + 1, + })); + await this.strategy3Repo.save(sortLevel); + return new HttpSuccess(sortLevel); + } + case 4: { + const data = await this.strategy4Repo.find({ + where: { id: requestBody.id ?? "" }, + }); + if (data == null) { + throw new HttpError(HttpStatus.NOT_FOUND, "not found strategy4."); + } + const sortLevel = data.map((data) => ({ + ...data, + level: requestBody.strategyId.indexOf(data.id) + 1, + })); + await this.strategy4Repo.save(sortLevel); + return new HttpSuccess(sortLevel); + } + case 5: { + const data = await this.strategy5Repo.find({ + where: { id: requestBody.id ?? "" }, + }); + if (data == null) { + throw new HttpError(HttpStatus.NOT_FOUND, "not found strategy5."); + } + const sortLevel = data.map((data) => ({ + ...data, + level: requestBody.strategyId.indexOf(data.id) + 1, + })); + await this.strategy5Repo.save(sortLevel); + return new HttpSuccess(sortLevel); + } + default: + throw new HttpError(HttpStatus.NOT_FOUND, "not found type: " + requestBody.strategy); + } + } } diff --git a/src/entities/StrategyChild1.ts b/src/entities/StrategyChild1.ts index 05c56ea..8bc9803 100644 --- a/src/entities/StrategyChild1.ts +++ b/src/entities/StrategyChild1.ts @@ -16,6 +16,13 @@ export class StrategyChild1 extends EntityBase { }) strategyChild1Name: string; + @Column({ + nullable: true, + comment: "ลำดับความสำคัญ", + default: null, + }) + order: number; + @OneToMany(() => StrategyChild2, (strategyChild2) => strategyChild2.strategyChild1) strategyChild2s: StrategyChild2[]; diff --git a/src/entities/StrategyChild2.ts b/src/entities/StrategyChild2.ts index 9425e59..0f57eef 100644 --- a/src/entities/StrategyChild2.ts +++ b/src/entities/StrategyChild2.ts @@ -22,6 +22,13 @@ export class StrategyChild2 extends EntityBase { }) strategyChild1Id: string; + @Column({ + nullable: true, + comment: "ลำดับความสำคัญ", + default: null, + }) + order: number; + @ManyToOne(() => StrategyChild1, (strategyChild1) => strategyChild1.strategyChild2s) @JoinColumn({ name: "strategyChild1Id" }) strategyChild1: StrategyChild1; diff --git a/src/entities/StrategyChild3.ts b/src/entities/StrategyChild3.ts index 9698d0c..d8c5ba7 100644 --- a/src/entities/StrategyChild3.ts +++ b/src/entities/StrategyChild3.ts @@ -28,6 +28,13 @@ export class StrategyChild3 extends EntityBase { }) strategyChild2Id: string; + @Column({ + nullable: true, + comment: "ลำดับความสำคัญ", + default: null, + }) + order: number; + @ManyToOne(() => StrategyChild1, (strategyChild1) => strategyChild1.strategyChild3s) @JoinColumn({ name: "strategyChild1Id" }) strategyChild1: StrategyChild1; diff --git a/src/entities/StrategyChild4.ts b/src/entities/StrategyChild4.ts index 4382a0c..6c5d58e 100644 --- a/src/entities/StrategyChild4.ts +++ b/src/entities/StrategyChild4.ts @@ -34,6 +34,13 @@ export class StrategyChild4 extends EntityBase { }) strategyChild3Id: string; + @Column({ + nullable: true, + comment: "ลำดับความสำคัญ", + default: null, + }) + order: number; + @ManyToOne(() => StrategyChild1, (strategyChild1) => strategyChild1.strategyChild4s) @JoinColumn({ name: "strategyChild1Id" }) strategyChild1: StrategyChild1; diff --git a/src/entities/StrategyChild5.ts b/src/entities/StrategyChild5.ts index 7282210..9d3f413 100644 --- a/src/entities/StrategyChild5.ts +++ b/src/entities/StrategyChild5.ts @@ -40,6 +40,13 @@ export class StrategyChild5 extends EntityBase { }) strategyChild4Id: string; + @Column({ + nullable: true, + comment: "ลำดับความสำคัญ", + default: null, + }) + order: number; + @ManyToOne(() => StrategyChild1, (strategyChild1) => strategyChild1.strategyChild5s) @JoinColumn({ name: "strategyChild1Id" }) strategyChild1: StrategyChild1; diff --git a/src/migration/1727719189429-update_developmentHis_add_isDoneIDP.ts b/src/migration/1727719189429-update_developmentHis_add_isDoneIDP.ts deleted file mode 100644 index c577bb8..0000000 --- a/src/migration/1727719189429-update_developmentHis_add_isDoneIDP.ts +++ /dev/null @@ -1,14 +0,0 @@ -import { MigrationInterface, QueryRunner } from "typeorm"; - -export class UpdateDevelopmentHisAddIsDoneIDP1727719189429 implements MigrationInterface { - name = 'UpdateDevelopmentHisAddIsDoneIDP1727719189429' - - public async up(queryRunner: QueryRunner): Promise { - await queryRunner.query(`ALTER TABLE \`developmentHistory\` ADD \`isDoneIDP\` tinyint NOT NULL COMMENT 'บันทึก IDP ที่ทะเบียนประวัติ' DEFAULT 0`); - } - - public async down(queryRunner: QueryRunner): Promise { - await queryRunner.query(`ALTER TABLE \`developmentHistory\` DROP COLUMN \`isDoneIDP\``); - } - -} diff --git a/src/migration/1727753251629-update_development_add_isReasonActual70.ts b/src/migration/1727753251629-update_development_add_isReasonActual70.ts deleted file mode 100644 index 32c8f84..0000000 --- a/src/migration/1727753251629-update_development_add_isReasonActual70.ts +++ /dev/null @@ -1,24 +0,0 @@ -import { MigrationInterface, QueryRunner } from "typeorm"; - -export class UpdateDevelopmentAddIsReasonActual701727753251629 implements MigrationInterface { - name = 'UpdateDevelopmentAddIsReasonActual701727753251629' - - public async up(queryRunner: QueryRunner): Promise { - await queryRunner.query(`ALTER TABLE \`development\` ADD \`isReasonPlanned70\` tinyint NOT NULL COMMENT 'รายละเอียดอื่นๆ 70 แผน' DEFAULT 0`); - await queryRunner.query(`ALTER TABLE \`development\` ADD \`isReasonPlanned20\` tinyint NOT NULL COMMENT 'รายละเอียดอื่นๆ 20 แผน' DEFAULT 0`); - await queryRunner.query(`ALTER TABLE \`development\` ADD \`isReasonPlanned10\` varchar(255) NULL COMMENT 'รายละเอียดอื่นๆ 10 แผน'`); - await queryRunner.query(`ALTER TABLE \`development\` ADD \`isReasonActual70\` tinyint NOT NULL COMMENT 'รายละเอียดอื่นๆ 70 จริง' DEFAULT 0`); - await queryRunner.query(`ALTER TABLE \`development\` ADD \`isReasonActual20\` tinyint NOT NULL COMMENT 'รายละเอียดอื่นๆ 20 จริง' DEFAULT 0`); - await queryRunner.query(`ALTER TABLE \`development\` ADD \`isReasonActual10\` varchar(255) NULL COMMENT 'รายละเอียดอื่นๆ 10 จริง'`); - } - - public async down(queryRunner: QueryRunner): Promise { - await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`isReasonActual10\``); - await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`isReasonActual20\``); - await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`isReasonActual70\``); - await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`isReasonPlanned10\``); - await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`isReasonPlanned20\``); - await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`isReasonPlanned70\``); - } - -} diff --git a/src/migration/1727755044851-update_development_add_isReasonActual10.ts b/src/migration/1727755044851-update_development_add_isReasonActual10.ts deleted file mode 100644 index a5a0c33..0000000 --- a/src/migration/1727755044851-update_development_add_isReasonActual10.ts +++ /dev/null @@ -1,20 +0,0 @@ -import { MigrationInterface, QueryRunner } from "typeorm"; - -export class UpdateDevelopmentAddIsReasonActual101727755044851 implements MigrationInterface { - name = 'UpdateDevelopmentAddIsReasonActual101727755044851' - - public async up(queryRunner: QueryRunner): Promise { - await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`isReasonPlanned10\``); - await queryRunner.query(`ALTER TABLE \`development\` ADD \`isReasonPlanned10\` tinyint NOT NULL COMMENT 'รายละเอียดอื่นๆ 10 แผน' DEFAULT 0`); - await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`isReasonActual10\``); - await queryRunner.query(`ALTER TABLE \`development\` ADD \`isReasonActual10\` tinyint NOT NULL COMMENT 'รายละเอียดอื่นๆ 10 จริง' DEFAULT 0`); - } - - public async down(queryRunner: QueryRunner): Promise { - await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`isReasonActual10\``); - await queryRunner.query(`ALTER TABLE \`development\` ADD \`isReasonActual10\` varchar(255) NULL COMMENT 'รายละเอียดอื่นๆ 10 จริง'`); - await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`isReasonPlanned10\``); - await queryRunner.query(`ALTER TABLE \`development\` ADD \`isReasonPlanned10\` varchar(255) NULL COMMENT 'รายละเอียดอื่นๆ 10 แผน'`); - } - -} diff --git a/src/migration/1737111015155-update_delete_dev_provincename.ts b/src/migration/1737111015155-update_delete_dev_provincename.ts deleted file mode 100644 index 9f0b4e5..0000000 --- a/src/migration/1737111015155-update_delete_dev_provincename.ts +++ /dev/null @@ -1,22 +0,0 @@ -import { MigrationInterface, QueryRunner } from "typeorm"; - -export class UpdateDeleteDevProvincename1737111015155 implements MigrationInterface { - name = 'UpdateDeleteDevProvincename1737111015155' - - public async up(queryRunner: QueryRunner): Promise { - await queryRunner.query(`ALTER TABLE \`developmentAddress\` DROP FOREIGN KEY \`FK_e2721b3f440256b56ce83a04fb2\``); - await queryRunner.query(`ALTER TABLE \`developmentOther\` DROP FOREIGN KEY \`FK_47bbbecaea9b7b31d2536054656\``); - await queryRunner.query(`ALTER TABLE \`development\` DROP FOREIGN KEY \`FK_bdafbb824b88c3bdb73adf7f220\``); - await queryRunner.query(`ALTER TABLE \`developmentAddress\` ADD \`provinceName\` varchar(255) NULL COMMENT 'โครงการ/หลักสูตรการฝึกอบรม'`); - await queryRunner.query(`ALTER TABLE \`developmentOther\` ADD \`provinceActualName\` varchar(255) NULL COMMENT 'จังหวัด(ข้อมูลวิชาการ)'`); - } - - public async down(queryRunner: QueryRunner): Promise { - await queryRunner.query(`ALTER TABLE \`developmentOther\` DROP COLUMN \`provinceActualName\``); - await queryRunner.query(`ALTER TABLE \`developmentAddress\` DROP COLUMN \`provinceName\``); - await queryRunner.query(`ALTER TABLE \`development\` ADD CONSTRAINT \`FK_bdafbb824b88c3bdb73adf7f220\` FOREIGN KEY (\`provinceActualId\`) REFERENCES \`province\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`); - await queryRunner.query(`ALTER TABLE \`developmentOther\` ADD CONSTRAINT \`FK_47bbbecaea9b7b31d2536054656\` FOREIGN KEY (\`provinceActualId\`) REFERENCES \`province\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`); - await queryRunner.query(`ALTER TABLE \`developmentAddress\` ADD CONSTRAINT \`FK_e2721b3f440256b56ce83a04fb2\` FOREIGN KEY (\`provinceId\`) REFERENCES \`province\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`); - } - -} diff --git a/src/migration/1738201344610-Updatedevadddna.ts b/src/migration/1738201344610-Updatedevadddna.ts deleted file mode 100644 index 4b3ebc1..0000000 --- a/src/migration/1738201344610-Updatedevadddna.ts +++ /dev/null @@ -1,28 +0,0 @@ -import { MigrationInterface, QueryRunner } from "typeorm"; - -export class Updatedevadddna1738201344610 implements MigrationInterface { - name = 'Updatedevadddna1738201344610' - - public async up(queryRunner: QueryRunner): Promise { - await queryRunner.query(`DROP INDEX \`FK_e2721b3f440256b56ce83a04fb2\` ON \`developmentAddress\``); - await queryRunner.query(`DROP INDEX \`FK_47bbbecaea9b7b31d2536054656\` ON \`developmentOther\``); - await queryRunner.query(`DROP INDEX \`FK_bdafbb824b88c3bdb73adf7f220\` ON \`development\``); - await queryRunner.query(`ALTER TABLE \`development\` ADD \`rootDnaId\` varchar(255) NULL COMMENT 'id Dna หน่วยงาน'`); - await queryRunner.query(`ALTER TABLE \`development\` ADD \`child1DnaId\` varchar(255) NULL COMMENT 'id Dna หน่วยงาน child1'`); - await queryRunner.query(`ALTER TABLE \`development\` ADD \`child2DnaId\` varchar(255) NULL COMMENT 'id Dna หน่วยงาน child2'`); - await queryRunner.query(`ALTER TABLE \`development\` ADD \`child3DnaId\` varchar(255) NULL COMMENT 'id Dna หน่วยงาน child3'`); - await queryRunner.query(`ALTER TABLE \`development\` ADD \`child4DnaId\` varchar(255) NULL COMMENT 'id Dna หน่วยงาน child4'`); - } - - public async down(queryRunner: QueryRunner): Promise { - await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`child4DnaId\``); - await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`child3DnaId\``); - await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`child2DnaId\``); - await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`child1DnaId\``); - await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`rootDnaId\``); - await queryRunner.query(`CREATE INDEX \`FK_bdafbb824b88c3bdb73adf7f220\` ON \`development\` (\`provinceActualId\`)`); - await queryRunner.query(`CREATE INDEX \`FK_47bbbecaea9b7b31d2536054656\` ON \`developmentOther\` (\`provinceActualId\`)`); - await queryRunner.query(`CREATE INDEX \`FK_e2721b3f440256b56ce83a04fb2\` ON \`developmentAddress\` (\`provinceId\`)`); - } - -} diff --git a/src/migration/1739444714910-updateView.ts b/src/migration/1739444714910-updateView.ts deleted file mode 100644 index ab12b2e..0000000 --- a/src/migration/1739444714910-updateView.ts +++ /dev/null @@ -1,23 +0,0 @@ -import { MigrationInterface, QueryRunner } from "typeorm"; - -export class UpdateView1739444714910 implements MigrationInterface { - name = 'UpdateView1739444714910' - - public async up(queryRunner: QueryRunner): Promise { - await queryRunner.query(`CREATE VIEW \`view_dev_scholarship\` AS SELECT MAX(\`rootId\`) AS rootId, - MAX(\`root\`) AS root,\`degreeLevel\`, - COUNT(*) AS numberOfRecords, - COUNT(DISTINCT \`scholarshipType\`) AS numberOfScholarshipTypes, - SUM(\`budgetApprove\`) AS totalBudgetApprove - FROM \`developmentScholarship\` - GROUP BY \`rootId\`,\`degreeLevel\` - `); - await queryRunner.query(`INSERT INTO \`bma_ehr_development_demo\`.\`typeorm_metadata\`(\`database\`, \`schema\`, \`table\`, \`type\`, \`name\`, \`value\`) VALUES (DEFAULT, ?, DEFAULT, ?, ?, ?)`, ["bma_ehr_development_demo","VIEW","view_dev_scholarship","SELECT MAX(`rootId`) AS rootId, \n MAX(`root`) AS root,`degreeLevel`,\n COUNT(*) AS numberOfRecords, \n COUNT(DISTINCT `scholarshipType`) AS numberOfScholarshipTypes,\n SUM(`budgetApprove`) AS totalBudgetApprove\n FROM `developmentScholarship`\n GROUP BY `rootId`,`degreeLevel`"]); - } - - public async down(queryRunner: QueryRunner): Promise { - await queryRunner.query(`DELETE FROM \`bma_ehr_development_demo\`.\`typeorm_metadata\` WHERE \`type\` = ? AND \`name\` = ? AND \`schema\` = ?`, ["VIEW","view_dev_scholarship","bma_ehr_development_demo"]); - await queryRunner.query(`DROP VIEW \`view_dev_scholarship\``); - } - -} diff --git a/src/migration/1739446719623-update_viewDevScholarship.ts b/src/migration/1739446719623-update_viewDevScholarship.ts deleted file mode 100644 index 9a1acbc..0000000 --- a/src/migration/1739446719623-update_viewDevScholarship.ts +++ /dev/null @@ -1,23 +0,0 @@ -import { MigrationInterface, QueryRunner } from "typeorm"; - -export class UpdateViewDevScholarship1739446719623 implements MigrationInterface { - name = 'UpdateViewDevScholarship1739446719623' - - public async up(queryRunner: QueryRunner): Promise { - await queryRunner.query(`CREATE VIEW \`view_dev_scholarship\` AS SELECT MAX(\`rootId\`) AS rootId, - MAX(\`root\`) AS root,\`degreeLevel\`, - COUNT(*) AS numberOfRecords, - COUNT(DISTINCT \`scholarshipType\`) AS numberOfScholarshipTypes, - SUM(\`budgetApprove\`) AS totalBudgetApprove - FROM \`developmentScholarship\` - GROUP BY \`rootId\`,\`degreeLevel\` - `); - await queryRunner.query(`INSERT INTO \`bma_ehr_development_demo\`.\`typeorm_metadata\`(\`database\`, \`schema\`, \`table\`, \`type\`, \`name\`, \`value\`) VALUES (DEFAULT, ?, DEFAULT, ?, ?, ?)`, ["bma_ehr_development_demo","VIEW","view_dev_scholarship","SELECT MAX(`rootId`) AS rootId, \n MAX(`root`) AS root,`degreeLevel`,\n COUNT(*) AS numberOfRecords, \n COUNT(DISTINCT `scholarshipType`) AS numberOfScholarshipTypes,\n SUM(`budgetApprove`) AS totalBudgetApprove\n FROM `developmentScholarship`\n GROUP BY `rootId`,`degreeLevel`"]); - } - - public async down(queryRunner: QueryRunner): Promise { - await queryRunner.query(`DELETE FROM \`bma_ehr_development_demo\`.\`typeorm_metadata\` WHERE \`type\` = ? AND \`name\` = ? AND \`schema\` = ?`, ["VIEW","view_dev_scholarship","bma_ehr_development_demo"]); - await queryRunner.query(`DROP VIEW \`view_dev_scholarship\``); - } - -} diff --git a/src/migration/1743061489009-update_strategyadddorder.ts b/src/migration/1743061489009-update_strategyadddorder.ts new file mode 100644 index 0000000..c6c6e16 --- /dev/null +++ b/src/migration/1743061489009-update_strategyadddorder.ts @@ -0,0 +1,22 @@ +import { MigrationInterface, QueryRunner } from "typeorm"; + +export class UpdateStrategyadddorder1743061489009 implements MigrationInterface { + name = 'UpdateStrategyadddorder1743061489009' + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`strategyChild4\` ADD \`order\` int NULL COMMENT 'ลำดับความสำคัญ'`); + await queryRunner.query(`ALTER TABLE \`strategyChild3\` ADD \`order\` int NULL COMMENT 'ลำดับความสำคัญ'`); + await queryRunner.query(`ALTER TABLE \`strategyChild2\` ADD \`order\` int NULL COMMENT 'ลำดับความสำคัญ'`); + await queryRunner.query(`ALTER TABLE \`strategyChild1\` ADD \`order\` int NULL COMMENT 'ลำดับความสำคัญ'`); + await queryRunner.query(`ALTER TABLE \`strategyChild5\` ADD \`order\` int NULL COMMENT 'ลำดับความสำคัญ'`); + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`strategyChild5\` DROP COLUMN \`order\``); + await queryRunner.query(`ALTER TABLE \`strategyChild1\` DROP COLUMN \`order\``); + await queryRunner.query(`ALTER TABLE \`strategyChild2\` DROP COLUMN \`order\``); + await queryRunner.query(`ALTER TABLE \`strategyChild3\` DROP COLUMN \`order\``); + await queryRunner.query(`ALTER TABLE \`strategyChild4\` DROP COLUMN \`order\``); + } + +} From c9845b0256846d739bb7cea044710526fca2d60b Mon Sep 17 00:00:00 2001 From: moss <> Date: Fri, 28 Mar 2025 15:10:26 +0700 Subject: [PATCH 221/250] sort data --- src/controllers/StrategyController.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/controllers/StrategyController.ts b/src/controllers/StrategyController.ts index 5861879..f9d7be8 100644 --- a/src/controllers/StrategyController.ts +++ b/src/controllers/StrategyController.ts @@ -674,7 +674,7 @@ export class StrategyController extends Controller { } const sortLevel = data.map((data) => ({ ...data, - level: requestBody.strategyId.indexOf(data.id) + 1, + order: requestBody.strategyId.indexOf(data.id) + 1, })); await this.strategy1Repo.save(sortLevel); return new HttpSuccess(sortLevel); @@ -688,7 +688,7 @@ export class StrategyController extends Controller { } const sortLevel = data.map((data) => ({ ...data, - level: requestBody.strategyId.indexOf(data.id) + 1, + order: requestBody.strategyId.indexOf(data.id) + 1, })); await this.strategy2Repo.save(sortLevel); return new HttpSuccess(sortLevel); @@ -702,7 +702,7 @@ export class StrategyController extends Controller { } const sortLevel = data.map((data) => ({ ...data, - level: requestBody.strategyId.indexOf(data.id) + 1, + order: requestBody.strategyId.indexOf(data.id) + 1, })); await this.strategy3Repo.save(sortLevel); return new HttpSuccess(sortLevel); @@ -716,7 +716,7 @@ export class StrategyController extends Controller { } const sortLevel = data.map((data) => ({ ...data, - level: requestBody.strategyId.indexOf(data.id) + 1, + order: requestBody.strategyId.indexOf(data.id) + 1, })); await this.strategy4Repo.save(sortLevel); return new HttpSuccess(sortLevel); @@ -730,7 +730,7 @@ export class StrategyController extends Controller { } const sortLevel = data.map((data) => ({ ...data, - level: requestBody.strategyId.indexOf(data.id) + 1, + order: requestBody.strategyId.indexOf(data.id) + 1, })); await this.strategy5Repo.save(sortLevel); return new HttpSuccess(sortLevel); From 28df293eef5b5b669d44897c1b391b7bba7b68f1 Mon Sep 17 00:00:00 2001 From: moss <> Date: Fri, 28 Mar 2025 21:44:55 +0700 Subject: [PATCH 222/250] sort --- .github/workflows/release.yaml | 73 +++++++++++++-------------- src/controllers/StrategyController.ts | 8 +-- 2 files changed, 40 insertions(+), 41 deletions(-) diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 2f29d54..6916881 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -67,41 +67,40 @@ jobs: docker compose pull docker compose up -d echo "${{ steps.gen_ver.outputs.image_ver }}"> success - - name: Notify Discord Success - if: success() - run: | - curl -H "Content-Type: application/json" \ - -X POST \ - -d '{ - "embeds": [{ - "title": "✅ Deployment Success!", - "description": "**Details:**\n- Image: `${{env.IMAGE_NAME}}`\n- Version: `${{ steps.gen_ver.outputs.image_ver }}`\n- Deployed by: `${{github.actor}}`", - "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() - run: | - curl -H "Content-Type: application/json" \ - -X POST \ - -d '{ - "embeds": [{ - "title": "❌ Deployment Failed!", - "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 }} + # - name: Notify Discord Success + # if: success() + # run: | + # curl -H "Content-Type: application/json" \ + # -X POST \ + # -d '{ + # "embeds": [{ + # "title": "✅ Deployment Success!", + # "description": "**Details:**\n- Image: `${{env.IMAGE_NAME}}`\n- Version: `${{ steps.gen_ver.outputs.image_ver }}`\n- Deployed by: `${{github.actor}}`", + # "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() + # run: | + # curl -H "Content-Type: application/json" \ + # -X POST \ + # -d '{ + # "embeds": [{ + # "title": "❌ Deployment Failed!", + # "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 }} diff --git a/src/controllers/StrategyController.ts b/src/controllers/StrategyController.ts index f9d7be8..bd29960 100644 --- a/src/controllers/StrategyController.ts +++ b/src/controllers/StrategyController.ts @@ -681,7 +681,7 @@ export class StrategyController extends Controller { } case 2: { const data = await this.strategy2Repo.find({ - where: { id: requestBody.id ?? "" }, + where: { strategyChild1Id: requestBody.id ?? "" }, }); if (data == null) { throw new HttpError(HttpStatus.NOT_FOUND, "not found strategy2."); @@ -695,7 +695,7 @@ export class StrategyController extends Controller { } case 3: { const data = await this.strategy3Repo.find({ - where: { id: requestBody.id ?? "" }, + where: { strategyChild2Id: requestBody.id ?? "" }, }); if (data == null) { throw new HttpError(HttpStatus.NOT_FOUND, "not found strategy3."); @@ -709,7 +709,7 @@ export class StrategyController extends Controller { } case 4: { const data = await this.strategy4Repo.find({ - where: { id: requestBody.id ?? "" }, + where: { strategyChild3Id: requestBody.id ?? "" }, }); if (data == null) { throw new HttpError(HttpStatus.NOT_FOUND, "not found strategy4."); @@ -723,7 +723,7 @@ export class StrategyController extends Controller { } case 5: { const data = await this.strategy5Repo.find({ - where: { id: requestBody.id ?? "" }, + where: { strategyChild4Id: requestBody.id ?? "" }, }); if (data == null) { throw new HttpError(HttpStatus.NOT_FOUND, "not found strategy5."); From 9f41422b1bf6d602ffda9c7c7637ab67d1017d3b Mon Sep 17 00:00:00 2001 From: moss <> Date: Tue, 1 Apr 2025 00:38:15 +0700 Subject: [PATCH 223/250] check type object log --- src/interfaces/utils.ts | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/interfaces/utils.ts b/src/interfaces/utils.ts index 30035f0..c667f54 100644 --- a/src/interfaces/utils.ts +++ b/src/interfaces/utils.ts @@ -19,10 +19,20 @@ export type LogSequence = { }; export function setLogDataDiff(req: RequestWithUser, data: DataDiff) { - req.app.locals.logData.dataDiff = { - before: JSON.stringify(data.before), - after: JSON.stringify(data.after), - }; + // Check if data.before and data.after are valid objects + if ( + data.before && + typeof data.before === "object" && + data.after && + typeof data.after === "object" + ) { + req.app.locals.logData.dataDiff = { + before: JSON.stringify(data.before), + after: JSON.stringify(data.after), + }; + } else { + console.error("Invalid data provided: both before and after must be valid objects."); + } } export function addLogSequence(req: RequestWithUser, data: LogSequence) { From c6668cbc27594b2ae3af25f00c9e0ecc1253ff1f Mon Sep 17 00:00:00 2001 From: moss <> Date: Tue, 1 Apr 2025 01:34:54 +0700 Subject: [PATCH 224/250] on noti --- .github/workflows/release.yaml | 72 +++++++++++++++++----------------- 1 file changed, 36 insertions(+), 36 deletions(-) diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 6916881..0d19c5a 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -67,40 +67,40 @@ jobs: docker compose pull docker compose up -d echo "${{ steps.gen_ver.outputs.image_ver }}"> success - # - name: Notify Discord Success - # if: success() - # run: | - # curl -H "Content-Type: application/json" \ - # -X POST \ - # -d '{ - # "embeds": [{ - # "title": "✅ Deployment Success!", - # "description": "**Details:**\n- Image: `${{env.IMAGE_NAME}}`\n- Version: `${{ steps.gen_ver.outputs.image_ver }}`\n- Deployed by: `${{github.actor}}`", - # "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 Success + if: success() + run: | + curl -H "Content-Type: application/json" \ + -X POST \ + -d '{ + "embeds": [{ + "title": "✅ Deployment Success!", + "description": "**Details:**\n- Image: `${{env.IMAGE_NAME}}`\n- Version: `${{ steps.gen_ver.outputs.image_ver }}`\n- Deployed by: `${{github.actor}}`", + "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() - # run: | - # curl -H "Content-Type: application/json" \ - # -X POST \ - # -d '{ - # "embeds": [{ - # "title": "❌ Deployment Failed!", - # "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 }} + - name: Notify Discord Failure + if: failure() + run: | + curl -H "Content-Type: application/json" \ + -X POST \ + -d '{ + "embeds": [{ + "title": "❌ Deployment Failed!", + "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 }} From 316334021591b3540a5c077a7665b07ee4770ab4 Mon Sep 17 00:00:00 2001 From: Bright Date: Thu, 10 Apr 2025 11:11:53 +0700 Subject: [PATCH 225/250] =?UTF-8?q?=E0=B9=81=E0=B8=81=E0=B9=89=E0=B8=9A?= =?UTF-8?q?=E0=B8=B1=E0=B8=84=E0=B8=A3=E0=B8=B0=E0=B8=9A=E0=B8=9A=E0=B8=9E?= =?UTF-8?q?=E0=B8=B1=E0=B8=92=E0=B8=99=E0=B8=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/DevelopmentController.ts | 54 ++++++++++++++++--- .../DevelopmentHistoryController.ts | 1 + src/controllers/ReportController.ts | 10 ++++ 3 files changed, 59 insertions(+), 6 deletions(-) diff --git a/src/controllers/DevelopmentController.ts b/src/controllers/DevelopmentController.ts index 2cd5f30..95d2ae4 100644 --- a/src/controllers/DevelopmentController.ts +++ b/src/controllers/DevelopmentController.ts @@ -2539,9 +2539,51 @@ export class DevelopmentController extends Controller { where: { developmentId: id, isDoneIDP: false }, relations: ["development", "development.developmentProjectTechniqueActuals"], }); + + let isDevelopment70: boolean = false + const dev70Lists = [ + "on_the_job_training", + "job_project_assignment", + "job_shadowing", + "job_enlargement", + "internal_trainer", + "rotation", + "activity", + "site_visit", + "benchmarking", + "problem_solving", + "team_working", + "other1" + ]; + let isDevelopment20: boolean = false + const dev20Lists = [ + "coaching", + "mentoring", + "team_meeting", + "consulting", + "feedback", + "other2" + ]; + let isDevelopment10: boolean = false + const dev10Lists = [ + "self_learning", + "classroom_training", + "in_house_training", + "public_training", + "e_training", + "meeting", + "seminar", + "other3" + ]; await Promise.all( getDevelopment.map(async (x) => { const _data = Object.assign(new DevelopmentHistory(), x); + + const techniqueActuals = x.development?.developmentProjectTechniqueActuals.flatMap(x => x.name) || []; + isDevelopment70 = techniqueActuals.length > 0 && dev70Lists.some(item => techniqueActuals.includes(item)); + isDevelopment20 = techniqueActuals.length > 0 && dev20Lists.some(item => techniqueActuals.includes(item)); + isDevelopment10 = techniqueActuals.length > 0 && dev10Lists.some(item => techniqueActuals.includes(item)); + if (x.type == "OFFICER") { await new CallAPI() .PostData(request, "/org/profile/development", { @@ -2555,9 +2597,9 @@ export class DevelopmentController extends Controller { reasonDevelopment70: x.development.reasonActual70, reasonDevelopment20: x.development.reasonActual20, reasonDevelopment10: x.development.reasonActual10, - isDevelopment70: x.development.isReasonActual70, - isDevelopment20: x.development.isReasonActual20, - isDevelopment10: x.development.isReasonActual10, + isDevelopment70: isDevelopment70, + isDevelopment20: isDevelopment20, + isDevelopment10: isDevelopment10, developmentTarget: null, developmentResults: null, developmentReport: null, @@ -2584,9 +2626,9 @@ export class DevelopmentController extends Controller { reasonDevelopment70: x.development.reasonActual70, reasonDevelopment20: x.development.reasonActual20, reasonDevelopment10: x.development.reasonActual10, - isDevelopment70: x.development.isReasonActual70, - isDevelopment20: x.development.isReasonActual20, - isDevelopment10: x.development.isReasonActual10, + isDevelopment70: isDevelopment70, + isDevelopment20: isDevelopment20, + isDevelopment10: isDevelopment10, developmentTarget: null, developmentResults: null, developmentReport: null, diff --git a/src/controllers/DevelopmentHistoryController.ts b/src/controllers/DevelopmentHistoryController.ts index e546a0c..5ab0f55 100644 --- a/src/controllers/DevelopmentHistoryController.ts +++ b/src/controllers/DevelopmentHistoryController.ts @@ -250,6 +250,7 @@ export class DevelopmentOfficerHistoryController extends Controller { .leftJoinAndSelect("developmentHistory.development", "development") .leftJoinAndSelect("developmentHistory.posLevel", "posLevel") .leftJoinAndSelect("developmentHistory.posType", "posType") + .where("developmentHistory.profileId IS NOT NULL") .andWhere( body.year != 0 && body.year != null && body.year != undefined ? "development.year = :year" diff --git a/src/controllers/ReportController.ts b/src/controllers/ReportController.ts index bf63247..ff19bb7 100644 --- a/src/controllers/ReportController.ts +++ b/src/controllers/ReportController.ts @@ -16,6 +16,7 @@ import { isNotEmittedStatement } from "typescript"; @Tags("Report") @Security("bearerAuth") export class ReportController extends Controller { + private developmentRepository = AppDataSource.getRepository(Development); private developmentScholarshipRepository = AppDataSource.getRepository(DevelopmentScholarship); private viewDevScholarship = AppDataSource.getRepository(viewDevScholarship); /** @@ -44,6 +45,7 @@ export class ReportController extends Controller { .leftJoinAndSelect("development.strategyChild5Actual", "strategy5") .where("development.status = :status", { status: "FINISH" }) .andWhere("development.strategyChild1ActualId IS NOT NULL") + .andWhere("development.rootDnaId = :rootDnaId", { rootDnaId: rootId }) .select([ "development.id AS id", "development.projectName AS projectName", @@ -114,6 +116,7 @@ export class ReportController extends Controller { .leftJoinAndSelect("development.strategyChild1Actual", "strategy1") .where("development.status = :status", { status: "FINISH" }) .andWhere("development.strategyChild1ActualId IS NOT NULL") + .andWhere("development.rootDnaId = :rootDnaId", { rootDnaId: rootId }) .select([ "development.rootId AS rootId", "development.strategyChild1ActualId AS strategyId", @@ -377,10 +380,17 @@ export class ReportController extends Controller { return formattedGroup; }); + const dev = await this.developmentRepository.findOne({ + where: { rootDnaId: rootId }, + select: ["root", "year"] + }) + return new HttpSuccess({ template: "development", reportName: "development", data: { + root: dev && dev.root ? dev.root : "-", + year: dev && dev.year ? Extension.ToThaiNumber((dev.year+543).toString()) : "-", data: mappedDataDev, resultAllStrategy: reformattedData, sumDev1: Extension.ToThaiNumber(sumDev1.toLocaleString()) ?? "-", From cd6ef2711619e88ee417e51a41ee33d59916e237 Mon Sep 17 00:00:00 2001 From: Bright Date: Thu, 10 Apr 2025 13:59:19 +0700 Subject: [PATCH 226/250] =?UTF-8?q?filter=20=E0=B8=AB=E0=B8=99=E0=B9=88?= =?UTF-8?q?=E0=B8=A7=E0=B8=A2=E0=B8=87=E0=B8=B2=E0=B8=99=20=E0=B8=A3?= =?UTF-8?q?=E0=B8=B2=E0=B8=A2=E0=B8=81=E0=B8=B2=E0=B8=A3=E0=B8=9B=E0=B8=A3?= =?UTF-8?q?=E0=B8=B0=E0=B8=A7=E0=B8=B1=E0=B8=95=E0=B8=B4=E0=B8=81=E0=B8=B2?= =?UTF-8?q?=E0=B8=A3=E0=B8=9D=E0=B8=B6=E0=B8=81=E0=B8=AD=E0=B8=9A=E0=B8=A3?= =?UTF-8?q?=E0=B8=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/ReportController.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/controllers/ReportController.ts b/src/controllers/ReportController.ts index ff19bb7..d9ff0eb 100644 --- a/src/controllers/ReportController.ts +++ b/src/controllers/ReportController.ts @@ -441,7 +441,7 @@ export class ReportController extends Controller { .andWhere(body.year != 0 && body.year != null ? "development.year = :year" : "1=1", { year: body.year, }) - .andWhere(body.root != null ? "development.root = :root" : "1=1", { + .andWhere(body.root != null ? "developmentHistory.root = :root" : "1=1", { root: body.root, }) .andWhere("developmentHistory.type = :type", { type: "OFFICER" }) From 719da258758fcb82dba6796b1262595733196c4e Mon Sep 17 00:00:00 2001 From: Bright Date: Thu, 10 Apr 2025 15:04:17 +0700 Subject: [PATCH 227/250] =?UTF-8?q?=E0=B8=A3=E0=B8=B2=E0=B8=A2=E0=B8=81?= =?UTF-8?q?=E0=B8=B2=E0=B8=A3=E0=B8=9B=E0=B8=A3=E0=B8=B0=E0=B8=A7=E0=B8=B1?= =?UTF-8?q?=E0=B8=95=E0=B8=B4=E0=B8=81=E0=B8=B2=E0=B8=A3=E0=B8=9D=E0=B8=B6?= =?UTF-8?q?=E0=B8=81=E0=B8=AD=E0=B8=9A=E0=B8=A3=E0=B8=A1=E0=B8=A5=E0=B8=B9?= =?UTF-8?q?=E0=B8=81=E0=B8=88=E0=B9=89=E0=B8=B2=E0=B8=87=20&=20=E0=B8=A3?= =?UTF-8?q?=E0=B8=B0=E0=B8=94=E0=B8=B1=E0=B8=9A=E0=B8=8A=E0=B8=B1=E0=B9=89?= =?UTF-8?q?=E0=B8=99=E0=B8=87=E0=B8=B2=E0=B8=99=E0=B8=A5=E0=B8=B9=E0=B8=81?= =?UTF-8?q?=E0=B8=88=E0=B9=89=E0=B8=B2=E0=B8=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/DevelopmentController.ts | 2 +- src/controllers/ReportController.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/controllers/DevelopmentController.ts b/src/controllers/DevelopmentController.ts index 95d2ae4..0e8e115 100644 --- a/src/controllers/DevelopmentController.ts +++ b/src/controllers/DevelopmentController.ts @@ -2434,7 +2434,7 @@ export class DevelopmentController extends Controller { ? item.posLevel.posLevelName : null : item.employeePosLevel - ? item.employeePosLevel.posLevelName + ? `${item.employeePosType.posTypeShortName ?? ""} ${item.employeePosLevel.posLevelName ?? ""}` : null, posExecutive: item.posExecutive, org: item.org, diff --git a/src/controllers/ReportController.ts b/src/controllers/ReportController.ts index d9ff0eb..3f1183d 100644 --- a/src/controllers/ReportController.ts +++ b/src/controllers/ReportController.ts @@ -505,7 +505,7 @@ export class ReportController extends Controller { .andWhere(body.year != 0 && body.year != null ? "development.year = :year" : "1=1", { year: body.year, }) - .andWhere(body.root != null ? "development.root = :root" : "1=1", { + .andWhere(body.root != null ? "developmentHistory.root = :root" : "1=1", { root: body.root, }) .andWhere("developmentHistory.type = :type", { type: "EMPLOYEE" }) From 60781ea2544e05eb3ec14c5d826be5e217238b59 Mon Sep 17 00:00:00 2001 From: Bright Date: Thu, 10 Apr 2025 16:20:30 +0700 Subject: [PATCH 228/250] =?UTF-8?q?=E0=B9=80=E0=B8=9E=E0=B8=B4=E0=B9=88?= =?UTF-8?q?=E0=B8=A1/=E0=B9=81=E0=B8=81=E0=B9=89=E0=B9=84=E0=B8=82=20?= =?UTF-8?q?=E0=B8=81=E0=B8=A5=E0=B8=B8=E0=B9=88=E0=B8=A1=E0=B9=80=E0=B8=9B?= =?UTF-8?q?=E0=B9=89=E0=B8=B2=E0=B8=AB=E0=B8=A1=E0=B8=B2=E0=B8=A2=20(?= =?UTF-8?q?=E0=B8=A5=E0=B8=B9=E0=B8=81=E0=B8=88=E0=B9=89=E0=B8=B2=E0=B8=87?= =?UTF-8?q?)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/DevelopmentController.ts | 88 ++++++++++++++++++------ 1 file changed, 68 insertions(+), 20 deletions(-) diff --git a/src/controllers/DevelopmentController.ts b/src/controllers/DevelopmentController.ts index 0e8e115..4310ce9 100644 --- a/src/controllers/DevelopmentController.ts +++ b/src/controllers/DevelopmentController.ts @@ -34,6 +34,8 @@ import { ActualGoal, CreateActualGoal } from "../entities/ActualGoal"; import { CreatePlannedGoal, PlannedGoal } from "../entities/PlannedGoal"; import { PosType } from "../entities/PosType"; import { PosLevel } from "../entities/PosLevel"; +import { EmployeePosType } from "../entities/EmployeePosType"; +import { EmployeePosLevel } from "../entities/EmployeePosLevel"; import { PlannedGoalPosition } from "../entities/PlannedGoalPosition"; import { CreateDevelopmentHistoryOBO, DevelopmentHistory } from "../entities/DevelopmentHistory"; import { DevelopmentProjectType } from "../entities/DevelopmentProjectType"; @@ -84,6 +86,8 @@ export class DevelopmentController extends Controller { private plannedGoalPositionRepository = AppDataSource.getRepository(PlannedGoalPosition); private posTypeRepository = AppDataSource.getRepository(PosType); private posLevelRepository = AppDataSource.getRepository(PosLevel); + private empPosTypeRepository = AppDataSource.getRepository(EmployeePosType); + private empPosLevelRepository = AppDataSource.getRepository(EmployeePosLevel); private strategyChild1Repository = AppDataSource.getRepository(StrategyChild1); private strategyChild2Repository = AppDataSource.getRepository(StrategyChild2); private strategyChild3Repository = AppDataSource.getRepository(StrategyChild3); @@ -367,19 +371,41 @@ export class DevelopmentController extends Controller { requestBody.positions.map(async (x) => { const _data = Object.assign(new PlannedGoalPosition(), x); if (x.posTypePlannedId != null) { - const checkId = await this.posTypeRepository.findOne({ - where: { id: x.posTypePlannedId }, - }); - if (!checkId) { - throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลประเภทตำแหน่ง"); + let checkId:any + if(requestBody.groupTarget == "PERSONNEL" && (requestBody.groupTargetSub == "EMPLOYEE" || requestBody.groupTargetSub == "EMPLOYEETEMP")) { + checkId = await this.empPosTypeRepository.findOne({ + where: { id: x.posTypePlannedId }, + }); + if (!checkId) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลกลุ่มงาน"); + } + } + else { + checkId = await this.posTypeRepository.findOne({ + where: { id: x.posTypePlannedId }, + }); + if (!checkId) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลประเภทตำแหน่ง"); + } } } if (x.posLevelPlannedId != null) { - const checkId = await this.posLevelRepository.findOne({ - where: { id: x.posLevelPlannedId }, - }); - if (!checkId) { - throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลระดับตำแหน่ง"); + let checkId:any + if (requestBody.groupTarget == "PERSONNEL" && (requestBody.groupTargetSub == "EMPLOYEE" || requestBody.groupTargetSub == "EMPLOYEETEMP")) { + checkId = await this.empPosLevelRepository.findOne({ + where: { id: x.posLevelPlannedId }, + }); + if (!checkId) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลระดับชั้นงาน"); + } + } + else { + checkId = await this.posLevelRepository.findOne({ + where: { id: x.posLevelPlannedId }, + }); + if (!checkId) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลระดับตำแหน่ง"); + } } } const before = structuredClone(development); @@ -608,19 +634,41 @@ export class DevelopmentController extends Controller { requestBody.positions.map(async (x) => { const _data = Object.assign(new PlannedGoalPosition(), x); if (x.posTypePlannedId != null) { - const checkId = await this.posTypeRepository.findOne({ - where: { id: x.posTypePlannedId }, - }); - if (!checkId) { - throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลประเภทตำแหน่ง"); + let checkId:any + if(requestBody.groupTarget == "PERSONNEL" && (requestBody.groupTargetSub == "EMPLOYEE" || requestBody.groupTargetSub == "EMPLOYEETEMP")) { + checkId = await this.empPosTypeRepository.findOne({ + where: { id: x.posTypePlannedId }, + }); + if (!checkId) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลกลุ่มงาน"); + } + } + else { + checkId = await this.posTypeRepository.findOne({ + where: { id: x.posTypePlannedId }, + }); + if (!checkId) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลประเภทตำแหน่ง"); + } } } if (x.posLevelPlannedId != null) { - const checkId = await this.posLevelRepository.findOne({ - where: { id: x.posLevelPlannedId }, - }); - if (!checkId) { - throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลระดับตำแหน่ง"); + let checkId:any + if (requestBody.groupTarget == "PERSONNEL" && (requestBody.groupTargetSub == "EMPLOYEE" || requestBody.groupTargetSub == "EMPLOYEETEMP")) { + checkId = await this.empPosLevelRepository.findOne({ + where: { id: x.posLevelPlannedId }, + }); + if (!checkId) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลระดับชั้นงาน"); + } + } + else { + checkId = await this.posLevelRepository.findOne({ + where: { id: x.posLevelPlannedId }, + }); + if (!checkId) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลระดับตำแหน่ง"); + } } } _data.createdUserId = request.user.sub; From dbfc678e9212543e459ea77aeb42c20db951f2ce Mon Sep 17 00:00:00 2001 From: Bright Date: Fri, 11 Apr 2025 10:58:34 +0700 Subject: [PATCH 229/250] =?UTF-8?q?migrate=20(=E0=B8=95=E0=B8=B1=E0=B8=94?= =?UTF-8?q?=20relation=20=E0=B8=9F=E0=B8=B4=E0=B8=A5=E0=B8=94=E0=B9=8C=20p?= =?UTF-8?q?osType,=20posLevel,=20empPosType,=20empPosLevel)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/DevelopmentController.ts | 285 +++++++++--------- src/entities/ActualGoal.ts | 42 ++- src/entities/PlannedGoalPosition.ts | 42 ++- src/entities/PosLevel.ts | 14 +- src/entities/PosType.ts | 14 +- ...able_actualGoal_and_plannedGoalPosition.ts | 36 +++ 6 files changed, 255 insertions(+), 178 deletions(-) create mode 100644 src/migration/1744342850196-update_table_actualGoal_and_plannedGoalPosition.ts diff --git a/src/controllers/DevelopmentController.ts b/src/controllers/DevelopmentController.ts index 4310ce9..82c6d93 100644 --- a/src/controllers/DevelopmentController.ts +++ b/src/controllers/DevelopmentController.ts @@ -370,44 +370,44 @@ export class DevelopmentController extends Controller { await Promise.all( requestBody.positions.map(async (x) => { const _data = Object.assign(new PlannedGoalPosition(), x); - if (x.posTypePlannedId != null) { - let checkId:any - if(requestBody.groupTarget == "PERSONNEL" && (requestBody.groupTargetSub == "EMPLOYEE" || requestBody.groupTargetSub == "EMPLOYEETEMP")) { - checkId = await this.empPosTypeRepository.findOne({ - where: { id: x.posTypePlannedId }, - }); - if (!checkId) { - throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลกลุ่มงาน"); - } - } - else { - checkId = await this.posTypeRepository.findOne({ - where: { id: x.posTypePlannedId }, - }); - if (!checkId) { - throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลประเภทตำแหน่ง"); - } - } - } - if (x.posLevelPlannedId != null) { - let checkId:any - if (requestBody.groupTarget == "PERSONNEL" && (requestBody.groupTargetSub == "EMPLOYEE" || requestBody.groupTargetSub == "EMPLOYEETEMP")) { - checkId = await this.empPosLevelRepository.findOne({ - where: { id: x.posLevelPlannedId }, - }); - if (!checkId) { - throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลระดับชั้นงาน"); - } - } - else { - checkId = await this.posLevelRepository.findOne({ - where: { id: x.posLevelPlannedId }, - }); - if (!checkId) { - throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลระดับตำแหน่ง"); - } - } - } + // if (x.posTypePlannedId != null) { + // let checkId:any + // if(requestBody.groupTarget == "PERSONNEL" && (requestBody.groupTargetSub == "EMPLOYEE" || requestBody.groupTargetSub == "EMPLOYEETEMP")) { + // checkId = await this.empPosTypeRepository.findOne({ + // where: { id: x.posTypePlannedId }, + // }); + // if (!checkId) { + // throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลกลุ่มงาน"); + // } + // } + // else { + // checkId = await this.posTypeRepository.findOne({ + // where: { id: x.posTypePlannedId }, + // }); + // if (!checkId) { + // throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลประเภทตำแหน่ง"); + // } + // } + // } + // if (x.posLevelPlannedId != null) { + // let checkId:any + // if (requestBody.groupTarget == "PERSONNEL" && (requestBody.groupTargetSub == "EMPLOYEE" || requestBody.groupTargetSub == "EMPLOYEETEMP")) { + // checkId = await this.empPosLevelRepository.findOne({ + // where: { id: x.posLevelPlannedId }, + // }); + // if (!checkId) { + // throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลระดับชั้นงาน"); + // } + // } + // else { + // checkId = await this.posLevelRepository.findOne({ + // where: { id: x.posLevelPlannedId }, + // }); + // if (!checkId) { + // throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลระดับตำแหน่ง"); + // } + // } + // } const before = structuredClone(development); _data.createdUserId = request.user.sub; _data.createdFullName = request.user.name; @@ -492,32 +492,32 @@ export class DevelopmentController extends Controller { if (!development) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงการ/หลักสูตรการฝึกอบรมนี้"); } - if (requestBody.posTypeActualId != null) { - // addLogSequence(request, { - // action: "database", - // status: "success", - // description: "Get Position Type.", - // }); - const checkId = await this.posTypeRepository.findOne({ - where: { id: requestBody.posTypeActualId }, - }); - if (!checkId) { - throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลประเภทตำแหน่ง"); - } - } - if (requestBody.posLevelActualId != null) { - // addLogSequence(request, { - // action: "database", - // status: "success", - // description: "Get Position Level.", - // }); - const checkId = await this.posLevelRepository.findOne({ - where: { id: requestBody.posLevelActualId }, - }); - if (!checkId) { - throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลระดับตำแหน่ง"); - } - } + // if (requestBody.posTypeActualId != null) { + // // addLogSequence(request, { + // // action: "database", + // // status: "success", + // // description: "Get Position Type.", + // // }); + // const checkId = await this.posTypeRepository.findOne({ + // where: { id: requestBody.posTypeActualId }, + // }); + // if (!checkId) { + // throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลประเภทตำแหน่ง"); + // } + // } + // if (requestBody.posLevelActualId != null) { + // // addLogSequence(request, { + // // action: "database", + // // status: "success", + // // description: "Get Position Level.", + // // }); + // const checkId = await this.posLevelRepository.findOne({ + // where: { id: requestBody.posLevelActualId }, + // }); + // if (!checkId) { + // throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลระดับตำแหน่ง"); + // } + // } const before = structuredClone(development); const data = Object.assign(new ActualGoal(), requestBody); data.createdUserId = request.user.sub; @@ -633,44 +633,44 @@ export class DevelopmentController extends Controller { await Promise.all( requestBody.positions.map(async (x) => { const _data = Object.assign(new PlannedGoalPosition(), x); - if (x.posTypePlannedId != null) { - let checkId:any - if(requestBody.groupTarget == "PERSONNEL" && (requestBody.groupTargetSub == "EMPLOYEE" || requestBody.groupTargetSub == "EMPLOYEETEMP")) { - checkId = await this.empPosTypeRepository.findOne({ - where: { id: x.posTypePlannedId }, - }); - if (!checkId) { - throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลกลุ่มงาน"); - } - } - else { - checkId = await this.posTypeRepository.findOne({ - where: { id: x.posTypePlannedId }, - }); - if (!checkId) { - throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลประเภทตำแหน่ง"); - } - } - } - if (x.posLevelPlannedId != null) { - let checkId:any - if (requestBody.groupTarget == "PERSONNEL" && (requestBody.groupTargetSub == "EMPLOYEE" || requestBody.groupTargetSub == "EMPLOYEETEMP")) { - checkId = await this.empPosLevelRepository.findOne({ - where: { id: x.posLevelPlannedId }, - }); - if (!checkId) { - throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลระดับชั้นงาน"); - } - } - else { - checkId = await this.posLevelRepository.findOne({ - where: { id: x.posLevelPlannedId }, - }); - if (!checkId) { - throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลระดับตำแหน่ง"); - } - } - } + // if (x.posTypePlannedId != null) { + // let checkId:any + // if(requestBody.groupTarget == "PERSONNEL" && (requestBody.groupTargetSub == "EMPLOYEE" || requestBody.groupTargetSub == "EMPLOYEETEMP")) { + // checkId = await this.empPosTypeRepository.findOne({ + // where: { id: x.posTypePlannedId }, + // }); + // if (!checkId) { + // throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลกลุ่มงาน"); + // } + // } + // else { + // checkId = await this.posTypeRepository.findOne({ + // where: { id: x.posTypePlannedId }, + // }); + // if (!checkId) { + // throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลประเภทตำแหน่ง"); + // } + // } + // } + // if (x.posLevelPlannedId != null) { + // let checkId:any + // if (requestBody.groupTarget == "PERSONNEL" && (requestBody.groupTargetSub == "EMPLOYEE" || requestBody.groupTargetSub == "EMPLOYEETEMP")) { + // checkId = await this.empPosLevelRepository.findOne({ + // where: { id: x.posLevelPlannedId }, + // }); + // if (!checkId) { + // throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลระดับชั้นงาน"); + // } + // } + // else { + // checkId = await this.posLevelRepository.findOne({ + // where: { id: x.posLevelPlannedId }, + // }); + // if (!checkId) { + // throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลระดับตำแหน่ง"); + // } + // } + // } _data.createdUserId = request.user.sub; _data.createdFullName = request.user.name; _data.lastUpdateUserId = request.user.sub; @@ -759,32 +759,32 @@ export class DevelopmentController extends Controller { if (!development) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงการ/หลักสูตรการฝึกอบรมนี้"); } - if (requestBody.posTypeActualId != null) { - // addLogSequence(request, { - // action: "database", - // status: "success", - // description: "Get Position Type.", - // }); - const checkId = await this.posTypeRepository.findOne({ - where: { id: requestBody.posTypeActualId }, - }); - if (!checkId) { - throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลประเภทตำแหน่ง"); - } - } - if (requestBody.posLevelActualId != null) { - // addLogSequence(request, { - // action: "database", - // status: "success", - // description: "Get Position Level.", - // }); - const checkId = await this.posLevelRepository.findOne({ - where: { id: requestBody.posLevelActualId }, - }); - if (!checkId) { - throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลระดับตำแหน่ง"); - } - } + // if (requestBody.posTypeActualId != null) { + // // addLogSequence(request, { + // // action: "database", + // // status: "success", + // // description: "Get Position Type.", + // // }); + // const checkId = await this.posTypeRepository.findOne({ + // where: { id: requestBody.posTypeActualId }, + // }); + // if (!checkId) { + // throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลประเภทตำแหน่ง"); + // } + // } + // if (requestBody.posLevelActualId != null) { + // // addLogSequence(request, { + // // action: "database", + // // status: "success", + // // description: "Get Position Level.", + // // }); + // const checkId = await this.posLevelRepository.findOne({ + // where: { id: requestBody.posLevelActualId }, + // }); + // if (!checkId) { + // throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลระดับตำแหน่ง"); + // } + // } const before = structuredClone(development); Object.assign(development, requestBody); development.lastUpdateUserId = request.user.sub; @@ -2164,17 +2164,18 @@ export class DevelopmentController extends Controller { if (_workflow == false) await new permission().PermissionGet(request, "SYS_DEV_PROJECT"); const getDevelopment = await this.developmentRepository.findOne({ where: { id: id }, + //posTypeActual relations: [ "developmentActualPeoples", "developmentPlannedPeoples", "developmentActualGoals", - "developmentActualGoals.posTypeActual", - "developmentActualGoals.posLevelActual", + // "developmentActualGoals.posTypeActual", + // "developmentActualGoals.posLevelActual", "developmentActualGoals", "developmentPlannedGoals", "developmentPlannedGoals.plannedGoalPositions", - "developmentPlannedGoals.plannedGoalPositions.posTypePlanned", - "developmentPlannedGoals.plannedGoalPositions.posLevelPlanned", + // "developmentPlannedGoals.plannedGoalPositions.posTypePlanned", + // "developmentPlannedGoals.plannedGoalPositions.posLevelPlanned", ], }); if (!getDevelopment) { @@ -2212,10 +2213,12 @@ export class DevelopmentController extends Controller { groupTarget: x.groupTarget, groupTargetSub: x.groupTargetSub, position: x.position, - posTypeId: x.posTypeActualId, - posType: x.posTypeActual == null ? null : x.posTypeActual.posTypeName, - posLevelId: x.posLevelActualId, - posLevel: x.posLevelActual == null ? null : x.posLevelActual.posLevelName, + // posTypeId: x.posTypeActualId, + // posType: x.posTypeActual == null ? null : x.posTypeActual.posTypeName, + // posLevelId: x.posLevelActualId, + // posLevel: x.posLevelActual == null ? null : x.posLevelActual.posLevelName, + posType: x.posTypeActual, + posLevel: x.posLevelActual, type: x.type, amount: x.amount, })), @@ -2237,10 +2240,12 @@ export class DevelopmentController extends Controller { id: y.id, position: y.position, posExecutive: y.posExecutive, - posTypeId: y.posTypePlannedId, - posType: y.posTypePlanned == null ? null : y.posTypePlanned.posTypeName, - posLevelId: y.posLevelPlannedId, - posLevel: y.posLevelPlanned == null ? null : y.posLevelPlanned.posLevelName, + // posTypeId: y.posTypePlannedId, + // posType: y.posTypePlanned == null ? null : y.posTypePlanned.posTypeName, + // posLevelId: y.posLevelPlannedId, + // posLevel: y.posLevelPlanned == null ? null : y.posLevelPlanned.posLevelName, + posType: y.posTypePlanned, + posLevel: y.posLevelPlanned, })), amount: x.amount, })), diff --git a/src/entities/ActualGoal.ts b/src/entities/ActualGoal.ts index cbe85aa..2fe2589 100644 --- a/src/entities/ActualGoal.ts +++ b/src/entities/ActualGoal.ts @@ -29,25 +29,39 @@ export class ActualGoal extends EntityBase { @Column({ nullable: true, - comment: "ประเภทตำแหน่ง", + comment: "ประเภทตำแหน่ง & กลุ่มงาน", default: null, }) - posTypeActualId: string; + posTypeActual: string; + + // @Column({ + // nullable: true, + // comment: "ประเภทตำแหน่ง", + // default: null, + // }) + // posTypeActualId: string; - @ManyToOne(() => PosType, (posType: PosType) => posType.actualGoals) - @JoinColumn({ name: "posTypeActualId" }) - posTypeActual: PosType; + // @ManyToOne(() => PosType, (posType: PosType) => posType.actualGoals) + // @JoinColumn({ name: "posTypeActualId" }) + // posTypeActual: PosType; @Column({ nullable: true, - comment: "ระดับตำแหน่ง", + comment: "ระดับตำแหน่ง & ระดับชั้นงาน", default: null, }) - posLevelActualId: string; + posLevelActual: string; - @ManyToOne(() => PosLevel, (posLevel: PosLevel) => posLevel.actualGoals) - @JoinColumn({ name: "posLevelActualId" }) - posLevelActual: PosLevel; + // @Column({ + // nullable: true, + // comment: "ระดับตำแหน่ง", + // default: null, + // }) + // posLevelActualId: string; + + // @ManyToOne(() => PosLevel, (posLevel: PosLevel) => posLevel.actualGoals) + // @JoinColumn({ name: "posLevelActualId" }) + // posLevelActual: PosLevel; @Column({ nullable: true, @@ -82,10 +96,14 @@ export class CreateActualGoal { groupTargetSub: string | null; @Column() position: string | null; + // @Column() + // posTypeActualId: string | null; + // @Column() + // posLevelActualId: string | null; @Column() - posTypeActualId: string | null; + posTypeActual: string | null; @Column() - posLevelActualId: string | null; + posLevelActual: string | null; @Column() type: string | null; @Column() diff --git a/src/entities/PlannedGoalPosition.ts b/src/entities/PlannedGoalPosition.ts index 990c977..a5df81d 100644 --- a/src/entities/PlannedGoalPosition.ts +++ b/src/entities/PlannedGoalPosition.ts @@ -22,25 +22,39 @@ export class PlannedGoalPosition extends EntityBase { @Column({ nullable: true, - comment: "ประเภทตำแหน่ง", + comment: "ประเภทตำแหน่ง & กลุ่มงาน", default: null, }) - posTypePlannedId: string; + posTypePlanned: string; - @ManyToOne(() => PosType, (posType: PosType) => posType.plannedGoalPositions) - @JoinColumn({ name: "posTypePlannedId" }) - posTypePlanned: PosType; + // @Column({ + // nullable: true, + // comment: "ประเภทตำแหน่ง", + // default: null, + // }) + // posTypePlannedId: string; + + // @ManyToOne(() => PosType, (posType: PosType) => posType.plannedGoalPositions) + // @JoinColumn({ name: "posTypePlannedId" }) + // posTypePlanned: PosType; @Column({ nullable: true, - comment: "ระดับตำแหน่ง", + comment: "ระดับตำแหน่ง & ระดับชั้นงาน", default: null, }) - posLevelPlannedId: string; + posLevelPlanned: string; - @ManyToOne(() => PosLevel, (posLevel: PosLevel) => posLevel.plannedGoalPositions) - @JoinColumn({ name: "posLevelPlannedId" }) - posLevelPlanned: PosLevel; + // @Column({ + // nullable: true, + // comment: "ระดับตำแหน่ง", + // default: null, + // }) + // posLevelPlannedId: string; + + // @ManyToOne(() => PosLevel, (posLevel: PosLevel) => posLevel.plannedGoalPositions) + // @JoinColumn({ name: "posLevelPlannedId" }) + // posLevelPlanned: PosLevel; @Column({ nullable: true, @@ -59,10 +73,14 @@ export class CreatePlannedGoalPosition { position: string | null; @Column() posExecutive: string | null; + // @Column() + // posTypePlannedId: string | null; + // @Column() + // posLevelPlannedId: string | null; @Column() - posTypePlannedId: string | null; + posTypePlanned: string | null; @Column() - posLevelPlannedId: string | null; + posLevelPlanned: string | null; } export type UpdatePlannedGoalPosition = Partial; diff --git a/src/entities/PosLevel.ts b/src/entities/PosLevel.ts index 705b6b8..3c686fa 100644 --- a/src/entities/PosLevel.ts +++ b/src/entities/PosLevel.ts @@ -48,14 +48,14 @@ export class PosLevel extends EntityBase { @JoinColumn({ name: "posTypeId" }) posType: PosType; - @OneToMany(() => ActualGoal, (actualGoal: ActualGoal) => actualGoal.posLevelActual) - actualGoals: ActualGoal[]; + // @OneToMany(() => ActualGoal, (actualGoal: ActualGoal) => actualGoal.posLevelActual) + // actualGoals: ActualGoal[]; - @OneToMany( - () => PlannedGoalPosition, - (plannedGoalPosition: PlannedGoalPosition) => plannedGoalPosition.posLevelPlanned, - ) - plannedGoalPositions: PlannedGoalPosition[]; + // @OneToMany( + // () => PlannedGoalPosition, + // (plannedGoalPosition: PlannedGoalPosition) => plannedGoalPosition.posLevelPlanned, + // ) + // plannedGoalPositions: PlannedGoalPosition[]; @OneToMany(() => DevelopmentHistory, (developmentHistory) => developmentHistory.posLevel) developmentHistorys: DevelopmentHistory[]; diff --git a/src/entities/PosType.ts b/src/entities/PosType.ts index d18e7fb..b28047b 100644 --- a/src/entities/PosType.ts +++ b/src/entities/PosType.ts @@ -28,14 +28,14 @@ export class PosType extends EntityBase { @OneToMany(() => PosLevel, (posLevel: PosLevel) => posLevel.posType) posLevels: PosLevel[]; - @OneToMany(() => ActualGoal, (actualGoal: ActualGoal) => actualGoal.posTypeActual) - actualGoals: ActualGoal[]; + // @OneToMany(() => ActualGoal, (actualGoal: ActualGoal) => actualGoal.posTypeActual) + // actualGoals: ActualGoal[]; - @OneToMany( - () => PlannedGoalPosition, - (plannedGoalPosition: PlannedGoalPosition) => plannedGoalPosition.posTypePlanned, - ) - plannedGoalPositions: PlannedGoalPosition[]; + // @OneToMany( + // () => PlannedGoalPosition, + // (plannedGoalPosition: PlannedGoalPosition) => plannedGoalPosition.posTypePlanned, + // ) + // plannedGoalPositions: PlannedGoalPosition[]; @OneToMany(() => DevelopmentHistory, (developmentHistory) => developmentHistory.posType) developmentHistorys: DevelopmentHistory[]; diff --git a/src/migration/1744342850196-update_table_actualGoal_and_plannedGoalPosition.ts b/src/migration/1744342850196-update_table_actualGoal_and_plannedGoalPosition.ts new file mode 100644 index 0000000..2888b6f --- /dev/null +++ b/src/migration/1744342850196-update_table_actualGoal_and_plannedGoalPosition.ts @@ -0,0 +1,36 @@ +import { MigrationInterface, QueryRunner } from "typeorm"; + +export class UpdateTableActualGoalAndPlannedGoalPosition1744342850196 implements MigrationInterface { + name = 'UpdateTableActualGoalAndPlannedGoalPosition1744342850196' + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`actualGoal\` DROP FOREIGN KEY \`FK_a9a864dd06eaa25edba8be8f24c\``); + await queryRunner.query(`ALTER TABLE \`actualGoal\` DROP FOREIGN KEY \`FK_e08e337e5ddeb4942c72393ff58\``); + await queryRunner.query(`ALTER TABLE \`plannedGoalPosition\` DROP FOREIGN KEY \`FK_4eef5d8c3ab92f7af4a762150a4\``); + await queryRunner.query(`ALTER TABLE \`plannedGoalPosition\` DROP FOREIGN KEY \`FK_8e7e0bf6eebd99f58e9b47c6b05\``); + await queryRunner.query(`ALTER TABLE \`actualGoal\` DROP COLUMN \`posLevelActualId\``); + await queryRunner.query(`ALTER TABLE \`actualGoal\` DROP COLUMN \`posTypeActualId\``); + await queryRunner.query(`ALTER TABLE \`plannedGoalPosition\` DROP COLUMN \`posLevelPlannedId\``); + await queryRunner.query(`ALTER TABLE \`plannedGoalPosition\` DROP COLUMN \`posTypePlannedId\``); + await queryRunner.query(`ALTER TABLE \`actualGoal\` ADD \`posTypeActual\` varchar(255) NULL COMMENT 'ประเภทตำแหน่ง & กลุ่มงาน'`); + await queryRunner.query(`ALTER TABLE \`actualGoal\` ADD \`posLevelActual\` varchar(255) NULL COMMENT 'ระดับตำแหน่ง & ระดับชั้นงาน'`); + await queryRunner.query(`ALTER TABLE \`plannedGoalPosition\` ADD \`posTypePlanned\` varchar(255) NULL COMMENT 'ประเภทตำแหน่ง & กลุ่มงาน'`); + await queryRunner.query(`ALTER TABLE \`plannedGoalPosition\` ADD \`posLevelPlanned\` varchar(255) NULL COMMENT 'ระดับตำแหน่ง & ระดับชั้นงาน'`); + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`plannedGoalPosition\` DROP COLUMN \`posLevelPlanned\``); + await queryRunner.query(`ALTER TABLE \`plannedGoalPosition\` DROP COLUMN \`posTypePlanned\``); + await queryRunner.query(`ALTER TABLE \`actualGoal\` DROP COLUMN \`posLevelActual\``); + await queryRunner.query(`ALTER TABLE \`actualGoal\` DROP COLUMN \`posTypeActual\``); + await queryRunner.query(`ALTER TABLE \`plannedGoalPosition\` ADD \`posTypePlannedId\` varchar(255) NULL COMMENT 'ประเภทตำแหน่ง'`); + await queryRunner.query(`ALTER TABLE \`plannedGoalPosition\` ADD \`posLevelPlannedId\` varchar(255) NULL COMMENT 'ระดับตำแหน่ง'`); + await queryRunner.query(`ALTER TABLE \`actualGoal\` ADD \`posTypeActualId\` varchar(255) NULL COMMENT 'ประเภทตำแหน่ง'`); + await queryRunner.query(`ALTER TABLE \`actualGoal\` ADD \`posLevelActualId\` varchar(255) NULL COMMENT 'ระดับตำแหน่ง'`); + await queryRunner.query(`ALTER TABLE \`plannedGoalPosition\` ADD CONSTRAINT \`FK_8e7e0bf6eebd99f58e9b47c6b05\` FOREIGN KEY (\`posLevelPlannedId\`) REFERENCES \`posLevel\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`); + await queryRunner.query(`ALTER TABLE \`plannedGoalPosition\` ADD CONSTRAINT \`FK_4eef5d8c3ab92f7af4a762150a4\` FOREIGN KEY (\`posTypePlannedId\`) REFERENCES \`posType\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`); + await queryRunner.query(`ALTER TABLE \`actualGoal\` ADD CONSTRAINT \`FK_e08e337e5ddeb4942c72393ff58\` FOREIGN KEY (\`posTypeActualId\`) REFERENCES \`posType\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`); + await queryRunner.query(`ALTER TABLE \`actualGoal\` ADD CONSTRAINT \`FK_a9a864dd06eaa25edba8be8f24c\` FOREIGN KEY (\`posLevelActualId\`) REFERENCES \`posLevel\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`); + } + +} From 2e7bef04759a5f4108a46bf72e959fc9792e847d Mon Sep 17 00:00:00 2001 From: Bright Date: Fri, 11 Apr 2025 15:38:32 +0700 Subject: [PATCH 230/250] validate --- src/controllers/DevelopmentController.ts | 320 ++++++++++++++--------- 1 file changed, 192 insertions(+), 128 deletions(-) diff --git a/src/controllers/DevelopmentController.ts b/src/controllers/DevelopmentController.ts index 82c6d93..82a70e9 100644 --- a/src/controllers/DevelopmentController.ts +++ b/src/controllers/DevelopmentController.ts @@ -370,44 +370,54 @@ export class DevelopmentController extends Controller { await Promise.all( requestBody.positions.map(async (x) => { const _data = Object.assign(new PlannedGoalPosition(), x); - // if (x.posTypePlannedId != null) { - // let checkId:any - // if(requestBody.groupTarget == "PERSONNEL" && (requestBody.groupTargetSub == "EMPLOYEE" || requestBody.groupTargetSub == "EMPLOYEETEMP")) { - // checkId = await this.empPosTypeRepository.findOne({ - // where: { id: x.posTypePlannedId }, - // }); - // if (!checkId) { - // throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลกลุ่มงาน"); - // } - // } - // else { - // checkId = await this.posTypeRepository.findOne({ - // where: { id: x.posTypePlannedId }, - // }); - // if (!checkId) { - // throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลประเภทตำแหน่ง"); - // } - // } - // } - // if (x.posLevelPlannedId != null) { - // let checkId:any - // if (requestBody.groupTarget == "PERSONNEL" && (requestBody.groupTargetSub == "EMPLOYEE" || requestBody.groupTargetSub == "EMPLOYEETEMP")) { - // checkId = await this.empPosLevelRepository.findOne({ - // where: { id: x.posLevelPlannedId }, - // }); - // if (!checkId) { - // throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลระดับชั้นงาน"); - // } - // } - // else { - // checkId = await this.posLevelRepository.findOne({ - // where: { id: x.posLevelPlannedId }, - // }); - // if (!checkId) { - // throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลระดับตำแหน่ง"); - // } - // } - // } + let checkPosType:any = null + let posTypeShortName:any = null + if (x.posTypePlanned != null) { + if(requestBody.groupTarget == "PERSONNEL" && + (requestBody.groupTargetSub == "EMPLOYEE" || requestBody.groupTargetSub == "EMPLOYEETEMP")) { + checkPosType = await this.empPosTypeRepository.findOne({ + where: { posTypeName: x.posTypePlanned }, + }); + if (!checkPosType) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลกลุ่มงาน"); + } + posTypeShortName = checkPosType.posTypeShortName + } + else { + checkPosType = await this.posTypeRepository.findOne({ + where: { posTypeName: x.posTypePlanned }, + }); + if (!checkPosType) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลประเภทตำแหน่ง"); + } + } + } + if (x.posLevelPlanned != null) { + let checkPosLevel:any + if (requestBody.groupTarget == "PERSONNEL" && + (requestBody.groupTargetSub == "EMPLOYEE" || requestBody.groupTargetSub == "EMPLOYEETEMP")) { + checkPosLevel = await this.empPosLevelRepository.find({ + where: { + posTypeId: checkPosType.id + }, + }); + const mapShortName = checkPosLevel.flatMap((x:any) => `${posTypeShortName} ${x.posLevelName}`); + if (checkPosLevel.length == 0 /*|| !mapShortName.includes(x.posLevelPlanned)*/) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลระดับชั้นงาน"); + } + } + else { + checkPosLevel = await this.posLevelRepository.findOne({ + where: { + posLevelName: x.posLevelPlanned, + posTypeId: checkPosType.id + }, + }); + if (!checkPosLevel) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลระดับตำแหน่ง"); + } + } + } const before = structuredClone(development); _data.createdUserId = request.user.sub; _data.createdFullName = request.user.name; @@ -492,32 +502,54 @@ export class DevelopmentController extends Controller { if (!development) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงการ/หลักสูตรการฝึกอบรมนี้"); } - // if (requestBody.posTypeActualId != null) { - // // addLogSequence(request, { - // // action: "database", - // // status: "success", - // // description: "Get Position Type.", - // // }); - // const checkId = await this.posTypeRepository.findOne({ - // where: { id: requestBody.posTypeActualId }, - // }); - // if (!checkId) { - // throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลประเภทตำแหน่ง"); - // } - // } - // if (requestBody.posLevelActualId != null) { - // // addLogSequence(request, { - // // action: "database", - // // status: "success", - // // description: "Get Position Level.", - // // }); - // const checkId = await this.posLevelRepository.findOne({ - // where: { id: requestBody.posLevelActualId }, - // }); - // if (!checkId) { - // throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลระดับตำแหน่ง"); - // } - // } + let checkPosType:any = null + let posTypeShortName:any = null + if (requestBody.posTypeActual != null) { + if(requestBody.groupTarget == "PERSONNEL" && + (requestBody.groupTargetSub == "EMPLOYEE" || requestBody.groupTargetSub == "EMPLOYEETEMP")) { + checkPosType = await this.empPosTypeRepository.findOne({ + where: { posTypeName: requestBody.posTypeActual }, + }); + if (!checkPosType) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลกลุ่มงาน"); + } + posTypeShortName = checkPosType.posTypeShortName + } + else { + checkPosType = await this.posTypeRepository.findOne({ + where: { posTypeName: requestBody.posTypeActual }, + }); + if (!checkPosType) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลประเภทตำแหน่ง"); + } + } + } + if (requestBody.posLevelActual != null) { + let checkPosLevel:any + if (requestBody.groupTarget == "PERSONNEL" && + (requestBody.groupTargetSub == "EMPLOYEE" || requestBody.groupTargetSub == "EMPLOYEETEMP")) { + checkPosLevel = await this.empPosLevelRepository.find({ + where: { + posTypeId: checkPosType.id + }, + }); + const mapShortName = checkPosLevel.flatMap((x:any) => `${posTypeShortName} ${x.posLevelName}`); + if (checkPosLevel.length == 0 /*|| !mapShortName.includes(x.posLevelPlanned)*/) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลระดับชั้นงาน"); + } + } + else { + checkPosLevel = await this.posLevelRepository.findOne({ + where: { + posLevelName: requestBody.posLevelActual, + posTypeId: checkPosType.id + }, + }); + if (!checkPosLevel) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลระดับตำแหน่ง"); + } + } + } const before = structuredClone(development); const data = Object.assign(new ActualGoal(), requestBody); data.createdUserId = request.user.sub; @@ -633,44 +665,54 @@ export class DevelopmentController extends Controller { await Promise.all( requestBody.positions.map(async (x) => { const _data = Object.assign(new PlannedGoalPosition(), x); - // if (x.posTypePlannedId != null) { - // let checkId:any - // if(requestBody.groupTarget == "PERSONNEL" && (requestBody.groupTargetSub == "EMPLOYEE" || requestBody.groupTargetSub == "EMPLOYEETEMP")) { - // checkId = await this.empPosTypeRepository.findOne({ - // where: { id: x.posTypePlannedId }, - // }); - // if (!checkId) { - // throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลกลุ่มงาน"); - // } - // } - // else { - // checkId = await this.posTypeRepository.findOne({ - // where: { id: x.posTypePlannedId }, - // }); - // if (!checkId) { - // throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลประเภทตำแหน่ง"); - // } - // } - // } - // if (x.posLevelPlannedId != null) { - // let checkId:any - // if (requestBody.groupTarget == "PERSONNEL" && (requestBody.groupTargetSub == "EMPLOYEE" || requestBody.groupTargetSub == "EMPLOYEETEMP")) { - // checkId = await this.empPosLevelRepository.findOne({ - // where: { id: x.posLevelPlannedId }, - // }); - // if (!checkId) { - // throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลระดับชั้นงาน"); - // } - // } - // else { - // checkId = await this.posLevelRepository.findOne({ - // where: { id: x.posLevelPlannedId }, - // }); - // if (!checkId) { - // throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลระดับตำแหน่ง"); - // } - // } - // } + let checkPosType:any = null + let posTypeShortName:any = null + if (x.posTypePlanned != null) { + if(requestBody.groupTarget == "PERSONNEL" && + (requestBody.groupTargetSub == "EMPLOYEE" || requestBody.groupTargetSub == "EMPLOYEETEMP")) { + checkPosType = await this.empPosTypeRepository.findOne({ + where: { posTypeName: x.posTypePlanned }, + }); + if (!checkPosType) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลกลุ่มงาน"); + } + posTypeShortName = checkPosType.posTypeShortName + } + else { + checkPosType = await this.posTypeRepository.findOne({ + where: { posTypeName: x.posTypePlanned }, + }); + if (!checkPosType) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลประเภทตำแหน่ง"); + } + } + } + if (x.posLevelPlanned != null) { + let checkPosLevel:any + if (requestBody.groupTarget == "PERSONNEL" && + (requestBody.groupTargetSub == "EMPLOYEE" || requestBody.groupTargetSub == "EMPLOYEETEMP")) { + checkPosLevel = await this.empPosLevelRepository.find({ + where: { + posTypeId: checkPosType.id + }, + }); + const mapShortName = checkPosLevel.flatMap((x:any) => `${posTypeShortName} ${x.posLevelName}`); + if (checkPosLevel.length == 0 /*|| !mapShortName.includes(x.posLevelPlanned)*/) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลระดับชั้นงาน"); + } + } + else { + checkPosLevel = await this.posLevelRepository.findOne({ + where: { + posLevelName: x.posLevelPlanned, + posTypeId: checkPosType.id + }, + }); + if (!checkPosLevel) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลระดับตำแหน่ง"); + } + } + } _data.createdUserId = request.user.sub; _data.createdFullName = request.user.name; _data.lastUpdateUserId = request.user.sub; @@ -759,32 +801,54 @@ export class DevelopmentController extends Controller { if (!development) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงการ/หลักสูตรการฝึกอบรมนี้"); } - // if (requestBody.posTypeActualId != null) { - // // addLogSequence(request, { - // // action: "database", - // // status: "success", - // // description: "Get Position Type.", - // // }); - // const checkId = await this.posTypeRepository.findOne({ - // where: { id: requestBody.posTypeActualId }, - // }); - // if (!checkId) { - // throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลประเภทตำแหน่ง"); - // } - // } - // if (requestBody.posLevelActualId != null) { - // // addLogSequence(request, { - // // action: "database", - // // status: "success", - // // description: "Get Position Level.", - // // }); - // const checkId = await this.posLevelRepository.findOne({ - // where: { id: requestBody.posLevelActualId }, - // }); - // if (!checkId) { - // throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลระดับตำแหน่ง"); - // } - // } + let checkPosType:any = null + let posTypeShortName:any = null + if (requestBody.posTypeActual != null) { + if(requestBody.groupTarget == "PERSONNEL" && + (requestBody.groupTargetSub == "EMPLOYEE" || requestBody.groupTargetSub == "EMPLOYEETEMP")) { + checkPosType = await this.empPosTypeRepository.findOne({ + where: { posTypeName: requestBody.posTypeActual }, + }); + if (!checkPosType) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลกลุ่มงาน"); + } + posTypeShortName = checkPosType.posTypeShortName + } + else { + checkPosType = await this.posTypeRepository.findOne({ + where: { posTypeName: requestBody.posTypeActual }, + }); + if (!checkPosType) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลประเภทตำแหน่ง"); + } + } + } + if (requestBody.posLevelActual != null) { + let checkPosLevel:any + if (requestBody.groupTarget == "PERSONNEL" && + (requestBody.groupTargetSub == "EMPLOYEE" || requestBody.groupTargetSub == "EMPLOYEETEMP")) { + checkPosLevel = await this.empPosLevelRepository.find({ + where: { + posTypeId: checkPosType.id + }, + }); + const mapShortName = checkPosLevel.flatMap((x:any) => `${posTypeShortName} ${x.posLevelName}`); + if (checkPosLevel.length == 0 /*|| !mapShortName.includes(x.posLevelPlanned)*/) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลระดับชั้นงาน"); + } + } + else { + checkPosLevel = await this.posLevelRepository.findOne({ + where: { + posLevelName: requestBody.posLevelActual, + posTypeId: checkPosType.id + }, + }); + if (!checkPosLevel) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลระดับตำแหน่ง"); + } + } + } const before = structuredClone(development); Object.assign(development, requestBody); development.lastUpdateUserId = request.user.sub; From 2eec9e5f602886e4f8e6e91268d9ccb2911bb4b9 Mon Sep 17 00:00:00 2001 From: Bright Date: Fri, 11 Apr 2025 15:46:28 +0700 Subject: [PATCH 231/250] no message --- src/controllers/DevelopmentController.ts | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/controllers/DevelopmentController.ts b/src/controllers/DevelopmentController.ts index 82a70e9..dadb34e 100644 --- a/src/controllers/DevelopmentController.ts +++ b/src/controllers/DevelopmentController.ts @@ -372,7 +372,7 @@ export class DevelopmentController extends Controller { const _data = Object.assign(new PlannedGoalPosition(), x); let checkPosType:any = null let posTypeShortName:any = null - if (x.posTypePlanned != null) { + if (x.posTypePlanned) { if(requestBody.groupTarget == "PERSONNEL" && (requestBody.groupTargetSub == "EMPLOYEE" || requestBody.groupTargetSub == "EMPLOYEETEMP")) { checkPosType = await this.empPosTypeRepository.findOne({ @@ -392,7 +392,7 @@ export class DevelopmentController extends Controller { } } } - if (x.posLevelPlanned != null) { + if (x.posLevelPlanned) { let checkPosLevel:any if (requestBody.groupTarget == "PERSONNEL" && (requestBody.groupTargetSub == "EMPLOYEE" || requestBody.groupTargetSub == "EMPLOYEETEMP")) { @@ -504,7 +504,7 @@ export class DevelopmentController extends Controller { } let checkPosType:any = null let posTypeShortName:any = null - if (requestBody.posTypeActual != null) { + if (requestBody.posTypeActual) { if(requestBody.groupTarget == "PERSONNEL" && (requestBody.groupTargetSub == "EMPLOYEE" || requestBody.groupTargetSub == "EMPLOYEETEMP")) { checkPosType = await this.empPosTypeRepository.findOne({ @@ -524,7 +524,7 @@ export class DevelopmentController extends Controller { } } } - if (requestBody.posLevelActual != null) { + if (requestBody.posLevelActual) { let checkPosLevel:any if (requestBody.groupTarget == "PERSONNEL" && (requestBody.groupTargetSub == "EMPLOYEE" || requestBody.groupTargetSub == "EMPLOYEETEMP")) { @@ -667,7 +667,7 @@ export class DevelopmentController extends Controller { const _data = Object.assign(new PlannedGoalPosition(), x); let checkPosType:any = null let posTypeShortName:any = null - if (x.posTypePlanned != null) { + if (x.posTypePlanned) { if(requestBody.groupTarget == "PERSONNEL" && (requestBody.groupTargetSub == "EMPLOYEE" || requestBody.groupTargetSub == "EMPLOYEETEMP")) { checkPosType = await this.empPosTypeRepository.findOne({ @@ -687,7 +687,7 @@ export class DevelopmentController extends Controller { } } } - if (x.posLevelPlanned != null) { + if (x.posLevelPlanned) { let checkPosLevel:any if (requestBody.groupTarget == "PERSONNEL" && (requestBody.groupTargetSub == "EMPLOYEE" || requestBody.groupTargetSub == "EMPLOYEETEMP")) { @@ -803,7 +803,7 @@ export class DevelopmentController extends Controller { } let checkPosType:any = null let posTypeShortName:any = null - if (requestBody.posTypeActual != null) { + if (requestBody.posTypeActual) { if(requestBody.groupTarget == "PERSONNEL" && (requestBody.groupTargetSub == "EMPLOYEE" || requestBody.groupTargetSub == "EMPLOYEETEMP")) { checkPosType = await this.empPosTypeRepository.findOne({ @@ -823,7 +823,7 @@ export class DevelopmentController extends Controller { } } } - if (requestBody.posLevelActual != null) { + if (requestBody.posLevelActual) { let checkPosLevel:any if (requestBody.groupTarget == "PERSONNEL" && (requestBody.groupTargetSub == "EMPLOYEE" || requestBody.groupTargetSub == "EMPLOYEETEMP")) { From bb6364e7c0fdf3eaa91e091a89a3640e6c06c461 Mon Sep 17 00:00:00 2001 From: AdisakKanthawilang Date: Thu, 17 Apr 2025 14:33:12 +0700 Subject: [PATCH 232/250] fix --- src/controllers/ReportController.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/controllers/ReportController.ts b/src/controllers/ReportController.ts index 3f1183d..7ad3c23 100644 --- a/src/controllers/ReportController.ts +++ b/src/controllers/ReportController.ts @@ -590,15 +590,15 @@ export class ReportController extends Controller { break; case "NOABROAD": getDevelopment.scholarshipType = - "ฝึกอบรมในประเทศที่ส่งไปพัฒนากับหน่วยวงานภายนอก (หลักสูตรที่ไม่มีการไปต่างประเทศ)"; + "ฝึกอบรมในประเทศที่ส่งไปพัฒนากับหน่วยงานภายนอก (หลักสูตรที่ไม่มีการไปต่างประเทศ)"; break; case "ABROAD": getDevelopment.scholarshipType = - "ฝึกอบรมในประเทศที่ส่งไปพัฒนากับหน่วยวงานภายนอก (หลักสูตรที่มีการไปต่างประเทศ)"; + "ฝึกอบรมในประเทศที่ส่งไปพัฒนากับหน่วยงานภายนอก (หลักสูตรที่มีการไปต่างประเทศ)"; break; case "EXECUTIVE": getDevelopment.scholarshipType = - "ฝึกอบรมในประเทศที่ส่งไปพัฒนากับหน่วยวงานภายนอก (หลักสูตรประเภทนักบริหาร)"; + "ฝึกอบรมในประเทศที่ส่งไปพัฒนากับหน่วยงานภายนอก (หลักสูตรประเภทนักบริหาร)"; break; case "RESEARCH": getDevelopment.scholarshipType = @@ -608,13 +608,13 @@ export class ReportController extends Controller { break; } } - + let _orgNoNewLine = (getDevelopment.org ? getDevelopment.org : "-").replace(/\n/g, " "); const formattedData = { id: getDevelopment.id, firstName: getDevelopment.firstName, lastName: getDevelopment.lastName, position: getDevelopment.position, - org: getDevelopment.org, + org: _orgNoNewLine, degreeLevel: getDevelopment.degreeLevel, course: getDevelopment.course, field: getDevelopment.field, From 101eabbac0ba711dbe3c2bce40b31007dde7fa50 Mon Sep 17 00:00:00 2001 From: AdisakKanthawilang Date: Fri, 18 Apr 2025 14:34:11 +0700 Subject: [PATCH 233/250] add api portfolio/user --- src/controllers/PortfolioController.ts | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/controllers/PortfolioController.ts b/src/controllers/PortfolioController.ts index d027420..294b7f6 100644 --- a/src/controllers/PortfolioController.ts +++ b/src/controllers/PortfolioController.ts @@ -59,6 +59,30 @@ export class PortfolioController extends Controller { return new HttpSuccess(_portfolio); } + /** + * API list รายการผลงานสำหรับระบบประเมิน + * + * @summary list รายการผลงานสำหรับระบบประเมิน + * + */ + @Get("user") + async GetResultForEva(@Request() request: RequestWithUser) { + const _portfolio = await this.portfolioRepository.find({ + where: { createdUserId: request.user.sub }, + select: [ + "id", + "name", + "detail", + "createdAt", + "lastUpdatedAt", + "createdFullName", + "lastUpdateFullName", + ], + order: { createdAt: "DESC" }, + }); + return new HttpSuccess(_portfolio); + } + /** * API รายละเอียดรายการผลงาน * From 8c7cbef72b6715446b0eb9d874378b6181dbc0fd Mon Sep 17 00:00:00 2001 From: Bright Date: Tue, 22 Apr 2025 10:14:31 +0700 Subject: [PATCH 234/250] =?UTF-8?q?[Edit=20SIT=20=E0=B8=A3=E0=B8=B0?= =?UTF-8?q?=E0=B8=9A=E0=B8=9A=E0=B8=9E=E0=B8=B1=E0=B8=92=E0=B8=99=E0=B8=B2?= =?UTF-8?q?]=20=E0=B8=A3=E0=B8=B2=E0=B8=A2=E0=B8=81=E0=B8=B2=E0=B8=A3?= =?UTF-8?q?=E0=B8=97=E0=B8=B5=E0=B9=88=E0=B8=95=E0=B9=89=E0=B8=AD=E0=B8=87?= =?UTF-8?q?=E0=B9=81=E0=B8=81=E0=B9=89=E0=B9=84=E0=B8=82=20#1331?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/DevelopmentController.ts | 10 ++++--- .../DevelopmentScholarshipController.ts | 4 +-- src/controllers/ReportController.ts | 2 +- src/entities/DevelopmentAddress.ts | 26 ++++++++++++++++++- src/entities/DevelopmentScholarship.ts | 16 +++++++++--- ...ddress_and_developScholaship_add_fields.ts | 24 +++++++++++++++++ 6 files changed, 71 insertions(+), 11 deletions(-) create mode 100644 src/migration/1745290442590-update_table_developAddress_and_developScholaship_add_fields.ts diff --git a/src/controllers/DevelopmentController.ts b/src/controllers/DevelopmentController.ts index dadb34e..a18787a 100644 --- a/src/controllers/DevelopmentController.ts +++ b/src/controllers/DevelopmentController.ts @@ -2568,9 +2568,9 @@ export class DevelopmentController extends Controller { } /** - * API รายละเอียดโครงการ/หลักสูตรการฝึกอบรม tab6 ส่งบันทึกทะเบียนประวัติ + * API รายละเอียดโครงการ/หลักสูตรการฝึกอบรม tab6 ส่งบันทึกทะเบียนประวัติ (ข้อมูลผลงาน>การฝึกอบรม/ดูงาน) * - * @summary DEV_00 - รายละเอียดโครงการ/หลักสูตรการฝึกอบรมtab6 ส่งบันทึกทะเบียนประวัติ # + * @summary DEV_00 - รายละเอียดโครงการ/หลักสูตรการฝึกอบรมtab6 ส่งบันทึกทะเบียนประวัติ (ข้อมูลผลงาน>การฝึกอบรม/ดูงาน) # * * @param {string} id Id โครงการ */ @@ -2598,6 +2598,7 @@ export class DevelopmentController extends Controller { startDate: x.dateStart, endDate: x.dateEnd, isDate: true, + developmentId: id }) .then((x) => { _data.isDone = true; @@ -2620,6 +2621,7 @@ export class DevelopmentController extends Controller { startDate: x.dateStart, endDate: x.dateEnd, isDate: true, + developmentId: id }) .then((x) => { _data.isDone = true; @@ -2644,9 +2646,9 @@ export class DevelopmentController extends Controller { } /** - * API รายละเอียดโครงการ/หลักสูตรการฝึกอบรม tab6 IDP ส่งบันทึกทะเบียนประวัติ + * API รายละเอียดโครงการ/หลักสูตรการฝึกอบรม tab6 IDP ส่งบันทึกทะเบียนประวัติ (ข้อมูลผลงาน>ผลการประเมินการปฏิบัติราชการ) * - * @summary DEV_00 - รายละเอียดโครงการ/หลักสูตรการฝึกอบรมtab6 IDP ส่งบันทึกทะเบียนประวัติ # + * @summary DEV_00 - รายละเอียดโครงการ/หลักสูตรการฝึกอบรมtab6 IDP ส่งบันทึกทะเบียนประวัติ (ข้อมูลผลงาน>ผลการประเมินการปฏิบัติราชการ)# * * @param {string} id Id โครงการ */ diff --git a/src/controllers/DevelopmentScholarshipController.ts b/src/controllers/DevelopmentScholarshipController.ts index 117dfb3..54bead1 100644 --- a/src/controllers/DevelopmentScholarshipController.ts +++ b/src/controllers/DevelopmentScholarshipController.ts @@ -322,7 +322,7 @@ export class DevelopmentScholarshipController extends Controller { bookNo: getDevelopment.bookNo ? getDevelopment.bookNo : null, bookNoDate: getDevelopment.bookNoDate ? getDevelopment.bookNoDate : null, bookApproveDate: getDevelopment.bookApproveDate ? getDevelopment.bookApproveDate : null, - useOfficialTime: getDevelopment.useOfficialTime ? getDevelopment.useOfficialTime : false, + useOfficialTime: getDevelopment.useOfficialTime ? getDevelopment.useOfficialTime : null, changeDetail: getDevelopment.changeDetail ? getDevelopment.changeDetail : null, scholarshipType: getDevelopment.scholarshipType ? getDevelopment.scholarshipType : null, fundType: getDevelopment.fundType ? getDevelopment.fundType : null, @@ -484,7 +484,7 @@ export class DevelopmentScholarshipController extends Controller { bookNo: getDevelopment.bookNo ? getDevelopment.bookNo : null, bookNoDate: getDevelopment.bookNoDate ? getDevelopment.bookNoDate : null, bookApproveDate: getDevelopment.bookApproveDate ? getDevelopment.bookApproveDate : null, - useOfficialTime: getDevelopment.useOfficialTime ? getDevelopment.useOfficialTime : false, + useOfficialTime: getDevelopment.useOfficialTime ? getDevelopment.useOfficialTime : null, changeDetail: getDevelopment.changeDetail ? getDevelopment.changeDetail : null, scholarshipType: getDevelopment.scholarshipType ? getDevelopment.scholarshipType : null, fundType: getDevelopment.fundType ? getDevelopment.fundType : null, diff --git a/src/controllers/ReportController.ts b/src/controllers/ReportController.ts index 7ad3c23..a6b6913 100644 --- a/src/controllers/ReportController.ts +++ b/src/controllers/ReportController.ts @@ -650,7 +650,7 @@ export class ReportController extends Controller { : Extension.ToThaiNumber(Extension.ToThaiFullDate3(getDevelopment.graduatedDate)), graduatedReason: getDevelopment.graduatedReason == null ? "" : getDevelopment.graduatedReason, useOfficialTime: getDevelopment.useOfficialTime, - useOffTime: getDevelopment.useOfficialTime == true ? "🗹 ใช้ ☐ ไม่ใช้" : "☐ ใช้ 🗹 ไม่ใช้", + useOffTime: getDevelopment.useOfficialTime == "NOUSETIME" ? "🗹 ใช้ ☐ ไม่ใช้" : "☐ ใช้ 🗹 ไม่ใช้", isGraduated: getDevelopment.isGraduated, isG1: getDevelopment.isGraduated == true ? "🗹" : "☐", isG2: getDevelopment.isGraduated == true ? "☐" : "🗹", diff --git a/src/entities/DevelopmentAddress.ts b/src/entities/DevelopmentAddress.ts index 1629293..8de2fa8 100644 --- a/src/entities/DevelopmentAddress.ts +++ b/src/entities/DevelopmentAddress.ts @@ -20,7 +20,7 @@ export class DevelopmentAddress extends EntityBase { @Column({ nullable: true, - comment: "โครงการ/หลักสูตรการฝึกอบรม", + comment: "ชื่อจังหวัด (กรณีเลือกสถานที่ดำเนินการในประเทศ)", default: null, }) provinceName: string; @@ -32,6 +32,20 @@ export class DevelopmentAddress extends EntityBase { }) developmentId: string; + @Column({ + nullable: true, + comment: "สถานที่ดำเนินการ ในประเทศ(IN_COUNTRY) หรือ ต่างประเทศ(ABROAD)", + default: null, + }) + addressType: string; + + @Column({ + nullable: true, + comment: "ชื่อประเทศ (กรณีเลือกสถานที่ดำเนินการต่างประเทศ)", + default: null, + }) + country: string; + @ManyToOne(() => Development, (development: Development) => development.developmentAddresss) @JoinColumn({ name: "developmentId" }) development: Development; @@ -39,6 +53,16 @@ export class DevelopmentAddress extends EntityBase { export class CreateDevelopmentAddress { @Column() address: string | null; + @Column() provinceId: string | null; + + @Column() + addressType?: string | null; + + @Column() + provinceName?: string | null; + + @Column() + country?: string | null; } diff --git a/src/entities/DevelopmentScholarship.ts b/src/entities/DevelopmentScholarship.ts index efa05ba..c0ef3cf 100644 --- a/src/entities/DevelopmentScholarship.ts +++ b/src/entities/DevelopmentScholarship.ts @@ -301,7 +301,7 @@ export class DevelopmentScholarship extends EntityBase { comment: "ใช้เวลาราชการ", default: false, }) - useOfficialTime: boolean; + useOfficialTime: string; @Column({ nullable: true, @@ -567,6 +567,13 @@ export class DevelopmentScholarship extends EntityBase { default: null, }) graduatedReason: string; + + @Column({ + nullable: true, + comment: "เงินอื่นๆ", + default: null, + }) + budgetSourceOther: number; } export class CreateDevelopmentScholarship { rootId: string | null; @@ -604,7 +611,7 @@ export class CreateDevelopmentScholarship { bookNo: string | null; bookNoDate: Date | null; bookApproveDate: Date | null; - useOfficialTime: boolean | false; + useOfficialTime: string | null; changeDetail: string | null; scholarshipType: string | null; fundType: string | null; @@ -631,6 +638,7 @@ export class CreateDevelopmentScholarship { totalPeriod: string | null; planType: string | null; isNoUseBudget: boolean | null; + budgetSourceOther?: number | null; } export class UpdateDevelopmentScholarship { @@ -669,7 +677,7 @@ export class UpdateDevelopmentScholarship { bookNo: string | null; bookNoDate: Date | null; bookApproveDate: Date | null; - useOfficialTime: boolean | false; + useOfficialTime: string | null; changeDetail: string | null; scholarshipType: string | null; fundType: string | null; @@ -696,6 +704,7 @@ export class UpdateDevelopmentScholarship { totalPeriod: string | null; planType: string | null; isNoUseBudget: boolean | null; + budgetSourceOther?: number | null; } export class UpdateDevelopmentScholarshipUser { @@ -706,4 +715,5 @@ export class UpdateDevelopmentScholarshipUser { isGraduated: boolean | null; graduatedDate: Date | null; graduatedReason: string | null; + budgetSourceOther?: number | null; } diff --git a/src/migration/1745290442590-update_table_developAddress_and_developScholaship_add_fields.ts b/src/migration/1745290442590-update_table_developAddress_and_developScholaship_add_fields.ts new file mode 100644 index 0000000..001ec46 --- /dev/null +++ b/src/migration/1745290442590-update_table_developAddress_and_developScholaship_add_fields.ts @@ -0,0 +1,24 @@ +import { MigrationInterface, QueryRunner } from "typeorm"; + +export class UpdateTableDevelopAddressAndDevelopScholashipAddFields1745290442590 implements MigrationInterface { + name = 'UpdateTableDevelopAddressAndDevelopScholashipAddFields1745290442590' + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`developmentScholarship\` ADD \`budgetSourceOther\` int NULL COMMENT 'เงินอื่นๆ'`); + await queryRunner.query(`ALTER TABLE \`developmentAddress\` ADD \`addressType\` varchar(255) NULL COMMENT 'สถานที่ดำเนินการ ในประเทศ(IN_COUNTRY) หรือ ต่างประเทศ(ABROAD)'`); + await queryRunner.query(`ALTER TABLE \`developmentAddress\` ADD \`country\` varchar(255) NULL COMMENT 'ชื่อประเทศ (กรณีเลือกสถานที่ดำเนินการต่างประเทศ)'`); + await queryRunner.query(`ALTER TABLE \`developmentScholarship\` DROP COLUMN \`useOfficialTime\``); + await queryRunner.query(`ALTER TABLE \`developmentScholarship\` ADD \`useOfficialTime\` varchar(255) NOT NULL COMMENT 'ใช้เวลาราชการ' DEFAULT 0`); + await queryRunner.query(`ALTER TABLE \`developmentAddress\` CHANGE \`provinceName\` \`provinceName\` varchar(255) NULL COMMENT 'ชื่อจังหวัด (กรณีเลือกสถานที่ดำเนินการในประเทศ)'`); + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`developmentAddress\` CHANGE \`provinceName\` \`provinceName\` varchar(255) NULL COMMENT 'โครงการ/หลักสูตรการฝึกอบรม'`); + await queryRunner.query(`ALTER TABLE \`developmentScholarship\` DROP COLUMN \`useOfficialTime\``); + await queryRunner.query(`ALTER TABLE \`developmentScholarship\` ADD \`useOfficialTime\` tinyint NOT NULL COMMENT 'ใช้เวลาราชการ' DEFAULT '0'`); + await queryRunner.query(`ALTER TABLE \`developmentAddress\` DROP COLUMN \`country\``); + await queryRunner.query(`ALTER TABLE \`developmentAddress\` DROP COLUMN \`addressType\``); + await queryRunner.query(`ALTER TABLE \`developmentScholarship\` DROP COLUMN \`budgetSourceOther\``); + } + +} From 588178f042016a0a5d645521991c32981287868e Mon Sep 17 00:00:00 2001 From: Bright Date: Tue, 22 Apr 2025 16:27:56 +0700 Subject: [PATCH 235/250] =?UTF-8?q?migrate=20&=20=E0=B9=80=E0=B8=9E?= =?UTF-8?q?=E0=B8=B4=E0=B9=88=E0=B8=A1=E0=B8=9F=E0=B8=B4=E0=B8=A5=E0=B8=94?= =?UTF-8?q?=E0=B9=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DevelopmentScholarshipController.ts | 1 + src/entities/DevelopmentScholarship.ts | 8 ++++---- ...8-update_table_developScholaship_edit_type.ts | 16 ++++++++++++++++ 3 files changed, 21 insertions(+), 4 deletions(-) create mode 100644 src/migration/1745313881448-update_table_developScholaship_edit_type.ts diff --git a/src/controllers/DevelopmentScholarshipController.ts b/src/controllers/DevelopmentScholarshipController.ts index 54bead1..d3df7e8 100644 --- a/src/controllers/DevelopmentScholarshipController.ts +++ b/src/controllers/DevelopmentScholarshipController.ts @@ -519,6 +519,7 @@ export class DevelopmentScholarshipController extends Controller { profileId: getDevelopment.profileId ? getDevelopment.profileId : null, planType: getDevelopment.planType ? getDevelopment.planType : null, isNoUseBudget: getDevelopment.isNoUseBudget ? getDevelopment.isNoUseBudget : null, + budgetSourceOther: getDevelopment.budgetSourceOther ? getDevelopment.budgetSourceOther : null, }; return new HttpSuccess(formattedData); } diff --git a/src/entities/DevelopmentScholarship.ts b/src/entities/DevelopmentScholarship.ts index c0ef3cf..976598e 100644 --- a/src/entities/DevelopmentScholarship.ts +++ b/src/entities/DevelopmentScholarship.ts @@ -573,7 +573,7 @@ export class DevelopmentScholarship extends EntityBase { comment: "เงินอื่นๆ", default: null, }) - budgetSourceOther: number; + budgetSourceOther: string; } export class CreateDevelopmentScholarship { rootId: string | null; @@ -638,7 +638,7 @@ export class CreateDevelopmentScholarship { totalPeriod: string | null; planType: string | null; isNoUseBudget: boolean | null; - budgetSourceOther?: number | null; + budgetSourceOther?: string | null; } export class UpdateDevelopmentScholarship { @@ -704,7 +704,7 @@ export class UpdateDevelopmentScholarship { totalPeriod: string | null; planType: string | null; isNoUseBudget: boolean | null; - budgetSourceOther?: number | null; + budgetSourceOther?: string | null; } export class UpdateDevelopmentScholarshipUser { @@ -715,5 +715,5 @@ export class UpdateDevelopmentScholarshipUser { isGraduated: boolean | null; graduatedDate: Date | null; graduatedReason: string | null; - budgetSourceOther?: number | null; + budgetSourceOther?: string | null; } diff --git a/src/migration/1745313881448-update_table_developScholaship_edit_type.ts b/src/migration/1745313881448-update_table_developScholaship_edit_type.ts new file mode 100644 index 0000000..c6c393f --- /dev/null +++ b/src/migration/1745313881448-update_table_developScholaship_edit_type.ts @@ -0,0 +1,16 @@ +import { MigrationInterface, QueryRunner } from "typeorm"; + +export class UpdateTableDevelopScholashipEditType1745313881448 implements MigrationInterface { + name = 'UpdateTableDevelopScholashipEditType1745313881448' + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`developmentScholarship\` DROP COLUMN \`budgetSourceOther\``); + await queryRunner.query(`ALTER TABLE \`developmentScholarship\` ADD \`budgetSourceOther\` varchar(255) NULL COMMENT 'เงินอื่นๆ'`); + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`developmentScholarship\` DROP COLUMN \`budgetSourceOther\``); + await queryRunner.query(`ALTER TABLE \`developmentScholarship\` ADD \`budgetSourceOther\` int NULL COMMENT 'เงินอื่นๆ'`); + } + +} From 65899d936a6a1f42e567fcdb15fd3b2b322e0aea Mon Sep 17 00:00:00 2001 From: Bright Date: Wed, 23 Apr 2025 09:27:31 +0700 Subject: [PATCH 236/250] =?UTF-8?q?api=20=E0=B8=A3=E0=B8=B2=E0=B8=A2?= =?UTF-8?q?=E0=B8=A5=E0=B8=B0=E0=B9=80=E0=B8=AD=E0=B8=B5=E0=B8=A2=E0=B8=94?= =?UTF-8?q?=E0=B8=97=E0=B8=B8=E0=B8=99=20&=20=E0=B9=81=E0=B8=81=E0=B9=89?= =?UTF-8?q?=E0=B9=84=E0=B8=82=E0=B8=A3=E0=B8=B2=E0=B8=A2=E0=B8=A5=E0=B8=B0?= =?UTF-8?q?=E0=B9=80=E0=B8=AD=E0=B8=B5=E0=B8=A2=E0=B8=94=E0=B8=97=E0=B8=B8?= =?UTF-8?q?=E0=B8=99=20=E0=B8=AA=E0=B8=B3=E0=B8=AB=E0=B8=A3=E0=B8=B1?= =?UTF-8?q?=E0=B8=9A=E0=B9=80=E0=B8=88=E0=B9=89=E0=B8=B2=E0=B8=AB=E0=B8=99?= =?UTF-8?q?=E0=B9=89=E0=B8=B2=E0=B8=97=E0=B8=B5=E0=B9=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DevelopmentScholarshipController.ts | 65 +++++++++++++++++++ 1 file changed, 65 insertions(+) diff --git a/src/controllers/DevelopmentScholarshipController.ts b/src/controllers/DevelopmentScholarshipController.ts index d3df7e8..8587ed5 100644 --- a/src/controllers/DevelopmentScholarshipController.ts +++ b/src/controllers/DevelopmentScholarshipController.ts @@ -559,6 +559,41 @@ export class DevelopmentScholarshipController extends Controller { return new HttpSuccess(getDevelopment); } + /** + * API รายละเอียดทุนของ admin + * + * @summary DEV_0 - รายละเอียดทุนของ admin # + * + * @param {string} id id รายการ + */ + @Get("admin/detail/{id}") + async GetDevelopemtScholarshipUserDetailAdminById(@Request() request: RequestWithUser, @Path() id: string) { + let _workflow = await new permission().Workflow(request, id, "SYS_DEV_SCHOLARSHIP"); + if (_workflow == false) await new permission().PermissionGet(request, "SYS_DEV_SCHOLARSHIP"); + const getDevelopment = await this.developmentScholarshipRepository.findOne({ + where: { id: id }, + select: [ + "id", + "scholarshipYear", + "scholarshipType", + "fundType", + "bookNumber", + "bookDate", + "governmentDate", + "governmentEndDate", + "isGraduated", + "graduatedDate", + "graduatedReason", + "org", + ], + }); + if (!getDevelopment) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลทุนการศึกษา/ฝึกอบรมนี้"); + } + + return new HttpSuccess(getDevelopment); + } + /** * API รายละเอียดทุนของ user * @@ -622,6 +657,36 @@ export class DevelopmentScholarshipController extends Controller { return new HttpSuccess(getDevelopment.id); } + /** + * API แก้ไขรายการทุนของ admin + * + * @summary DEV_015 - แก้ไขรายการทุนของ admin #15 + * + * @param {string} id รายการ + */ + @Put("admin/detail/{id}") + async UpdateDevelopemtScholarshipAdminById( + @Path() id: string, + @Body() requestBody: UpdateDevelopmentScholarshipUser, + @Request() request: RequestWithUser, + ) { + await new permission().PermissionUpdate(request, "SYS_DEV_SCHOLARSHIP"); + const getDevelopment = await this.developmentScholarshipRepository.findOne({ + where: { id: id }, + }); + if (!getDevelopment) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลทุนการศึกษา/ฝึกอบรมนี้"); + } + const before = structuredClone(getDevelopment); + Object.assign(getDevelopment, requestBody); + getDevelopment.lastUpdateUserId = request.user.sub; + getDevelopment.lastUpdateFullName = request.user.name; + getDevelopment.lastUpdatedAt = new Date(); + await this.developmentScholarshipRepository.save(getDevelopment, { data: request }); + setLogDataDiff(request, { before, after: getDevelopment }); + return new HttpSuccess(getDevelopment.id); + } + /** * API เปลี่ยนสถานะ * From 374bec32e486c611be4b9f9488d744a0b3d412a1 Mon Sep 17 00:00:00 2001 From: AdisakKanthawilang Date: Fri, 2 May 2025 15:14:49 +0700 Subject: [PATCH 237/250] fix --- src/controllers/StrategyController.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/controllers/StrategyController.ts b/src/controllers/StrategyController.ts index bd29960..1f5b4c0 100644 --- a/src/controllers/StrategyController.ts +++ b/src/controllers/StrategyController.ts @@ -254,6 +254,7 @@ export class StrategyController extends Controller { switch (body.levelnode) { case 0: const ckOrder = await this.strategy1Repo.findOne({ + where: {}, order: { order: "DESC" }, }); strategyRepo = this.strategy1Repo; From e16390b78737709766ad30552a413512e8f0ca8c Mon Sep 17 00:00:00 2001 From: waruneeauy Date: Fri, 13 Jun 2025 14:40:43 +0700 Subject: [PATCH 238/250] fix sort developmentAddresss get tab3 --- src/controllers/DevelopmentController.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/controllers/DevelopmentController.ts b/src/controllers/DevelopmentController.ts index a18787a..db37d6c 100644 --- a/src/controllers/DevelopmentController.ts +++ b/src/controllers/DevelopmentController.ts @@ -2385,8 +2385,7 @@ export class DevelopmentController extends Controller { dateStart: getDevelopment.dateStart, dateEnd: getDevelopment.dateEnd, totalDate: getDevelopment.totalDate, - developmentAddresss: - getDevelopment.developmentAddresss == null ? null : getDevelopment.developmentAddresss, + developmentAddresss: getDevelopment.developmentAddresss == null ? null : getDevelopment.developmentAddresss.sort((a, b) => new Date(a.createdAt).getTime() - new Date(b.createdAt).getTime()), }; return new HttpSuccess(_getDevelopment); } From d51357e715d4ddb7f044bd84cff6f9cc227c0ffa Mon Sep 17 00:00:00 2001 From: Moss <> Date: Mon, 16 Jun 2025 21:34:15 +0700 Subject: [PATCH 239/250] migrate dna --- src/controllers/DevelopmentController.ts | 251 ++++++++++++------ .../DevelopmentScholarshipController.ts | 31 ++- src/entities/DevelopmentScholarship.ts | 18 ++ .../1743061489009-update_strategyadddorder.ts | 22 -- ...able_actualGoal_and_plannedGoalPosition.ts | 36 --- ...ddress_and_developScholaship_add_fields.ts | 24 -- ...pdate_table_developScholaship_edit_type.ts | 16 -- .../1750083465733-update30062025604.ts | 14 + .../1750083913468-update30062025605.ts | 14 + 9 files changed, 243 insertions(+), 183 deletions(-) delete mode 100644 src/migration/1743061489009-update_strategyadddorder.ts delete mode 100644 src/migration/1744342850196-update_table_actualGoal_and_plannedGoalPosition.ts delete mode 100644 src/migration/1745290442590-update_table_developAddress_and_developScholaship_add_fields.ts delete mode 100644 src/migration/1745313881448-update_table_developScholaship_edit_type.ts create mode 100644 src/migration/1750083465733-update30062025604.ts create mode 100644 src/migration/1750083913468-update30062025605.ts diff --git a/src/controllers/DevelopmentController.ts b/src/controllers/DevelopmentController.ts index db37d6c..77986d2 100644 --- a/src/controllers/DevelopmentController.ts +++ b/src/controllers/DevelopmentController.ts @@ -370,20 +370,22 @@ export class DevelopmentController extends Controller { await Promise.all( requestBody.positions.map(async (x) => { const _data = Object.assign(new PlannedGoalPosition(), x); - let checkPosType:any = null - let posTypeShortName:any = null + let checkPosType: any = null; + let posTypeShortName: any = null; if (x.posTypePlanned) { - if(requestBody.groupTarget == "PERSONNEL" && - (requestBody.groupTargetSub == "EMPLOYEE" || requestBody.groupTargetSub == "EMPLOYEETEMP")) { + if ( + requestBody.groupTarget == "PERSONNEL" && + (requestBody.groupTargetSub == "EMPLOYEE" || + requestBody.groupTargetSub == "EMPLOYEETEMP") + ) { checkPosType = await this.empPosTypeRepository.findOne({ where: { posTypeName: x.posTypePlanned }, }); if (!checkPosType) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลกลุ่มงาน"); } - posTypeShortName = checkPosType.posTypeShortName - } - else { + posTypeShortName = checkPosType.posTypeShortName; + } else { checkPosType = await this.posTypeRepository.findOne({ where: { posTypeName: x.posTypePlanned }, }); @@ -393,24 +395,28 @@ export class DevelopmentController extends Controller { } } if (x.posLevelPlanned) { - let checkPosLevel:any - if (requestBody.groupTarget == "PERSONNEL" && - (requestBody.groupTargetSub == "EMPLOYEE" || requestBody.groupTargetSub == "EMPLOYEETEMP")) { + let checkPosLevel: any; + if ( + requestBody.groupTarget == "PERSONNEL" && + (requestBody.groupTargetSub == "EMPLOYEE" || + requestBody.groupTargetSub == "EMPLOYEETEMP") + ) { checkPosLevel = await this.empPosLevelRepository.find({ - where: { - posTypeId: checkPosType.id + where: { + posTypeId: checkPosType.id, }, }); - const mapShortName = checkPosLevel.flatMap((x:any) => `${posTypeShortName} ${x.posLevelName}`); + const mapShortName = checkPosLevel.flatMap( + (x: any) => `${posTypeShortName} ${x.posLevelName}`, + ); if (checkPosLevel.length == 0 /*|| !mapShortName.includes(x.posLevelPlanned)*/) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลระดับชั้นงาน"); } - } - else { + } else { checkPosLevel = await this.posLevelRepository.findOne({ - where: { + where: { posLevelName: x.posLevelPlanned, - posTypeId: checkPosType.id + posTypeId: checkPosType.id, }, }); if (!checkPosLevel) { @@ -502,20 +508,21 @@ export class DevelopmentController extends Controller { if (!development) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงการ/หลักสูตรการฝึกอบรมนี้"); } - let checkPosType:any = null - let posTypeShortName:any = null + let checkPosType: any = null; + let posTypeShortName: any = null; if (requestBody.posTypeActual) { - if(requestBody.groupTarget == "PERSONNEL" && - (requestBody.groupTargetSub == "EMPLOYEE" || requestBody.groupTargetSub == "EMPLOYEETEMP")) { + if ( + requestBody.groupTarget == "PERSONNEL" && + (requestBody.groupTargetSub == "EMPLOYEE" || requestBody.groupTargetSub == "EMPLOYEETEMP") + ) { checkPosType = await this.empPosTypeRepository.findOne({ where: { posTypeName: requestBody.posTypeActual }, }); if (!checkPosType) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลกลุ่มงาน"); } - posTypeShortName = checkPosType.posTypeShortName - } - else { + posTypeShortName = checkPosType.posTypeShortName; + } else { checkPosType = await this.posTypeRepository.findOne({ where: { posTypeName: requestBody.posTypeActual }, }); @@ -525,24 +532,27 @@ export class DevelopmentController extends Controller { } } if (requestBody.posLevelActual) { - let checkPosLevel:any - if (requestBody.groupTarget == "PERSONNEL" && - (requestBody.groupTargetSub == "EMPLOYEE" || requestBody.groupTargetSub == "EMPLOYEETEMP")) { + let checkPosLevel: any; + if ( + requestBody.groupTarget == "PERSONNEL" && + (requestBody.groupTargetSub == "EMPLOYEE" || requestBody.groupTargetSub == "EMPLOYEETEMP") + ) { checkPosLevel = await this.empPosLevelRepository.find({ - where: { - posTypeId: checkPosType.id + where: { + posTypeId: checkPosType.id, }, }); - const mapShortName = checkPosLevel.flatMap((x:any) => `${posTypeShortName} ${x.posLevelName}`); + const mapShortName = checkPosLevel.flatMap( + (x: any) => `${posTypeShortName} ${x.posLevelName}`, + ); if (checkPosLevel.length == 0 /*|| !mapShortName.includes(x.posLevelPlanned)*/) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลระดับชั้นงาน"); } - } - else { + } else { checkPosLevel = await this.posLevelRepository.findOne({ - where: { + where: { posLevelName: requestBody.posLevelActual, - posTypeId: checkPosType.id + posTypeId: checkPosType.id, }, }); if (!checkPosLevel) { @@ -665,20 +675,22 @@ export class DevelopmentController extends Controller { await Promise.all( requestBody.positions.map(async (x) => { const _data = Object.assign(new PlannedGoalPosition(), x); - let checkPosType:any = null - let posTypeShortName:any = null + let checkPosType: any = null; + let posTypeShortName: any = null; if (x.posTypePlanned) { - if(requestBody.groupTarget == "PERSONNEL" && - (requestBody.groupTargetSub == "EMPLOYEE" || requestBody.groupTargetSub == "EMPLOYEETEMP")) { + if ( + requestBody.groupTarget == "PERSONNEL" && + (requestBody.groupTargetSub == "EMPLOYEE" || + requestBody.groupTargetSub == "EMPLOYEETEMP") + ) { checkPosType = await this.empPosTypeRepository.findOne({ where: { posTypeName: x.posTypePlanned }, }); if (!checkPosType) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลกลุ่มงาน"); } - posTypeShortName = checkPosType.posTypeShortName - } - else { + posTypeShortName = checkPosType.posTypeShortName; + } else { checkPosType = await this.posTypeRepository.findOne({ where: { posTypeName: x.posTypePlanned }, }); @@ -688,24 +700,28 @@ export class DevelopmentController extends Controller { } } if (x.posLevelPlanned) { - let checkPosLevel:any - if (requestBody.groupTarget == "PERSONNEL" && - (requestBody.groupTargetSub == "EMPLOYEE" || requestBody.groupTargetSub == "EMPLOYEETEMP")) { + let checkPosLevel: any; + if ( + requestBody.groupTarget == "PERSONNEL" && + (requestBody.groupTargetSub == "EMPLOYEE" || + requestBody.groupTargetSub == "EMPLOYEETEMP") + ) { checkPosLevel = await this.empPosLevelRepository.find({ - where: { - posTypeId: checkPosType.id + where: { + posTypeId: checkPosType.id, }, }); - const mapShortName = checkPosLevel.flatMap((x:any) => `${posTypeShortName} ${x.posLevelName}`); + const mapShortName = checkPosLevel.flatMap( + (x: any) => `${posTypeShortName} ${x.posLevelName}`, + ); if (checkPosLevel.length == 0 /*|| !mapShortName.includes(x.posLevelPlanned)*/) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลระดับชั้นงาน"); } - } - else { + } else { checkPosLevel = await this.posLevelRepository.findOne({ - where: { + where: { posLevelName: x.posLevelPlanned, - posTypeId: checkPosType.id + posTypeId: checkPosType.id, }, }); if (!checkPosLevel) { @@ -801,20 +817,21 @@ export class DevelopmentController extends Controller { if (!development) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงการ/หลักสูตรการฝึกอบรมนี้"); } - let checkPosType:any = null - let posTypeShortName:any = null + let checkPosType: any = null; + let posTypeShortName: any = null; if (requestBody.posTypeActual) { - if(requestBody.groupTarget == "PERSONNEL" && - (requestBody.groupTargetSub == "EMPLOYEE" || requestBody.groupTargetSub == "EMPLOYEETEMP")) { + if ( + requestBody.groupTarget == "PERSONNEL" && + (requestBody.groupTargetSub == "EMPLOYEE" || requestBody.groupTargetSub == "EMPLOYEETEMP") + ) { checkPosType = await this.empPosTypeRepository.findOne({ where: { posTypeName: requestBody.posTypeActual }, }); if (!checkPosType) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลกลุ่มงาน"); } - posTypeShortName = checkPosType.posTypeShortName - } - else { + posTypeShortName = checkPosType.posTypeShortName; + } else { checkPosType = await this.posTypeRepository.findOne({ where: { posTypeName: requestBody.posTypeActual }, }); @@ -824,24 +841,27 @@ export class DevelopmentController extends Controller { } } if (requestBody.posLevelActual) { - let checkPosLevel:any - if (requestBody.groupTarget == "PERSONNEL" && - (requestBody.groupTargetSub == "EMPLOYEE" || requestBody.groupTargetSub == "EMPLOYEETEMP")) { + let checkPosLevel: any; + if ( + requestBody.groupTarget == "PERSONNEL" && + (requestBody.groupTargetSub == "EMPLOYEE" || requestBody.groupTargetSub == "EMPLOYEETEMP") + ) { checkPosLevel = await this.empPosLevelRepository.find({ - where: { - posTypeId: checkPosType.id + where: { + posTypeId: checkPosType.id, }, }); - const mapShortName = checkPosLevel.flatMap((x:any) => `${posTypeShortName} ${x.posLevelName}`); + const mapShortName = checkPosLevel.flatMap( + (x: any) => `${posTypeShortName} ${x.posLevelName}`, + ); if (checkPosLevel.length == 0 /*|| !mapShortName.includes(x.posLevelPlanned)*/) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลระดับชั้นงาน"); } - } - else { + } else { checkPosLevel = await this.posLevelRepository.findOne({ - where: { + where: { posLevelName: requestBody.posLevelActual, - posTypeId: checkPosType.id + posTypeId: checkPosType.id, }, }); if (!checkPosLevel) { @@ -2046,7 +2066,13 @@ export class DevelopmentController extends Controller { @Query("node") node?: number | null, @Query("keyword") keyword?: string, ) { - // await new permission().PermissionOrgList(request, "SYS_DEV_SCHOLARSHIP"); + let _data = await new permission().PermissionOrgList(request, "SYS_DEV_PROJECT"); + await new CallAPI() + .PostData(request, "/org/finddna", _data) + .then((x) => { + _data = x; + }) + .catch((x) => {}); const [development, total] = await AppDataSource.getRepository(Development) .createQueryBuilder("development") .andWhere(year > 0 ? "development.year LIKE :year" : "1=1", { @@ -2086,6 +2112,56 @@ export class DevelopmentController extends Controller { keyword: `%${keyword}%`, }, ) + .andWhere( + _data.root != undefined && _data.root != null + ? _data.root[0] != null + ? `development.rootDnaId IN (:...root)` + : `development.rootDnaId is null` + : "1=1", + { + root: _data.root, + }, + ) + .andWhere( + _data.child1 != undefined && _data.child1 != null + ? _data.child1[0] != null + ? `development.child1DnaId IN (:...child1)` + : `development.child1DnaId is null` + : "1=1", + { + child1: _data.child1, + }, + ) + .andWhere( + _data.child2 != undefined && _data.child2 != null + ? _data.child2[0] != null + ? `development.child2DnaId IN (:...child2)` + : `development.child2DnaId is null` + : "1=1", + { + child2: _data.child2, + }, + ) + .andWhere( + _data.child3 != undefined && _data.child3 != null + ? _data.child3[0] != null + ? `development.child3DnaId IN (:...child3)` + : `development.child3DnaId is null` + : "1=1", + { + child3: _data.child3, + }, + ) + .andWhere( + _data.child4 != undefined && _data.child4 != null + ? _data.child4[0] != null + ? `development.child4DnaId IN (:...child4)` + : `development.child4DnaId is null` + : "1=1", + { + child4: _data.child4, + }, + ) .select([ "development.id", "development.projectName", @@ -2385,7 +2461,12 @@ export class DevelopmentController extends Controller { dateStart: getDevelopment.dateStart, dateEnd: getDevelopment.dateEnd, totalDate: getDevelopment.totalDate, - developmentAddresss: getDevelopment.developmentAddresss == null ? null : getDevelopment.developmentAddresss.sort((a, b) => new Date(a.createdAt).getTime() - new Date(b.createdAt).getTime()), + developmentAddresss: + getDevelopment.developmentAddresss == null + ? null + : getDevelopment.developmentAddresss.sort( + (a, b) => new Date(a.createdAt).getTime() - new Date(b.createdAt).getTime(), + ), }; return new HttpSuccess(_getDevelopment); } @@ -2597,7 +2678,7 @@ export class DevelopmentController extends Controller { startDate: x.dateStart, endDate: x.dateEnd, isDate: true, - developmentId: id + developmentId: id, }) .then((x) => { _data.isDone = true; @@ -2620,7 +2701,7 @@ export class DevelopmentController extends Controller { startDate: x.dateStart, endDate: x.dateEnd, isDate: true, - developmentId: id + developmentId: id, }) .then((x) => { _data.isDone = true; @@ -2658,7 +2739,7 @@ export class DevelopmentController extends Controller { relations: ["development", "development.developmentProjectTechniqueActuals"], }); - let isDevelopment70: boolean = false + let isDevelopment70: boolean = false; const dev70Lists = [ "on_the_job_training", "job_project_assignment", @@ -2671,18 +2752,18 @@ export class DevelopmentController extends Controller { "benchmarking", "problem_solving", "team_working", - "other1" + "other1", ]; - let isDevelopment20: boolean = false + let isDevelopment20: boolean = false; const dev20Lists = [ "coaching", "mentoring", "team_meeting", "consulting", "feedback", - "other2" + "other2", ]; - let isDevelopment10: boolean = false + let isDevelopment10: boolean = false; const dev10Lists = [ "self_learning", "classroom_training", @@ -2691,17 +2772,21 @@ export class DevelopmentController extends Controller { "e_training", "meeting", "seminar", - "other3" + "other3", ]; await Promise.all( getDevelopment.map(async (x) => { const _data = Object.assign(new DevelopmentHistory(), x); - const techniqueActuals = x.development?.developmentProjectTechniqueActuals.flatMap(x => x.name) || []; - isDevelopment70 = techniqueActuals.length > 0 && dev70Lists.some(item => techniqueActuals.includes(item)); - isDevelopment20 = techniqueActuals.length > 0 && dev20Lists.some(item => techniqueActuals.includes(item)); - isDevelopment10 = techniqueActuals.length > 0 && dev10Lists.some(item => techniqueActuals.includes(item)); - + const techniqueActuals = + x.development?.developmentProjectTechniqueActuals.flatMap((x) => x.name) || []; + isDevelopment70 = + techniqueActuals.length > 0 && dev70Lists.some((item) => techniqueActuals.includes(item)); + isDevelopment20 = + techniqueActuals.length > 0 && dev20Lists.some((item) => techniqueActuals.includes(item)); + isDevelopment10 = + techniqueActuals.length > 0 && dev10Lists.some((item) => techniqueActuals.includes(item)); + if (x.type == "OFFICER") { await new CallAPI() .PostData(request, "/org/profile/development", { diff --git a/src/controllers/DevelopmentScholarshipController.ts b/src/controllers/DevelopmentScholarshipController.ts index 8587ed5..af23f0a 100644 --- a/src/controllers/DevelopmentScholarshipController.ts +++ b/src/controllers/DevelopmentScholarshipController.ts @@ -161,7 +161,13 @@ export class DevelopmentScholarshipController extends Controller { @Query("year") year?: number, @Query("scholarshipType") scholarshipType?: string, ) { - await new permission().PermissionList(request, "SYS_DEV_SCHOLARSHIP"); + let _data = await new permission().PermissionOrgList(request, "SYS_DEV_SCHOLARSHIP"); + await new CallAPI() + .PostData(request, "/org/finddna", _data) + .then((x) => { + _data = x; + }) + .catch((x) => {}); const [development, total] = await AppDataSource.getRepository(DevelopmentScholarship) .createQueryBuilder("developmentScholarship") .leftJoinAndSelect("developmentScholarship.posLevel", "posLevel") @@ -226,6 +232,16 @@ export class DevelopmentScholarshipController extends Controller { ); }), ) + .andWhere( + _data.root != undefined && _data.root != null + ? _data.root[0] != null + ? `developmentScholarship.rootDnaId IN (:...root)` + : `developmentScholarship.rootDnaId is null` + : "1=1", + { + root: _data.root, + }, + ) .orderBy("developmentScholarship.scholarshipYear", "DESC") .addOrderBy("developmentScholarship.createdAt", "DESC") .skip((page - 1) * pageSize) @@ -264,6 +280,7 @@ export class DevelopmentScholarshipController extends Controller { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลทุนการศึกษา/ฝึกอบรมนี้"); } const formattedData = { + rootDnaId: getDevelopment.rootDnaId ? getDevelopment.rootDnaId : null, rootId: getDevelopment.rootId ? getDevelopment.rootId : null, root: getDevelopment.root ? getDevelopment.root : null, org: getDevelopment.org ? getDevelopment.org : null, @@ -282,6 +299,9 @@ export class DevelopmentScholarshipController extends Controller { : null, posTypeId: getDevelopment.posTypeId ? getDevelopment.posTypeId : null, posTypeName: getDevelopment.posType?.posTypeName ? getDevelopment.posType?.posTypeName : null, + guarantorRootDnaId: getDevelopment.guarantorRootDnaId + ? getDevelopment.guarantorRootDnaId + : null, guarantorRootId: getDevelopment.guarantorRootId ? getDevelopment.guarantorRootId : null, guarantorRoot: getDevelopment.guarantorRoot ? getDevelopment.guarantorRoot : null, guarantorOrg: getDevelopment.guarantorOrg ? getDevelopment.guarantorOrg : null, @@ -426,6 +446,7 @@ export class DevelopmentScholarshipController extends Controller { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลทุนการศึกษา/ฝึกอบรมนี้"); } const formattedData = { + rootDnaId: getDevelopment.rootDnaId ? getDevelopment.rootDnaId : null, rootId: getDevelopment.rootId ? getDevelopment.rootId : null, root: getDevelopment.root ? getDevelopment.root : null, org: getDevelopment.org ? getDevelopment.org : null, @@ -444,6 +465,9 @@ export class DevelopmentScholarshipController extends Controller { : null, posTypeId: getDevelopment.posTypeId ? getDevelopment.posTypeId : null, posTypeName: getDevelopment.posType?.posTypeName ? getDevelopment.posType?.posTypeName : null, + guarantorRootDnaId: getDevelopment.guarantorRootDnaId + ? getDevelopment.guarantorRootDnaId + : null, guarantorRootId: getDevelopment.guarantorRootId ? getDevelopment.guarantorRootId : null, guarantorRoot: getDevelopment.guarantorRoot ? getDevelopment.guarantorRoot : null, guarantorOrg: getDevelopment.guarantorOrg ? getDevelopment.guarantorOrg : null, @@ -567,7 +591,10 @@ export class DevelopmentScholarshipController extends Controller { * @param {string} id id รายการ */ @Get("admin/detail/{id}") - async GetDevelopemtScholarshipUserDetailAdminById(@Request() request: RequestWithUser, @Path() id: string) { + async GetDevelopemtScholarshipUserDetailAdminById( + @Request() request: RequestWithUser, + @Path() id: string, + ) { let _workflow = await new permission().Workflow(request, id, "SYS_DEV_SCHOLARSHIP"); if (_workflow == false) await new permission().PermissionGet(request, "SYS_DEV_SCHOLARSHIP"); const getDevelopment = await this.developmentScholarshipRepository.findOne({ diff --git a/src/entities/DevelopmentScholarship.ts b/src/entities/DevelopmentScholarship.ts index 976598e..cd1c614 100644 --- a/src/entities/DevelopmentScholarship.ts +++ b/src/entities/DevelopmentScholarship.ts @@ -5,6 +5,13 @@ import { PosType } from "./PosType"; @Entity("developmentScholarship") export class DevelopmentScholarship extends EntityBase { + @Column({ + nullable: true, + comment: "id dna หน่วยงาน", + default: null, + }) + rootDnaId: string; + @Column({ nullable: true, comment: "id หน่วยงาน", @@ -137,6 +144,13 @@ export class DevelopmentScholarship extends EntityBase { @JoinColumn({ name: "posTypeId" }) posType: PosType; + @Column({ + nullable: true, + comment: "id Dna หน่วยงาน", + default: null, + }) + guarantorRootDnaId: string; + @Column({ nullable: true, comment: "id หน่วยงาน", @@ -576,6 +590,7 @@ export class DevelopmentScholarship extends EntityBase { budgetSourceOther: string; } export class CreateDevelopmentScholarship { + rootDnaId?: string | null; rootId: string | null; root: string | null; org: string | null; @@ -591,6 +606,7 @@ export class CreateDevelopmentScholarship { posExecutive: string | null; posLevelId: string | null; posTypeId: string | null; + guarantorRootDnaId: string | null; guarantorRootId: string | null; guarantorRoot: string | null; guarantorOrg: string | null; @@ -642,6 +658,7 @@ export class CreateDevelopmentScholarship { } export class UpdateDevelopmentScholarship { + rootDnaId?: string | null; rootId: string | null; root: string | null; org: string | null; @@ -657,6 +674,7 @@ export class UpdateDevelopmentScholarship { posExecutive: string | null; posLevelId: string | null; posTypeId: string | null; + guarantorRootDnaId?: string | null; guarantorRootId?: string | null; guarantorRoot?: string | null; guarantorOrg?: string | null; diff --git a/src/migration/1743061489009-update_strategyadddorder.ts b/src/migration/1743061489009-update_strategyadddorder.ts deleted file mode 100644 index c6c6e16..0000000 --- a/src/migration/1743061489009-update_strategyadddorder.ts +++ /dev/null @@ -1,22 +0,0 @@ -import { MigrationInterface, QueryRunner } from "typeorm"; - -export class UpdateStrategyadddorder1743061489009 implements MigrationInterface { - name = 'UpdateStrategyadddorder1743061489009' - - public async up(queryRunner: QueryRunner): Promise { - await queryRunner.query(`ALTER TABLE \`strategyChild4\` ADD \`order\` int NULL COMMENT 'ลำดับความสำคัญ'`); - await queryRunner.query(`ALTER TABLE \`strategyChild3\` ADD \`order\` int NULL COMMENT 'ลำดับความสำคัญ'`); - await queryRunner.query(`ALTER TABLE \`strategyChild2\` ADD \`order\` int NULL COMMENT 'ลำดับความสำคัญ'`); - await queryRunner.query(`ALTER TABLE \`strategyChild1\` ADD \`order\` int NULL COMMENT 'ลำดับความสำคัญ'`); - await queryRunner.query(`ALTER TABLE \`strategyChild5\` ADD \`order\` int NULL COMMENT 'ลำดับความสำคัญ'`); - } - - public async down(queryRunner: QueryRunner): Promise { - await queryRunner.query(`ALTER TABLE \`strategyChild5\` DROP COLUMN \`order\``); - await queryRunner.query(`ALTER TABLE \`strategyChild1\` DROP COLUMN \`order\``); - await queryRunner.query(`ALTER TABLE \`strategyChild2\` DROP COLUMN \`order\``); - await queryRunner.query(`ALTER TABLE \`strategyChild3\` DROP COLUMN \`order\``); - await queryRunner.query(`ALTER TABLE \`strategyChild4\` DROP COLUMN \`order\``); - } - -} diff --git a/src/migration/1744342850196-update_table_actualGoal_and_plannedGoalPosition.ts b/src/migration/1744342850196-update_table_actualGoal_and_plannedGoalPosition.ts deleted file mode 100644 index 2888b6f..0000000 --- a/src/migration/1744342850196-update_table_actualGoal_and_plannedGoalPosition.ts +++ /dev/null @@ -1,36 +0,0 @@ -import { MigrationInterface, QueryRunner } from "typeorm"; - -export class UpdateTableActualGoalAndPlannedGoalPosition1744342850196 implements MigrationInterface { - name = 'UpdateTableActualGoalAndPlannedGoalPosition1744342850196' - - public async up(queryRunner: QueryRunner): Promise { - await queryRunner.query(`ALTER TABLE \`actualGoal\` DROP FOREIGN KEY \`FK_a9a864dd06eaa25edba8be8f24c\``); - await queryRunner.query(`ALTER TABLE \`actualGoal\` DROP FOREIGN KEY \`FK_e08e337e5ddeb4942c72393ff58\``); - await queryRunner.query(`ALTER TABLE \`plannedGoalPosition\` DROP FOREIGN KEY \`FK_4eef5d8c3ab92f7af4a762150a4\``); - await queryRunner.query(`ALTER TABLE \`plannedGoalPosition\` DROP FOREIGN KEY \`FK_8e7e0bf6eebd99f58e9b47c6b05\``); - await queryRunner.query(`ALTER TABLE \`actualGoal\` DROP COLUMN \`posLevelActualId\``); - await queryRunner.query(`ALTER TABLE \`actualGoal\` DROP COLUMN \`posTypeActualId\``); - await queryRunner.query(`ALTER TABLE \`plannedGoalPosition\` DROP COLUMN \`posLevelPlannedId\``); - await queryRunner.query(`ALTER TABLE \`plannedGoalPosition\` DROP COLUMN \`posTypePlannedId\``); - await queryRunner.query(`ALTER TABLE \`actualGoal\` ADD \`posTypeActual\` varchar(255) NULL COMMENT 'ประเภทตำแหน่ง & กลุ่มงาน'`); - await queryRunner.query(`ALTER TABLE \`actualGoal\` ADD \`posLevelActual\` varchar(255) NULL COMMENT 'ระดับตำแหน่ง & ระดับชั้นงาน'`); - await queryRunner.query(`ALTER TABLE \`plannedGoalPosition\` ADD \`posTypePlanned\` varchar(255) NULL COMMENT 'ประเภทตำแหน่ง & กลุ่มงาน'`); - await queryRunner.query(`ALTER TABLE \`plannedGoalPosition\` ADD \`posLevelPlanned\` varchar(255) NULL COMMENT 'ระดับตำแหน่ง & ระดับชั้นงาน'`); - } - - public async down(queryRunner: QueryRunner): Promise { - await queryRunner.query(`ALTER TABLE \`plannedGoalPosition\` DROP COLUMN \`posLevelPlanned\``); - await queryRunner.query(`ALTER TABLE \`plannedGoalPosition\` DROP COLUMN \`posTypePlanned\``); - await queryRunner.query(`ALTER TABLE \`actualGoal\` DROP COLUMN \`posLevelActual\``); - await queryRunner.query(`ALTER TABLE \`actualGoal\` DROP COLUMN \`posTypeActual\``); - await queryRunner.query(`ALTER TABLE \`plannedGoalPosition\` ADD \`posTypePlannedId\` varchar(255) NULL COMMENT 'ประเภทตำแหน่ง'`); - await queryRunner.query(`ALTER TABLE \`plannedGoalPosition\` ADD \`posLevelPlannedId\` varchar(255) NULL COMMENT 'ระดับตำแหน่ง'`); - await queryRunner.query(`ALTER TABLE \`actualGoal\` ADD \`posTypeActualId\` varchar(255) NULL COMMENT 'ประเภทตำแหน่ง'`); - await queryRunner.query(`ALTER TABLE \`actualGoal\` ADD \`posLevelActualId\` varchar(255) NULL COMMENT 'ระดับตำแหน่ง'`); - await queryRunner.query(`ALTER TABLE \`plannedGoalPosition\` ADD CONSTRAINT \`FK_8e7e0bf6eebd99f58e9b47c6b05\` FOREIGN KEY (\`posLevelPlannedId\`) REFERENCES \`posLevel\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`); - await queryRunner.query(`ALTER TABLE \`plannedGoalPosition\` ADD CONSTRAINT \`FK_4eef5d8c3ab92f7af4a762150a4\` FOREIGN KEY (\`posTypePlannedId\`) REFERENCES \`posType\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`); - await queryRunner.query(`ALTER TABLE \`actualGoal\` ADD CONSTRAINT \`FK_e08e337e5ddeb4942c72393ff58\` FOREIGN KEY (\`posTypeActualId\`) REFERENCES \`posType\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`); - await queryRunner.query(`ALTER TABLE \`actualGoal\` ADD CONSTRAINT \`FK_a9a864dd06eaa25edba8be8f24c\` FOREIGN KEY (\`posLevelActualId\`) REFERENCES \`posLevel\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`); - } - -} diff --git a/src/migration/1745290442590-update_table_developAddress_and_developScholaship_add_fields.ts b/src/migration/1745290442590-update_table_developAddress_and_developScholaship_add_fields.ts deleted file mode 100644 index 001ec46..0000000 --- a/src/migration/1745290442590-update_table_developAddress_and_developScholaship_add_fields.ts +++ /dev/null @@ -1,24 +0,0 @@ -import { MigrationInterface, QueryRunner } from "typeorm"; - -export class UpdateTableDevelopAddressAndDevelopScholashipAddFields1745290442590 implements MigrationInterface { - name = 'UpdateTableDevelopAddressAndDevelopScholashipAddFields1745290442590' - - public async up(queryRunner: QueryRunner): Promise { - await queryRunner.query(`ALTER TABLE \`developmentScholarship\` ADD \`budgetSourceOther\` int NULL COMMENT 'เงินอื่นๆ'`); - await queryRunner.query(`ALTER TABLE \`developmentAddress\` ADD \`addressType\` varchar(255) NULL COMMENT 'สถานที่ดำเนินการ ในประเทศ(IN_COUNTRY) หรือ ต่างประเทศ(ABROAD)'`); - await queryRunner.query(`ALTER TABLE \`developmentAddress\` ADD \`country\` varchar(255) NULL COMMENT 'ชื่อประเทศ (กรณีเลือกสถานที่ดำเนินการต่างประเทศ)'`); - await queryRunner.query(`ALTER TABLE \`developmentScholarship\` DROP COLUMN \`useOfficialTime\``); - await queryRunner.query(`ALTER TABLE \`developmentScholarship\` ADD \`useOfficialTime\` varchar(255) NOT NULL COMMENT 'ใช้เวลาราชการ' DEFAULT 0`); - await queryRunner.query(`ALTER TABLE \`developmentAddress\` CHANGE \`provinceName\` \`provinceName\` varchar(255) NULL COMMENT 'ชื่อจังหวัด (กรณีเลือกสถานที่ดำเนินการในประเทศ)'`); - } - - public async down(queryRunner: QueryRunner): Promise { - await queryRunner.query(`ALTER TABLE \`developmentAddress\` CHANGE \`provinceName\` \`provinceName\` varchar(255) NULL COMMENT 'โครงการ/หลักสูตรการฝึกอบรม'`); - await queryRunner.query(`ALTER TABLE \`developmentScholarship\` DROP COLUMN \`useOfficialTime\``); - await queryRunner.query(`ALTER TABLE \`developmentScholarship\` ADD \`useOfficialTime\` tinyint NOT NULL COMMENT 'ใช้เวลาราชการ' DEFAULT '0'`); - await queryRunner.query(`ALTER TABLE \`developmentAddress\` DROP COLUMN \`country\``); - await queryRunner.query(`ALTER TABLE \`developmentAddress\` DROP COLUMN \`addressType\``); - await queryRunner.query(`ALTER TABLE \`developmentScholarship\` DROP COLUMN \`budgetSourceOther\``); - } - -} diff --git a/src/migration/1745313881448-update_table_developScholaship_edit_type.ts b/src/migration/1745313881448-update_table_developScholaship_edit_type.ts deleted file mode 100644 index c6c393f..0000000 --- a/src/migration/1745313881448-update_table_developScholaship_edit_type.ts +++ /dev/null @@ -1,16 +0,0 @@ -import { MigrationInterface, QueryRunner } from "typeorm"; - -export class UpdateTableDevelopScholashipEditType1745313881448 implements MigrationInterface { - name = 'UpdateTableDevelopScholashipEditType1745313881448' - - public async up(queryRunner: QueryRunner): Promise { - await queryRunner.query(`ALTER TABLE \`developmentScholarship\` DROP COLUMN \`budgetSourceOther\``); - await queryRunner.query(`ALTER TABLE \`developmentScholarship\` ADD \`budgetSourceOther\` varchar(255) NULL COMMENT 'เงินอื่นๆ'`); - } - - public async down(queryRunner: QueryRunner): Promise { - await queryRunner.query(`ALTER TABLE \`developmentScholarship\` DROP COLUMN \`budgetSourceOther\``); - await queryRunner.query(`ALTER TABLE \`developmentScholarship\` ADD \`budgetSourceOther\` int NULL COMMENT 'เงินอื่นๆ'`); - } - -} diff --git a/src/migration/1750083465733-update30062025604.ts b/src/migration/1750083465733-update30062025604.ts new file mode 100644 index 0000000..8fcdedc --- /dev/null +++ b/src/migration/1750083465733-update30062025604.ts @@ -0,0 +1,14 @@ +import { MigrationInterface, QueryRunner } from "typeorm"; + +export class Update300620256041750083465733 implements MigrationInterface { + name = 'Update300620256041750083465733' + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`developmentScholarship\` ADD \`rootDnaId\` varchar(255) NULL COMMENT 'id dna หน่วยงาน'`); + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`developmentScholarship\` DROP COLUMN \`rootDnaId\``); + } + +} diff --git a/src/migration/1750083913468-update30062025605.ts b/src/migration/1750083913468-update30062025605.ts new file mode 100644 index 0000000..644e8c2 --- /dev/null +++ b/src/migration/1750083913468-update30062025605.ts @@ -0,0 +1,14 @@ +import { MigrationInterface, QueryRunner } from "typeorm"; + +export class Update300620256051750083913468 implements MigrationInterface { + name = 'Update300620256051750083913468' + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`developmentScholarship\` ADD \`guarantorRootDnaId\` varchar(255) NULL COMMENT 'id Dna หน่วยงาน'`); + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`developmentScholarship\` DROP COLUMN \`guarantorRootDnaId\``); + } + +} From 468f0b304fd2d4e5c26e1526eac063dbe9f1d0b9 Mon Sep 17 00:00:00 2001 From: AdisakKanthawilang Date: Tue, 15 Jul 2025 16:59:23 +0700 Subject: [PATCH 240/250] #1626 --- src/controllers/ReportController.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/controllers/ReportController.ts b/src/controllers/ReportController.ts index a6b6913..e6b9826 100644 --- a/src/controllers/ReportController.ts +++ b/src/controllers/ReportController.ts @@ -604,6 +604,14 @@ export class ReportController extends Controller { getDevelopment.scholarshipType = "ศึกษา ฝึกอบรม ประชุม ดูงาน และปฏิบัติการวิจัย ณ ต่างประเทศ"; break; + case "STUDY": + getDevelopment.scholarshipType = + "ทุนการศึกษา ณ ต่างประเทศ"; + break; + case "TRAINING": + getDevelopment.scholarshipType = + "ทุนฝึกอบรม ณ ต่างประเทศ"; + break; default: break; } From ce39e89ccebe71f2e389a13997365840630d28af Mon Sep 17 00:00:00 2001 From: AdisakKanthawilang Date: Wed, 16 Jul 2025 11:11:48 +0700 Subject: [PATCH 241/250] update --- src/controllers/DevelopmentController.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/controllers/DevelopmentController.ts b/src/controllers/DevelopmentController.ts index 77986d2..5aa9632 100644 --- a/src/controllers/DevelopmentController.ts +++ b/src/controllers/DevelopmentController.ts @@ -2678,6 +2678,7 @@ export class DevelopmentController extends Controller { startDate: x.dateStart, endDate: x.dateEnd, isDate: true, + isEntry: false, developmentId: id, }) .then((x) => { @@ -2701,6 +2702,7 @@ export class DevelopmentController extends Controller { startDate: x.dateStart, endDate: x.dateEnd, isDate: true, + isEntry: false, developmentId: id, }) .then((x) => { From b95d59783b50ba3d30eb1540fcf26ab24d265eaa Mon Sep 17 00:00:00 2001 From: AdisakKanthawilang Date: Wed, 16 Jul 2025 14:26:48 +0700 Subject: [PATCH 242/250] update --- src/controllers/DevelopmentController.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/controllers/DevelopmentController.ts b/src/controllers/DevelopmentController.ts index 5aa9632..77986d2 100644 --- a/src/controllers/DevelopmentController.ts +++ b/src/controllers/DevelopmentController.ts @@ -2678,7 +2678,6 @@ export class DevelopmentController extends Controller { startDate: x.dateStart, endDate: x.dateEnd, isDate: true, - isEntry: false, developmentId: id, }) .then((x) => { @@ -2702,7 +2701,6 @@ export class DevelopmentController extends Controller { startDate: x.dateStart, endDate: x.dateEnd, isDate: true, - isEntry: false, developmentId: id, }) .then((x) => { From e78811dfd6bf5e903189964422180028d7afef6f Mon Sep 17 00:00:00 2001 From: AdisakKanthawilang Date: Wed, 16 Jul 2025 15:10:37 +0700 Subject: [PATCH 243/250] #963 , #964 --- src/controllers/DevelopmentEmployeeHistoryController.ts | 1 + src/controllers/DevelopmentHistoryController.ts | 1 + 2 files changed, 2 insertions(+) diff --git a/src/controllers/DevelopmentEmployeeHistoryController.ts b/src/controllers/DevelopmentEmployeeHistoryController.ts index 2b8054f..2fb81f3 100644 --- a/src/controllers/DevelopmentEmployeeHistoryController.ts +++ b/src/controllers/DevelopmentEmployeeHistoryController.ts @@ -403,6 +403,7 @@ export class DevelopmentEmployeeHistoryController extends Controller { dateStart: getDevelopment.development != null ? getDevelopment.development.dateStart : null, dateEnd: getDevelopment.development != null ? getDevelopment.development.dateEnd : null, totalDate: getDevelopment.development != null ? getDevelopment.development.totalDate : null, + trainingDays: getDevelopment.development != null ? getDevelopment.trainingDays : null, // addressAcademic: // getDevelopment.development != null ? getDevelopment.development.addressAcademic : null, // topicAcademic: diff --git a/src/controllers/DevelopmentHistoryController.ts b/src/controllers/DevelopmentHistoryController.ts index 5ab0f55..edb65eb 100644 --- a/src/controllers/DevelopmentHistoryController.ts +++ b/src/controllers/DevelopmentHistoryController.ts @@ -390,6 +390,7 @@ export class DevelopmentOfficerHistoryController extends Controller { dateStart: getDevelopment.development != null ? getDevelopment.development.dateStart : null, dateEnd: getDevelopment.development != null ? getDevelopment.development.dateEnd : null, totalDate: getDevelopment.development != null ? getDevelopment.development.totalDate : null, + trainingDays: getDevelopment.development != null ? getDevelopment.trainingDays : null, // addressAcademic: // getDevelopment.development != null ? getDevelopment.development.addressAcademic : null, // topicAcademic: From 06385990b56e691ea45e0652675d5996e8d38a2f Mon Sep 17 00:00:00 2001 From: AdisakKanthawilang Date: Wed, 16 Jul 2025 16:36:14 +0700 Subject: [PATCH 244/250] #1635 --- src/controllers/DevelopmentController.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/controllers/DevelopmentController.ts b/src/controllers/DevelopmentController.ts index 77986d2..8bc84cf 100644 --- a/src/controllers/DevelopmentController.ts +++ b/src/controllers/DevelopmentController.ts @@ -1551,7 +1551,7 @@ export class DevelopmentController extends Controller { if (!development) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงการ/หลักสูตรการฝึกอบรมนี้"); } - Object.assign(development, { ...requestBody, developmentAddresss: [] }); + Object.assign(development, { ...requestBody}); development.lastUpdateUserId = request.user.sub; development.lastUpdateFullName = request.user.name; development.lastUpdatedAt = new Date(); From 9f21a4d49866b1e921c556ebdb59b15f4c132d85 Mon Sep 17 00:00:00 2001 From: AdisakKanthawilang Date: Thu, 17 Jul 2025 18:21:01 +0700 Subject: [PATCH 245/250] #1412 --- src/controllers/DevelopmentController.ts | 75 ++++++------------------ 1 file changed, 19 insertions(+), 56 deletions(-) diff --git a/src/controllers/DevelopmentController.ts b/src/controllers/DevelopmentController.ts index 8bc84cf..1bb0417 100644 --- a/src/controllers/DevelopmentController.ts +++ b/src/controllers/DevelopmentController.ts @@ -1946,6 +1946,9 @@ export class DevelopmentController extends Controller { developmentProjectTechniqueActuals: true, developmentEvaluations: true, developmentAddresss: true, + developmentRisks: true, + developmentHistorys: true, + developmentOthers: true, }, }); if (!development) { @@ -1959,92 +1962,46 @@ export class DevelopmentController extends Controller { const plannedGoalPosition = await this.plannedGoalPositionRepository.find({ where: { plannedGoalId: In(development.developmentPlannedGoals.map((x) => x.id)) }, }); - // addLogSequence(request, { - // action: "remove", - // status: "success", - // description: "Remove PlannedGoalPosition.", - // }); await this.plannedGoalPositionRepository.remove(plannedGoalPosition, { data: request }); } - // addLogSequence(request, { - // action: "remove", - // status: "success", - // description: "Remove ActualPeople.", - // }); await this.actualPeopleRepository.remove(development.developmentActualPeoples, { data: request, }); - // addLogSequence(request, { - // action: "remove", - // status: "success", - // description: "Remove PlannedPeople.", - // }); await this.plannedPeopleRepository.remove(development.developmentPlannedPeoples, { data: request, }); - // addLogSequence(request, { - // action: "remove", - // status: "success", - // description: "Remove ActualGoal.", - // }); await this.actualGoalRepository.remove(development.developmentActualGoals, { data: request }); - // addLogSequence(request, { - // action: "remove", - // status: "success", - // description: "Remove PlannedGoal.", - // }); await this.plannedGoalRepository.remove(development.developmentPlannedGoals, { data: request }); - // addLogSequence(request, { - // action: "remove", - // status: "success", - // description: "Remove DevelopmentProjectType.", - // }); await this.developmentProjectTypeRepository.remove(development.developmentProjectTypes, { data: request, }); - // addLogSequence(request, { - // action: "remove", - // status: "success", - // description: "Remove DevelopmentProjectTechniquePlanned.", - // }); await this.developmentProjectTechniquePlannedRepository.remove( development.developmentProjectTechniquePlanneds, { data: request, }, ); - // addLogSequence(request, { - // action: "remove", - // status: "success", - // description: "Remove DevelopmentProjectTechniqueActuals.", - // }); await this.developmentProjectTechniqueActualRepository.remove( development.developmentProjectTechniqueActuals, { data: request, }, ); - // addLogSequence(request, { - // action: "remove", - // status: "success", - // description: "Remove DevelopmentEvaluation.", - // }); await this.developmentEvaluationRepository.remove(development.developmentEvaluations, { data: request, }); - // addLogSequence(request, { - // action: "remove", - // status: "success", - // description: "Remove DevelopmentAddresss.", - // }); await this.developmentAddresssRepository.remove(development.developmentAddresss, { data: request, }); - // addLogSequence(request, { - // action: "remove", - // status: "success", - // description: "Remove Development.", - // }); + await this.developmentRiskRepository.remove(development.developmentRisks, { + data: request, + }); + await this.developmentHistoryRepository.remove(development.developmentHistorys, { + data: request, + }); + await this.developmentOtherRepository.remove(development.developmentOthers, { + data: request, + }); await this.developmentRepository.remove(development, { data: request }); return new HttpSuccess(); } @@ -2786,7 +2743,13 @@ export class DevelopmentController extends Controller { techniqueActuals.length > 0 && dev20Lists.some((item) => techniqueActuals.includes(item)); isDevelopment10 = techniqueActuals.length > 0 && dev10Lists.some((item) => techniqueActuals.includes(item)); - + + console.log("x.development?.developmentProjectTechniqueActuals",x.development?.developmentProjectTechniqueActuals); + console.log("techniqueActuals",techniqueActuals); + console.log("isDevelopment70",isDevelopment70); + console.log("isDevelopment20",isDevelopment20); + console.log("isDevelopment10",isDevelopment10); + if (x.type == "OFFICER") { await new CallAPI() .PostData(request, "/org/profile/development", { From 8c51bcc920c77a48f2a7500cb974577739836001 Mon Sep 17 00:00:00 2001 From: AdisakKanthawilang Date: Thu, 24 Jul 2025 13:41:09 +0700 Subject: [PATCH 246/250] delete log --- src/controllers/DevelopmentController.ts | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/controllers/DevelopmentController.ts b/src/controllers/DevelopmentController.ts index 1bb0417..0642d60 100644 --- a/src/controllers/DevelopmentController.ts +++ b/src/controllers/DevelopmentController.ts @@ -2743,12 +2743,6 @@ export class DevelopmentController extends Controller { techniqueActuals.length > 0 && dev20Lists.some((item) => techniqueActuals.includes(item)); isDevelopment10 = techniqueActuals.length > 0 && dev10Lists.some((item) => techniqueActuals.includes(item)); - - console.log("x.development?.developmentProjectTechniqueActuals",x.development?.developmentProjectTechniqueActuals); - console.log("techniqueActuals",techniqueActuals); - console.log("isDevelopment70",isDevelopment70); - console.log("isDevelopment20",isDevelopment20); - console.log("isDevelopment10",isDevelopment10); if (x.type == "OFFICER") { await new CallAPI() From 0f5b9401adc7c5d045a2c9114c5471b5542daaf6 Mon Sep 17 00:00:00 2001 From: kittapath-Jool Date: Fri, 1 Aug 2025 15:50:28 +0700 Subject: [PATCH 247/250] delete dna post --- .github/workflows/release.yaml | 72 +++++++++++++------------- src/entities/DevelopmentScholarship.ts | 2 +- 2 files changed, 37 insertions(+), 37 deletions(-) diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 0d19c5a..6916881 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -67,40 +67,40 @@ jobs: docker compose pull docker compose up -d echo "${{ steps.gen_ver.outputs.image_ver }}"> success - - name: Notify Discord Success - if: success() - run: | - curl -H "Content-Type: application/json" \ - -X POST \ - -d '{ - "embeds": [{ - "title": "✅ Deployment Success!", - "description": "**Details:**\n- Image: `${{env.IMAGE_NAME}}`\n- Version: `${{ steps.gen_ver.outputs.image_ver }}`\n- Deployed by: `${{github.actor}}`", - "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 Success + # if: success() + # run: | + # curl -H "Content-Type: application/json" \ + # -X POST \ + # -d '{ + # "embeds": [{ + # "title": "✅ Deployment Success!", + # "description": "**Details:**\n- Image: `${{env.IMAGE_NAME}}`\n- Version: `${{ steps.gen_ver.outputs.image_ver }}`\n- Deployed by: `${{github.actor}}`", + # "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() - run: | - curl -H "Content-Type: application/json" \ - -X POST \ - -d '{ - "embeds": [{ - "title": "❌ Deployment Failed!", - "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 }} + # - name: Notify Discord Failure + # if: failure() + # run: | + # curl -H "Content-Type: application/json" \ + # -X POST \ + # -d '{ + # "embeds": [{ + # "title": "❌ Deployment Failed!", + # "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 }} diff --git a/src/entities/DevelopmentScholarship.ts b/src/entities/DevelopmentScholarship.ts index cd1c614..24745ae 100644 --- a/src/entities/DevelopmentScholarship.ts +++ b/src/entities/DevelopmentScholarship.ts @@ -606,7 +606,7 @@ export class CreateDevelopmentScholarship { posExecutive: string | null; posLevelId: string | null; posTypeId: string | null; - guarantorRootDnaId: string | null; + guarantorRootDnaId?: string | null; guarantorRootId: string | null; guarantorRoot: string | null; guarantorOrg: string | null; From d93edbf97addd025eefbcd5f8a6d36eeca498720 Mon Sep 17 00:00:00 2001 From: kittapath-Jool Date: Fri, 1 Aug 2025 15:54:00 +0700 Subject: [PATCH 248/250] add noti --- .github/workflows/release.yaml | 72 +++++++++++++++++----------------- 1 file changed, 36 insertions(+), 36 deletions(-) diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 6916881..0d19c5a 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -67,40 +67,40 @@ jobs: docker compose pull docker compose up -d echo "${{ steps.gen_ver.outputs.image_ver }}"> success - # - name: Notify Discord Success - # if: success() - # run: | - # curl -H "Content-Type: application/json" \ - # -X POST \ - # -d '{ - # "embeds": [{ - # "title": "✅ Deployment Success!", - # "description": "**Details:**\n- Image: `${{env.IMAGE_NAME}}`\n- Version: `${{ steps.gen_ver.outputs.image_ver }}`\n- Deployed by: `${{github.actor}}`", - # "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 Success + if: success() + run: | + curl -H "Content-Type: application/json" \ + -X POST \ + -d '{ + "embeds": [{ + "title": "✅ Deployment Success!", + "description": "**Details:**\n- Image: `${{env.IMAGE_NAME}}`\n- Version: `${{ steps.gen_ver.outputs.image_ver }}`\n- Deployed by: `${{github.actor}}`", + "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() - # run: | - # curl -H "Content-Type: application/json" \ - # -X POST \ - # -d '{ - # "embeds": [{ - # "title": "❌ Deployment Failed!", - # "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 }} + - name: Notify Discord Failure + if: failure() + run: | + curl -H "Content-Type: application/json" \ + -X POST \ + -d '{ + "embeds": [{ + "title": "❌ Deployment Failed!", + "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 }} From 217354f65319b344df0ee163d21364e6aaae136f Mon Sep 17 00:00:00 2001 From: Bright Date: Wed, 6 Aug 2025 10:53:06 +0700 Subject: [PATCH 249/250] =?UTF-8?q?api=20=E0=B8=A3=E0=B8=B2=E0=B8=A2?= =?UTF-8?q?=E0=B8=A5=E0=B8=B0=E0=B9=80=E0=B8=AD=E0=B8=B5=E0=B8=A2=E0=B8=94?= =?UTF-8?q?=E0=B8=A3=E0=B8=B2=E0=B8=A2=E0=B8=81=E0=B8=B2=E0=B8=A3=E0=B8=9C?= =?UTF-8?q?=E0=B8=A5=E0=B8=87=E0=B8=B2=E0=B8=99=20=E0=B9=83=E0=B8=8A?= =?UTF-8?q?=E0=B9=89.o=E0=B8=A3=E0=B8=B2=E0=B8=A2=E0=B8=87=E0=B8=B2?= =?UTF-8?q?=E0=B8=99=20=E0=B8=81.=E0=B8=9E.7/=E0=B8=81.=E0=B8=81.1=20#1642?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/PortfolioController.ts | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/controllers/PortfolioController.ts b/src/controllers/PortfolioController.ts index 294b7f6..eecf28a 100644 --- a/src/controllers/PortfolioController.ts +++ b/src/controllers/PortfolioController.ts @@ -103,6 +103,32 @@ export class PortfolioController extends Controller { return new HttpSuccess(_portfolio); } + /** + * API รายละเอียดรายการผลงาน ใช้แสดงในรายงาน ก.พ.7/ก.ก.1 + * + * @summary รายละเอียดรายการผลงาน ใช้แสดงในรายงาน ก.พ.7/ก.ก.1 + * + */ + @Get("kk1/{keycloak}") + async GetPortfolio(@Path() keycloak: string, @Request() request: RequestWithUser) { + const _portfolio = await this.portfolioRepository.find({ + where: { createdUserId: keycloak }, + select: [ + "name", + "createdAt" + ], + order: { createdAt: "DESC" }, + }); + const result = + _portfolio.map(x => ({ + name: x.name, + year: x.createdAt.getFullYear() > 2500 + ? x.createdAt.getFullYear() + : x.createdAt.getFullYear()+543 + })); + return new HttpSuccess(result); + } + /** * API สร้างรายการ body ผลงาน * From 0f4b9778eeac59ee99e38c051c9b4d1fefd02533 Mon Sep 17 00:00:00 2001 From: AdisakKanthawilang Date: Mon, 18 Aug 2025 16:36:23 +0700 Subject: [PATCH 250/250] update search --- src/controllers/DevelopmentEmployeeHistoryController.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/controllers/DevelopmentEmployeeHistoryController.ts b/src/controllers/DevelopmentEmployeeHistoryController.ts index 2fb81f3..007d978 100644 --- a/src/controllers/DevelopmentEmployeeHistoryController.ts +++ b/src/controllers/DevelopmentEmployeeHistoryController.ts @@ -276,6 +276,14 @@ export class DevelopmentEmployeeHistoryController extends Controller { keyword: `%${body.keyword}%`, }, ) + .orWhere( + body.keyword != null && body.keyword != "" + ? "CONCAT(employeePosType.posTypeShortName,' ',employeePosLevel.posLevelName) LIKE :keyword" + : "1=1", + { + keyword: `%${body.keyword}%`, + }, + ) .orWhere( body.keyword != null && body.keyword != "" ? "developmentHistory.position LIKE :keyword"