diff --git a/src/controllers/KpiPlanController.ts b/src/controllers/KpiPlanController.ts index e3ee479..22a8134 100644 --- a/src/controllers/KpiPlanController.ts +++ b/src/controllers/KpiPlanController.ts @@ -445,51 +445,30 @@ export class kpiPlanController extends Controller { } parameters.nodeId = `%${requestBody.nodeId}%`; } - // if (requestBody.year && requestBody.period && requestBody.isNull === true) { - // condition += ` AND (kpiPlan.year LIKE :year OR kpiPlan.year IS NULL) AND (kpiPlan.period LIKE :period OR kpiPlan.period IS NULL)`; - // parameters.year = `%${requestBody.year}%`; - // parameters.period = `%${requestBody.period}%`; - // } const [kpiPlan, total] = await AppDataSource.getRepository(KpiPlan) .createQueryBuilder("kpiPlan") .leftJoinAndSelect("kpiPlan.kpiPeriod", "kpiPeriod") .andWhere(condition, parameters) - // .andWhere( - // requestBody.year && requestBody.period - // ? "kpiPlan.year LIKE :year AND kpiPlan.period LIKE :period" - // : "1=1", - // { - // year: `%${requestBody.year}%`, - // period: `%${requestBody.period}%`, - // }, - // ) - .andWhere( - requestBody.year - ? "kpiPlan.year LIKE :year" - : "1=1", - { - year: `%${requestBody.year}%`, - }, - ) - .andWhere( - requestBody.period - ? "kpiPlan.period LIKE :period" - : "1=1", - { - period: `%${requestBody.period}%`, - }, - ) + .andWhere(requestBody.year ? "kpiPlan.year LIKE :year" : "1=1", { + year: `%${requestBody.year}%`, + }) + .andWhere(requestBody.period ? "kpiPlan.period LIKE :period" : "1=1", { + period: `%${requestBody.period}%`, + }) .andWhere( new Brackets((qb) => { qb.orWhere("kpiPlan.including LIKE :keyword", { keyword: `%${requestBody.keyword}%`, - }).orWhere("kpiPlan.includingName LIKE :keyword", { - keyword: `%${requestBody.keyword}%`, - }).orWhere("kpiPlan.year LIKE :keyword",{ - keyword: `%${requestBody.keyword}%` - }).orWhere("kpiPlan.period LIKE :keyword",{ - keyword: `%${requestBody.keyword}%` - }); + }) + .orWhere("kpiPlan.includingName LIKE :keyword", { + keyword: `%${requestBody.keyword}%`, + }) + .orWhere("kpiPlan.year LIKE :keyword", { + keyword: `%${requestBody.keyword}%`, + }) + .orWhere("kpiPlan.period LIKE :keyword", { + keyword: `%${requestBody.keyword}%`, + }); }), ) .select([ @@ -594,21 +573,21 @@ export class kpiPlanController extends Controller { return new HttpSuccess(); } - /** + /** * API ประวัดิตัวชี้วัดิตามแผน * @param id Guid, *Id ประวัดิตัวชี้วัดตามแผน */ - @Get("history/{id}") - async GetHistory(@Path() id: string) { - const kpiPlanHistory = await this.kpiPlanHistoryRepository.find({ - where: { kpiPlanId: id }, - order:{ - createdAt: "ASC" - } - }); - if (!kpiPlanHistory) { - throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลประวัดิตัวชี้วัดตามแผนนี้"); - } - return new HttpSuccess(kpiPlanHistory); + @Get("history/{id}") + async GetHistory(@Path() id: string) { + const kpiPlanHistory = await this.kpiPlanHistoryRepository.find({ + where: { kpiPlanId: id }, + order: { + createdAt: "ASC", + }, + }); + if (!kpiPlanHistory) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลประวัดิตัวชี้วัดตามแผนนี้"); } + return new HttpSuccess(kpiPlanHistory); + } } diff --git a/src/controllers/KpiUserEvaluationController.ts b/src/controllers/KpiUserEvaluationController.ts index c429776..b070790 100644 --- a/src/controllers/KpiUserEvaluationController.ts +++ b/src/controllers/KpiUserEvaluationController.ts @@ -179,6 +179,79 @@ export class KpiUserEvaluationController extends Controller { return new HttpSuccess({ data: mapData, total }); } + /** + * API + * + * @summary รายการประเมินผลการปฏิบัติราชการระดับบุคคลทั้งหมด + * + */ + @Post("list") + async listKpiListEvaluation( + @Request() request: { user: Record }, + @Body() + requestBody: { + page: number; + pageSize: number; + kpiPeriodId?: string; + keyword?: string; + status?: string | null; + results?: string | null; + reqedit?: string | null; + evaluating?: boolean | null; + }, + ) { + + const [kpiUserEvaluation, total] = await AppDataSource.getRepository(KpiUserEvaluation) + .createQueryBuilder("kpiUserEvaluation") + .andWhere(requestBody.kpiPeriodId ? "kpiPeriodId LIKE :kpiPeriodId" : "1=1", { + kpiPeriodId: requestBody.kpiPeriodId, + }) + .andWhere( + requestBody.results != null && requestBody.results != undefined + ? "evaluationResults LIKE :results" + : "1=1", + { + results: + requestBody.results == null || requestBody.results == undefined + ? null + : requestBody.results.trim().toUpperCase(), + }, + ) + .andWhere( + new Brackets((qb) => { + qb.orWhere("kpiUserEvaluation.prefix LIKE :keyword", { + keyword: `%${requestBody.keyword}%`, + }) + .orWhere("kpiUserEvaluation.firstName LIKE :keyword", { + keyword: `%${requestBody.keyword}%`, + }) + .orWhere("kpiUserEvaluation.lastName LIKE :keyword", { + keyword: `%${requestBody.keyword}%`, + }); + }), + ) + .orderBy("kpiUserEvaluation.createdAt", "ASC") + .skip((requestBody.page - 1) * requestBody.pageSize) + .take(requestBody.pageSize) + .getManyAndCount(); + + const mapData = kpiUserEvaluation.map((item) => ({ + id: item.id, + profileId: item.profileId, + prefix: item.prefix, + firstname: item.firstName, + lastname: item.lastName, + kpiPeriodId: item.kpiPeriodId, + evaluationStatus: item.evaluationStatus, + evaluationResults: item.evaluationResults, + createdAt: item.createdAt, + evaluatorId: item.evaluatorId, + commanderId: item.commanderId, + commanderHighId: item.commanderHighId, + })); + return new HttpSuccess({ data: mapData, total }); + } + /** * API สร้างรายการประเมินผลการปฏิบัติราชการระดับบุคคล (USER) * diff --git a/src/entities/kpiUserEvaluation.ts b/src/entities/kpiUserEvaluation.ts index 0c06610..b4918be 100644 --- a/src/entities/kpiUserEvaluation.ts +++ b/src/entities/kpiUserEvaluation.ts @@ -185,20 +185,20 @@ export class KpiUserEvaluation extends EntityBase { } export class createKpiUserEvaluation { - // @Column() - // prefix: string; - // @Column() - // firstName: string; - // @Column() - // lastName: string; - // @Column() - // position: string | null; - // @Column() - // posTypeName: string | null; - // @Column() - // posLevelName: string | null; - // @Column() - // posExecutiveName: string | null; + @Column() + prefix?: string | null; + @Column() + firstName?: string | null; + @Column() + lastName?: string | null; + @Column() + position?: string | null; + @Column() + posTypeName?: string | null; + @Column() + posLevelName?: string | null; + @Column() + posExecutiveName?: string | null; @Column() kpiPeriodId: string; @Column()