diff --git a/src/controllers/KpiUserEvaluationController.ts b/src/controllers/KpiUserEvaluationController.ts index 460a456..374b68c 100644 --- a/src/controllers/KpiUserEvaluationController.ts +++ b/src/controllers/KpiUserEvaluationController.ts @@ -53,16 +53,39 @@ export class KpiUserEvaluationController extends Controller { */ @Get("admin") async listKpiAdminEvaluation( + @Request() request: { user: Record }, @Query("page") page: number = 1, @Query("pageSize") pageSize: number = 10, @Query("kpiPeriodId") kpiPeriodId?: string, @Query("keyword") keyword?: string, ) { + let profileId: any = null; + await new CallAPI() + .GetData(request, "org/profile/keycloak/position") + .then((x) => { + profileId = x.profileId; + }) + .catch((x) => { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลในทะเบียนประวัติ"); + }); const [kpiUserEvaluation, total] = await AppDataSource.getRepository(KpiUserEvaluation) .createQueryBuilder("kpiUserEvaluation") .andWhere(kpiPeriodId ? "kpiPeriodId LIKE :kpiPeriodId" : "1=1", { kpiPeriodId: kpiPeriodId, }) + .andWhere( + new Brackets((qb) => { + qb.orWhere("kpiUserEvaluation.evaluatorId LIKE :profileId", { + profileId: `%${profileId}%`, + }) + .orWhere("kpiUserEvaluation.commanderId LIKE :profileId", { + profileId: `%${profileId}%`, + }) + .orWhere("kpiUserEvaluation.commanderHighId LIKE :profileId", { + profileId: `%${profileId}%`, + }); + }), + ) .andWhere( new Brackets((qb) => { qb.orWhere("kpiUserEvaluation.prefix LIKE :keyword", { keyword: `%${keyword}%` })