From 613dd34ad770ce234550e6ee6cd0b0c75cf6c96e Mon Sep 17 00:00:00 2001 From: Kittapath Date: Thu, 6 Jun 2024 18:04:11 +0700 Subject: [PATCH] =?UTF-8?q?=E0=B9=81=E0=B8=81=E0=B9=89=E0=B9=84=E0=B8=82?= =?UTF-8?q?=E0=B8=A7=E0=B8=B1=E0=B8=99=E0=B8=97=E0=B8=B5=E0=B9=88=E0=B9=80?= =?UTF-8?q?=E0=B8=81=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 | 25 +++++++++++++++++++ src/entities/Profile.ts | 14 ++++++++--- ...1714-update_table_Profile_add_dateLeave.ts | 16 ++++++++++++ 3 files changed, 52 insertions(+), 3 deletions(-) create mode 100644 src/migration/1717671751714-update_table_Profile_add_dateLeave.ts diff --git a/src/controllers/ProfileController.ts b/src/controllers/ProfileController.ts index 99ac32e5..bdce1e54 100644 --- a/src/controllers/ProfileController.ts +++ b/src/controllers/ProfileController.ts @@ -3009,4 +3009,29 @@ export class ProfileController extends Controller { }); return new HttpSuccess(formattedData); } + + /** + * API อัพเดทเกษียณ + * + * @summary อัพเดทเกษียณ (ADMIN) + * + * @param {string} id Id ทะเบียนประวัติ + */ + @Put("salary/{id}") + async updateLeaveUser( + @Path() id: string, + @Body() + requestBody: { isLeave: boolean; leaveReason: string; dateLeave: Date }, + ) { + const profile = await this.profileRepo.findOne({ + where: { id: id }, + }); + if (!profile) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); + + profile.isLeave = requestBody.isLeave; + profile.leaveReason = requestBody.leaveReason; + profile.dateLeave = requestBody.dateLeave; + await this.profileRepo.save(profile); + return new HttpSuccess(); + } } diff --git a/src/entities/Profile.ts b/src/entities/Profile.ts index a4e2dae6..ffc7015e 100644 --- a/src/entities/Profile.ts +++ b/src/entities/Profile.ts @@ -166,6 +166,14 @@ export class Profile extends EntityBase { }) leaveReason: string; + @Column({ + nullable: true, + type: "datetime", + comment: "วันพ้นราชการ", + default: null, + }) + dateLeave: Date; + @Column({ nullable: true, type: "datetime", @@ -466,15 +474,15 @@ export class Profile extends EntityBase { @Column({ nullable: true, length: 40, - comment: "ไอดีรอบลงเวลาล่าสุด" + comment: "ไอดีรอบลงเวลาล่าสุด", }) - dutyTimeId : string; + dutyTimeId: string; @Column({ nullable: true, type: "datetime", comment: "รอบลงเวลาล่าสุด", - default: null + default: null, }) dutyTimeEffectiveDate: Date; } diff --git a/src/migration/1717671751714-update_table_Profile_add_dateLeave.ts b/src/migration/1717671751714-update_table_Profile_add_dateLeave.ts new file mode 100644 index 00000000..f0a1aa09 --- /dev/null +++ b/src/migration/1717671751714-update_table_Profile_add_dateLeave.ts @@ -0,0 +1,16 @@ +import { MigrationInterface, QueryRunner } from "typeorm"; + +export class UpdateTableProfileAddDateLeave1717671751714 implements MigrationInterface { + name = 'UpdateTableProfileAddDateLeave1717671751714' + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`profile\` ADD \`dateLeave\` datetime NULL COMMENT 'วันพ้นราชการ'`); + await queryRunner.query(`ALTER TABLE \`profileHistory\` ADD \`dateLeave\` datetime NULL COMMENT 'วันพ้นราชการ'`); + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`profileHistory\` DROP COLUMN \`dateLeave\``); + await queryRunner.query(`ALTER TABLE \`profile\` DROP COLUMN \`dateLeave\``); + } + +}