From 814572235506cc09e83504f9ace0690c3018ee65 Mon Sep 17 00:00:00 2001 From: Kittapath Date: Wed, 12 Jun 2024 09:25:59 +0700 Subject: [PATCH 1/2] =?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=AA=E0=B9=88=E0=B8=87?= =?UTF-8?q?=E0=B8=A7=E0=B8=B1=E0=B8=99=E0=B8=97=E0=B8=B5=E0=B9=88=E0=B8=A2?= =?UTF-8?q?=E0=B8=81=E0=B9=80=E0=B8=A5=E0=B8=B4=E0=B8=81=E0=B9=80=E0=B8=81?= =?UTF-8?q?=E0=B8=A9=E0=B8=B5=E0=B8=A2=E0=B8=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/ProfileController.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/controllers/ProfileController.ts b/src/controllers/ProfileController.ts index 7862f8f0..72bcb67c 100644 --- a/src/controllers/ProfileController.ts +++ b/src/controllers/ProfileController.ts @@ -1483,6 +1483,7 @@ export class ProfileController extends Controller { citizenId: profile.citizenId, birthDate: profile.birthDate, position: profile.position, + leaveDate: profile.dateLeave, posMaster: posMaster == null ? null : posMaster.posMasterNo, posMasterNo: posMaster == null ? null : posMaster.posMasterNo, posLevelName: profile.posLevel == null ? null : profile.posLevel.posLevelName, @@ -1617,6 +1618,7 @@ export class ProfileController extends Controller { citizenId: profile.citizenId, birthDate: profile.birthDate, position: profile.position, + leaveDate: profile.dateLeave, posMasterNo: posMaster == null ? null : posMaster.posMasterNo, posLevelName: profile.posLevel == null ? null : profile.posLevel.posLevelName, posLevelRank: profile.posLevel == null ? null : profile.posLevel.posLevelRank, @@ -1738,6 +1740,7 @@ export class ProfileController extends Controller { lastName: profile.lastName, citizenId: profile.citizenId, position: profile.position, + leaveDate: profile.dateLeave, posMasterNo: posMaster == null ? null : posMaster.posMasterNo, posLevelName: profile.posLevel == null ? null : profile.posLevel.posLevelName, posLevelRank: profile.posLevel == null ? null : profile.posLevel.posLevelRank, @@ -1859,6 +1862,7 @@ export class ProfileController extends Controller { lastName: profile.lastName, citizenId: profile.citizenId, position: profile.position, + leaveDate: profile.dateLeave, posMasterNo: posMaster == null ? null : posMaster.posMasterNo, posLevelName: profile.posLevel == null ? null : profile.posLevel.posLevelName, posLevelRank: profile.posLevel == null ? null : profile.posLevel.posLevelRank, From c1602a5512a06030fd57a426051cc1adb12a206e Mon Sep 17 00:00:00 2001 From: Bright Date: Wed, 12 Jun 2024 10:06:53 +0700 Subject: [PATCH 2/2] =?UTF-8?q?api=20=E0=B8=A3=E0=B8=AD=E0=B8=9A=E0=B8=A2?= =?UTF-8?q?=E0=B9=89=E0=B8=B2=E0=B8=A2=E0=B8=AA=E0=B8=B1=E0=B8=9A=E0=B9=80?= =?UTF-8?q?=E0=B8=9B=E0=B8=A5=E0=B8=B5=E0=B9=88=E0=B8=A2=E0=B8=99=E0=B8=95?= =?UTF-8?q?=E0=B8=B3=E0=B9=81=E0=B8=AB=E0=B8=99=E0=B9=88=E0=B8=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/ChangePositionController.ts | 118 ++++++++++++++++++- src/controllers/ProfileEmployeeController.ts | 1 + 2 files changed, 114 insertions(+), 5 deletions(-) diff --git a/src/controllers/ChangePositionController.ts b/src/controllers/ChangePositionController.ts index 09f231d8..0d604c61 100644 --- a/src/controllers/ChangePositionController.ts +++ b/src/controllers/ChangePositionController.ts @@ -19,11 +19,13 @@ import { 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 { Equal, ILike, In, IsNull, Like, Not, Brackets, MoreThan } from "typeorm"; -import { ChangePosition } from "../entities/ChangePosition"; +import { RequestWithUser } from "../middlewares/user"; +import { ChangePosition, CreateChangePosition, UpdateChangePosition } from "../entities/ChangePosition"; @Route("api/v1/placement/change-position") -@Tags("Switch") +@Tags("Placement") @Security("bearerAuth") @Response( HttpStatusCode.INTERNAL_SERVER_ERROR, @@ -34,17 +36,123 @@ export class ChangePositionController extends Controller { private ChangePositionRepository = AppDataSource.getRepository(ChangePosition); /** - * API รายการออกคำสั่งย้ายสับเปลี่ยนตำแหน่ง + * API เพิ่มรอบย้ายสับเปลี่ยนตำแหน่ง * - * @summary API รายการออกคำสั่งย้ายสับเปลี่ยนตำแหน่ง + * @summary เพิ่มรอบย้ายสับเปลี่ยนตำแหน่ง (ADMIN) + * + */ + @Post() + async CreateChangePosition( + @Body() body: CreateChangePosition, + @Request() request: RequestWithUser, + ) { + const _changePosition = await this.ChangePositionRepository.findOne({ + where: { name: body.name }, + }); + if(_changePosition){ + throw new HttpError( + HttpStatusCode.INTERNAL_SERVER_ERROR, + "ชื่อรอบการย้ายสับเปลี่ยนตำแหน่งนี้มีอยู่ในระบบแล้ว", + ); + } + + const changePosition = new ChangePosition(); + Object.assign(changePosition, body); + changePosition.date = new Date, + changePosition.status = "WAITTING", + changePosition.createdUserId = request.user.sub; + changePosition.createdFullName = request.user.name; + changePosition.lastUpdateUserId = request.user.sub; + changePosition.lastUpdateFullName = request.user.name; + await this.ChangePositionRepository.save(changePosition); + return new HttpSuccess(); + } + + /** + * API ลบรอบย้ายสับเปลี่ยนตำแหน่ง + * + * @summary ลบรอบย้ายสับเปลี่ยนตำแหน่ง (ADMIN) + * + * @param {string} id Id รอบย้ายสับเปลี่ยนตำแหน่ง + */ + @Delete("{id}") + async DeleteChangePosition(@Path() id: string) { + let result: any; + try { + result = await this.ChangePositionRepository.delete({ id: id }); + } catch { + throw new HttpError( + HttpStatusCode.NOT_FOUND, + "ไม่สามารถลบได้เนื่องจากมีการใช้งานรอบย้ายสับเปลี่ยนตำแหน่งนี้อยู่", + ); + } + if (result.affected == undefined || result.affected <= 0) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล"); + } + return new HttpSuccess(); + } + + /** + * API แก้ไขรอบย้ายสับเปลี่ยนตำแหน่ง + * + * @summary แก้ไขรอบย้ายสับเปลี่ยนตำแหน่ง (ADMIN) + * + * @param {string} id Id รอบย้ายสับเปลี่ยนตำแหน่ง + */ + @Put("{id}") + async UpdateChangePosition( + @Request() request: RequestWithUser, + @Path() id: string, + @Body() body: UpdateChangePosition, + ) { + + const changePosition = await this.ChangePositionRepository.findOneBy({ id }); + if (!changePosition) throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล"); + + const checkDuplicate = await this.ChangePositionRepository.find({ + where: { + id: Not(id), + name: body.name + }, + }); + if(checkDuplicate.length > 0){ + throw new HttpError( + HttpStatusCode.INTERNAL_SERVER_ERROR, + "ชื่อรอบการย้ายสับเปลี่ยนตำแหน่งนี้มีอยู่ในระบบแล้ว", + ); + } + Object.assign(changePosition, body); + changePosition.lastUpdateUserId = request.user.sub; + changePosition.lastUpdateFullName = request.user.name; + await this.ChangePositionRepository.save(changePosition); + return new HttpSuccess(); + } + + /** + * API รายการรอบย้ายสับเปลี่ยนตำแหน่ง + * + * @summary API รายการรอบย้ายสับเปลี่ยนตำแหน่ง (ADMIN) * */ @Get("") async GetChangePositionLists() { - const data = await this.ChangePositionRepository.find(); return new HttpSuccess(data); + } + /** + * API รายละเอียดรอบย้ายสับเปลี่ยนตำแหน่ง + * + * @summary API รายละเอียดรอบย้ายสับเปลี่ยนตำแหน่ง (ADMIN) + * + * @param {string} id Id รอบย้ายสับเปลี่ยนตำแหน่ง + */ + @Get("{id}") + async GetChangePositionById( @Path() id: string ) { + + const data = await this.ChangePositionRepository.findOne({ where: { id: id }}); + if (!data) throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลรอบย้ายสับเปลี่ยนตำแหน่ง"); + return new HttpSuccess(data); } } diff --git a/src/controllers/ProfileEmployeeController.ts b/src/controllers/ProfileEmployeeController.ts index e6f70abb..075251b9 100644 --- a/src/controllers/ProfileEmployeeController.ts +++ b/src/controllers/ProfileEmployeeController.ts @@ -535,6 +535,7 @@ export class ProfileEmployeeController extends Controller { profile.dateRetire = calculateRetireDate(profile.birthDate); profile.dateRetireLaw = calculateRetireLaw(profile.birthDate); profile.citizenId = Extension.CheckCitizen(profile.citizenId); + profile.statusTemp = profile.employeeClass.toLocaleUpperCase() == "TEMP" ? "WAITTING" : ""; profile.employeeClass = profile.employeeClass.toLocaleUpperCase(); await this.profileRepo.save(profile); return new HttpSuccess();