diff --git a/src/controllers/KpiCapacityController.ts b/src/controllers/KpiCapacityController.ts index 210983a..1f20c24 100644 --- a/src/controllers/KpiCapacityController.ts +++ b/src/controllers/KpiCapacityController.ts @@ -350,11 +350,7 @@ export class kpiCapacityController extends Controller { const [kpiCapacity, total] = await AppDataSource.getRepository(KpiCapacity) .createQueryBuilder("kpiCapacity") .leftJoinAndSelect("kpiCapacity.kpiCapacityDetails", "kpiCapacityDetail") - .andWhere( - keyword == undefined - ? "1=1" - : [{ name: Like(`%${keyword}%`) }, { description: Like(`%${keyword}%`) }], - ) + .andWhere(keyword == undefined ? "1=1" : [{ name: Like(`%${keyword}%`) }]) .andWhere(type == undefined ? "1=1" : { type: type }) .orderBy("kpiCapacity.createdAt", "ASC") .skip((page - 1) * pageSize) diff --git a/src/controllers/KpiGroupController.ts b/src/controllers/KpiGroupController.ts index 5e03bd6..a0b82e1 100644 --- a/src/controllers/KpiGroupController.ts +++ b/src/controllers/KpiGroupController.ts @@ -18,12 +18,14 @@ import { import { AppDataSource } from "../database/data-source"; import HttpSuccess from "../interfaces/http-success"; import HttpError from "../interfaces/http-error"; -import { Like, Not } from "typeorm"; +import { In, Like, Not } from "typeorm"; import HttpStatusCode from "../interfaces/http-status"; import { KpiGroup, createKpiGroup, updateKpiGroup } from "../entities/kpiGroup"; import permission from "../interfaces/permission"; import { RequestWithUser } from "../middlewares/user"; import { setLogDataDiff } from "../interfaces/utils"; +import { KpiLink } from "../entities/kpiLink"; +import { Position } from "../entities/position"; @Route("api/v1/kpi/group") @Tags("kpiGroup") @@ -35,6 +37,8 @@ import { setLogDataDiff } from "../interfaces/utils"; @SuccessResponse(HttpStatusCode.OK, "สำเร็จ") export class kpiGroupController extends Controller { private kpiGroupRepository = AppDataSource.getRepository(KpiGroup); + private kpiLinkRepository = AppDataSource.getRepository(KpiLink); + private positionRepository = AppDataSource.getRepository(Position); /** * API สร้างกลุ่มงาน @@ -192,7 +196,11 @@ export class kpiGroupController extends Controller { if (!kpiGroup) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลกลุ่มงานนี้"); } - + const kpiLink = await this.kpiLinkRepository.find({ + where: { kpiGroupId: id }, + }); + await this.positionRepository.delete({ kpiLinkId: In(kpiLink.map((x) => x.id)) }); + await this.kpiLinkRepository.remove(kpiLink, { data: request }); await this.kpiGroupRepository.remove(kpiGroup, { data: request }); return new HttpSuccess(); } diff --git a/src/controllers/KpiRoleController.ts b/src/controllers/KpiRoleController.ts index be3fb42..6a80ee0 100644 --- a/src/controllers/KpiRoleController.ts +++ b/src/controllers/KpiRoleController.ts @@ -47,17 +47,16 @@ export class kpiRoleController extends Controller { async createKpiRole(@Body() requestBody: createKpiRole, @Request() request: RequestWithUser) { await new permission().PermissionCreate(request, "SYS_EVA_INDICATOR"); const kpiRole = Object.assign(new KpiRole(), requestBody); - if (requestBody.year != null && requestBody.period != null) { + if (requestBody.year != null && requestBody.period != null && requestBody.period != "") { const kpiPeriod = await this.kpiPeriodRepository .createQueryBuilder("kpiPeriod") .where("kpiPeriod.year = :year", { year: requestBody.year }) .andWhere("kpiPeriod.durationKPI = :durationKPI", { durationKPI: requestBody.period }) .getOne(); if (!kpiPeriod) { - // throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลตัวชี้วัดตามตำแหน่งนี้"); throw new HttpError( HttpStatusCode.NOT_FOUND, - "ไม่พบข้อมูลรอบการประเมินนี้ในปีงบประมาณ " + requestBody.year, + "ไม่พบข้อมูลรอบการประเมินนี้ในปีงบประมาณ " + (requestBody.year + 543), ); } }