From d2cb9870495a4b7d79c806df88b7934275001da3 Mon Sep 17 00:00:00 2001 From: Kittapath Date: Thu, 9 May 2024 10:23:46 +0700 Subject: [PATCH 1/3] no message --- src/entities/kpiUserEvaluation.ts | 6 ++++-- ..._kpiUserEvaluation_add_evaluationReqEdit.ts | 18 ++++++++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) create mode 100644 src/migration/1715224977872-update_table_kpiUserEvaluation_add_evaluationReqEdit.ts diff --git a/src/entities/kpiUserEvaluation.ts b/src/entities/kpiUserEvaluation.ts index 354359e..0754186 100644 --- a/src/entities/kpiUserEvaluation.ts +++ b/src/entities/kpiUserEvaluation.ts @@ -85,10 +85,12 @@ export class KpiUserEvaluation extends EntityBase { evaluationResults: string; @Column({ + nullable: true, + length: 40, comment: "คำขอแก้ไข", - default: false, + default: null, }) - isReqEdit: boolean; + evaluationReqEdit: string; @Column({ type: "double", diff --git a/src/migration/1715224977872-update_table_kpiUserEvaluation_add_evaluationReqEdit.ts b/src/migration/1715224977872-update_table_kpiUserEvaluation_add_evaluationReqEdit.ts new file mode 100644 index 0000000..7e0c5a9 --- /dev/null +++ b/src/migration/1715224977872-update_table_kpiUserEvaluation_add_evaluationReqEdit.ts @@ -0,0 +1,18 @@ +import { MigrationInterface, QueryRunner } from "typeorm"; + +export class UpdateTableKpiUserEvaluationAddEvaluationReqEdit1715224977872 implements MigrationInterface { + name = 'UpdateTableKpiUserEvaluationAddEvaluationReqEdit1715224977872' + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`kpiUserEvaluation\` CHANGE \`isReqEdit\` \`evaluationReqEdit\` tinyint NOT NULL COMMENT 'คำขอแก้ไข' DEFAULT '0'`); + await queryRunner.query(`ALTER TABLE \`kpiUserEvaluation\` DROP COLUMN \`evaluationReqEdit\``); + await queryRunner.query(`ALTER TABLE \`kpiUserEvaluation\` ADD \`evaluationReqEdit\` varchar(40) NULL COMMENT 'คำขอแก้ไข'`); + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`kpiUserEvaluation\` DROP COLUMN \`evaluationReqEdit\``); + await queryRunner.query(`ALTER TABLE \`kpiUserEvaluation\` ADD \`evaluationReqEdit\` tinyint NOT NULL COMMENT 'คำขอแก้ไข' DEFAULT '0'`); + await queryRunner.query(`ALTER TABLE \`kpiUserEvaluation\` CHANGE \`evaluationReqEdit\` \`isReqEdit\` tinyint NOT NULL COMMENT 'คำขอแก้ไข' DEFAULT '0'`); + } + +} From fecbce6f88a99fbb5464ebb16db5d5d10f6185f5 Mon Sep 17 00:00:00 2001 From: Kittapath Date: Thu, 9 May 2024 10:54:19 +0700 Subject: [PATCH 2/3] =?UTF-8?q?=E0=B8=84=E0=B9=89=E0=B8=99=E0=B8=AB?= =?UTF-8?q?=E0=B8=B2=20special?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/KpiSpecialController.ts | 99 ++++++++++++++----------- 1 file changed, 55 insertions(+), 44 deletions(-) diff --git a/src/controllers/KpiSpecialController.ts b/src/controllers/KpiSpecialController.ts index fffd3b6..6b1ae48 100644 --- a/src/controllers/KpiSpecialController.ts +++ b/src/controllers/KpiSpecialController.ts @@ -45,12 +45,12 @@ export class kpiSpecialController extends Controller { @Request() request: { user: Record }, ) { const chk_kpiSpecial = await this.kpiSpecialRepository.findOne({ - where: { + where: { including: String(requestBody.including), includingName: String(requestBody.includingName), }, }); - if(chk_kpiSpecial){ + if (chk_kpiSpecial) { throw new HttpError( HttpStatusCode.CONFLICT, "ไม่สามารถเพิ่มข้อมูลได้เนื่องจากข้อมูลตัวชี้วัดซ้ำ", @@ -88,13 +88,13 @@ export class kpiSpecialController extends Controller { } const chk_kpiSpecial = await this.kpiSpecialRepository.findOne({ - where: { + where: { id: Not(id), including: String(requestBody.including), includingName: String(requestBody.includingName), }, }); - if(chk_kpiSpecial){ + if (chk_kpiSpecial) { throw new HttpError( HttpStatusCode.CONFLICT, "ไม่สามารถเพิ่มข้อมูลได้เนื่องจากข้อมูลตัวชี้วัดซ้ำ", @@ -114,7 +114,7 @@ export class kpiSpecialController extends Controller { @Get("{id}") async GetKpiSpecialById(@Path() id: string) { const KpiSpecial = await this.kpiSpecialRepository.findOne({ - where: { id: id } + where: { id: id }, }); if (!KpiSpecial) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลตัวชี้วัด Specialนี้"); @@ -151,50 +151,61 @@ export class kpiSpecialController extends Controller { * @param pageSize * @param keyword */ - @Get() + @Post("search") async listKpiSpecial( - @Query("page") page: number = 1, - @Query("pageSize") pageSize: number = 10, - @Query("keyword") keyword?: string, + @Body() + requestBody: { + page: number; + pageSize: number; + year?: string | null; + period?: string | null; + keyword?: string | null; + }, ) { - let whereClause: any = {}; - if (keyword !== undefined && keyword !== "") { - whereClause = { - where: [{ - including: Like(`%${keyword}%`), - includingName: Like(`%${keyword}%`), - }], + let condition: any = {}; + if (requestBody.keyword !== undefined && requestBody.keyword !== "") { + condition = { + where: [ + { + including: Like(`%${requestBody.keyword}%`), + includingName: Like(`%${requestBody.keyword}%`), + }, + ], }; } - const [kpiSpecial, total] = await this.kpiSpecialRepository.findAndCount({ - ...whereClause, - ...(keyword ? {} : { skip: (page - 1) * pageSize, take: pageSize }), - order: { createdAt: "ASC" }, - }); - const mapData = kpiSpecial.map((KpiSpecial) => ({ - id: KpiSpecial.id, - period: KpiSpecial.period, - year: KpiSpecial.year, - including: KpiSpecial.including, - includingName: KpiSpecial.includingName, - target: KpiSpecial.target, - unit: KpiSpecial.unit, - weight: KpiSpecial.weight, - point: KpiSpecial.point, - summary: KpiSpecial.summary, - documentInfoEvidence: KpiSpecial.documentInfoEvidence, - startDate: KpiSpecial.startDate, - endDate: KpiSpecial.endDate, - achievement1: KpiSpecial.achievement1, - achievement2: KpiSpecial.achievement2, - achievement3: KpiSpecial.achievement3, - achievement4: KpiSpecial.achievement4, - achievement5: KpiSpecial.achievement5, - meaning: KpiSpecial.meaning, - formula: KpiSpecial.formula, - })); - return new HttpSuccess({ data: mapData, total }); + const [kpiSpecial, total] = await AppDataSource.getRepository(KpiSpecial) + .createQueryBuilder("kpiSpecial") + .andWhere(condition) + .andWhere(requestBody.year ? "kpiSpecial.year LIKE :year" : "1=1", { + year: `%${requestBody.year}%`, + }) + .andWhere(requestBody.period ? "kpiSpecial.period LIKE :period" : "1=1", { + period: `%${requestBody.period}%`, + }) + .andWhere( + new Brackets((qb) => { + qb.orWhere("kpiSpecial.including LIKE :keyword", { + keyword: `%${requestBody.keyword}%`, + }).orWhere("kpiSpecial.includingName LIKE :keyword", { + keyword: `%${requestBody.keyword}%`, + }); + }), + ) + .select([ + "kpiSpecial.id", + "kpiSpecial.year", + "kpiSpecial.period", + "kpiSpecial.including", + "kpiSpecial.includingName", + "kpiSpecial.createdAt", + ]) + .orderBy("kpiSpecial.createdAt", "DESC") + .skip((requestBody.page - 1) * requestBody.pageSize) + .take(requestBody.pageSize) + .getManyAndCount(); + + return new HttpSuccess({ data: kpiSpecial, total }); } /** From fec583d13169859526b72fd440e8056ee1495978 Mon Sep 17 00:00:00 2001 From: Bright Date: Thu, 9 May 2024 10:59:49 +0700 Subject: [PATCH 3/3] =?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=20year,=20durationKPI?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../KpiUserEvaluationController.ts | 44 +++++++++++-------- 1 file changed, 25 insertions(+), 19 deletions(-) diff --git a/src/controllers/KpiUserEvaluationController.ts b/src/controllers/KpiUserEvaluationController.ts index 3b2032b..7490744 100644 --- a/src/controllers/KpiUserEvaluationController.ts +++ b/src/controllers/KpiUserEvaluationController.ts @@ -240,25 +240,8 @@ export class KpiUserEvaluationController extends Controller { @Get("{id}") async GetKpiUserEvaluationById(@Path() id: string) { const kpiUserEvaluation = await this.kpiUserEvalutionRepository.findOne({ + relations:["kpiPeriod"], where: { id: id }, - select: [ - "id", - "profileId", - "prefix", - "firstName", - "lastName", - "kpiPeriodId", - "evaluationStatus", - "evaluationResults", - "createdAt", - "evaluatorId", - "commanderId", - "commanderHighId", - "plannedPoint", - "rolePoint", - "specialPoint", - "capacityPoint", - ], }); if (!kpiUserEvaluation) { throw new HttpError( @@ -266,7 +249,27 @@ export class KpiUserEvaluationController extends Controller { "ไม่พบข้อมูลรายการประเมินผลการปฏิบัติราชการระดับบุคคลนี้", ); } - return new HttpSuccess(kpiUserEvaluation); + const mapData = { + id: kpiUserEvaluation.id, + profileId: kpiUserEvaluation.profileId, + prefix: kpiUserEvaluation.prefix, + firstName: kpiUserEvaluation.firstName, + lastName: kpiUserEvaluation.lastName, + evaluationStatus: kpiUserEvaluation.evaluationStatus, + evaluationResults: kpiUserEvaluation.evaluationResults, + createdAt: kpiUserEvaluation.createdAt, + evaluatorId: kpiUserEvaluation.evaluatorId, + commanderId: kpiUserEvaluation.commanderId, + commanderHighId: kpiUserEvaluation.commanderHighId, + plannedPoint: kpiUserEvaluation.plannedPoint, + rolePoint: kpiUserEvaluation.rolePoint, + specialPoint: kpiUserEvaluation.specialPoint, + capacityPoint: kpiUserEvaluation.capacityPoint, + kpiPeriodId: kpiUserEvaluation.kpiPeriodId, + year: kpiUserEvaluation.kpiPeriod == null ? null : kpiUserEvaluation.kpiPeriod.year, + durationKPI: kpiUserEvaluation.kpiPeriod == null ? null : kpiUserEvaluation.kpiPeriod.durationKPI, + } + return new HttpSuccess(mapData); } /** @@ -286,6 +289,7 @@ export class KpiUserEvaluationController extends Controller { ) { const [kpiUserEvaluation, total] = await AppDataSource.getRepository(KpiUserEvaluation) .createQueryBuilder("kpiUserEvaluation") + .leftJoinAndSelect("kpiUserEvaluation.kpiPeriod", "kpiPeriod") .andWhere(kpiPeriodId ? "kpiPeriodId LIKE :kpiPeriodId" : "1=1", { kpiPeriodId: kpiPeriodId, }) @@ -318,6 +322,8 @@ export class KpiUserEvaluationController extends Controller { rolePoint: item.rolePoint, specialPoint: item.specialPoint, capacityPoint: item.capacityPoint, + year: item.kpiPeriod ? item.kpiPeriod.year : null, + durationKPI: item.kpiPeriod ? item.kpiPeriod.durationKPI : null, })); return new HttpSuccess({ data: mapData, total }); }