diff --git a/src/controllers/KpiRoleController.ts b/src/controllers/KpiRoleController.ts index 7908ec8..5191671 100644 --- a/src/controllers/KpiRoleController.ts +++ b/src/controllers/KpiRoleController.ts @@ -231,7 +231,9 @@ export class kpiRoleController extends Controller { const kpiPeriod = await this.kpiPeriodRepository .createQueryBuilder("kpiPeriod") .where("kpiPeriod.year = :year", { year: requestBody.year }) - .andWhere("kpiPeriod.durationKPI = :durationKPI", { durationKPI: requestBody.period }) + .andWhere(requestBody.period ? "kpiPeriod.durationKPI = :durationKPI" : "1=1", { + durationKPI: requestBody.period, + }) .getOne(); if (!kpiPeriod) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลตัวชี้วัดตามตำแหน่งนี้");