From 78ce7fa6126cb89c47176803731b7a16a2deb0bf Mon Sep 17 00:00:00 2001 From: kittapath Date: Tue, 3 Sep 2024 19:08:13 +0700 Subject: [PATCH] =?UTF-8?q?=E0=B9=81=E0=B8=81=E0=B9=89=20import=20data=20?= =?UTF-8?q?=E0=B9=84=E0=B8=A1=E0=B8=9E=E0=B8=9A=E0=B8=82=E0=B9=89=E0=B8=AD?= =?UTF-8?q?=E0=B8=A1=E0=B8=B9=E0=B8=A5=E0=B9=83=E0=B8=99=E0=B8=97=E0=B8=B0?= =?UTF-8?q?=E0=B9=80=E0=B8=9A=E0=B8=B5=E0=B8=A2=E0=B8=99=E0=B8=9B=E0=B8=A3?= =?UTF-8?q?=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 *