From ecbb9c0d9f1bc5d09ce48a187ec5c1b363ed960d Mon Sep 17 00:00:00 2001 From: Kittapath Date: Fri, 26 Apr 2024 13:08:23 +0700 Subject: [PATCH] =?UTF-8?q?=E0=B9=80=E0=B8=9E=E0=B8=B4=E0=B9=88=E0=B8=A1?= =?UTF-8?q?=E0=B8=9F=E0=B8=B4=E0=B8=A7=E0=B8=9C=E0=B8=B9=E0=B9=89=E0=B8=9A?= =?UTF-8?q?=E0=B8=B1=E0=B8=87=E0=B8=84=E0=B8=B1=E0=B8=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/KpiEvaluationController.ts | 51 ++++++++-------- .../KpiUserEvaluationController.ts | 60 ++++++++++++++----- src/controllers/KpiUserPlannedController.ts | 17 ++++-- src/controllers/KpiUserRoleController.ts | 18 ++++-- src/controllers/KpiUserSpecialController.ts | 26 +++++--- src/entities/kpiUserEvaluation.ts | 45 +++++++++++++- ..._table_kpiUserEvalution_add_evaluatorId.ts | 18 ++++++ 7 files changed, 171 insertions(+), 64 deletions(-) create mode 100644 src/migration/1714111345274-update_table_kpiUserEvalution_add_evaluatorId.ts diff --git a/src/controllers/KpiEvaluationController.ts b/src/controllers/KpiEvaluationController.ts index 057b6f7..ee3eb52 100644 --- a/src/controllers/KpiEvaluationController.ts +++ b/src/controllers/KpiEvaluationController.ts @@ -37,32 +37,31 @@ export class kpiEvaluationController extends Controller { * @param id ไอดีของเกณฑ์การประเมิน */ @Put() -async updateKpiEvaluations( - @Body() requestBody: updateKpiEvaluation[], - @Request() request: { user: Record }, -) { - const updatedIds: string[] = []; + async updateKpiEvaluations( + @Body() requestBody: updateKpiEvaluation[], + @Request() request: { user: Record }, + ) { + const updatedIds: string[] = []; - for (const item of requestBody) { - const kpiEvaluation = await this.kpiEvaluationRepository.findOne({ - where: { id: item.id }, - }); - if (!kpiEvaluation) { - throw new HttpError(HttpStatusCode.NOT_FOUND, `ไม่พบข้อมูลเกณฑ์การประเมินนี้: ${item.id}`); + for (const item of requestBody) { + const kpiEvaluation = await this.kpiEvaluationRepository.findOne({ + where: { id: item.id }, + }); + if (!kpiEvaluation) { + throw new HttpError(HttpStatusCode.NOT_FOUND, `ไม่พบข้อมูลเกณฑ์การประเมินนี้: ${item.id}`); + } + + this.kpiEvaluationRepository.merge(kpiEvaluation, item); + kpiEvaluation.lastUpdateUserId = request.user.sub; + kpiEvaluation.lastUpdateFullName = request.user.name; + await this.kpiEvaluationRepository.save(kpiEvaluation); + + updatedIds.push(item.id); } - this.kpiEvaluationRepository.merge(kpiEvaluation, item); - kpiEvaluation.lastUpdateUserId = request.user.sub; - kpiEvaluation.lastUpdateFullName = request.user.name; - await this.kpiEvaluationRepository.save(kpiEvaluation); - - updatedIds.push(item.id); + return new HttpSuccess(); } - return new HttpSuccess(); -} - - /** * API list เกณฑ์การประเมิน * @param page @@ -81,20 +80,20 @@ async updateKpiEvaluations( where: [{ description: Like(`%${keyword}%`) }], }; whereClause.where.push({ level: Like(`%${keyword}%`) }); - } - + const [kpiEvaluation, total] = await this.kpiEvaluationRepository.findAndCount({ ...whereClause, ...(keyword ? {} : { skip: (page - 1) * pageSize, take: pageSize }), - order:{ - level: "DESC"} + order: { + level: "DESC", + }, }); const formatted = kpiEvaluation.map((item) => ({ id: item.id, level: item.level, - description: item.description + description: item.description, })); return new HttpSuccess({ data: formatted, total }); } diff --git a/src/controllers/KpiUserEvaluationController.ts b/src/controllers/KpiUserEvaluationController.ts index 4fb7d10..a6f1b09 100644 --- a/src/controllers/KpiUserEvaluationController.ts +++ b/src/controllers/KpiUserEvaluationController.ts @@ -24,6 +24,7 @@ import { KpiPeriod } from "../entities/kpiPeriod"; import { KpiUserEvaluation, createKpiUserEvaluation, + updateKpiUserCheckEvaluation, updateKpiUserEvaluation, } from "../entities/kpiUserEvaluation"; import { Like, In } from "typeorm"; @@ -120,6 +121,35 @@ export class KpiUserEvaluationController extends Controller { return new HttpSuccess(kpiUserEvaluation.id); } + /** + * API แก้ไขคนประเมิน (USER) + * + * @summary แก้ไขคนประเมิน (USER) + * + * @param {string} id Guid, *Id คนประเมิน (USER) + */ + @Put("check/{id}") + async updateKpiUserCheckEvaluation( + @Path() id: string, + @Body() requestBody: updateKpiUserCheckEvaluation, + @Request() request: { user: Record }, + ) { + const kpiUserEvaluation = await this.kpiUserEvalutionRepository.findOne({ + where: { id: id }, + }); + if (!kpiUserEvaluation) { + throw new HttpError( + HttpStatusCode.NOT_FOUND, + "ไม่พบข้อมูลรายการประเมินผลการปฏิบัติราชการระดับบุคคลนี้", + ); + } + kpiUserEvaluation.lastUpdateUserId = request.user.sub; + kpiUserEvaluation.lastUpdateFullName = request.user.name; + Object.assign(kpiUserEvaluation, requestBody); + await this.kpiUserEvalutionRepository.save(kpiUserEvaluation); + return new HttpSuccess(kpiUserEvaluation.id); + } + /** * API แก้ไขรายการประเมินผลการปฏิบัติราชการระดับบุคคล (USER) * @@ -136,7 +166,7 @@ export class KpiUserEvaluationController extends Controller { const kpiUserEvaluation = await this.kpiUserEvalutionRepository.findOne({ where: { id: id }, }); - if (!KpiUserEvaluation) { + if (!kpiUserEvaluation) { throw new HttpError( HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลรายการประเมินผลการปฏิบัติราชการระดับบุคคลนี้", @@ -153,15 +183,13 @@ export class KpiUserEvaluationController extends Controller { ); } - if (kpiUserEvaluation) { - // kpiUserEvaluation.evaluationStatus = requestBody.evaluationStatus - // kpiUserEvaluation.evaluationResults = requestBody.evaluationResults - kpiUserEvaluation.lastUpdateUserId = request.user.sub; - kpiUserEvaluation.lastUpdateFullName = request.user.name; - this.kpiUserEvalutionRepository.merge(kpiUserEvaluation, requestBody); - await this.kpiUserEvalutionRepository.save(kpiUserEvaluation); - return new HttpSuccess(kpiUserEvaluation.id); - } + // kpiUserEvaluation.evaluationStatus = requestBody.evaluationStatus + // kpiUserEvaluation.evaluationResults = requestBody.evaluationResults + kpiUserEvaluation.lastUpdateUserId = request.user.sub; + kpiUserEvaluation.lastUpdateFullName = request.user.name; + this.kpiUserEvalutionRepository.merge(kpiUserEvaluation, requestBody); + await this.kpiUserEvalutionRepository.save(kpiUserEvaluation); + return new HttpSuccess(kpiUserEvaluation.id); } /** @@ -173,7 +201,7 @@ export class KpiUserEvaluationController extends Controller { */ @Get("{id}") async GetKpiUserEvaluationById(@Path() id: string) { - const KpiUserEvaluation = await this.kpiUserEvalutionRepository.findOne({ + const kpiUserEvaluation = await this.kpiUserEvalutionRepository.findOne({ where: { id: id }, select: [ "id", @@ -187,13 +215,13 @@ export class KpiUserEvaluationController extends Controller { "createdAt", ], }); - if (!KpiUserEvaluation) { + if (!kpiUserEvaluation) { throw new HttpError( HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลรายการประเมินผลการปฏิบัติราชการระดับบุคคลนี้", ); } - return new HttpSuccess(KpiUserEvaluation); + return new HttpSuccess(kpiUserEvaluation); } /** @@ -242,16 +270,16 @@ export class KpiUserEvaluationController extends Controller { */ @Delete("{id}") async deleteKpiUserEvaluation(@Path() id: string) { - const KpiUserEvaluation = await this.kpiUserEvalutionRepository.findOne({ + const kpiUserEvaluation = await this.kpiUserEvalutionRepository.findOne({ where: { id: id }, }); - if (!KpiUserEvaluation) { + if (!kpiUserEvaluation) { throw new HttpError( HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลการประเมินผลการปฏิบัติราชการระดับบุคคลนี้", ); } - await this.kpiUserEvalutionRepository.remove(KpiUserEvaluation); + await this.kpiUserEvalutionRepository.remove(kpiUserEvaluation); return new HttpSuccess(); } } diff --git a/src/controllers/KpiUserPlannedController.ts b/src/controllers/KpiUserPlannedController.ts index 35bd8db..a9bea51 100644 --- a/src/controllers/KpiUserPlannedController.ts +++ b/src/controllers/KpiUserPlannedController.ts @@ -74,9 +74,12 @@ export class KpiUserPlannedController extends Controller { kpiUserEvaluationId: requestBody.kpiUserEvaluationId, kpiPlanId: requestBody.kpiPlanId, }, - }) + }); if (chk_indicator) { - throw new HttpError(HttpStatusCode.CONFLICT, "ไม่สามารถเพิ่มข้อมูลได้เนื่องจากข้อมูลตัวชี้วัดซ้ำ"); + throw new HttpError( + HttpStatusCode.CONFLICT, + "ไม่สามารถเพิ่มข้อมูลได้เนื่องจากข้อมูลตัวชี้วัดซ้ำ", + ); } const kpiUserPlanned = Object.assign(new KpiUserPlanned(), requestBody); @@ -105,21 +108,23 @@ export class KpiUserPlannedController extends Controller { @Body() requestBody: UpdateKpiUserPlanned, @Request() request: { user: Record }, ) { - const kpiUserPlanned = await this.kpiUserPlannedRepository.findOne({ where: { id } }); if (!kpiUserPlanned) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลงานตามแผนปฏิบัติราชการประจำปีนี้"); } - + const chk_indicator = await this.kpiUserPlannedRepository.findOne({ where: { id: Not(id), kpiUserEvaluationId: requestBody.kpiUserEvaluationId, kpiPlanId: requestBody.kpiPlanId, }, - }) + }); if (chk_indicator) { - throw new HttpError(HttpStatusCode.CONFLICT, "ไม่สามารถเพิ่มข้อมูลได้เนื่องจากข้อมูลตัวชี้วัดซ้ำ"); + throw new HttpError( + HttpStatusCode.CONFLICT, + "ไม่สามารถเพิ่มข้อมูลได้เนื่องจากข้อมูลตัวชี้วัดซ้ำ", + ); } kpiUserPlanned.lastUpdateUserId = request.user.sub; diff --git a/src/controllers/KpiUserRoleController.ts b/src/controllers/KpiUserRoleController.ts index 905d129..c0cb331 100644 --- a/src/controllers/KpiUserRoleController.ts +++ b/src/controllers/KpiUserRoleController.ts @@ -76,15 +76,18 @@ export class KpiUserRoleController extends Controller { if (!kpiUserRole) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล"); } - + const chk_indicator = await this.kpiUserRoleRepository.findOne({ where: { kpiUserEvaluationId: requestBody.kpiUserEvaluationId, kpiRoleId: requestBody.kpiRoleId, }, - }) + }); if (chk_indicator) { - throw new HttpError(HttpStatusCode.CONFLICT, "ไม่สามารถเพิ่มข้อมูลได้เนื่องจากข้อมูลตัวชี้วัดซ้ำ"); + throw new HttpError( + HttpStatusCode.CONFLICT, + "ไม่สามารถเพิ่มข้อมูลได้เนื่องจากข้อมูลตัวชี้วัดซ้ำ", + ); } kpiUserRole.createdUserId = request.user.sub; @@ -128,16 +131,19 @@ export class KpiUserRoleController extends Controller { "ไม่พบข้อมูลแบบประเมินตามหน้าที่ความรับผิดชอบหลัก", ); } - + const chk_indicator = await this.kpiUserRoleRepository.findOne({ where: { id: Not(id), kpiUserEvaluationId: requestBody.kpiUserEvaluationId, kpiRoleId: requestBody.kpiRoleId, }, - }) + }); if (chk_indicator) { - throw new HttpError(HttpStatusCode.CONFLICT, "ไม่สามารถเพิ่มข้อมูลได้เนื่องจากข้อมูลตัวชี้วัดซ้ำ"); + throw new HttpError( + HttpStatusCode.CONFLICT, + "ไม่สามารถเพิ่มข้อมูลได้เนื่องจากข้อมูลตัวชี้วัดซ้ำ", + ); } kpiUserRole.lastUpdateUserId = request.user.sub; diff --git a/src/controllers/KpiUserSpecialController.ts b/src/controllers/KpiUserSpecialController.ts index a347cb9..07915f7 100644 --- a/src/controllers/KpiUserSpecialController.ts +++ b/src/controllers/KpiUserSpecialController.ts @@ -63,17 +63,21 @@ export class KpiUserSpecialController extends Controller { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล"); } - const chk_indicator = await this.kpiUserSpecialRepository.findOne({ where: { kpiUserEvaluationId: requestBody.kpiUserEvaluationId, }, - }) - if (chk_indicator && chk_indicator.including == requestBody.including || chk_indicator && chk_indicator.includingName == requestBody.includingName) { - throw new HttpError(HttpStatusCode.CONFLICT, "ไม่สามารถเพิ่มข้อมูลได้เนื่องจากข้อมูลตัวชี้วัดซ้ำ"); + }); + if ( + (chk_indicator && chk_indicator.including == requestBody.including) || + (chk_indicator && chk_indicator.includingName == requestBody.includingName) + ) { + throw new HttpError( + HttpStatusCode.CONFLICT, + "ไม่สามารถเพิ่มข้อมูลได้เนื่องจากข้อมูลตัวชี้วัดซ้ำ", + ); } - kpiUserSpecial.createdUserId = request.user.sub; kpiUserSpecial.createdFullName = request.user.name; kpiUserSpecial.lastUpdateUserId = request.user.sub; @@ -111,9 +115,15 @@ export class KpiUserSpecialController extends Controller { id: Not(id), kpiUserEvaluationId: requestBody.kpiUserEvaluationId, }, - }) - if (chk_indicator && chk_indicator.including == requestBody.including || chk_indicator && chk_indicator.includingName == requestBody.includingName) { - throw new HttpError(HttpStatusCode.CONFLICT, "ไม่สามารถเพิ่มข้อมูลได้เนื่องจากข้อมูลตัวชี้วัดซ้ำ"); + }); + if ( + (chk_indicator && chk_indicator.including == requestBody.including) || + (chk_indicator && chk_indicator.includingName == requestBody.includingName) + ) { + throw new HttpError( + HttpStatusCode.CONFLICT, + "ไม่สามารถเพิ่มข้อมูลได้เนื่องจากข้อมูลตัวชี้วัดซ้ำ", + ); } kpiUserSpecial.lastUpdateUserId = request.user.sub; diff --git a/src/entities/kpiUserEvaluation.ts b/src/entities/kpiUserEvaluation.ts index 05ac3c1..d964c34 100644 --- a/src/entities/kpiUserEvaluation.ts +++ b/src/entities/kpiUserEvaluation.ts @@ -47,11 +47,36 @@ export class KpiUserEvaluation extends EntityBase { }) profileId: string; + @Column({ + nullable: true, + length: 40, + comment: "ไอดีผู้ประเมิน", + default: null, + }) + evaluatorId: string; + + @Column({ + nullable: true, + length: 40, + comment: "ไอดีผู้บังคับบัญชาเหนือขึ้นไป", + default: null, + }) + commanderId: string; + + @Column({ + nullable: true, + length: 40, + comment: "ไอดีผู้บังคับบัญชาเหนือขึ้นไปอีกชั้นหนึ่ง", + default: null, + }) + commanderHighId: string; + @Column({ // "สถานะการประเมินผล ดังนี้ PENDING = รอดำเนินการ, INPROGRESS = กําลังดำเนินการ, DONE = ประเมินเสร็จสิ้น", nullable: true, length: 40, - comment: "สถานะการประเมินผล ดังนี้ PENDING = รอดำเนินการ, INPROGRESS = กําลังดำเนินการ, DONE = ประเมินเสร็จสิ้น", + comment: + "สถานะการประเมินผล ดังนี้ PENDING = รอดำเนินการ, INPROGRESS = กําลังดำเนินการ, DONE = ประเมินเสร็จสิ้น", default: null, }) evaluationStatus: string; @@ -60,7 +85,8 @@ export class KpiUserEvaluation extends EntityBase { // "ผลการประเมิน ดังนี้ PENDING = รอดำเนินการ, PASSED = ผ่านการประเมิน, NOTPASSED = ไม่ผ่านการประเมิน", nullable: true, length: 40, - comment: "ผลการประเมิน ดังนี้ PENDING = รอดำเนินการ, PASSED = ผ่านการประเมิน, NOTPASSED = ไม่ผ่านการประเมิน", + comment: + "ผลการประเมิน ดังนี้ PENDING = รอดำเนินการ, PASSED = ผ่านการประเมิน, NOTPASSED = ไม่ผ่านการประเมิน", default: null, }) evaluationResults: string; @@ -93,6 +119,12 @@ export class createKpiUserEvaluation { kpiPeriodId: string; @Column() profileId: string; + @Column() + evaluatorId: string | null; + @Column() + commanderId: string | null; + @Column() + commanderHighId: string | null; } export class updateKpiUserEvaluation { @@ -107,3 +139,12 @@ export class updateKpiUserEvaluation { @Column() profileId: string; } + +export class updateKpiUserCheckEvaluation { + @Column() + evaluatorId: string | null; + @Column() + commanderId: string | null; + @Column() + commanderHighId: string | null; +} diff --git a/src/migration/1714111345274-update_table_kpiUserEvalution_add_evaluatorId.ts b/src/migration/1714111345274-update_table_kpiUserEvalution_add_evaluatorId.ts new file mode 100644 index 0000000..c049425 --- /dev/null +++ b/src/migration/1714111345274-update_table_kpiUserEvalution_add_evaluatorId.ts @@ -0,0 +1,18 @@ +import { MigrationInterface, QueryRunner } from "typeorm"; + +export class UpdateTableKpiUserEvalutionAddEvaluatorId1714111345274 implements MigrationInterface { + name = 'UpdateTableKpiUserEvalutionAddEvaluatorId1714111345274' + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`kpiUserEvaluation\` ADD \`evaluatorId\` varchar(40) NULL COMMENT 'ไอดีผู้ประเมิน'`); + await queryRunner.query(`ALTER TABLE \`kpiUserEvaluation\` ADD \`commanderId\` varchar(40) NULL COMMENT 'ไอดีผู้บังคับบัญชาเหนือขึ้นไป'`); + await queryRunner.query(`ALTER TABLE \`kpiUserEvaluation\` ADD \`commanderHighId\` varchar(40) NULL COMMENT 'ไอดีผู้บังคับบัญชาเหนือขึ้นไปอีกชั้นหนึ่ง'`); + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`kpiUserEvaluation\` DROP COLUMN \`commanderHighId\``); + await queryRunner.query(`ALTER TABLE \`kpiUserEvaluation\` DROP COLUMN \`commanderId\``); + await queryRunner.query(`ALTER TABLE \`kpiUserEvaluation\` DROP COLUMN \`evaluatorId\``); + } + +}