From f75bd88f6b1aad91b2c4223242dc803966c84c14 Mon Sep 17 00:00:00 2001 From: Kittapath Date: Tue, 16 Apr 2024 07:50:53 +0700 Subject: [PATCH] =?UTF-8?q?=E0=B9=80=E0=B8=9B=E0=B8=B4=E0=B8=94=E0=B8=9B?= =?UTF-8?q?=E0=B8=B4=E0=B8=94=E0=B8=A3=E0=B8=AD=E0=B8=9A=E0=B8=9B=E0=B8=A3?= =?UTF-8?q?=E0=B8=B0=E0=B9=80=E0=B8=A1=E0=B8=B4=E0=B8=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/KpiPeriodController.ts | 56 ++++++++++++++++++- src/entities/kpi.ts | 10 ++++ ...389-update_table_kpiperiod_add_isactive.ts | 14 +++++ 3 files changed, 79 insertions(+), 1 deletion(-) create mode 100644 src/migration/1713223298389-update_table_kpiperiod_add_isactive.ts diff --git a/src/controllers/KpiPeriodController.ts b/src/controllers/KpiPeriodController.ts index 190c285..e938aed 100644 --- a/src/controllers/KpiPeriodController.ts +++ b/src/controllers/KpiPeriodController.ts @@ -88,6 +88,56 @@ export class kpiController extends Controller { return new HttpSuccess(id); } + /** + * API ปิดรอบการประเมินผลการปฏิบัติหน้าที่ราชการ + * @param id Guid, *Id ปิดรอบการประเมินผลการปฏิบัติหน้าที่ราชการ + */ + @Get("close/{id}") + @Example({ + durationKPI: "string", //รอบเดือนที่สร้าง + startDate: "datetime", //วันเริ่มต้น + endDate: "datetime", //วันสิ้นสุด + }) + async CloseSalaryById(@Path() id: string) { + const kpi = await this.kpiRepository.findOne({ + where: { id: id }, + }); + if (!kpi) { + throw new HttpError( + HttpStatusCode.NOT_FOUND, + "ไม่พบข้อมูลรอบการประเมินผลการปฏิบัติหน้าที่ราชการนี้", + ); + } + kpi.isActive = false; + await this.kpiRepository.save(kpi); + return new HttpSuccess(kpi); + } + + /** + * API เปิดรอบการประเมินผลการปฏิบัติหน้าที่ราชการ + * @param id Guid, *Id เปิดรอบการประเมินผลการปฏิบัติหน้าที่ราชการ + */ + @Get("open/{id}") + @Example({ + durationKPI: "string", //รอบเดือนที่สร้าง + startDate: "datetime", //วันเริ่มต้น + endDate: "datetime", //วันสิ้นสุด + }) + async OpenSalaryById(@Path() id: string) { + const kpi = await this.kpiRepository.findOne({ + where: { id: id }, + }); + if (!kpi) { + throw new HttpError( + HttpStatusCode.NOT_FOUND, + "ไม่พบข้อมูลรอบการประเมินผลการปฏิบัติหน้าที่ราชการนี้", + ); + } + kpi.isActive = true; + await this.kpiRepository.save(kpi); + return new HttpSuccess(kpi); + } + /** * API รอบการประเมินผลการปฏิบัติหน้าที่ราชการ * @param id Guid, *Id รอบการประเมินผลการปฏิบัติหน้าที่ราชการ @@ -101,7 +151,7 @@ export class kpiController extends Controller { async GetSalaryById(@Path() id: string) { const kpi = await this.kpiRepository.findOne({ where: { id: id }, - select: ["durationKPI", "startDate", "endDate"], + select: ["durationKPI", "startDate", "endDate", "isActive"], }); if (!kpi) { throw new HttpError( @@ -122,9 +172,13 @@ export class kpiController extends Controller { async listKpiPeriod( @Query("page") page: number = 1, @Query("pageSize") pageSize: number = 10, + @Query("year") year?: string, @Query("keyword") keyword?: string, ) { const [kpiPeriod, total] = await this.kpiRepository.findAndCount({ + // where: { + // name: Like(`%${keyword}%`), + // }, ...(keyword ? {} : { skip: (page - 1) * pageSize, take: pageSize }), }); diff --git a/src/entities/kpi.ts b/src/entities/kpi.ts index e9ccfd4..c1001b8 100644 --- a/src/entities/kpi.ts +++ b/src/entities/kpi.ts @@ -25,6 +25,12 @@ export class KpiPeriod extends EntityBase { default: null, }) endDate: Date; + + @Column({ + comment: "รอบ", + default: false, + }) + isActive: boolean; } export class createKpi { @Column() @@ -33,6 +39,8 @@ export class createKpi { startDate: Date; @Column() endDate: Date; + @Column() + isActive: boolean; } export class updateKpi { @@ -42,4 +50,6 @@ export class updateKpi { startDate: Date; @Column() endDate: Date; + @Column() + isActive: boolean; } diff --git a/src/migration/1713223298389-update_table_kpiperiod_add_isactive.ts b/src/migration/1713223298389-update_table_kpiperiod_add_isactive.ts new file mode 100644 index 0000000..8ebf0f9 --- /dev/null +++ b/src/migration/1713223298389-update_table_kpiperiod_add_isactive.ts @@ -0,0 +1,14 @@ +import { MigrationInterface, QueryRunner } from "typeorm"; + +export class UpdateTableKpiperiodAddIsactive1713223298389 implements MigrationInterface { + name = 'UpdateTableKpiperiodAddIsactive1713223298389' + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`kpiPeriod\` ADD \`isActive\` tinyint NOT NULL COMMENT 'รอบ' DEFAULT 0`); + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`kpiPeriod\` DROP COLUMN \`isActive\``); + } + +}