From b8e1c93cb48f4eba2e9f65e8d515f1eacba5e5dc Mon Sep 17 00:00:00 2001 From: Kittapath Date: Wed, 10 Apr 2024 11:53:25 +0700 Subject: [PATCH] =?UTF-8?q?=E0=B8=9A=E0=B8=B1=E0=B8=99=E0=B8=97=E0=B8=B6?= =?UTF-8?q?=E0=B8=81=E0=B8=A5=E0=B8=87=E0=B8=97=E0=B8=B0=E0=B9=80=E0=B8=9A?= =?UTF-8?q?=E0=B8=B5=E0=B8=A2=E0=B8=99=E0=B8=9B=E0=B8=A3=E0=B8=B0=E0=B8=A7?= =?UTF-8?q?=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\``); + } + +}