From eaff0dac2cde7e605092d0179328883f82c5280c Mon Sep 17 00:00:00 2001 From: AnandaTon Date: Wed, 17 Apr 2024 18:15:24 +0700 Subject: [PATCH] =?UTF-8?q?API=20=E0=B8=81=E0=B8=A5=E0=B8=B8=E0=B9=88?= =?UTF-8?q?=E0=B8=A1=E0=B8=87=E0=B8=B2=E0=B8=99=20=E0=B9=81=E0=B8=81?= =?UTF-8?q?=E0=B9=89=E0=B9=84=E0=B8=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...uopController.ts => KpiGroupController.ts} | 44 +++++++-------- src/controllers/KpiPeriodController.ts | 54 +++++++++---------- src/entities/kpi.ts | 4 +- src/entities/kpiGrop.ts | 4 +- 4 files changed, 53 insertions(+), 53 deletions(-) rename src/controllers/{KpiGruopController.ts => KpiGroupController.ts} (71%) diff --git a/src/controllers/KpiGruopController.ts b/src/controllers/KpiGroupController.ts similarity index 71% rename from src/controllers/KpiGruopController.ts rename to src/controllers/KpiGroupController.ts index d80c09b..4db8e51 100644 --- a/src/controllers/KpiGruopController.ts +++ b/src/controllers/KpiGroupController.ts @@ -19,7 +19,7 @@ import { AppDataSource } from "../database/data-source"; import HttpSuccess from "../interfaces/http-success"; import HttpError from "../interfaces/http-error"; import HttpStatusCode from "../interfaces/http-status"; -import { KpiGroup, creatGroupKpi, updateGroupKpi } from "../entities/kpiGrop"; +import { KpiGroup, creatKpiGroup, updateKpiGroup } from "../entities/kpiGrop"; @Route("api/v1/kpi/group") @Tags("kpi") @Security("bearerAuth") @@ -29,7 +29,7 @@ import { KpiGroup, creatGroupKpi, updateGroupKpi } from "../entities/kpiGrop"; ) @SuccessResponse(HttpStatusCode.OK, "สำเร็จ") export class kpiGroupController extends Controller { - private kpiRepository = AppDataSource.getRepository(KpiGroup); + private kpiGroupRepository = AppDataSource.getRepository(KpiGroup); /** * API สร้างกลุ่มงาน @@ -41,17 +41,17 @@ export class kpiGroupController extends Controller { @Example({ nameGroupKPI: "string", //ชื่อกลุ่มงาน }) - async createKpi( - @Body() requestBody: creatGroupKpi, + async createKpiGroup( + @Body() requestBody: creatKpiGroup, @Request() request: { user: Record }, ) { const kpi = Object.assign(new KpiGroup(), requestBody); - kpi.nameGroupKPI = requestBody.nameGroupKPI.trim().toUpperCase(); + kpi.nameGroupKPI = requestBody.nameGroupKPI; kpi.createdUserId = request.user.sub; kpi.createdFullName = request.user.name; kpi.lastUpdateUserId = request.user.sub; kpi.lastUpdateFullName = request.user.name; - await this.kpiRepository.save(kpi); + await this.kpiGroupRepository.save(kpi); return new HttpSuccess(kpi.id); } @@ -60,25 +60,25 @@ export class kpiGroupController extends Controller { * @param id ไอดีของกลุ่มงาน */ @Put("{id}") - async update_kpi( + async updateKpiGroup( @Path() id: string, - @Body() requestBody: updateGroupKpi, + @Body() requestBody: updateKpiGroup, @Request() request: { user: Record }, ) { - const kpi_update = await this.kpiRepository.findOne({ + const kpiUpdate = await this.kpiGroupRepository.findOne({ where: { id: id }, }); - if (!kpi_update) { + if (!kpiUpdate) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลกลุ่มงานนี้"); } requestBody.nameGroupKPI = requestBody.nameGroupKPI.trim().toUpperCase(); - this.kpiRepository.merge(kpi_update, requestBody); - kpi_update.createdUserId = request.user.sub; - kpi_update.createdFullName = request.user.name; - kpi_update.lastUpdateUserId = request.user.sub; - kpi_update.lastUpdateFullName = request.user.name; - await this.kpiRepository.save(kpi_update); + this.kpiGroupRepository.merge(kpiUpdate, requestBody); + kpiUpdate.createdUserId = request.user.sub; + kpiUpdate.createdFullName = request.user.name; + kpiUpdate.lastUpdateUserId = request.user.sub; + kpiUpdate.lastUpdateFullName = request.user.name; + await this.kpiGroupRepository.save(kpiUpdate); return new HttpSuccess(id); } @@ -90,8 +90,8 @@ export class kpiGroupController extends Controller { @Example({ nameGroupKPI: "string", //ชื่อกลุ่มงาน }) - async CloseSalaryById(@Path() id: string) { - const kpi = await this.kpiRepository.findOne({ + async KpiGroupById(@Path() id: string) { + const kpi = await this.kpiGroupRepository.findOne({ where: { id: id }, select: ["nameGroupKPI"], }); @@ -106,15 +106,15 @@ export class kpiGroupController extends Controller { * @param id */ @Delete("{id}") - async delete_salary(@Path() id: string) { - const chk_KpiGroup = await this.kpiRepository.findOne({ + async deleteKpiGroup(@Path() id: string) { + const chkKpiGroup = await this.kpiGroupRepository.findOne({ where: { id: id }, }); - if (!chk_KpiGroup) { + if (!chkKpiGroup) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลกลุ่มงานนี้"); } - await this.kpiRepository.remove(chk_KpiGroup); + await this.kpiGroupRepository.remove(chkKpiGroup); return new HttpSuccess(); } } diff --git a/src/controllers/KpiPeriodController.ts b/src/controllers/KpiPeriodController.ts index e938aed..9156ef7 100644 --- a/src/controllers/KpiPeriodController.ts +++ b/src/controllers/KpiPeriodController.ts @@ -19,7 +19,7 @@ import { AppDataSource } from "../database/data-source"; import HttpSuccess from "../interfaces/http-success"; import HttpError from "../interfaces/http-error"; import HttpStatusCode from "../interfaces/http-status"; -import { KpiPeriod, createKpi, updateKpi } from "../entities/kpi"; +import { KpiPeriod, createKpiPeriod, updateKpiPeriod } from "../entities/kpi"; @Route("api/v1/kpi/period") @Tags("kpi") @@ -30,7 +30,7 @@ import { KpiPeriod, createKpi, updateKpi } from "../entities/kpi"; ) @SuccessResponse(HttpStatusCode.OK, "สำเร็จ") export class kpiController extends Controller { - private kpiRepository = AppDataSource.getRepository(KpiPeriod); + private kpiPeriodRepository = AppDataSource.getRepository(KpiPeriod); /** * สร้างรอบการประเมินผลการปฏิบัติหน้าที่ราชการ * @param requestBody @@ -43,7 +43,7 @@ export class kpiController extends Controller { endDate: "datetime", //วันสิ้นสุด }) async createKpi( - @Body() requestBody: createKpi, + @Body() requestBody: createKpiPeriod, @Request() request: { user: Record }, ) { const kpi = Object.assign(new KpiPeriod(), requestBody); @@ -52,7 +52,7 @@ export class kpiController extends Controller { kpi.createdFullName = request.user.name; kpi.lastUpdateUserId = request.user.sub; kpi.lastUpdateFullName = request.user.name; - await this.kpiRepository.save(kpi); + await this.kpiPeriodRepository.save(kpi); return new HttpSuccess(kpi.id); } @@ -63,15 +63,15 @@ export class kpiController extends Controller { * @param request */ @Put("{id}") - async update_kpi( + async updateKpiPeriod( @Path() id: string, - @Body() requestBody: updateKpi, + @Body() requestBody: updateKpiPeriod, @Request() request: { user: Record }, ) { - const kpi_update = await this.kpiRepository.findOne({ + const kpiUpdate = await this.kpiPeriodRepository.findOne({ where: { id: id }, }); - if (!kpi_update) { + if (!kpiUpdate) { throw new HttpError( HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลรอบการประเมินผลการปฏิบัติหน้าที่ราชการนี้", @@ -79,12 +79,12 @@ export class kpiController extends Controller { } requestBody.durationKPI = requestBody.durationKPI.trim().toUpperCase(); - this.kpiRepository.merge(kpi_update, requestBody); - kpi_update.createdUserId = request.user.sub; - kpi_update.createdFullName = request.user.name; - kpi_update.lastUpdateUserId = request.user.sub; - kpi_update.lastUpdateFullName = request.user.name; - await this.kpiRepository.save(kpi_update); + this.kpiPeriodRepository.merge(kpiUpdate, requestBody); + kpiUpdate.createdUserId = request.user.sub; + kpiUpdate.createdFullName = request.user.name; + kpiUpdate.lastUpdateUserId = request.user.sub; + kpiUpdate.lastUpdateFullName = request.user.name; + await this.kpiPeriodRepository.save(kpiUpdate); return new HttpSuccess(id); } @@ -98,8 +98,8 @@ export class kpiController extends Controller { startDate: "datetime", //วันเริ่มต้น endDate: "datetime", //วันสิ้นสุด }) - async CloseSalaryById(@Path() id: string) { - const kpi = await this.kpiRepository.findOne({ + async CloseKpiPeriodById(@Path() id: string) { + const kpi = await this.kpiPeriodRepository.findOne({ where: { id: id }, }); if (!kpi) { @@ -109,7 +109,7 @@ export class kpiController extends Controller { ); } kpi.isActive = false; - await this.kpiRepository.save(kpi); + await this.kpiPeriodRepository.save(kpi); return new HttpSuccess(kpi); } @@ -123,8 +123,8 @@ export class kpiController extends Controller { startDate: "datetime", //วันเริ่มต้น endDate: "datetime", //วันสิ้นสุด }) - async OpenSalaryById(@Path() id: string) { - const kpi = await this.kpiRepository.findOne({ + async OpenKpiPeriodById(@Path() id: string) { + const kpi = await this.kpiPeriodRepository.findOne({ where: { id: id }, }); if (!kpi) { @@ -134,7 +134,7 @@ export class kpiController extends Controller { ); } kpi.isActive = true; - await this.kpiRepository.save(kpi); + await this.kpiPeriodRepository.save(kpi); return new HttpSuccess(kpi); } @@ -148,8 +148,8 @@ export class kpiController extends Controller { startDate: "datetime", //วันเริ่มต้น endDate: "datetime", //วันสิ้นสุด }) - async GetSalaryById(@Path() id: string) { - const kpi = await this.kpiRepository.findOne({ + async GetKpiPeriodById(@Path() id: string) { + const kpi = await this.kpiPeriodRepository.findOne({ where: { id: id }, select: ["durationKPI", "startDate", "endDate", "isActive"], }); @@ -175,7 +175,7 @@ export class kpiController extends Controller { @Query("year") year?: string, @Query("keyword") keyword?: string, ) { - const [kpiPeriod, total] = await this.kpiRepository.findAndCount({ + const [kpiPeriod, total] = await this.kpiPeriodRepository.findAndCount({ // where: { // name: Like(`%${keyword}%`), // }, @@ -190,18 +190,18 @@ export class kpiController extends Controller { * @param id */ @Delete("{id}") - async delete_salary(@Path() id: string) { - const chk_KpiPeriod = await this.kpiRepository.findOne({ + async deleteKpiPerriod(@Path() id: string) { + const chkKpiPeriod = await this.kpiPeriodRepository.findOne({ where: { id: id }, }); - if (!chk_KpiPeriod) { + if (!chkKpiPeriod) { throw new HttpError( HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลรอบการประเมินผลการปฏิบัติหน้าที่ราชการนี้", ); } - await this.kpiRepository.remove(chk_KpiPeriod); + await this.kpiPeriodRepository.remove(chkKpiPeriod); return new HttpSuccess(); } } diff --git a/src/entities/kpi.ts b/src/entities/kpi.ts index c1001b8..8a57d6a 100644 --- a/src/entities/kpi.ts +++ b/src/entities/kpi.ts @@ -32,7 +32,7 @@ export class KpiPeriod extends EntityBase { }) isActive: boolean; } -export class createKpi { +export class createKpiPeriod { @Column() durationKPI: string; @Column() @@ -43,7 +43,7 @@ export class createKpi { isActive: boolean; } -export class updateKpi { +export class updateKpiPeriod { @Column() durationKPI: string; @Column() diff --git a/src/entities/kpiGrop.ts b/src/entities/kpiGrop.ts index f1871cb..9e2956e 100644 --- a/src/entities/kpiGrop.ts +++ b/src/entities/kpiGrop.ts @@ -10,12 +10,12 @@ export class KpiGroup extends EntityBase { }) nameGroupKPI: string; } -export class creatGroupKpi { +export class creatKpiGroup { @Column() nameGroupKPI: string; } -export class updateGroupKpi { +export class updateKpiGroup { @Column() nameGroupKPI: string; }